From 0dff08b0c3c5e30db8eb075cd6c10c0c24bf4774 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 2 Oct 2015 08:41:12 +0200 Subject: [PATCH] SSR: cleanup --- .../LiteralWithSubstitutionHandler.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/LiteralWithSubstitutionHandler.java b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/LiteralWithSubstitutionHandler.java index 78967106755f..57e37f3a273e 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/LiteralWithSubstitutionHandler.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/handlers/LiteralWithSubstitutionHandler.java @@ -2,11 +2,10 @@ 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.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.List; /** * Created by IntelliJ IDEA. @@ -20,30 +19,30 @@ public class LiteralWithSubstitutionHandler extends MatchingHandler { private Matcher matcher; private final List handlers; - public LiteralWithSubstitutionHandler(String _matchedExpression,List _handlers) { + public LiteralWithSubstitutionHandler(String _matchedExpression, List _handlers) { matchExpression = _matchedExpression; handlers = _handlers; } + @Override public boolean match(PsiElement patternNode, PsiElement matchedNode, MatchContext context) { - final String text = RegExpPredicate.getMeaningfulText(matchedNode); - int offset = matchedNode.getText().indexOf(text); + final String text = matchedNode.getText(); 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; + if (!matcher.find()) { + return false; } - return false; + for (int i = 0; i < handlers.size(); ++i) { + final SubstitutionHandler handler = handlers.get(i); + + if (!handler.handle(matchedNode, matcher.start(i + 1), matcher.end(i + 1), context)) { + return false; + } + } + return true; } }