/// <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 void Execute(Action <DaemonStageResult> commiter) { var consumer = new DefaultHighlightingConsumer(this, settingsStore); foreach (IFile psiFile in DaemonProcess.SourceFile.EnumeratePsiFiles()) { psiFile.ProcessChildren <ITypeDeclaration>(declaration => { if (declaration.DeclaredElement == null) // type is not (yet) declared { return; } RegistrationInfo registrationInfo = cachedComponentRegistrations.FirstOrDefault(c => c.Registration.IsSatisfiedBy(declaration.DeclaredElement)); if (registrationInfo != null) { consumer.AddHighlighting(new RegisteredByContainerHighlighting(registrationInfo), declaration.GetNameDocumentRange(), registrationInfo.GetRegistrationFile()); typeUsageManager.MarkTypeAsUsed(declaration); } }); } commiter(new DaemonStageResult(consumer.Highlightings)); }
public void Execute(Action <DaemonStageResult> commiter) { var consumer = new DefaultHighlightingConsumer(this, settingsStore); #if SDK70 foreach (IFile psiFile in DaemonProcess.SourceFile.EnumeratePsiFiles()) #else foreach (IFile psiFile in EnumeratePsiFiles()) #endif { IFile file = psiFile; psiFile.ProcessChildren <ITypeDeclaration>(declaration => { if (declaration.DeclaredElement == null) // type is not (yet) declared { return; } RegistrationInfo registrationInfo = patternManager.GetRegistrationsForFile(file.GetSourceFile()). FirstOrDefault(c => c.Registration.IsSatisfiedBy(declaration.DeclaredElement)); if (registrationInfo != null) { IPsiSourceFile psiSourceFile = registrationInfo.GetSourceFile(); consumer.AddHighlighting(new RegisteredByContainerHighlighting(registrationInfo), declaration.GetNameDocumentRange(), psiSourceFile.GetTheOnlyPsiFile(psiSourceFile.PrimaryPsiLanguage)); typeUsageManager.MarkTypeAsUsed(declaration); } }); } commiter(new DaemonStageResult(consumer.Highlightings)); }
public void Execute(Action<DaemonStageResult> commiter) { var consumer = new DefaultHighlightingConsumer(this, settingsStore); foreach (IFile psiFile in DaemonProcess.SourceFile.EnumeratePsiFiles()) { psiFile.ProcessChildren<ITypeDeclaration>(declaration => { if (declaration.DeclaredElement == null) // type is not (yet) declared { return; } RegistrationInfo registrationInfo = cachedComponentRegistrations.FirstOrDefault(c => c.Registration.IsSatisfiedBy(declaration.DeclaredElement)); if (registrationInfo != null) { consumer.AddHighlighting(new RegisteredByContainerHighlighting(registrationInfo), declaration.GetNameDocumentRange(), registrationInfo.GetRegistrationFile()); typeUsageManager.MarkTypeAsUsed(declaration); } }); } commiter(new DaemonStageResult(consumer.Highlightings)); }
public void Execute(Action <DaemonStageResult> action) { IPsiModule module = _file.GetPsiModule(); ResXSettings settings = _settingsStore.GetKey <ResXSettings>(SettingsOptimization.OptimizeDefault); IAttributesSet moduleAttributes = _file.GetSolution().GetPsiServices().Symbols.GetModuleAttributes(module); string defaultResXDic = "en-US"; IList <IAttributeInstance> attributes = moduleAttributes .GetAttributeInstances(new ClrTypeName(typeof(NeutralResourcesLanguageAttribute).FullName), false); if (attributes != null && attributes.Count > 0 && attributes[0].PositionParameter(0).ConstantValue.Value != null) { defaultResXDic = attributes[0].PositionParameter(0).ConstantValue.Value.ToString(); } #if RESHARPER20173 var consumer = new DefaultHighlightingConsumer(_daemonProcess.SourceFile); #else var consumer = new DefaultHighlightingConsumer(this, _settingsStore); #endif ISpellChecker checker = SpellCheckManager.GetSpellChecker(_settingsStore, _file, defaultResXDic); if (checker != null) { foreach (IXmlToken token in getStringsToCheck()) { WordLexer lexer = new WordLexer(token.GetText()); lexer.Start(); while (lexer.TokenType != null) { if (SpellCheckUtil.ShouldSpellCheck(lexer.TokenText, settings.CompiledWordsToIgnore) && !checker.TestWord(lexer.TokenText, false)) { DocumentRange docRange = token.GetDocumentRange(); TextRange textRange = new TextRange(docRange.TextRange.StartOffset + lexer.TokenStart, docRange.TextRange.StartOffset + lexer.TokenEnd); DocumentRange range = new DocumentRange(docRange.Document, textRange); ResXSpellHighlighting highlighting = new ResXSpellHighlighting(lexer.TokenText, _file, checker, range, _settingsStore); consumer.AddHighlighting(highlighting, range); } lexer.Advance(); } } } action(new DaemonStageResult(consumer.Highlightings)); }
public void Execute(Action <DaemonStageResult> committer) { MarkModulesAsUsed(collectUsagesStageProcess); var consumer = new DefaultHighlightingConsumer(this, settingsStore); var referenceProcessor = new RecursiveReferenceProcessor <IMvcReference>(reference => { InterruptableActivityCookie.CheckAndThrow(); IHighlighting highlighting; switch (reference.MvcKind) { case MvcKind.Area: highlighting = CheckArea(reference); break; case MvcKind.Controller: highlighting = CheckResolved(reference, _ => (IHighlighting) new MvcControllerHighlighting(_)); break; case MvcKind.Action: highlighting = CheckResolved(reference, _ => (IHighlighting) new MvcActionHighlighting(_)); break; case MvcKind.View: case MvcKind.PartialView: case MvcKind.Master: case MvcKind.DisplayTemplate: case MvcKind.EditorTemplate: case MvcKind.Template: highlighting = CheckResolved(reference, _ => (IHighlighting) new MvcViewHighlighting((IMvcViewReference)_)); break; default: highlighting = null; break; } if (highlighting == null) { return; } consumer.AddHighlighting(highlighting, GetMvcReferenceHighlightingRange(reference), reference.GetTreeNode().GetContainingFile()); }); foreach (IFile file in DaemonProcess.SourceFile.EnumerateDominantPsiFiles()) { file.ProcessDescendants(referenceProcessor); } committer(new DaemonStageResult(consumer.Highlightings)); }
private void ProcessFile(IFile psiFile, DefaultHighlightingConsumer consumer) { foreach (var declaration in psiFile.ThisAndDescendants <ITypeDeclaration>()) { if (declaration.DeclaredElement == null) // type is not (yet) declared { return; } RegistrationInfo registrationInfo = patternManager.GetRegistrationsForFile(psiFile.GetSourceFile()). FirstOrDefault(c => c.Registration.IsSatisfiedBy(declaration.DeclaredElement)); if (registrationInfo != null) { consumer.AddHighlighting(new RegisteredByContainerHighlighting(registrationInfo), declaration.GetNameDocumentRange(), psiFile); } } }
private void ProcessFile(IFile psiFile, DefaultHighlightingConsumer consumer) { foreach (var declaration in psiFile.ThisAndDescendants<ITypeDeclaration>()) { if (declaration.DeclaredElement == null) // type is not (yet) declared { return; } RegistrationInfo registrationInfo = patternManager.GetRegistrationsForFile(psiFile.GetSourceFile()). FirstOrDefault(c => c.Registration.IsSatisfiedBy(declaration.DeclaredElement)); if (registrationInfo != null) { consumer.AddHighlighting(new RegisteredByContainerHighlighting(registrationInfo), declaration.GetNameDocumentRange(), psiFile); } } }
public void CheckCommentSpelling(IClassMemberDeclaration decl, [CanBeNull] IDocCommentBlock docNode, DefaultHighlightingConsumer consumer, 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)) { consumer.AddHighlighting( new CanBeSurroundedWithMetatagsHighlight(word, range, decl, _solution), range); } else if (spellCheck) { this.CheckWordSpelling(decl, wordRange, consumer, range); } } } }
private void CheckWordSpelling(IClassMemberDeclaration decl, Range wordRange, DefaultHighlightingConsumer consumer, DocumentRange range) { // 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)) { consumer.AddHighlighting( new WordIsNotInDictionaryHighlight( wordRange.Word, range, humpToken, _solution, this._xmlDocumentationSpellChecker, _settingsStore), range); break; } } }
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(); } }
protected void AddHighlighting(DocumentRange range, IHighlighting highlighting) { _highlightingConsumer.AddHighlighting(highlighting, range); }
public void CheckMemberSpelling(IDeclaration declaration, DefaultHighlightingConsumer consumer, bool spellCheck) { if (this._identifierSpellChecker == null || !spellCheck) { return; } if (declaration is IIndexerDeclaration || declaration is IDestructorDeclaration || declaration is IAccessorDeclaration || declaration is IConstructorDeclaration || (declaration.DeclaredName.Contains(".") && !(declaration is INamespaceDeclaration))) { return; } /*if (ComplexMatchEvaluator.IsMatch(declaration, _settings.IdentifiersToSpellCheck, * _settings.IdentifiersNotToSpellCheck, true) == null) * { * return null; * }*/ HashSet <string> localNames = getLocalNames(declaration); CamelHumpLexer lexer = new CamelHumpLexer(declaration.DeclaredName, 0, declaration.DeclaredName.Length); foreach (LexerToken token in lexer) { string val = token.Value; string lowerVal = val.ToLower(); //val.Length > MAX_LENGTH_TO_SKIP && if ( !IsAbbreviation(val) && SpellCheckUtil.ShouldSpellCheck(val, _identifierSettings.CompiledWordsToIgnore) && !localNames.Contains(lowerVal) && !this._identifierSpellChecker.TestWord(val, false)) { bool found = false; foreach (string entry in localNames) { if (entry.StartsWith(lowerVal)) { found = true; break; } } if (!found) { var containingFile = declaration.GetContainingFile(); consumer.AddHighlighting( new IdentifierSpellCheckHighlighting( declaration, token, _solution, this._identifierSpellChecker, _settingsStore), containingFile.TranslateRangeForHighlighting(declaration.GetNameRange())); } } } }
public void Execute(Action<DaemonStageResult> committer) { MarkModulesAsUsed(collectUsagesStageProcess); var consumer = new DefaultHighlightingConsumer(this, settingsStore); var referenceProcessor = new RecursiveReferenceProcessor<IMvcReference>(reference => { InterruptableActivityCookie.CheckAndThrow(); IHighlighting highlighting; switch (reference.MvcKind) { case MvcKind.Area: highlighting = CheckArea(reference); break; case MvcKind.Controller: highlighting = CheckResolved(reference, _ => (IHighlighting)new MvcControllerHighlighting(_)); break; case MvcKind.Action: highlighting = CheckResolved(reference, _ => (IHighlighting)new MvcActionHighlighting(_)); break; case MvcKind.View: case MvcKind.PartialView: case MvcKind.Master: case MvcKind.DisplayTemplate: case MvcKind.EditorTemplate: case MvcKind.Template: highlighting = CheckResolved(reference, _ => (IHighlighting)new MvcViewHighlighting((IMvcViewReference)_)); break; default: highlighting = null; break; } if (highlighting == null) { return; } consumer.AddHighlighting(highlighting, GetMvcReferenceHighlightingRange(reference), reference.GetTreeNode().GetContainingFile()); }); foreach (IFile file in DaemonProcess.SourceFile.EnumerateDominantPsiFiles()) { file.ProcessDescendants(referenceProcessor); } committer(new DaemonStageResult(consumer.Highlightings)); }