mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SSR: fix literal matching when negated or combined with other constraints
This commit is contained in:
+28
-6
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-6
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user