Commit c150b3d1 authored by Bas Leijdekkers's avatar Bas Leijdekkers
Browse files

SSR: don't try to match when there are no more pattern nodes (EA-120394, IDEA-197743)

parent 3d777dc8
Branches unavailable Tags unavailable
No related merge requests found
Showing with 16 additions and 4 deletions
+16 -4
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.structuralsearch.impl.matcher.handlers;
import com.intellij.dupLocator.iterators.FilteringNodeIterator;
......@@ -373,7 +373,7 @@ public class SubstitutionHandler extends MatchingHandler {
if (patternNodes.hasNext()) {
final MatchingHandler nextHandler = context.getPattern().getHandler(patternNodes.current());
while(matchedOccurs >= minOccurs) {
while(matchedOccurs >= minOccurs && patternNodes.hasNext()) {
if (nextHandler.matchSequentially(patternNodes, matchNodes, context)) {
totalMatchedOccurs = matchedOccurs;
// match found
......
......@@ -2384,13 +2384,18 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
"}" +
"interface ABC {" +
" void m();" +
"}" +
"interface KLM {" +
"}" +
"interface I {" +
" void m();" +
"}";
String pattern1 = "interface '_Class { default '_ReturnType 'MethodName+('_ParameterType '_Parameter*);}";
assertEquals("should find default method", 1, findMatchesCount(source, pattern1));
String pattern2 = "interface 'Class { default '_ReturnType '_MethodName{0,0}('_ParameterType '_Parameter*);}";
assertEquals("should find interface without default methods", 1, findMatchesCount(source, pattern2));
assertEquals("should find interface without default methods", 3, findMatchesCount(source, pattern2));
String pattern3 = "default '_ReturnType 'MethodName('_ParameterType '_Parameter*);";
assertEquals("find naked default method", 1, findMatchesCount(source, pattern3));
......@@ -2423,6 +2428,14 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
assertEquals("should find Runnable method references", 4, findMatchesCount(source, pattern5));
}
public void testNoException() {
String s = "class X {" +
" void x(String[] tt, String[] ss, String s) {}" +
"}";
assertEquals("don't throw exception during matching", 0,
findMatchesCount(s, "void '_Method('_ParameterType '_Parameter*, '_LastType[] '_lastParameter);"));
}
public void testNoUnexpectedException() {
String source = "";
......@@ -2444,7 +2457,6 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
findMatchesCount(source, pattern3);
fail("malformed pattern warning expected");
} catch (MalformedPatternException ignored) {}
}
public void testInvalidPatternWarnings() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment