private void HighlightCategorizedToken(CategorizedToken token, List <SyntaxHighlightToken> syntaxTokens) { Color backColor = editor.ActiveView.BackColor; SyntaxHighlightProperties highlightProperties = syntaxHighlightInfo.CalculateTokenCategoryHighlight(token.Category); SyntaxHighlightToken syntaxToken = SetTokenColor(token, highlightProperties, backColor); if (syntaxToken != null) { syntaxTokens.Add(syntaxToken); } }
private static bool IsFieldOrPropertyOrVariable(CategorizedToken token) { if (CodeRush.Source.DeclaresLocal(token.Value)) { // local variable or parameter return(true); } IMemberElement member = CodeRush.Source.GetMember(CodeRush.Source.ActiveClassInterfaceStructOrModule, token.Value); if (member != null && (member is Property || member is Variable || member is Event)) { // is declared property or field or event return(true); } return(false); }
private static bool IsNamespaceOrAlias(TextViewCaret caret, CategorizedToken token) { foreach (DictionaryEntry @namespace in caret.TextDocument.NamespaceReferences) { if (@namespace.Key.ToString() == token.Value) { return(true); } } foreach (string alias in caret.TextDocument.Aliases) { if (alias == token.Value) { return(true); } } return(false); }
private static bool IsPossibleTypeOrMethodName(TextViewCaret caret, CategorizedToken token) { if (token == null) { return(false); } if (token.Category != TokenCategory.Identifier) { return(false); } if (IsFieldOrPropertyOrVariable(token)) { return(false); } if (IsNamespaceOrAlias(caret, token)) { return(false); } return(true); }
void HighlightCategorizedToken(CategorizedToken token, List<SyntaxHighlightToken> syntaxTokens) { SyntaxHighlightProperties highlightProperties = _syntaxHighlightInfo.CalculateTokenCategoryHighlight(token.Category); SyntaxHighlightToken syntaxToken = SetTokenColor(token, highlightProperties); if (syntaxToken != null) syntaxTokens.Add(syntaxToken); }
private void HighlightCategorizedToken(CategorizedToken token, List<SyntaxHighlightToken> syntaxTokens) { Color backColor = syntaxEditor.ActiveView.BackColor; TokenCategory category = token.Category; if (category == TokenCategory.Comment) { syntaxTokens.Add(SetTokenColor(token, commentProperties, backColor)); } else { if (category == TokenCategory.Keyword) { syntaxTokens.Add(SetTokenColor(token, keywordProperties, backColor)); } else { if (category == TokenCategory.String) { syntaxTokens.Add(SetTokenColor(token, stringProperties, backColor)); } else { if (category == TokenCategory.XmlComment) { syntaxTokens.Add(SetTokenColor(token, xmlCommentProperties, backColor)); } else { syntaxTokens.Add(SetTokenColor(token, textProperties, backColor)); } } } } }
static void AppendCodes(List <CodeLine> lines, ref CodeLine currentLine, string code, int pos, CategorizedToken token) { AppendCode(lines, ref currentLine, code.Substring(pos, token.StartPosition - pos), null); AppendCode(lines, ref currentLine, token.Value, CssClasses[token.Category].GetClassName(token.Language)); }
static string GetFormattedAspxCode(string code, DevExpress.CodeParser.TokenCollection tokens, string[] highlightedTagNames) { int position = 0; int highlightedTagsCount = 0; bool needCloseHighlightedBlock = false; bool isStartedHighlightedComment = false; bool thisTagIsComplex = true; CodeLine currentLine = new CodeLine(); List <CodeLine> lines = new List <CodeLine>(); StartNotHighlightedBlock(lines); for (int i = 0; i < tokens.Count; i++) { CategorizedToken token = tokens[i] as CategorizedToken; if (token.Value == StartHighlightedCodeBlockMarker) { isStartedHighlightedComment = true; position = token.EndPosition; continue; } if (ContainsTokenInTagNames(token.Value, highlightedTagNames)) { if (tokens[i - 1].Value == "<" && tokens[i + 1].Value != ">") { highlightedTagsCount++; thisTagIsComplex = IsComplexTag(tokens, i); } if (highlightedTagsCount > 0) { if (highlightedTagsCount == 1 && tokens[i + 1].Value != ">" && lines.Count > 0) { StartHighlightedBlockAndCloseNotHighlighted(lines, false); } AppendCodes(lines, ref currentLine, code, position, token); if (tokens[i - 1].Value == "</" && tokens[i + 1].Value == ">") { highlightedTagsCount--; needCloseHighlightedBlock = highlightedTagsCount == 0; } } } else { if (token.Value != StartHighlightedCodeBlockMarker && token.Value != EndHighlightedCodeBlockMarker) { AppendCodes(lines, ref currentLine, code, position, token); } if (lines.Count > 0 && isStartedHighlightedComment) { StartHighlightedBlockAndCloseNotHighlighted(lines, true); isStartedHighlightedComment = false; } if (!thisTagIsComplex && token.Value == "/>" || needCloseHighlightedBlock || token.Value == EndHighlightedCodeBlockMarker) { EndHighlightedBlockAndStartNotHighlighted(ref currentLine); } if (!thisTagIsComplex && token.Value == "/>") { if (highlightedTagsCount > 0) { highlightedTagsCount--; } } if (needCloseHighlightedBlock) { needCloseHighlightedBlock = false; } } position = token.EndPosition; } AppendCode(lines, ref currentLine, code.Substring(position), null); EndNotHighlightedBlock(ref currentLine); lines.Add(currentLine); return(MergeCodeLines(lines)); }
static void AppendCodes(List<CodeLine> lines, ref CodeLine currentLine, string code, int pos, CategorizedToken token) { AppendCode(lines, ref currentLine, code.Substring(pos, token.StartPosition - pos), null); AppendCode(lines, ref currentLine, token.Value, CssClasses[token.Category].GetClassName(token.Language)); }
private static bool NeedGenerics(TextViewCaret caret) { CategorizedToken leftToken = GetLeftToken(caret); return(IsPossibleTypeOrMethodName(caret, leftToken)); }
private static bool IsNamespaceOrAlias(TextViewCaret caret, CategorizedToken token) { foreach (DictionaryEntry @namespace in caret.TextDocument.NamespaceReferences) { if (@namespace.Key.ToString() == token.Value) { return true; } } foreach (string alias in caret.TextDocument.Aliases) { if (alias == token.Value) { return true; } } return false; }
private static bool IsFieldOrPropertyOrVariable(CategorizedToken token) { if (CodeRush.Source.DeclaresLocal(token.Value)) { // local variable or parameter return true; } IMemberElement member = CodeRush.Source.GetMember(CodeRush.Source.ActiveClassInterfaceStructOrModule, token.Value); if (member != null && (member is Property || member is Variable || member is Event)) { // is declared property or field or event return true; } return false; }
private static bool IsPossibleTypeOrMethodName(TextViewCaret caret, CategorizedToken token) { if (token == null) { return false; } if (token.Category != TokenCategory.Identifier) { return false; } if (IsFieldOrPropertyOrVariable(token)) { return false; } if (IsNamespaceOrAlias(caret, token)) { return false; } return true; }