/// <summary> /// Check that the given declaration has an xml documentation comment. /// </summary> /// <param name="declaration">The declaration to check</param> /// <param name="docNode">The documentation node to check.</param> /// <param name="consumer">The list of highlights (errors) that were found - add to this any new issues</param> public void CheckMemberHasComment(IClassMemberDeclaration declaration, XmlNode docNode, DefaultHighlightingConsumer consumer) { // Only process this one if its range is invalid. //if (!_daemonProcess.IsRangeInvalidated(declaration.GetDocumentRange())) return; // Check if the parent doco is null if (_xmlDocumentationSettings.SuppressIfBaseHasComment) { if (docNode == null && declaration.GetXMLDoc(true) != null) { return; } } if (docNode != null) { return; } Match[] publicMembers = new[] { new Match( Declaration.Any, AccessLevels.Public | AccessLevels.Protected | AccessLevels.ProtectedInternal) }; Match[] internalMembers = new[] { new Match(Declaration.Any, AccessLevels.Internal) }; Match[] privateMembers = new[] { new Match(Declaration.Any, AccessLevels.Private) }; Match match = ComplexMatchEvaluator.IsMatch(declaration, privateMembers, null, true); IFile containingFile = declaration.GetContainingFile(); if (match != null) { consumer.AddHighlighting( new PrivateMemberMissingXmlCommentHighlighting(declaration, match), containingFile.TranslateRangeForHighlighting(declaration.GetNameRange())); return; } match = ComplexMatchEvaluator.IsMatch(declaration, internalMembers, null, true); if (match != null) { consumer.AddHighlighting( new InternalMemberMissingXmlCommentHighlighting(declaration, match), containingFile.TranslateRangeForHighlighting(declaration.GetNameRange())); return; } match = ComplexMatchEvaluator.IsMatch(declaration, publicMembers, null, true); if (match != null) { consumer.AddHighlighting( new PublicMemberMissingXmlCommentHighlighting(declaration, match), containingFile.TranslateRangeForHighlighting(declaration.GetNameRange())); } }
public CanBeSurroundedWithMetatagsHighlight( string word, DocumentRange highlightingRange, IClassMemberDeclaration declaration, ISolution solution) { _range = highlightingRange; _solution = solution; _declaration = declaration; _word = word; }
private bool isStaticMatch(IDeclaration declaration) { if (IsStatic == FuzzyBool.Maybe) { return(true); } IClassMemberDeclaration decl = declaration as IClassMemberDeclaration; return(decl != null && (IsStatic == FuzzyBool.True && decl.IsStatic || IsStatic == FuzzyBool.False && !decl.IsStatic)); }
private bool isReadOnlyMatch(IDeclaration declaration) { if (IsReadOnly == FuzzyBool.Maybe) { return(true); } IClassMemberDeclaration decl = declaration as IClassMemberDeclaration; return(decl != null && (IsReadOnly == FuzzyBool.True && decl.IsReadonly || IsReadOnly == FuzzyBool.False && !decl.IsReadonly)); }
protected override void AppendTooltip(CycleInStructLayoutError highlighting, CSharpColorizer colorizer) { IClassMemberDeclaration declaration = highlighting.Declaration; ITypeMember declaredElement = declaration.DeclaredElement; if (declaredElement == null) { return; } colorizer.AppendPlainText(declaredElement.GetElementKindString(false, false, false, false, false).Capitalize()); colorizer.AppendPlainText(" '"); colorizer.AppendDeclaredElement(declaredElement, EmptySubstitution.INSTANCE, PresenterOptions.NameOnly, declaration); colorizer.AppendPlainText("' of type '"); colorizer.AppendExpressionType(highlighting.Type, false, PresenterOptions.NameOnly); colorizer.AppendPlainText("' causes a cycle in the struct layout"); }
private void CheckMember( IClassMemberDeclaration declaration, IHighlightingConsumer highlightingConsumer, CommentAnalyzer commentAnalyzer, IdentifierSpellCheckAnalyzer identifierAnalyzer) { if (declaration is IConstructorDeclaration && declaration.IsStatic) { // TODO: probably need to put this somewhere in settings. //Static constructors have no visibility so not clear how to check them. return; } // Documentation doesn't work properly on multiple declarations (as of R# 6.1) so see if we can get it from the parent XmlNode docNode = null; IDocCommentBlockNode commentBlock; var multipleDeclarationMember = declaration as IMultipleDeclarationMember; if (multipleDeclarationMember != null) { // get the parent IMultipleDeclaration multipleDeclaration = multipleDeclarationMember.MultipleDeclaration; // Now ask for the actual comment block commentBlock = SharedImplUtil.GetDocCommentBlockNode(multipleDeclaration); if (commentBlock != null) { docNode = commentBlock.GetXML(null); } } else { commentBlock = SharedImplUtil.GetDocCommentBlockNode(declaration); docNode = declaration.GetXMLDoc(false); } commentAnalyzer.CheckMemberHasComment(declaration, docNode, highlightingConsumer); commentAnalyzer.CheckCommentSpelling(declaration, commentBlock, highlightingConsumer, true); identifierAnalyzer.CheckMemberSpelling(declaration, highlightingConsumer, true); }
public void CheckCommentSpelling( IClassMemberDeclaration decl, IDocCommentBlockNode docNode, IHighlightingConsumer highlightingConsumer, bool spellCheck) { if (docNode == null) { return; } IFile file = decl.GetContainingFile(); if (file == null) { return; } foreach (Range wordRange in this.GetWordsFromXmlComment(docNode)) { DocumentRange range = file.GetDocumentRange(wordRange.TreeTextRange); string word = wordRange.Word; if (decl.DeclaredName != word) { if ((IdentifierResolver.IsIdentifier(decl, _solution, word, _identifierSettings.IdentifierLookupScope) || IdentifierResolver.IsKeyword(decl, _solution, word)) && IdentifierResolver.AnalyzeForMetaTagging(word, _xmlDocumentationSettings.CompiledWordsToIgnoreForMetatagging)) { var highlighting = new CanBeSurroundedWithMetatagsHighlight(word, range, decl, _solution); highlightingConsumer.AddHighlighting(highlighting, range, file); } else if (spellCheck) { this.CheckWordSpelling(decl, wordRange, highlightingConsumer, range, file); } } } }
private void CheckWordSpelling( IClassMemberDeclaration decl, Range wordRange, IHighlightingConsumer highlightingConsumer, DocumentRange range, IFile file) { // If we dont have a spell checker then go no further if (this._xmlDocumentationSpellChecker == null) { return; } // First check the whole word range. if (!SpellCheckUtil.ShouldSpellCheck(wordRange.Word, _xmlDocumentationSettings.CompiledWordsToIgnore) || this._xmlDocumentationSpellChecker.TestWord(wordRange.Word, true)) { return; } // We are checking this word and the whole range doesn't spell anything so try breaking the word into bits. CamelHumpLexer camelHumpLexer = new CamelHumpLexer(wordRange.Word, 0, wordRange.Word.Length); foreach (LexerToken humpToken in camelHumpLexer) { if (SpellCheckUtil.ShouldSpellCheck(humpToken.Value, _xmlDocumentationSettings.CompiledWordsToIgnore) && !this._xmlDocumentationSpellChecker.TestWord(humpToken.Value, true)) { var highlighting = new WordIsNotInDictionaryHighlight(wordRange.Word, range, humpToken, _solution, this._xmlDocumentationSpellChecker, _settingsStore); highlightingConsumer.AddHighlighting(highlighting, range, file); break; } } }
public void RemoveClassMemberDeclaration(IClassMemberDeclaration param) { _classDeclaration.RemoveClassMemberDeclaration(param); }
public T ReplaceClassMemberDeclaration <T> (IClassMemberDeclaration oldDeclaration, T newDeclaration) where T : IClassMemberDeclaration { return(_classDeclaration.ReplaceClassMemberDeclaration(oldDeclaration, newDeclaration)); }
public T AddClassMemberDeclarationBefore <T> (T param, IClassMemberDeclaration anchor) where T : IClassMemberDeclaration { return(_classDeclaration.AddClassMemberDeclarationBefore(param, anchor)); }
public static bool IsMethod(this IClassMemberDeclaration member) { return(member is IMethodDeclaration); }
public static bool IsProperty(this IClassMemberDeclaration member) { return(member is IPropertyDeclaration); }
public static void SpellCheck(IDocument document, ITokenNode token, ISpellChecker spellChecker, ISolution solution, DefaultHighlightingConsumer consumer, IContextBoundSettingsStore settingsStore, StringSettings settings) { if (spellChecker == null) { return; } string buffer = unescape(token.GetText()); ILexer wordLexer = new WordLexer(buffer); wordLexer.Start(); while (wordLexer.TokenType != null) { string tokenText = wordLexer.GetCurrTokenText(); if (SpellCheckUtil.ShouldSpellCheck(tokenText, settings.CompiledWordsToIgnore) && !spellChecker.TestWord(tokenText, true)) { IClassMemberDeclaration containingElement = token.GetContainingNode <IClassMemberDeclaration>(false); if (containingElement == null || !IdentifierResolver.IsIdentifier(containingElement, solution, tokenText)) { CamelHumpLexer camelHumpLexer = new CamelHumpLexer(buffer, wordLexer.TokenStart, wordLexer.TokenEnd); foreach (LexerToken humpToken in camelHumpLexer) { if (SpellCheckUtil.ShouldSpellCheck(humpToken.Value, settings.CompiledWordsToIgnore) && !spellChecker.TestWord(humpToken.Value, true)) { //int start = token.GetTreeStartOffset().Offset + wordLexer.TokenStart; //int end = start + tokenText.Length; //TextRange range = new TextRange(start, end); //DocumentRange documentRange = new DocumentRange(document, range); DocumentRange documentRange = token.GetContainingFile().TranslateRangeForHighlighting(token.GetTreeTextRange()); documentRange = documentRange.ExtendLeft(-wordLexer.TokenStart); documentRange = documentRange.ExtendRight(-1 * (documentRange.GetText().Length - tokenText.Length)); TextRange textRange = new TextRange(humpToken.Start - wordLexer.TokenStart, humpToken.End - wordLexer.TokenStart); //string word = document.GetText(range); string word = documentRange.GetText(); consumer.AddHighlighting( new StringSpellCheckHighlighting( word, documentRange, humpToken.Value, textRange, solution, spellChecker, settingsStore), documentRange); break; } } } } wordLexer.Advance(); } }