summaryrefslogtreecommitdiff
path: root/plugins/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/LiteralWithSubstitutionHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/LiteralWithSubstitutionHandler.java')
-rw-r--r--plugins/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/LiteralWithSubstitutionHandler.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/plugins/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/LiteralWithSubstitutionHandler.java b/plugins/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/LiteralWithSubstitutionHandler.java
new file mode 100644
index 000000000000..78967106755f
--- /dev/null
+++ b/plugins/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/LiteralWithSubstitutionHandler.java
@@ -0,0 +1,49 @@
+package com.intellij.structuralsearch.impl.matcher.handlers;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.structuralsearch.impl.matcher.MatchContext;
+import com.intellij.structuralsearch.impl.matcher.predicates.RegExpPredicate;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.List;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Maxim.Mossienko
+ * Date: Jun 30, 2004
+ * Time: 5:07:33 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class LiteralWithSubstitutionHandler extends MatchingHandler {
+ private final String matchExpression;
+ private Matcher matcher;
+ private final List<SubstitutionHandler> handlers;
+
+ public LiteralWithSubstitutionHandler(String _matchedExpression,List<SubstitutionHandler> _handlers) {
+ matchExpression = _matchedExpression;
+ handlers = _handlers;
+ }
+
+ public boolean match(PsiElement patternNode, PsiElement matchedNode, MatchContext context) {
+ final String text = RegExpPredicate.getMeaningfulText(matchedNode);
+ int offset = matchedNode.getText().indexOf(text);
+ if (matcher==null) {
+ matcher = Pattern.compile(matchExpression).matcher(text);
+ } else {
+ matcher.reset(text);
+ }
+
+ while (matcher.find()) {
+ for (int i = 0; i < handlers.size(); ++i) {
+ SubstitutionHandler handler = handlers.get(i);
+
+ if (!handler.handle(matchedNode,offset + matcher.start(i+1), offset + matcher.end(i+1),context)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+}