mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SSR: use GlobalMatchingVisitor.matchText() for XML
This commit is contained in:
+8
-17
@@ -2,6 +2,7 @@
|
||||
package com.intellij.structuralsearch.impl.matcher;
|
||||
|
||||
import com.intellij.dupLocator.iterators.ArrayBackedNodeIterator;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.XmlElementVisitor;
|
||||
import com.intellij.psi.xml.*;
|
||||
@@ -13,18 +14,16 @@ import com.intellij.structuralsearch.impl.matcher.iterators.SsrFilteringNodeIter
|
||||
*/
|
||||
public class XmlMatchingVisitor extends XmlElementVisitor {
|
||||
private final GlobalMatchingVisitor myMatchingVisitor;
|
||||
private final boolean myCaseSensitive;
|
||||
|
||||
public XmlMatchingVisitor(GlobalMatchingVisitor matchingVisitor) {
|
||||
myMatchingVisitor = matchingVisitor;
|
||||
myCaseSensitive = myMatchingVisitor.getMatchContext().getOptions().isCaseSensitiveMatch();
|
||||
}
|
||||
|
||||
@Override public void visitXmlAttribute(XmlAttribute attribute) {
|
||||
final XmlAttribute another = (XmlAttribute)myMatchingVisitor.getElement();
|
||||
final boolean isTypedVar = myMatchingVisitor.getMatchContext().getPattern().isTypedVar(attribute.getName());
|
||||
|
||||
if (!myMatchingVisitor.setResult(isTypedVar || matches(attribute.getName(), another.getName()))) return;
|
||||
if (!myMatchingVisitor.setResult(isTypedVar || myMatchingVisitor.matchText(attribute.getName(), another.getName()))) return;
|
||||
final XmlAttributeValue valueElement = attribute.getValueElement();
|
||||
if (valueElement != null && !myMatchingVisitor.setResult(myMatchingVisitor.match(valueElement, another.getValueElement()))) return;
|
||||
|
||||
@@ -42,10 +41,10 @@ public class XmlMatchingVisitor extends XmlElementVisitor {
|
||||
if (myMatchingVisitor.getMatchContext().getPattern().isTypedVar(text)) {
|
||||
final SubstitutionHandler handler = (SubstitutionHandler)myMatchingVisitor.getMatchContext().getPattern().getHandler(text);
|
||||
final String text2 = another.getText();
|
||||
final int offset = !text2.isEmpty() && (text2.charAt(0) == '"' || text2.charAt(0) == '\'') ? 1 : 0;
|
||||
final int offset = StringUtil.isQuotedString(text2) ? 1 : 0;
|
||||
myMatchingVisitor.setResult(handler.handle(another, offset, text2.length() - offset, myMatchingVisitor.getMatchContext()));
|
||||
} else {
|
||||
myMatchingVisitor.setResult(matches(text, another.getValue()));
|
||||
myMatchingVisitor.setResult(myMatchingVisitor.matchText(text, another.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +52,7 @@ public class XmlMatchingVisitor extends XmlElementVisitor {
|
||||
final XmlTag another = (XmlTag)myMatchingVisitor.getElement();
|
||||
final boolean isTypedVar = myMatchingVisitor.getMatchContext().getPattern().isTypedVar(tag.getName());
|
||||
|
||||
if (!myMatchingVisitor.setResult((matches(tag.getName(), another.getName()) || isTypedVar) &&
|
||||
if (!myMatchingVisitor.setResult((isTypedVar || myMatchingVisitor.matchText(tag.getName(), another.getName())) &&
|
||||
myMatchingVisitor.matchInAnyOrder(tag.getAttributes(), another.getAttributes()))) return;
|
||||
|
||||
final SsrFilteringNodeIterator patternNodes = new SsrFilteringNodeIterator(new ArrayBackedNodeIterator(tag.getValue().getChildren()));
|
||||
@@ -73,17 +72,9 @@ public class XmlMatchingVisitor extends XmlElementVisitor {
|
||||
}
|
||||
|
||||
@Override public void visitXmlText(XmlText text) {
|
||||
final boolean isTypedVar = myMatchingVisitor.getMatchContext().getPattern().isTypedVar(text);
|
||||
final PsiElement element = myMatchingVisitor.getElement();
|
||||
if (isTypedVar) {
|
||||
myMatchingVisitor.setResult(myMatchingVisitor.handleTypedElement(text, element));
|
||||
}
|
||||
else {
|
||||
myMatchingVisitor.setResult(element instanceof XmlText && matches(text.getText().trim(), element.getText().trim()));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean matches(String a, String b) {
|
||||
return myCaseSensitive ? a.equals(b) : a.equalsIgnoreCase(b);
|
||||
myMatchingVisitor.setResult(myMatchingVisitor.getMatchContext().getPattern().isTypedVar(text)
|
||||
? myMatchingVisitor.handleTypedElement(text, element)
|
||||
: element instanceof XmlText && myMatchingVisitor.matchText(text.getText().trim(), element.getText().trim()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user