SSR: Constraints only allowed on first of variable

This commit is contained in:
Bas Leijdekkers
2015-03-05 11:43:45 +01:00
parent 0534f1a9a6
commit 1fd7a91990
5 changed files with 22 additions and 5 deletions
@@ -76,7 +76,7 @@ class JavaPredefinedConfigurations {
),
createSearchTemplateInfo(
SSRBundle.message("predefined.configuration.constructors.of.the.class"),
"class 'Class {\n 'Class+('_ParameterType* '_ParameterName*) {\n '_Statement*;\n }\n}",
"class 'Class {\n 'Class('_ParameterType* '_ParameterName*) {\n '_Statement*;\n }\n}",
CLASS_TYPE
),
createSearchTemplateInfo(
@@ -130,6 +130,7 @@ class StringToConstraintsTransformer {
}
// Check the number of occurrences for typed variable
final int savedIndex = index;
if (index < length) {
char possibleQuantifier = pattern.charAt(index);
@@ -189,10 +190,13 @@ class StringToConstraintsTransformer {
constraint.setGreedy(greedy);
constraint.setPartOfSearchResults(!anonymous);
if (targetFound && !anonymous) {
throw new MalformedPatternException("Pattern may have only one target");
throw new MalformedPatternException("Only one target allowed");
}
targetFound = !anonymous;
}
else if (savedIndex != index) {
throw new MalformedPatternException("Constraints only allowed on first of variable");
}
if (index < length && pattern.charAt(index) == ':') {
++index;
@@ -203,6 +207,9 @@ class StringToConstraintsTransformer {
buf.append(ch);
}
else {
if (!constraintCreated) {
throw new MalformedPatternException("Constraints only allowed on first of variable");
}
index = eatTypedVarCondition(index, pattern, miscBuffer, constraint);
}
}
@@ -786,7 +786,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase {
" 'l{2,2};\n" +
" }\n" +
" public void run2() {\n" +
" 'l{2,2};\n" +
" 'l;\n" +
" }\n" +
"\n" +
" };";
@@ -99,7 +99,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
private static final String s20_2 = "'_T1 '_T2 = ('_T1)'_T3;";
private static final String s21_1 = "'_T1:Aa* 'T2 = ('_T1)'_T3;";
private static final String s21_2 = "'_T1:A* 'T2 = ( '_T1:A+ )'_T3;";
private static final String s21_3 = "'_T1:Aa* 'T2 = ( '_T1:Aa* )'_T3;";
private static final String s21_3 = "'_T1:Aa* 'T2 = ( '_T1 )'_T3;";
private static final String s22 = "Aaa a = (Aaa)b; Bbb c = (Bbb)d;";
@@ -1803,7 +1803,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
" '_*;\n" +
" }\n" +
" private static '_Class2:* '_Instance;\n" +
" static '_Class2:* '_GetInstance() {\n" +
" static '_Class2 '_GetInstance() {\n" +
" '_*;\n" +
" return '_Instance;\n" +
" }\n" +
@@ -116,6 +116,16 @@ public class StringToConstraintsTransformerTest {
test("'a:x!(");
}
@Test(expected = MalformedPatternException.class)
public void testRepeatingConstraints() {
test("'a*:foo 'a+:[regex( bla )]");
}
@Test(expected = MalformedPatternException.class)
public void testRepeatingConstraints2() {
test("'a:foo 'a*");
}
@Test
public void testMethodReference() {
test("'_a::'_b");