private HashSet <string> getLocalNames(IDeclaration declaration) { HashSet <string> localNames = new HashSet <string>(); ITypeOwner var = declaration as ITypeOwner; if (var != null) { string name = var.Type.GetPresentableName(declaration.Language); string acronym = ""; foreach (char c in name) { if (char.IsUpper(c)) { acronym += c; } } localNames.Add(acronym.ToLower()); CamelHumpLexer lexer = new CamelHumpLexer(name, 0, name.Length); foreach (LexerToken token in lexer) { localNames.Add(token.Value.ToLower()); } } IClassLikeDeclaration decl = declaration as IClassLikeDeclaration; if (decl != null) { foreach (IDeclaredType type in decl.SuperTypes) { string name = type.GetPresentableName(declaration.Language); CamelHumpLexer lexer = new CamelHumpLexer(name, 0, name.Length); foreach (LexerToken token in lexer) { localNames.Add(token.Value.ToLower()); } } } return(localNames); }
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 CheckMemberSpelling( IDeclaration declaration, IHighlightingConsumer highlightingConsumer, 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 highlighting = new IdentifierSpellCheckHighlighting( declaration, token, _solution, this._identifierSpellChecker, _settingsStore); var file = declaration.GetContainingFile(); var range = declaration.GetNameDocumentRange(); highlightingConsumer.AddHighlighting(highlighting, range, file); } } } }
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(); } }