diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/predicates/BinaryPredicate.java b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/predicates/BinaryPredicate.java index b7d5432964d4..bded2a66bced 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/predicates/BinaryPredicate.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/predicates/BinaryPredicate.java @@ -1,8 +1,23 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.structuralsearch.impl.matcher.predicates; import com.intellij.psi.PsiElement; -import com.intellij.structuralsearch.impl.matcher.handlers.MatchPredicate; import com.intellij.structuralsearch.impl.matcher.MatchContext; +import com.intellij.structuralsearch.impl.matcher.handlers.MatchPredicate; /** * Binary predicate @@ -18,13 +33,20 @@ public final class BinaryPredicate extends MatchPredicate { this.or = or; } + @Override public boolean match(PsiElement patternNode, PsiElement matchedNode, MatchContext context) { + return match(patternNode, matchedNode, 0, -1, context); + } + + @Override + public boolean match(PsiElement patternNode, PsiElement matchedNode, int start, int end, MatchContext context) { if (or) { - return first.match(patternNode,matchedNode,context) || - second.match(patternNode,matchedNode,context); - } else { - return first.match(patternNode,matchedNode,context) && - second.match(patternNode,matchedNode,context); + return first.match(patternNode, matchedNode, start, end, context) || + second.match(patternNode, matchedNode, start, end, context); + } + else { + return first.match(patternNode, matchedNode, start, end, context) && + second.match(patternNode, matchedNode, start, end, context); } } diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/predicates/NotPredicate.java b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/predicates/NotPredicate.java index 3d28a635e3af..943eedaddddd 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/predicates/NotPredicate.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/predicates/NotPredicate.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.structuralsearch.impl.matcher.predicates; import com.intellij.psi.PsiElement; @@ -8,17 +23,19 @@ import com.intellij.structuralsearch.impl.matcher.handlers.MatchPredicate; * Negates predicate */ public final class NotPredicate extends MatchPredicate { - private final MatchPredicate handler; + private final MatchPredicate myPredicate; - public NotPredicate(final MatchPredicate _handler) { - handler = _handler; + public NotPredicate(final MatchPredicate predicate) { + myPredicate = predicate; } + @Override public boolean match(PsiElement patternNode, PsiElement matchedNode, MatchContext context) { - return !handler.match(patternNode,matchedNode,context); + return match(patternNode, matchedNode, 0, -1, context); } - public MatchPredicate getHandler() { - return handler; + @Override + public boolean match(PsiElement patternNode, PsiElement matchedNode, int start, int end, MatchContext context) { + return !myPredicate.match(patternNode, matchedNode, start, end, context); } } diff --git a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java index f2d5301537e8..97312d15a285 100644 --- a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java +++ b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java @@ -453,6 +453,15 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " @SuppressWarnings({\"other\", \"test\"}) String field;" + "}"; assertEquals("String literal in annotation", 2, findMatchesCount(source, "\"test\"")); + + String s2 = "class A {" + + " String a = \"Alpha\";" + + " String b = \"Bravo\";" + + " String c = \"Charlie\";" + + "}"; + assertEquals("match literal contents", 1, findMatchesCount(s2, "\"'String:[regex( alpha )]\"")); + assertEquals("negate match literal contents", 2, findMatchesCount(s2, "\"'String:[!regex( alpha )]\"")); + assertEquals("match literal contents and all types", 1, findMatchesCount(s2, "\"'String:[regex( alpha ) && exprtype( .* )]\"")); } public void testCovariantArraySearch() {