mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SSR: error checking for xml templates
This commit is contained in:
+29
@@ -3,6 +3,7 @@ package com.intellij.structuralsearch;
|
||||
|
||||
import com.intellij.codeInsight.template.TemplateContextType;
|
||||
import com.intellij.codeInsight.template.XmlContextType;
|
||||
import com.intellij.dupLocator.iterators.NodeIterator;
|
||||
import com.intellij.dupLocator.util.NodeFilter;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.StdLanguages;
|
||||
@@ -112,6 +113,34 @@ public class XmlStructuralSearchProfile extends StructuralSearchProfile {
|
||||
return StdFileTypes.XML;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkSearchPattern(CompiledPattern pattern) {
|
||||
final ValidatingVisitor visitor = new ValidatingVisitor();
|
||||
final NodeIterator nodes = pattern.getNodes();
|
||||
while (nodes.hasNext()) {
|
||||
nodes.current().accept(visitor);
|
||||
nodes.advance();
|
||||
}
|
||||
nodes.reset();
|
||||
}
|
||||
|
||||
static class ValidatingVisitor extends PsiRecursiveElementWalkingVisitor {
|
||||
|
||||
@Override
|
||||
public void visitErrorElement(PsiErrorElement element) {
|
||||
super.visitErrorElement(element);
|
||||
final String errorDescription = element.getErrorDescription();
|
||||
final PsiElement parent = element.getParent();
|
||||
if (parent instanceof XmlAttribute && "'=' expected".equals(errorDescription)) {
|
||||
return;
|
||||
}
|
||||
else if (parent instanceof XmlTag && errorDescription.startsWith("Element") && errorDescription.endsWith(" is not closed")) {
|
||||
return;
|
||||
}
|
||||
throw new MalformedPatternException(errorDescription);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkReplacementPattern(Project project, ReplaceOptions options) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user