diff --git a/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaStructuralSearchProfile.java b/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaStructuralSearchProfile.java index 0e3f832d54b3..9babfd56bca2 100644 --- a/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaStructuralSearchProfile.java +++ b/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaStructuralSearchProfile.java @@ -913,9 +913,9 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile { if (grandParent instanceof PsiPolyadicExpression) return true; if (grandParent instanceof PsiExpressionStatement && hasSemicolon(grandParent)) return true; if (grandParent instanceof PsiReferenceList) { - final PsiReferenceList referenceList = (PsiReferenceList)grandParent; - final PsiElement greatGrandParent = referenceList.getParent(); - return !(greatGrandParent instanceof PsiClass) || ((PsiClass)greatGrandParent).getExtendsList() != referenceList; + final PsiElement greatGrandParent = grandParent.getParent(); + return !(greatGrandParent instanceof PsiClass) || ((PsiClass)greatGrandParent).getExtendsList() != grandParent || + greatGrandParent instanceof PsiTypeParameter; } return false; } @@ -933,12 +933,11 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile { return name != null && !"_Dummy_".equals(name); } final PsiElement grandParent = parent.getParent(); - if (grandParent instanceof PsiAnnotation && !(grandParent.getParent().getNextSibling() instanceof PsiErrorElement)) { - return true; - } + if (grandParent instanceof PsiCatchSection && parent instanceof PsiParameter) return true; + if (grandParent instanceof PsiAnnotation && !(grandParent.getParent().getNextSibling() instanceof PsiErrorElement)) return true; if (grandParent instanceof PsiParameterList || grandParent instanceof PsiExpressionList || grandParent instanceof PsiTypeParameterList || grandParent instanceof PsiResourceList || - grandParent instanceof PsiArrayInitializerExpression) { + grandParent instanceof PsiArrayInitializerExpression || grandParent instanceof PsiArrayInitializerMemberValue) { return true; } if (grandParent instanceof PsiTypeElement) { @@ -946,8 +945,7 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile { if (greatGrandParent instanceof PsiReferenceParameterList || greatGrandParent instanceof PsiClass) return true; } if (grandParent instanceof PsiAnnotationParameterList && parent instanceof PsiNameValuePair) { - final PsiNameValuePair nameValuePair = (PsiNameValuePair)parent; - return nameValuePair.getNameIdentifier() == variableNode; + return ((PsiNameValuePair)parent).getNameIdentifier() == variableNode; } return false; } diff --git a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java index b3a65b472460..1136159997b4 100644 --- a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java +++ b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java @@ -636,7 +636,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "try { a(); } catch(Exception ex) {}" + "}}"; assertEquals("catch parameter matching", 3, - findMatchesCount(s10031, "try { a(); } catch('_Type+ 'Arg+) { '_Statements*; }\n")); + findMatchesCount(s10031, "try { a(); } catch('_Type 'Arg+) { '_Statements*; }\n")); String s10033 = "class X {{ " + "return x;\n" + @@ -826,7 +826,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "class D { void method() {} }\n" + "class E {}"; assertEquals("parameterless constructor search", 3, - findMatchesCount(s143, "class '_a { '_d{0,0}:[ script( \"__context__.constructor\" ) ]('_b+ '_c+); }")); + findMatchesCount(s143, "class '_a { '_d{0,0}:[ script( \"__context__.constructor\" ) ]('_b '_c+); }")); assertEquals("parameterless constructor search 2", 2, findMatchesCount(s143, "'_Constructor() { '_st*; }")); } @@ -999,7 +999,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " void a(String in, String pattern) {}\n" + " }"; String s1001 = "class '_Class { \n" + - " '_ReturnType+ 'MethodName+ ('_ParameterType '_Parameter* );\n" + + " '_ReturnType 'MethodName+ ('_ParameterType '_Parameter* );\n" + "}"; assertEquals("handling of no match", 2, findMatchesCount(s1000,s1001)); } @@ -1284,7 +1284,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "} " + "public class DoEnrollStudent extends SimpleStudentEventActionImpl { }" + "public class DoCancelStudent extends SimpleStudentEventActionImpl { }"; - String s136 = "public class 'StrutsActionClass extends '_*:Action {" + + String s136 = "public class 'StrutsActionClass extends '_:*Action {" + " public ActionForward '_AnActionMethod:*execute (ActionMapping '_,\n" + " ActionForm '_,\n" + " HttpServletRequest '_,\n" + @@ -1787,7 +1787,6 @@ public class StructuralSearchTest extends StructuralSearchTestCase { assertEquals("Find SuppressWarnings annotations", 2, findMatchesCount(source6, "@SuppressWarnings")); assertEquals("Find SuppressWarnings annotations", 2, findMatchesCount(source6, "@SuppressWarnings(value='_any)")); assertEquals("Find annotation with 3 value array initializer", 1, findMatchesCount(source6, "@SuppressWarnings({'_value{3,3} })")); - } public void testBoxingAndUnboxing() { @@ -2183,22 +2182,22 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "}"; String pattern1 = "class '_A {" + - " '_type+ 'method+ () throws '_E{0,0};" + + " '_type 'method+ () throws '_E{0,0};" + "}"; assertEquals(1, findMatchesCount(source, pattern1)); String pattern2 = "class '_A {" + - " '_type+ 'method+ () throws '_E{1,2};" + + " '_type 'method+ () throws '_E{1,2};" + "}"; assertEquals(2, findMatchesCount(source, pattern2)); String pattern3 = "class '_A {" + - " '_type+ 'method+ () throws '_E{2,2};" + + " '_type 'method+ () throws '_E{2,2};" + "}"; assertEquals(1, findMatchesCount(source, pattern3)); String pattern4 = "class '_A {" + - " '_type+ 'method+ () throws '_E{0,0}:[ regex( E2 )];" + + " '_type 'method+ () throws '_E{0,0}:[ regex( E2 )];" + "}"; assertEquals(2, findMatchesCount(source, pattern4)); } @@ -2336,10 +2335,10 @@ public class StructuralSearchTest extends StructuralSearchTestCase { " void m();" + "}"; - String pattern1 = "interface '_Class { default '_ReturnType+ 'MethodName+('_ParameterType '_Parameter*);}"; + 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*);}"; + String pattern2 = "interface 'Class { default '_ReturnType '_MethodName{0,0}('_ParameterType '_Parameter*);}"; assertEquals("should find interface without default methods", 1, findMatchesCount(source, pattern2)); } @@ -2430,6 +2429,15 @@ public class StructuralSearchTest extends StructuralSearchTestCase { } catch (MalformedPatternException ignored) {} } + public void testNotApplicableConstraints() { + options.fillSearchCriteria("class A extends '_B* {}"); + assertEquals("MAXIMUM UNLIMITED not applicable for B", checkApplicableConstraints()); + + options.clearVariableConstraints(); + options.fillSearchCriteria("'_a?.'_b?"); + assertEquals("MINIMUM ZERO not applicable for b", checkApplicableConstraints()); + } + public void testFindInnerClass() { String source = "class Foo {\n" + " static class Bar {}\n" + diff --git a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTestCase.java b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTestCase.java index 49f817b6e1d6..649ca34e8605 100644 --- a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTestCase.java +++ b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTestCase.java @@ -76,6 +76,9 @@ public abstract class StructuralSearchTestCase extends LightQuickFixTestCase { if (constraint.getMinCount() == 0) { usedConstraints.add(UIUtil.MINIMUM_ZERO); } + if (constraint.getMaxCount() > 1) { + usedConstraints.add(UIUtil.MAXIMUM_UNLIMITED); + } // todo check other constraints for (String usedConstraint : usedConstraints) { if (!profile.isApplicableConstraint(usedConstraint, nodes, false, constraint.isPartOfSearchResults())) {