use of com.intellij.lexer.XmlLexer in project intellij-community by JetBrains.
the class XmlParsingTest method _testLexerPerformance2.
public void _testLexerPerformance2() throws Exception {
final String text = loadFile("performance2.xml");
XmlLexer lexer = new XmlLexer();
doLex(lexer, text);
final FilterLexer filterLexer = new FilterLexer(new XmlLexer(), new FilterLexer.SetFilter(LanguageParserDefinitions.INSTANCE.forLanguage(XMLLanguage.INSTANCE).getWhitespaceTokens()));
doLex(filterLexer, text);
doLex(lexer, text);
for (int i = 0; i < 20; i++) {
doLex(filterLexer, text);
}
}
use of com.intellij.lexer.XmlLexer in project intellij-community by JetBrains.
the class XmlParsingTest method _testLexerPerformance1.
public void _testLexerPerformance1() throws Exception {
final String text = loadFile("pallada.xml");
XmlLexer lexer = new XmlLexer();
doLex(lexer, text);
final FilterLexer filterLexer = new FilterLexer(new XmlLexer(), new FilterLexer.SetFilter(LanguageParserDefinitions.INSTANCE.forLanguage(XMLLanguage.INSTANCE).getWhitespaceTokens()));
doLex(filterLexer, text);
doLex(lexer, text);
doLex(filterLexer, text);
doLex(filterLexer, text);
}
use of com.intellij.lexer.XmlLexer in project intellij-community by JetBrains.
the class CheckValidXmlInScriptBodyInspectionBase method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new XmlElementVisitor() {
@Override
public void visitXmlTag(final XmlTag tag) {
if (HtmlUtil.isHtmlTag(tag))
return;
if (HtmlUtil.SCRIPT_TAG_NAME.equals(tag.getName()) || tag instanceof HtmlTag && HtmlUtil.SCRIPT_TAG_NAME.equalsIgnoreCase(tag.getName())) {
final PsiFile psiFile = tag.getContainingFile();
final FileType fileType = psiFile.getFileType();
if (fileType instanceof XmlLikeFileType) {
synchronized (CheckValidXmlInScriptBodyInspectionBase.class) {
if (myXmlLexer == null)
myXmlLexer = new XmlLexer();
final XmlTagValue tagValue = tag.getValue();
final String tagBodyText = tagValue.getText();
if (!tagBodyText.isEmpty()) {
myXmlLexer.start(tagBodyText);
while (myXmlLexer.getTokenType() != null) {
IElementType tokenType = myXmlLexer.getTokenType();
if (tokenType == XmlTokenType.XML_CDATA_START) {
while (tokenType != null && tokenType != XmlTokenType.XML_CDATA_END) {
myXmlLexer.advance();
tokenType = myXmlLexer.getTokenType();
}
if (tokenType == null)
break;
}
if (tokenType == XmlTokenType.XML_BAD_CHARACTER && "&".equals(TreeUtil.getTokenText(myXmlLexer)) || tokenType == XmlTokenType.XML_START_TAG_START) {
final int valueStart = tagValue.getTextRange().getStartOffset();
final int offset = valueStart + myXmlLexer.getTokenStart();
final PsiElement psiElement = psiFile.findElementAt(offset);
final TextRange elementRange = psiElement.getTextRange();
final int offsetInElement = offset - elementRange.getStartOffset();
holder.registerProblem(psiElement, XmlBundle.message("unescaped.xml.character"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, createFix(psiElement, offsetInElement));
int endOfElementInScriptTag = elementRange.getEndOffset() - valueStart;
while (myXmlLexer.getTokenEnd() < endOfElementInScriptTag) {
myXmlLexer.advance();
if (myXmlLexer.getTokenType() == null)
break;
}
}
myXmlLexer.advance();
}
}
}
}
}
}
};
}
Aggregations