diff --git a/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaPredefinedConfigurations.java b/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaPredefinedConfigurations.java index 45c38a57154f..85bdf9c1398a 100644 --- a/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaPredefinedConfigurations.java +++ b/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaPredefinedConfigurations.java @@ -165,7 +165,7 @@ class JavaPredefinedConfigurations { createSearchTemplateInfo(SSRBundle.message("predefined.configuration.typed.symbol"),"'Symbol <'_GenericArgument+>", GENERICS_TYPE), createSearchTemplateInfo(SSRBundle.message("predefined.configuration.generic.casts"),"( '_Type <'_GenericArgument+> ) '_Expr", GENERICS_TYPE), createSearchTemplateInfo(SSRBundle.message("predefined.configuration.type.var.substitutions.in.intanceof.with.generic.types"),"'_Expr instanceof '_Type <'Substitutions+> ", GENERICS_TYPE), - createSearchTemplateInfo(SSRBundle.message("predefined.configuration.variables.of.generic.types"),"'_Type <'_GenericArgument+> 'Var = 'Init?;", GENERICS_TYPE), + createSearchTemplateInfo(SSRBundle.message("predefined.configuration.variables.of.generic.types"),"'_Type <'_GenericArgument+> 'Var = '_Init?;", GENERICS_TYPE), createSearchTemplateInfo(SSRBundle.message("predefined.configuration.diamond.operators"), "new 'ClassName<>('_Argument*)", GENERICS_TYPE), // Add comments and metadata @@ -226,7 +226,7 @@ class JavaPredefinedConfigurations { " public void ejbRemove();\n" + "}", J2EE_TYPE), createSearchTemplateInfoSimple(SSRBundle.message("predefined.configuration.ejb.interface"),"interface 'EjbInterface extends EJBObject {\n" + - " 'Type+ 'Method+('ParamType* 'ParamName*);\n" + + " '_Type+ '_Method+('_ParamType* '_ParamName*);\n" + "}", J2EE_TYPE), createSearchTemplateInfoSimple(SSRBundle.message("predefined.configuration.servlets"),"public class 'Servlet extends '_ParentClass:*HttpServlet {\n" + " public void '_InitServletMethod?:init ();\n" + @@ -243,19 +243,19 @@ class JavaPredefinedConfigurations { // Misc types createSearchTemplateInfo(SSRBundle.message("predefined.configuration.serializable.classes.and.their.serialization.implementation"), - "class '_Class implements '_Serializable:*Serializable {\n" + - " static final long 'VersionField?:serialVersionUID = '_VersionFieldInit?;\n" + + "class 'Class implements '_Serializable:*Serializable {\n" + + " static final long '_VersionField?:serialVersionUID = '_VersionFieldInit?;\n" + " private static final ObjectStreamField[] '_persistentFields?:serialPersistentFields = '_persistentFieldInitial?; \n" + - " private void 'SerializationWriteHandler?:writeObject (ObjectOutputStream '_stream) throws IOException;\n" + - " private void 'SerializationReadHandler?:readObject (ObjectInputStream '_stream2) throws IOException, ClassNotFoundException;\n" + - " Object 'SpecialSerializationReadHandler?:readResolve () throws ObjectStreamException;\n" + - " Object 'SpecialSerializationWriteHandler?:writeReplace () throws ObjectStreamException;\n" + + " private void '_SerializationWriteHandler?:writeObject (ObjectOutputStream '_stream) throws IOException;\n" + + " private void '_SerializationReadHandler?:readObject (ObjectInputStream '_stream2) throws IOException, ClassNotFoundException;\n" + + " Object '_SpecialSerializationReadHandler?:readResolve () throws ObjectStreamException;\n" + + " Object '_SpecialSerializationWriteHandler?:writeReplace () throws ObjectStreamException;\n" + "}",MISC_TYPE), createSearchTemplateInfo(SSRBundle.message("predefined.configuration.cloneable.implementations"), "class '_Class implements '_Interface:*Cloneable {\n" + " Object 'CloningMethod:*clone ();\n" + "}",MISC_TYPE), - createSearchTemplateInfoSimple(SSRBundle.message("predefined.configuration.]junit.test.cases"),"public class 'TestCase extends 'TestCaseClazz:*TestCase {\n" + + createSearchTemplateInfoSimple(SSRBundle.message("predefined.configuration.]junit.test.cases"),"public class 'TestCase extends '_TestCaseClazz:*TestCase {\n" + " public void '_testMethod+:test.* ();\n" + "}", MISC_TYPE), createSearchTemplateInfo(SSRBundle.message("predefined.configuration.singletons"),"class 'Class {\n" + @@ -285,7 +285,7 @@ class JavaPredefinedConfigurations { createSearchTemplateInfo(SSRBundle.message("predefined.configuration.symbol"),"'Symbol",INTERESTING_TYPE), createSearchTemplateInfo(SSRBundle.message("predefined.configuration.fields.variables.read"),"'Symbol:[read]",INTERESTING_TYPE), createSearchTemplateInfo(SSRBundle.message("predefined.configuration.fields_variables.with.given.name.pattern.updated"),"'Symbol:[regex( name ) && write]",INTERESTING_TYPE), - createSearchTemplateInfo(SSRBundle.message("predefined.configuration.usage.of.derived.type.in.cast"),"('CastType:*Base ) 'Expr",INTERESTING_TYPE), + createSearchTemplateInfo(SSRBundle.message("predefined.configuration.usage.of.derived.type.in.cast"),"('CastType:*[regex( Base )]) '_Expr",INTERESTING_TYPE), createSearchTemplateInfo(SSRBundle.message("predefined.configuration.boxing.in.declarations"),"'_Type:Object|Integer|Boolean|Long|Character|Short|Byte 'Var = '_Value:[exprtype( int|boolean|long|char|short|byte )]",INTERESTING_TYPE), createSearchTemplateInfo(SSRBundle.message("predefined.configuration.unboxing.in.declarations"),"'_Type:int|boolean|long|char|short|byte 'Var = '_Value:[exprtype( Integer|Boolean|Long|Character|Short|Byte )]",INTERESTING_TYPE), createSearchTemplateInfo(SSRBundle.message("predefined.configuration.boxing.in.method.calls"),"'_Instance?.'Call('_BeforeParam*,'_Param:[ exprtype( int|boolean|long|char|short|byte ) && formal( Object|Integer|Boolean|Long|Character|Short|Byte )],'_AfterParam*)",INTERESTING_TYPE), diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/StringToConstraintsTransformer.java b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/StringToConstraintsTransformer.java index dfaed19ef3ed..0ac16b386a19 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/StringToConstraintsTransformer.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/StringToConstraintsTransformer.java @@ -42,6 +42,7 @@ class StringToConstraintsTransformer { StringBuilder miscBuffer = null; int anonymousTypedVarsCount = 0; + boolean targetFound = false; for(int index=0;index < pattern.length();++index) { char ch = pattern.charAt(index); @@ -187,6 +188,10 @@ class StringToConstraintsTransformer { constraint.setMaxCount(maxOccurs); constraint.setGreedy(greedy); constraint.setPartOfSearchResults(!anonymous); + if (targetFound && !anonymous) { + throw new MalformedPatternException("Pattern may have only one target"); + } + targetFound = !anonymous; } if (index < length && pattern.charAt(index) == ':') { diff --git a/platform/structuralsearch/testData/java/ReformatAndShortenClassRefPerformance_pattern.java b/platform/structuralsearch/testData/java/ReformatAndShortenClassRefPerformance_pattern.java index 1200d6f9624f..4dd5df59b3c2 100644 --- a/platform/structuralsearch/testData/java/ReformatAndShortenClassRefPerformance_pattern.java +++ b/platform/structuralsearch/testData/java/ReformatAndShortenClassRefPerformance_pattern.java @@ -1 +1 @@ -assertTrue(StrictMath.abs('v1 - 'v2) < 't); \ No newline at end of file +assertTrue(StrictMath.abs('_v1 - '_v2) < '_t); \ No newline at end of file diff --git a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralReplaceTest.java b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralReplaceTest.java index a8d846767a86..6a656a736654 100644 --- a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralReplaceTest.java +++ b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralReplaceTest.java @@ -22,8 +22,8 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { public void testReplaceInLiterals() { String s1 = "String ID_SPEED = \"Speed\";"; - String s2 = "String 'name = \"'string\";"; - String s2_2 = "String 'name = \"'string:[regex( .* )]\";"; + String s2 = "String 'name = \"'_string\";"; + String s2_2 = "String 'name = \"'_string:[regex( .* )]\";"; String s3 = "VSegAttribute $name$ = new VSegAttribute(\"$string$\");"; String expectedResult = "VSegAttribute ID_SPEED = new VSegAttribute(\"Speed\");"; @@ -58,7 +58,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { String s7 = "IconLoader.getIcon(\"/ant/property.png\");\n" + "IconLoader.getIcon(\"/ant/another/property.png\");\n"; - String s8 = "IconLoader.getIcon(\"/'module/'name:[regex( \\w+ )].png\");"; + String s8 = "IconLoader.getIcon(\"/'_module/'_name:[regex( \\w+ )].png\");"; String s9 = "Icons.$module$.$name$;"; String expectedResult3 = "Icons.ant.property;\n" + "IconLoader.getIcon(\"/ant/another/property.png\");\n"; @@ -101,7 +101,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { " JOptionPane.showMessageDialog(null, \"MESSAGE\");\n" + " }\n" + "}"; - String s2 = "JOptionPane.'showDialog(null, 'msg);"; + String s2 = "JOptionPane.'showDialog(null, '_msg);"; String s3 = "//FIXME provide a parent frame\n" + "JOptionPane.$showDialog$(null, $msg$);"; @@ -125,7 +125,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { ); String s4 = "myButton.setText(\"Ok\");"; - String s5 = "'Instance.'MethodCall:[regex( setText )]('Parameter*:[regex( \"Ok\" )]);"; + String s5 = "'_Instance.'_MethodCall:[regex( setText )]('_Parameter*:[regex( \"Ok\" )]);"; String s6 = "$Instance$.$MethodCall$(\"OK\");"; String expectedResult2 = "myButton.setText(\"OK\");"; @@ -155,9 +155,9 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { " matches = testMatcher.findMatches(s7,s8, options);\n" + " if (matches.size()!=2) return false;"; - String str2=" lastTest = 'Descr;\n" + - " matches = testMatcher.findMatches('In,'Pattern, options);\n" + - " if (matches.size()!='Number) return false;"; + String str2=" lastTest = '_Descr;\n" + + " matches = testMatcher.findMatches('_In,'_Pattern, options);\n" + + " if (matches.size()!='_Number) return false;"; String str3 = "assertEquals($Descr$,testMatcher.findMatches($In$,$Pattern$, options).size(),$Number$);"; String expectedResult1 = "// searching for several constructions\n" + " lastTest = \"several constructions match\";\n" + @@ -191,7 +191,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { assertEquals("Empty replacement",expectedResult2,actualResult); - String str5 = "testMatcher.findMatches('In,'Pattern, options).size()"; + String str5 = "testMatcher.findMatches('_In,'_Pattern, options).size()"; String str6 = "findMatchesCount($In$,$Pattern$)"; String expectedResult3="// searching for several constructions\n" + " lastTest = \"several constructions match\";\n" + @@ -220,9 +220,9 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { " if (asyncMode) {\n" + " myTreeModel.nodesWereInserted(parentNode,new int[] {i} );\n" + " }"; - String str11 = " 'parentNode.insert('newNode, 'i);\n" + + String str11 = " '_parentNode.insert('_newNode, '_i);\n" + " if (asyncMode) {\n" + - " myTreeModel.nodesWereInserted('parentNode,new int[] {'i} );\n" + + " myTreeModel.nodesWereInserted('_parentNode,new int[] {'_i} );\n" + " }"; String str12 = "addChild($parentNode$,$newNode$, $i$);"; String expectedResult5 = " addChild(parentNode,compositeNode, i);"; @@ -231,7 +231,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { assertEquals( "Array initializer replacement", expectedResult5,actualResult); String str13 = " aaa(5,6,3,4,1,2);"; - String str14 = "aaa('t{2,2},3,4,'q{2,2});"; + String str14 = "aaa('_t{2,2},3,4,'_q{2,2});"; String str15 = "aaa($q$,3,4,$t$);"; String expectedResult6 = " aaa(1,2,3,4,5,6);"; @@ -239,7 +239,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { assertEquals("Parameter multiple match",expectedResult6,actualResult); String str16 = " int c = a();"; - String str17 = "'t:a ('q*,'p*)"; + String str17 = "'_t:a ('_q*,'_p*)"; String str18 = "$t$($q$,1,$p$)"; String expectedResult7 = " int c = a(1);"; @@ -255,7 +255,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { assertEquals("One substition replacement",expectedResult8,actualResult); String str22 = " instance.setAAA(anotherInstance.getBBB());"; - String str23 = " 'i.'m:set(.+) ('a.'m2:get(.+) ());"; + String str23 = " '_i.'_m:set(.+) ('_a.'_m2:get(.+) ());"; String str24 = " $a$.set$m2_1$( $i$.get$m_1$() );"; String expectedResult9 = " anotherInstance.setBBB( instance.getAAA() );"; @@ -291,7 +291,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { String str28 = "UTElementNode elementNode = new UTElementNode(myProject, processedElement, psiFile,\n" + " processedElement.getTextOffset(), true,\n" + " !myUsageViewDescriptor.toMarkInvalidOrReadonlyUsages(), null);"; - String str29 = "new UTElementNode('param, 'directory, 'null, '0, 'true, !'descr.toMarkInvalidOrReadonlyUsages(),\n" + + String str29 = "new UTElementNode('_param, '_directory, '_null, '_0, '_true, !'_descr.toMarkInvalidOrReadonlyUsages(),\n" + " 'referencesWord)"; String str30 = "new UTElementNode($param$, $directory$, $null$, $0$, $true$, true,\n" + " $referencesWord$)"; @@ -314,7 +314,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { ); String s34 = "ParamChecker.isTrue(1==1, \"!!!\");"; - String s35 = "ParamChecker.isTrue('expr, 'msg)"; + String s35 = "ParamChecker.isTrue('_expr, '_msg)"; String s36 = "assert $expr$ : $msg$"; String expectedResult13 = "assert 1==1 : \"!!!\";"; @@ -346,7 +346,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { ); String s40 = "ParamChecker.instanceOf(queryKey, GroupBySqlTypePolicy.GroupKey.class);"; - String s41 = "ParamChecker.instanceOf('obj, 'class.class);"; + String s41 = "ParamChecker.instanceOf('_obj, '_class.class);"; String s42 = "assert $obj$ instanceof $class$ : \"$obj$ is an instance of \" + $obj$.getClass() + \"; expected \" + $class$.class;"; String expectedResult15 = "assert queryKey instanceof GroupBySqlTypePolicy.GroupKey : \"queryKey is an instance of \" + queryKey.getClass() + \"; expected \" + GroupBySqlTypePolicy.GroupKey.class;"; @@ -361,7 +361,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { " static final String TAG_BEAN_VALUE = \"\";\n" + "}\n" + "XmlTag beanTag = rootTag.findSubTag(Wpd.TAG_BEAN_VALUE);"; - String s44 = "'Instance?.findSubTag( 'Parameter:[exprtype( *String ) ])"; + String s44 = "'_Instance?.findSubTag( '_Parameter:[exprtype( *String ) ])"; String s45 = "jetbrains.fabrique.util.XmlApiUtil.findSubTag($Instance$, $Parameter$)"; String expectedResult16 = "class Wpd {\n" + " static final String TAG_BEAN_VALUE = \"\";\n" + @@ -398,7 +398,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { String s49 = "class A {}\n" + "class B extends A {}\n" + "A a = new B();"; - String s50 = "A 'b = new 'B:*A ();"; + String s50 = "A '_b = new '_B:*A ();"; String s51 = "A $b$ = new $B$(\"$b$\");"; String expectedResult18 = "class A {}\n" + "class B extends A {}\n" + @@ -430,8 +430,8 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { "} catch(Exception ex) {\n" + " aaa5();\n" + "}\n"; - String s53 = "try { 'a; } finally {\n" + - " 'b;" + + String s53 = "try { '_a; } finally {\n" + + " '_b;" + "}"; String s54 = "$a$;"; String expectedResult19 = "aaa();\n" + @@ -501,7 +501,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { String s64 = "int x = 42;\n" + "int y = 42; // Stuff"; - String s65 = "'Type 'Variable = 'Value; // 'Comment"; + String s65 = "'_Type '_Variable = '_Value; // '_Comment"; String s66 = "/**\n" + " *$Comment$\n" + " */\n" + @@ -521,7 +521,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { ); String s61 = "try { 1=1; } catch(Exception e) { 1=1; } catch(Throwable t) { 2=2; }"; - String s62 = "try { 'a; } catch(Exception e) { 'b; }"; + String s62 = "try { '_a; } catch(Exception e) { '_b; }"; String s63 = "try { $a$; } catch(Exception1 e) { $b$; } catch(Exception2 e) { $b$; }"; String expectedResult22 = "try { 1=1; } catch(Exception1 e) { 1=1; } catch(Exception2 e) { 1=1; } catch (Throwable t) { 2=2; }"; @@ -697,10 +697,10 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { "}"; String s8 = "new Runnable() {\n" + " public void run() {\n" + - " 'l ();\n" + + " '_l ();\n" + " }\n" + - " private void 'l () {\n" + - " 'st{2,2};\n" + + " private void '_l () {\n" + + " '_st{2,2};\n" + " }\n" + "};"; String s9 = "new My() {\n" + @@ -980,7 +980,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { options.setToReformatAccordingToStyle(true); String s1 = "class A { public void b() {} }"; - String s2 = "class 'a { 'Other* }"; + String s2 = "class 'a { '_Other* }"; String s3 = "class $a$New { Logger LOG; $Other$ }"; String expectedResult = " class ANew {\n" + " Logger LOG;\n\n" + @@ -996,7 +996,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { ); String s4 = "class A { class C {} public void b() {} int f; }"; - String s5 = "class 'a { 'Other* }"; + String s5 = "class 'a { '_Other* }"; String s6 = "class $a$ { Logger LOG; $Other$ }"; String expectedResult2 = " class A {\n" + " Logger LOG;\n\n" + @@ -1015,7 +1015,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { ); String s7 = "class A extends B { int c; void b() {} { a = 1; } }"; - String s8 = "class 'A extends B { 'Other* }"; + String s8 = "class 'A extends B { '_Other* }"; String s9 = "class $A$ extends B2 { $Other$ }"; String expectedResult3 = " class A extends B2 {\n" + " int c;\n\n" + @@ -1036,7 +1036,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { " public void b() {}\n" + " int f;\n" + "}"; - String s11 = "class 'a { 'Other* }"; + String s11 = "class 'a { '_Other* }"; String s12 = "public class $a$ {\n" + " $Other$\n" + "}"; @@ -1068,9 +1068,9 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { "}\n" + "}"; String s14 = "class 'Class extends Thread {\n" + - " 'Class('ParameterType* 'ParameterName*) {\n" + - "\t super (CustomThreadGroup.getThreadGroup(), 'superarg* );\n" + - " 'Statement*;\n" + + " 'Class('_ParameterType* '_ParameterName*) {\n" + + "\t super (CustomThreadGroup.getThreadGroup(), '_superarg* );\n" + + " '_Statement*;\n" + " }\n" + "}"; String s15 = "class $Class$ extends CustomThread {\n" + @@ -1100,8 +1100,8 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { String s16 = "public class A {}\n" + "final class B {}"; - String s17 = "class 'A { 'Other* }"; - String s17_2 = "class 'A { private Log log = LogFactory.createLog(); 'Other* }"; + String s17 = "class 'A { '_Other* }"; + String s17_2 = "class 'A { private Log log = LogFactory.createLog(); '_Other* }"; String s18 = "class $A$ { private Log log = LogFactory.createLog(); $Other$ }"; String s18_2 = "class $A$ { $Other$ }"; @@ -1116,7 +1116,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { assertEquals("Removing field",expectedResult7,actualResult); String s19 = "public class A extends Object implements Cloneable {}\n"; - String s20 = "class 'A { 'Other* }"; + String s20 = "class 'A { '_Other* }"; String s21 = "class $A$ { private Log log = LogFactory.createLog(); $Other$ }"; actualResult = replacer.testReplace(s19,s20,s21,options); @@ -1124,7 +1124,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { assertEquals("Extends / implements list for class",expectedResult8,actualResult); String s22 = "public class A { int Afield; }\n"; - String s23 = "class 'A { 'Other* }"; + String s23 = "class 'A { '_Other* }"; String s24 = "class $A$ { private Log log = LogFactory.createLog(); $Other$ }"; actualResult = replacer.testReplace(s22,s23,s24,options); @@ -1152,8 +1152,8 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { String s28 = "aaa"; String s29 = "class 'Class {\n" + - " 'Class('ParameterType 'ParameterName) {\n" + - " 'Class('ParameterName);\n" + + " 'Class('_ParameterType '_ParameterName) {\n" + + " 'Class('_ParameterName);\n" + " }\n" + "}"; String s30 = "class $Class$ {\n" + @@ -1177,7 +1177,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { " int c; // comment2\n" + "}"; - String s32 = "'Type 'Variable = 'Value?; //'Comment"; + String s32 = "'_Type 'Variable = '_Value?; //'_Comment"; String s33 = "/**$Comment$*/\n" + "$Type$ $Variable$ = $Value$;"; @@ -1212,7 +1212,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { "}"; String s35 = "public interface 'MessageInterface {\n" + - " public static final String 'X = 'VALUE;\n" + + " public static final String '_X = '_VALUE;\n" + " 'blah*" + "}"; String s36 = "public interface $MessageInterface$ {\n" + @@ -1266,7 +1266,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { " private int c = 2;\n" + "}"; - String s2 = "@Modifier(\"PackageLocal\") 'Type 'Instance = 'Init?;"; + String s2 = "@Modifier(\"PackageLocal\") '_Type '_Instance = '_Init?;"; String s3 = "public $Type$ $Instance$ = $Init$;"; String expectedResult = "class A {\n" + @@ -1348,7 +1348,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { " /**\n" + " * zzz\n" + " */\n" + - " void f('t 'p){'s+;}\n" + + " void f('_t '_p){'_s+;}\n" + "}"; String s3 = "class $c$ {\n" + " /**\n" + @@ -1408,13 +1408,13 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { "}"; String s2 = "/**\n" + "* Created by IntelliJ IDEA.\n" + - "* User: 'USER\n" + - "* Date: 'DATE\n" + - "* Time: 'TIME\n" + + "* User: '_USER\n" + + "* Date: '_DATE\n" + + "* Time: '_TIME\n" + "* To change this template use File | Settings | File Templates.\n" + "*/\n" + "class 'c {\n" + - " 'other*\n" + + " '_other*\n" + "}"; String s3 = "/**\n" + "* by: $USER$\n" + @@ -1469,11 +1469,11 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { public void testClassReplacement9() throws IOException { String s1 = loadFile("before1.java"); - String s2 = "class 'A extends 'TestCaseCass:[regex( .*TestCase ) ] {\n" + - " 'OtherStatement*;\n" + - " public void 'testMethod*:[regex( test.* )] () {\n" + + String s2 = "class 'A extends '_TestCaseCass:[regex( .*TestCase ) ] {\n" + + " '_OtherStatement*;\n" + + " public void '_testMethod*:[regex( test.* )] () {\n" + " }\n" + - " 'OtherStatement2*;\n" + + " '_OtherStatement2*;\n" + "}"; String s3 = "class $A$ extends $TestCaseCass$ {\n" + " $OtherStatement$;\n" + @@ -1560,7 +1560,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { String actualResult; String s43 = "public @Deprecated class Foo implements Comparable {\n int x;\n void m(){}\n }"; - String s44 = "class 'Class implements 'Interface { 'Content* }"; + String s44 = "class 'Class implements '_Interface { '_Content* }"; String s45 = "@MyAnnotation\n" + "class $Class$ implements $Interface$ {$Content$}"; String expectedResult16 = "@MyAnnotation public @Deprecated\n" + @@ -1579,7 +1579,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { String actualResult; String s43 = "public @Deprecated class Foo implements Comparable {\n int x;\n void m(){}\n }"; - String s44 = "class 'Class implements 'Interface {}"; + String s44 = "class 'Class implements '_Interface {}"; String s45 = "@MyAnnotation\n" + "class $Class$ implements $Interface$ {}"; String expectedResult16 = "@MyAnnotation public @Deprecated\n" + @@ -1794,7 +1794,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { " catch (final Exception e)\n" + " { continue; }\n" + "}"; - String toFind = "try { 'TryStatement*; } catch(Exception 'ExceptionDcl) { 'CatchStatement*; }"; + String toFind = "try { '_TryStatement*; } catch(Exception '_ExceptionDcl) { '_CatchStatement*; }"; String replacement = "try { $TryStatement$; }\n" + "catch(Throwable $ExceptionDcl$) { $CatchStatement$; }"; String expectedResult = "for (int i = 0; i < MIMEHelper.MIME_MAP.length; i++)\n" + "{\n" + @@ -1841,7 +1841,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { " Math.sin(0.5);\n" + " Math.max(1, 2);\n" + "}}"; - final String what = "Math.'m('a*)"; + final String what = "Math.'m('_a*)"; final String by = "Math.$m$($a$)"; options.setToUseStaticImport(true); @@ -1961,7 +1961,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { " } catch (PersistenceException e) {\n" + " // good\n" + " }"; - String s2 = "try { 'TryStatement; } catch('ExceptionType 'ExceptionDcl) { /* 'CommentContent */ }"; + String s2 = "try { '_TryStatement; } catch('_ExceptionType '_ExceptionDcl) { /* '_CommentContent */ }"; String replacement = "try { $TryStatement$; } catch($ExceptionType$ $ExceptionDcl$) { _logger.warning(\"$CommentContent$\", $ExceptionDcl$); }"; String expected = "try { em.persist(p); } catch(PersistenceException e) { _logger.warning(\" good\", e); }"; @@ -2077,9 +2077,9 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { "a = 2;\n" + "int b = a;\n" + "b2 = 3;"; - String s2 = "int 'a = 'i;\n" + - "'st*;\n" + - "'a = 'c;"; + String s2 = "int '_a = '_i;\n" + + "'_st*;\n" + + "'_a = '_c;"; String s3 = "$st$;\n" + "$c$ = $i$;"; @@ -2092,9 +2092,9 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { actualResult ); - String s2_2 = "int 'a = 'i;\n" + - "'st*;\n" + - "int 'c = 'a;"; + String s2_2 = "int '_a = '_i;\n" + + "'_st*;\n" + + "int '_c = '_a;"; String s3_2 = "$st$;\n" + "int $c$ = $i$;"; String expected_2 = "a = 2;\nint b = 1;\nb2 = 3;"; @@ -2123,7 +2123,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { public void testReplaceMultipleFieldsInSingleDeclaration() { String source = "abstract class MyClass implements java.util.List {\n private String a, b;\n}"; - String search = "class 'Name implements java.util.List {\n 'ClassContent*\n}"; + String search = "class 'Name implements java.util.List {\n '_ClassContent*\n}"; String replace = "class $Name$ {\n $ClassContent$\n}"; String expectedResult = "abstract class MyClass {\n private String a,b;\n}"; @@ -2139,7 +2139,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { String source = "import java.io.Externalizable;\n" + "import java.io.Serializable;\n" + "abstract class MyClass implements Serializable, java.util.List, Externalizable {}"; - String search = "class 'TestCase implements java.util.List, 'others* {\n 'MyClassContent\n}"; + String search = "class 'TestCase implements java.util.List, '_others* {\n '_MyClassContent\n}"; String replace = "class $TestCase$ implements $others$ {\n $MyClassContent$\n}"; String expectedResult = "import java.io.Externalizable;\n" + "import java.io.Serializable;\n" + @@ -2158,7 +2158,7 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase { " public void foo() {\n" + " }\n" + "}"; - String search = "class 'Class {\n 'Content*\n}"; + String search = "class 'Class {\n '_Content*\n}"; String replace = "class $Class$ {\n" + " void x() {}\n" + " $Content$\n" + diff --git a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java index ef53d82b13ed..fbc3533e6887 100644 --- a/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java +++ b/platform/structuralsearch/testSource/com/intellij/structuralsearch/StructuralSearchTest.java @@ -826,7 +826,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase { String s10031 = "try { a(); } catch(Exception ex) {} catch(Error error) { 1=1; }\n" + "try { a(); } catch(Exception ex) {}"; - String s10032 = "try { a(); } catch('_Type+ 'Arg+) { 'Statements*; }\n"; + String s10032 = "try { a(); } catch('_Type+ 'Arg+) { '_Statements*; }\n"; assertEquals( "finally matching", 2, @@ -2440,12 +2440,12 @@ public class StructuralSearchTest extends StructuralSearchTestCase { "@Foo(value2=baz4) int a3;\n" + "}"; String s12 = "@Foo(value=baz) int 'a;)"; - String s12_2 = "@Foo(value='baz:baz2 ) int 'a;)"; - String s12_3 = "@Foo('value:value2 = baz3 ) int 'a;)"; - String s12_4 = "@Foo('value:value2 = 'baz3:baz3 ) int 'a;)"; - String s12_5 = "@Foo('value:value2 = 'baz3:baz ) int 'a;)"; - String s12_6 = "@Foo('value:value2 = 'baz3 ) int 'a;)"; - String s12_7 = "@Foo('value:value2 = ) int 'a;"; + String s12_2 = "@Foo(value='baz:baz2 ) int '_a;)"; + String s12_3 = "@Foo('value:value2 = baz3 ) int '_a;)"; + String s12_4 = "@Foo('value:value2 = '_baz3:baz3 ) int '_a;)"; + String s12_5 = "@Foo('value:value2 = '_baz3:baz ) int '_a;)"; + String s12_6 = "@Foo('value:value2 = '_baz3 ) int '_a;)"; + String s12_7 = "@Foo('value:value2 = ) int '_a;"; assertEquals("Find anno parameter value",1,findMatchesCount(s11,s12)); assertEquals("Find anno parameter value",2,findMatchesCount(s11,s12_2));