Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
291,800
void () { String s1 = """ class X {{ class A {} class B extends A { static void foo(); } class B2 extends A { static void foo(int a); } class B3 extends A { static void foo(int a, int b); } class C { static void foo(); } B.foo(); B2.foo(1); B3.foo(2,3); C.foo(); }}"""; assertEquals("Find static methods within expr type hierarchy", 3, findMatchesCount(s1, "'_Instance:[regex( *A )].'_Method:[regex( foo )] ( '_Params* )")); String s2 = """ import static java.lang.String.valueOf; class A { void x() { valueOf(1); } } class B { void x() { valueOf(1); } void valueOf(int i) {} }"""; assertEquals("matching implicit class qualifier within hierarchy", 1, findMatchesCount(s2, "'_Q?:*Object .'_m:valueOf ('_a)")); }
testFindStaticMethodsWithinHierarchy
291,801
void () { String s1 = """ class A implements I {} interface I {} class B extends A implements I { } class B2 implements I { } class B3 extends A { } class C extends B2 { static void foo(); } """; assertEquals("Find class within type hierarchy with not", 1, findMatchesCount(s1, "class '_ extends '_Extends:[!regex( *A )] implements '_Implements:[regex( *I )] {}")); assertEquals("Find class within type hierarchy with not 2", 2, findMatchesCount(s1, "class '_C:[!regex( *A )] implements '_Implements:[regex( *I )] {}")); assertEquals("Find class within type hierarchy with not 3", 1, findMatchesCount(s1, "class '_ extends '_Extends:[!regex( *A )]{}")); assertEquals("Search in hierarchy on class identifier", 2, findMatchesCount(s1, "class '_X:*B2 {}")); String in2 = """ class A {} class B extends A {{ new Object() {}; new A() {}; new B() {}; new B(); new Object(); }}"""; assertEquals("Find anonymous class in hierarchy", 2, findMatchesCount(in2, "new '_X:*A () {}")); assertEquals("Find new expression in hierarchy", 3, findMatchesCount(in2, "new '_X:*A ()")); assertEquals("Find anonymous class in hierarchy negated", 1, findMatchesCount(in2, "new '_X:!*A () {}")); String in3 = """ class A {} class B extends A {} class C extends B {} class D extends Object {}"""; assertEquals("Find in hierarchy negated on class identifier", 1, findMatchesCount(in3, "class '_X:!*A {}")); }
testFindClassesWithinHierarchy
291,802
void () { String s1 = """ class X {{ try { conn = 1; } finally { conn.close(); } try { conn = 1; } finally { int a = 1; } try { conn = 1; } finally { int a = 1; } }}"""; String s2 = "try { '_StatementBefore*; '_Dcl:[regex( conn = 1 )]; '_StatementAfter*; } finally { '_Finally*:[!regex( .*conn.* ) ]; }"; assertEquals("FindTryWithoutProperFinally", 2, findMatchesCount(s1,s2)); }
testFindTryWithoutProperFinally
291,803
void () { String s1 = """ public class DiallingNumber extends DataGroup { protected static byte [] CLEAR = { }; private static DataItemTemplate template; \tprotected DataTemplate createDefaultTemplate() \t{ return null; } }"""; String s2 = """ class '_Class { static '_FieldType '_FieldName:.*template.* = '_FieldInitial?; '_RetType createDefaultTemplate() { '_Statements*; } \t'_Content* }"""; assertEquals("Bug in class matching", 1, findMatchesCount(s1,s2)); }
testBug
291,804
void () { String s1 = """ public class DiallingNumber { static { int a = 1; } static { int b = 1; } { int c = 2; } }"""; assertEquals("Static / instance initializers", 2, findMatchesCount(s1, "static { '_t*; }")); assertEquals("Static / instance initializers", 1, findMatchesCount(s1, "@Modifier(\"Instance\") { '_t*; }")); assertEquals("Static / instance initializers", 3, findMatchesCount(s1, "{ '_t*; }")); }
testStaticInstanceInitializers
291,805
String () { return PlatformTestUtil.getCommunityPath() + "/platform/structuralsearch/testData/java/"; }
getTestDataPath
291,806
void () { '_t*:[ !regex( .*return.* ) ]; }
run
291,807
void () { String source = """ class X { void x() { y(); } void y() {} void z() { z(); } void a() { a(); } }"""; String pattern = """ void '_a() { '_a(); }"""; assertEquals(2, findMatchesCount(source, pattern)); }
testFindRecursiveCall
291,808
void () { String s1 = """ class A { int bbb(int c, int ddd, int eee) { int a = 1; try { int b = 1; } catch(Type t) { a = 2; } catch(Type2 t2) { a = 3; } } }"""; final List<PsiVariable> vars = new ArrayList<>(); @SuppressWarnings("deprecation") final PsiFile file = PsiFileFactory.getInstance(getProject()).createFileFromText("_.java", s1); //noinspection AnonymousInnerClassMayBeStatic file.acceptChildren(new JavaRecursiveElementWalkingVisitor() { @Override public void visitVariable(final @NotNull PsiVariable variable) { super.visitVariable(variable); vars.add(variable); } }); assertEquals(7, vars.size()); MatchOptions options = new MatchOptions(); options.fillSearchCriteria("try { '_st*; } catch('_Type 't+) { '_st2*; }"); options.setFileType(JavaFileType.INSTANCE); List<MatchResult> results = new ArrayList<>(); for(PsiVariable var:vars) { final List<MatchResult> matchResult = new Matcher(getProject(), options).matchByDownUp(var); results.addAll(matchResult); assertTrue((var instanceof PsiParameter && var.getParent() instanceof PsiCatchSection && !matchResult.isEmpty()) || matchResult.isEmpty()); } assertEquals(2, results.size()); MatchResult result = results.get(0); assertEquals("t", result.getMatchImage()); result = results.get(1); assertEquals("t2", result.getMatchImage()); results.clear(); options.fillSearchCriteria("try { '_st*; } catch('Type:Type2 '_t) { '_st2*; }"); for(PsiVariable var:vars) { final PsiTypeElement typeElement = var.getTypeElement(); final List<MatchResult> matchResult = new Matcher(getProject(), options).matchByDownUp(typeElement); results.addAll(matchResult); assertTrue((var instanceof PsiParameter && var.getParent() instanceof PsiCatchSection && !matchResult.isEmpty()) || matchResult.isEmpty()); } assertEquals(1, results.size()); result = results.get(0); assertEquals("Type2", result.getMatchImage()); }
testDownUpMatch
291,809
void () { String s1 = """ class X {{ int a; a = 1; } { int b = 1; b = 1; } { int c = 2; c = 2; }}"""; assertEquals(2, findMatchesCount(s1, "{ '_a*:[contains( \"'type '_a = '_b;\" )]; }")); assertEquals(1, findMatchesCount(s1, "{ '_a*:[!contains( \"'_type '_a = '_b;\" )]; }")); }
_testContainsPredicate
291,810
void () { String s1 = """ class X {{ if (true) { int a = 1; } if (true) { int b = 1; } while(true) { int c = 2; } }}"""; String s2 = "[within( \"if ('_a) { '_st*; }\" )]'_type 'a = '_b;"; assertEquals(2,findMatchesCount(s1, s2)); String s2_2 = "[!within( \"if ('_a) { '_st*; }\" )]'_type 'a = '_b;"; assertEquals(1,findMatchesCount(s1, s2_2)); String s3 = """ class X {{ if (true) { if (true) return; int a = 1; } else if (true) { int b = 2; return; } int c = 3; }}"""; assertEquals(2,findMatchesCount(s3, s2)); assertEquals(1,findMatchesCount(s3, s2_2)); }
testWithinPredicate
291,811
void () { String s3 = """ class C { void aaa() { LOG.debug(1); LOG.debug(2); LOG.debug(3); LOG.debug(4); LOG.debug(5); if (true) { LOG.debug(6); } if (true) LOG.debug(7); if (true) { int L = 1; } else { LOG.debug(8); } if (true) { if (true) {} if (true) {} } else{ LOG.debug(9); } } }"""; String s4 = "[!within( \"if('_a) { 'st*; }\" )]LOG.debug('_params*);"; assertEquals(7,findMatchesCount(s3, s4)); }
testWithinPredicate2
291,812
void () { String s = "class X {{ Integer i; i.valueOf(); }}"; assertEquals(1, findMatchesCount(s, "Integer '_i;\n'_i.valueOf();")); String s_2 = "class X {{ Integer i; int a = 1; i.valueOf(); }}"; assertEquals(1, findMatchesCount(s_2, "Integer '_i;\n'_st; '_i.valueOf();")); String pattern = "Integer '_i;\n'_st*; '_i.valueOf();"; assertEquals(1, findMatchesCount(s_2, pattern)); assertEquals(1, findMatchesCount(s, pattern)); }
testMultiStatementPatternWithTypedVariable
291,813
void () { String s = "interface Foo {} interface Bar {} @interface X {}"; String s2 = "@interface 'x {}"; assertEquals(1, findMatchesCount(s,s2)); }
testFindAnnotationDeclarations
291,814
void () { String s = "class Foo {} class Bar {} enum X {}"; assertEquals(1, findMatchesCount(s, "enum 'x {}")); String in = """ enum E { A(1), B(2), C(3) }"""; assertEquals(1, findMatchesCount(in, "enum '_E { 'A(2) }")); assertEquals(0, findMatchesCount(in, "enum '_E { 'A('_x{0,0}) }")); assertEquals(0, findMatchesCount(in, "enum '_E { 'A(2) {} }")); }
testFindEnums
291,815
void () { String in = """ public class F { static Category cat = Category.getInstance(F.class.getName()); Category cat2 = Category.getInstance(F.class.getName()); Category cat3 = Category.getInstance(F.class.getName()); }"""; String pattern = "static '_Category '_cat = '_Category.getInstance('_Arg);"; assertEquals(1, findMatchesCount(in, pattern)); String in2 = """ class X { private String s = new String(); }"""; assertEquals(1, findMatchesCount(in2, "'_X '_a = new '_X();")); }
testFindDeclaration
291,816
void () { String source = "class X {{ String.format(\"\"); String.format(\"\", 1); String.format(\"\", 1, 2); String.format(\"\", 1, 2, 3); }}"; String pattern = "'_Instance.'_MethodCall('_Parameter{2,3})"; assertEquals(2, findMatchesCount(source, pattern)); }
testFindMethodCallWithTwoOrThreeParameters
291,817
void () { String source = """ class A { void a() {} void b() throws E1 {} void c() throws E1, E2{} void d() throws E1, E2, E3 {} }"""; String pattern1 = """ class '_A { '_type 'method() throws '_E{0,0}; }"""; assertEquals(1, findMatchesCount(source, pattern1)); String pattern2 = """ class '_A { '_type 'method () throws '_E{1,2}; }"""; assertEquals(2, findMatchesCount(source, pattern2)); String pattern3 = """ class '_A { '_type 'method () throws '_E{2,2}; }"""; assertEquals(1, findMatchesCount(source, pattern3)); String pattern4 = """ class '_A { '_type 'method () throws '_E{0,0}:[ regex( E2 ) ]; }"""; assertEquals(2, findMatchesCount(source, pattern4)); }
testFindMethodWithCountedExceptionsInThrows
291,818
void () { String source = """ class A { void a() {} static void b() {} void c() { a(); b(); } } class B extends A { void d() { a(); b(); } }"""; String pattern1 = "this.a()"; assertEquals(2, findMatchesCount(source, pattern1)); }
testFindMethodsCalledWithinClass
291,819
void () {}
b
291,820
void () { String source = """ class A { String value; A(String v) { value = (value); System.out.println(((2))); System.out.println(2); } }"""; String pattern1a = "'_value='_value"; assertEquals(1, findMatchesCount(source, pattern1a)); String pattern1b = "System.out.println('_v);\n" + "System.out.println('_v);"; assertEquals(1, findMatchesCount(source, pattern1b)); String source2 = """ class B {{ System.out.println((3 * 8) + 2 + (((2)))); }}"""; String pattern2 = "3 * 8 + 2 + 2"; assertEquals(1, findMatchesCount(source2, pattern2)); String source3 = """ class C { static int foo() { return (Integer.parseInt("3")); } }"""; String pattern3 = "Integer.parseInt('_x)"; assertEquals(1, findMatchesCount(source3, pattern3)); String source4 = """ class X {{ (System.out).println(1); }}"""; String pattern4 = "System.out.println('_x);"; assertEquals(1, findMatchesCount(source4, pattern4)); }
testFindReferenceWithParentheses
291,821
int () { return (Integer.parseInt("3")); }
foo
291,822
void () { String source = """ class A { protected String s; A(String t) { this.s = s; t = t; s = this.s; } } class B extends A { B(String t) { super.s = s; } }"""; String pattern = "'_var='_var"; assertEquals(4, findMatchesCount(source, pattern)); }
testFindSelfAssignment
291,823
void () { String source = """ class LambdaParameter { void x() { String s; java.util.function.Consumer<String> c = a -> System.out.println(a); java.util.function.Consumer<String> c2 = a -> System.out.println(a); } }"""; assertEquals("should find lambda parameter", 3, findMatchesCount(source, "String '_a;")); assertEquals("should find lambda parameter 2", 1, findMatchesCount(source, "'_T:String '_a;")); assertEquals("should find lambda parameter 3", 3, findMatchesCount(source, "'_T?:String '_a;")); assertEquals("should find lambda parameter 4", 2, findMatchesCount(source, "'_T{,0}:String '_a;")); }
testFindLambdaParameter
291,824
void () { String source = """ public interface IntFunction<R> { R apply(int value); } public interface Function<T, R> { R apply(T t); } class A { void m() { Runnable q = () -> { /*comment*/ }; Runnable r = () -> { System.out.println(); }; IntFunction<String> f = a -> "hello"; Function<String, String> g = a -> "world"; } }"""; String pattern1 = "() -> '_body"; assertEquals("should find lambdas", 4, findMatchesCount(source, pattern1)); String pattern2 = "(int '_a) -> '_body"; assertEquals("should find lambdas with specific parameter type", 1, findMatchesCount(source, pattern2)); String pattern3 = "('_a{0,0})->'_body"; assertEquals("should find lambdas without any parameters", 2, findMatchesCount(source, pattern3)); String pattern4 = "()->System.out.println()"; assertEquals("should find lambdas with matching body", 1, findMatchesCount(source, pattern4)); String pattern5 = "()->{/*comment*/}"; assertEquals("should find lambdas with comment body", 1, findMatchesCount(source, pattern5)); String pattern6 = "('_Parameter+) -> System.out.println()"; assertEquals("should find lambdas with at least one parameter and matching body", 0, findMatchesCount(source, pattern6)); String typePattern = "'_X:[exprtype( Runnable )]"; assertEquals("should find Runnable lambda's", 2, findMatchesCount(source, typePattern)); String source2 = """ import java.util.function.Function; public class Test { public static void main(String[] args) { System.out.println(Function.<String>identity().andThen((a) -> { String prefix = a; return new Function<String, String>() { @Override public String apply(String b) { return prefix + b; } }; }).apply("a").apply("b")); } }"""; String pattern7 = """ (a) -> { '_Statement; return new Function<String, String>() { public String apply(String b) { '_Statement2; } }; }"""; assertEquals("match statement body correctly", 1, findMatchesCount(source2, pattern7)); String source3 = """ class LambdaParameter { void x() { Runnable r = (var a) -> a = ""; } }"""; String pattern8 = "String '_x;"; assertEquals("avoid IncorrectOperationException", 0, findMatchesCount(source3, pattern8)); String source4 = """ class Main2 { public static void main(String[] args) { //need to match this JSTestUtils.testES6("myProject", () -> { doTest1(); doTest2(); }); } private static void doTest1() { } private static void doTest2() { } static class JSTestUtils { private JSTestUtils() { } static void testES6(Object project, Runnable runnable) { runnable.run(); } } }"""; String pattern9 = """ JSTestUtils.testES6('_expression, () -> { '_statements*; })"""; assertEquals("match lambda body correctly", 1, findMatchesCount(source4, pattern9)); String source5 = """ class X { void x() { Runnable r = () -> {}; } }"""; String pattern10 = "() -> '_B"; assertEquals("match empty lambda expression body", 1, findMatchesCount(source5, pattern10)); final String pattern11 = "() -> { '_body*; }"; assertEquals("match empty lambda expression body 2", 1, findMatchesCount(source5, pattern11)); String source6 = """ class X { void x() { Runnable r = () -> { // comment System.out.println(); System.out.println(); }; } }"""; assertEquals("match lambda code block body", 1, findMatchesCount(source6, pattern10)); assertEquals("match lambda body starting with comment", 1, findMatchesCount(source6, pattern11)); }
testFindLambdas
291,825
void (String[] args) { System.out.println(Function.<String>identity().andThen((a) -> { String prefix = a; return new Function<String, String>() { @Override public String apply(String b) { return prefix + b; } }; }).apply("a").apply("b")); }
main
291,826
String (String b) { return prefix + b; }
apply
291,827
String (String b) { '_Statement2; }
apply
291,828
void (String[] args) { //need to match this JSTestUtils.testES6("myProject", () -> { doTest1(); doTest2(); }); }
main
291,829
void () { }
doTest1
291,830
void () { }
doTest2
291,831
void (Object project, Runnable runnable) { runnable.run(); }
testES6
291,832
void () { String source = """ interface XYZ { default void m() { System.out.println(); } void f(); void g(); } 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", 3, findMatchesCount(source, pattern2)); String pattern3 = "default '_ReturnType 'MethodName('_ParameterType '_Parameter*);"; assertEquals("find naked default method", 1, findMatchesCount(source, pattern3)); }
testFindDefaultMethods
291,833
void () { String source = """ class A { Runnable r = System.out::println; Runnable s = this::hashCode; Runnable t = this::new; Runnable u = @AA A::new; static { System.out.println(); } }"""; String pattern1 = "System . out :: println"; assertEquals("should find method reference", 1, findMatchesCount(source, pattern1)); String pattern2 = "this::'_a"; assertEquals("should find method reference 2", 2, findMatchesCount(source, pattern2)); String pattern3 = "'_a::'_b"; assertEquals("should find all method references", 4, findMatchesCount(source, pattern3)); String pattern4 = "@AA A::new"; assertEquals("should find annotated method references", 1, findMatchesCount(source, pattern4)); String pattern5 = "'_X:[exprtype( Runnable )]"; assertEquals("should find Runnable method references", 4, findMatchesCount(source, pattern5)); }
testFindMethodReferences
291,834
void () { 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);")); String s2 = """ class X { void x() { x(); } }"""; assertEquals("don't throw exception during matching", 0, findMatchesCount(s2, """ void '_x() { '_x; }""")); }
testNoException
291,835
void () { String source = ""; try { findMatchesCount(source, "/*$A$a*/"); fail("malformed pattern warning expected"); } catch (MalformedPatternException ignored) {} try { findMatchesCount(source, "class $A$Visitor {}"); fail("malformed pattern warning expected"); } catch (MalformedPatternException ignored) { } try { String pattern3 = """ class $Class$ { class $n$$FieldType$ $FieldName$ = $Init$; }"""; findMatchesCount(source, pattern3); fail("malformed pattern warning expected"); } catch (MalformedPatternException ignored) {} try { findMatchesCount(source, "@SuppressWarnings(\\\"NONE\\\") @Deprecated"); fail("malformed pattern warning expected"); } catch (MalformedPatternException ignored) {} }
testNoUnexpectedException
291,836
void () { final String source = ""; try { findMatchesCount(source, "import java.util.ArrayList;"); fail("malformed pattern warning expected"); } catch (MalformedPatternException ignored) {} try { findMatchesCount(source, "\\'aa\\'"); fail("malformed pattern warning expected"); } catch (MalformedPatternException ignored) {} try { findMatchesCount(source, "\\'$var$ \\'"); fail("malformed pattern warning expected"); } catch (MalformedPatternException ignored) {} try { findMatchesCount(source, "0x100000000"); fail("malformed pattern warning expected"); } catch (MalformedPatternException ignored) {} try { findMatchesCount(source, "assert '_C;\n" + "System.out.println("); fail("malformed pattern warning expected"); } catch (MalformedPatternException ignored) {} try { findMatchesCount(source, "get'_property()"); fail("malformed pattern warning expected"); } catch (MalformedPatternException ignored) {} try { findMatchesCount(source, "'_exp // asdf"); fail("malformed pattern warning expected"); } catch (MalformedPatternException ignored) {} try { findMatchesCount(source, "<'_E extends '_T>"); fail("don't hide malformed patterns"); } catch (MalformedPatternException ignored) {} }
testInvalidPatternWarnings
291,837
void () { final CompiledPattern pattern = compilePattern("class A extends '_B* {}", true); assertEquals("MAXIMUM UNLIMITED not applicable for B", checkApplicableConstraints(options, pattern)); assertEquals("MINIMUM ZERO not applicable for b", checkApplicableConstraints(options, compilePattern("'_a?.'_b?", true))); assertNull(checkApplicableConstraints(options, compilePattern("case '_a* :", true))); assertEquals("TEXT HIERARCHY not applicable for a", checkApplicableConstraints(options, compilePattern("int '_a:* ;", true))); assertEquals("TEXT HIERARCHY not applicable for a", checkApplicableConstraints(options, compilePattern("void '_a:* ();", true))); assertEquals("MINIMUM ZERO not applicable for st", checkApplicableConstraints(options, compilePattern("if (true) '_st{0,0};", true))); assertEquals("MAXIMUM UNLIMITED not applicable for st", checkApplicableConstraints(options, compilePattern("while (true) '_st+;", true))); assertNull(checkApplicableConstraints(options, compilePattern("class A { '_body* }", false))); assertEquals("MINIMUM ZERO not applicable for var", checkApplicableConstraints(options, compilePattern("'_a instanceof ('_Type '_var{0,0})", true))); }
testApplicableConstraints
291,838
CompiledPattern (String criteria, boolean checkForErrors) { options.fillSearchCriteria(criteria); options.setFileType(JavaFileType.INSTANCE); return PatternCompiler.compilePattern(getProject(), options, checkForErrors, false); }
compilePattern
291,839
void () { String source = """ class Foo { static class Bar {} } class A {{ new Foo.Bar(); }}"""; String pattern = "new Foo.Bar();"; assertEquals("should find qualified with outer class", 1, findMatchesCount(source, pattern)); }
testFindInnerClass
291,840
void () { String source = """ abstract class A<T/*1*/> implements java.util.List<T/*2*/>, /*3*/java.io.Serializable { @SuppressWarnings({"one",/*10*/ "two"}) public /*11*/ static void m(/*12*/) { System./*4*/out.println(/*5*/); A<String/*6*/> a1 = new A(){}; int i = 1 + /*7*/ + 2; try (java.io.FileInputStream /*8*/in = new java.io.FileInputStream("name")) { } catch (java.lang./*9*/Exception e) { } } }"""; String pattern = "/*$Text$*/"; assertEquals("should find comments in all the right places", 12, findMatchesCount(source, pattern)); String source2 = """ package /*test*/ xxx; import /*test*/ java.util.*; public class XXX {}"""; String pattern2 = "/*test*/"; assertEquals("find comments in package and import statements", 2, findMatchesCount(source2, pattern2)); String source3 = """ class X { void m() { System.out.println(); // tokamak } }"""; String pattern3 = "'_st;\n" + "// tokamak"; assertEquals("find statement followed by comment", 1, findMatchesCount(source3, pattern3)); String source4 = "/*"; String pattern4 = "//'_comment:[regex( .* )]"; assertEquals("no error on broken code", 1, findMatchesCount(source4, pattern4)); }
testFindCommentsEverywhere
291,841
void () { String source = """ /* HELLO */ class A<T> { private char b = 'C'; void m() { @X String s = ""; s.equals(""); s = s; this.b = 'D'; } }"""; String pattern1 = "a"; assertEquals("should find symbol case insensitively", 1, findMatchesCount(source, pattern1)); String pattern2 = "class a {}"; assertEquals("should find class case insensitively", 1, findMatchesCount(source, pattern2)); String pattern3 = "/* hello */"; assertEquals("should find comment case insensitively", 1, findMatchesCount(source, pattern3)); String pattern4 = "'c'"; assertEquals("should find character literal case insensitively", 1, findMatchesCount(source, pattern4)); String pattern5 = "char B = '_initializer;"; assertEquals("should find variable case insensitively", 1, findMatchesCount(source, pattern5)); String pattern6 = "class '_a<t> {}"; assertEquals("should find type parameter case insensitively", 1, findMatchesCount(source, pattern6)); String pattern7 = """ class '_A { void M(); }"""; assertEquals("should find class with method case insensitively", 1, findMatchesCount(source, pattern7)); String pattern8 = "'_a.EQUALS('_b)"; assertEquals("should find method call case insensitively", 1, findMatchesCount(source, pattern8)); String pattern9 = "S.'_call('_e)"; assertEquals("should find qualifier case insensitively", 1, findMatchesCount(source, pattern9)); String pattern10 = "S = S"; assertEquals("should find reference case insensitively", 1, findMatchesCount(source, pattern10)); String pattern11 = "this.B"; assertEquals("should find qualified reference case insensitively", 1, findMatchesCount(source, pattern11)); String pattern12 = "@x"; assertEquals("should find annotation case insensitively", 1, findMatchesCount(source, pattern12)); }
testCaseInsensitive
291,842
void () { String source = """ class A {{ try (InputStream in = new FileInputStream("tmp")) { } try { } catch (FileNotFoundException e) { } finally {} try { } catch(NullPointerException | UnsupportedOperationException e) { throw e; } catch(Exception e) { throw new RuntimeException(e); } finally {} try { throw new NoRouteToHostException(); } catch (NoRouteToHostException e) { System.out.println(); } catch (SocketException e) { System.out.println(); } catch (IOException e) { } catch (RuntimeException e) { System.out.println(); } finally {} }}"""; String pattern1 = "try ('_ResourceType '_Var = '_exp) { '_Statement*; }"; assertEquals("Find try-with-resources", 1, findMatchesCount(source, pattern1)); String pattern2 = "try { '_St1*; } catch ('_ExceptionType1 '_e1) { '_St2*; } catch ('_ExceptionType2 '_e2) { '_St3*; }"; assertEquals("Find try with two or more catch blocks", 2, findMatchesCount(source, pattern2)); String pattern3 = "try { '_St1*; } finally { '_St2*; }"; assertEquals("Find try with finally block", 3, findMatchesCount(source, pattern3)); String pattern4 = "try { '_St1*; } catch (NullPointerException | IllegalArgumentException '_e) { '_St2*; }"; assertEquals("Match multi catch correctly", 0, findMatchesCount(source, pattern4)); String pattern5 = "try { '_St1*; } catch (UnsupportedOperationException | NullPointerException '_e) { '_St2*; }"; assertEquals("Find multi catch", 1, findMatchesCount(source, pattern5)); String pattern6 = "try { '_St1*; } catch ('_E1 | '_E2 '_e) { '_St2*; }"; assertEquals("Find multi catch with variables", 1, findMatchesCount(source, pattern6)); String pattern7 = "try { '_St1*; } catch ('E '_e) { '_St2*; }"; final List<MatchResult> matches = findMatches(source, pattern7); assertEquals(3, matches.size()); assertEquals("NullPointerException | UnsupportedOperationException", matches.get(1).getMatchImage()); String pattern8 = "try { '_St1*; } catch ('_E '_e{2,2}) { '_St2*; }"; final List<MatchResult> matches2 = findMatches(source, pattern8); assertEquals(1, matches2.size()); assertEquals("Find try with exactly 2 catch blocks", """ try { } catch(NullPointerException | UnsupportedOperationException e) { throw e; } catch(Exception e) { throw new RuntimeException(e); } finally {}""", matches2.get(0).getMatchImage()); String pattern9 = "try { '_st1*; } catch ('_E '_e{0,0}) { '_St2*; }"; final List<MatchResult> matches3 = findMatches(source, pattern9); assertEquals(1, matches3.size()); assertEquals("Should find try without catch blocks", "try (InputStream in = new FileInputStream(\"tmp\")) {\n" + " }", matches3.get(0).getMatchImage()); String source2 = """ class X {{ try {} catch (Thowable e) {} finally {} try {} finally {} }}"""; String pattern10 = "try { '_st1*; } catch ('_E '_e{0,0}) { '_St2*; } finally { '_St3*; }"; final List<MatchResult> matches4 = findMatches(source2, pattern10); assertEquals(1, matches4.size()); assertEquals("Should find try without catch blocks", "try {} finally {}", matches4.get(0).getMatchImage()); }
testFindTry
291,843
void () { String source = """ class A { void f(int i) { assert i > 0; assert i < 10 : "i: " + i; assert i == 5; } }"""; assertEquals("find assert statements", 3, findMatchesCount(source, "assert '_a;")); assertEquals("find assert statements 2", 3, findMatchesCount(source, "assert '_a : '_b?;")); assertEquals("find assert statement with messages", 1, findMatchesCount(source, "assert '_a : '_b;")); assertEquals("find assert statement without messages", 2, findMatchesCount(source, "assert 'a : '_b{0,0};")); }
testFindAsserts
291,844
void () { String source = """ class A { void f() { int i = 1 + 2; int j = 1 + 2 + 3; int k = 1 + 2 + 3 + 4; } }"""; assertEquals("find polyadic expression", 3, findMatchesCount(source, "'_a + '_b+")); assertEquals("find polyadic expression of 3 operands", 1, findMatchesCount(source, "'_a + '_b{2,2}")); assertEquals("find polyadic expression of >3 operands", 2, findMatchesCount(source, "'_a + '_b{2,100}")); }
testPolyadicExpression
291,845
void () { String source = """ class A { int i; int j, /*1*/ k; int l, /*2*/ m, n; { int o, p, q; } }"""; assertEquals("find multiple fields in one declaration 1", 3, findMatchesCount(source, "'_a '_b{2,100};")); assertEquals("find multiple fields in one declaration 2", 3, findMatchesCount(source, "int '_b{2,100};")); assertEquals("find multiple fields in one declaration 2", 2, findMatchesCount(source, "int '_b{3,3};")); assertEquals("find declarations with only one field", 1, findMatchesCount(source, "int '_a;")); assertEquals("find all declarations", 4, findMatchesCount(source, "int '_a+;")); assertEquals("find all fields & vars", 9, findMatchesCount(source, "int 'a;")); options.setPatternContext(JavaStructuralSearchProfile.MEMBER_CONTEXT); assertEquals("find all fields", 6, findMatchesCount(source, "int 'x;")); options.setPatternContext(JavaStructuralSearchProfile.DEFAULT_CONTEXT); String source2 = """ class ABC { String u; String s,t; void m() {} }"""; assertEquals("find incomplete code", 1, findMatchesCount(source2, "'_a '_b{2,100};")); }
testMultipleFieldsInOneDeclaration
291,846
void () { String source = """ class X { static {} static {} static { System.out.println(); } void one() {} void two() { System.out.println(); } <T> T three() { return null; } }"""; assertEquals("find with simple method pattern", 2, findMatchesCount(source, "void '_a();")); assertEquals("find with simple method pattern 2", 1, findMatchesCount(source, "void one();")); assertEquals("find with simple method pattern 3", 3, findMatchesCount(source, "'_t '_a('_pt '_p*);")); assertEquals("find with simple generic method pattern", 1, findMatchesCount(source, "<'_+> '_Type '_Method('_ '_*);")); assertEquals("find with simple static initializer pattern", 3, findMatchesCount(source, "static { '_statement*;}")); }
testFindWithSimpleMemberPattern
291,847
void () { String source = """ class X { final int var1; void a(final int var2) { final int var3; } }"""; assertEquals("parameters and local variables are not package-private", 1, findMatchesCount(source, "@Modifier(\"packageLocal\") '_T '_a;")); assertEquals("any variable can be final", 3, findMatchesCount(source, "@Modifier(\"final\") '_T '_a;")); assertEquals("parameters and local variables are not instance fields", 1, findMatchesCount(source, "@Modifier(\"Instance\") '_T '_a;")); }
testFindPackageLocalAndInstanceFields
291,848
void () { String source = """ interface Foo { <T> T bar(); <S, T> void bar2(S s, T t); } class X { <T> X(T t) {} X() {} void x(Foo foo) { foo.<String>bar(); foo.<Integer>bar(); String s = foo.bar(); foo.bar2(1, 2); } void y(String s) { new <String>X(); new <String>X(); new X(); new X() {}; new <String>X("") {}; new <String>X(s); new <String, Integer>X(s); } }"""; assertEquals("find parameterized method calls 1", 1, findMatchesCount(source, "foo.<Integer>bar()")); assertEquals("find parameterized method calls 2", 2, findMatchesCount(source, "foo.<String>bar()")); assertEquals("find parameterized method calls 3", 3, findMatchesCount(source, "'_a.<'_b>'_c('_d*)")); assertEquals("find parameterized method calls 4", 4, findMatchesCount(source, "'_a.<'_b+>'_c('_d*)")); assertEquals("find parameterized constructor calls 1", 2, findMatchesCount(source, "new <String>X()")); assertEquals("find parameterized constructor calls 2", 1, findMatchesCount(source, "new <String>X(s)")); assertEquals("find parameterized constructor calls 3", 5, findMatchesCount(source, "new <'_a+>'_b('_c*)")); assertEquals("find parameterized constructor calls 4", 4, findMatchesCount(source, "new <'_a>'_b('_c*)")); assertEquals("find parameterized anonymous class", 1, findMatchesCount(source, "new <'_a>'_b('_c*) {}")); assertEquals("find constructor calls 3", 7, findMatchesCount(source, "new X('_a*)")); }
testFindParameterizedMethodCalls
291,849
void () { String source = """ class A<X, Y> {} class B {{ A<Integer, String> a1 = new A<>(); A<Integer, String> a2 = new A<Integer, String>(); A<Double, Boolean> a3 = new A<>(); A<Double, Boolean> a4 = new A<>(); }}"""; assertEquals("find diamond new expressions", 3, findMatchesCount(source, "new A<>()")); assertEquals("find parameterized new expressions", 2, findMatchesCount(source, "new A<Integer, String>()")); assertEquals("find non-diamond", 1, findMatchesCount(source, "new A<'_p{1,100}>()")); }
testFindDiamondTypes
291,850
void () { String source = """ class A { public String toString() { System.out.println(); if (false) { toString(); this.toString(); } return super.toString(); } }"""; assertEquals("find super call", 1, findMatchesCount(source, "super.'_m()")); assertEquals("find super and non super call", 2, findMatchesCount(source, "'_q:[regex( super|this )].'_m()")); String source2 = """ class A { public boolean equals(Object o) { return super.equals(o); } }"""; assertEquals("find method with super call and matching parameter", 1, findMatchesCount(source2, "'_rt '_m('_t '_p*) { return super.'_m('_p); }")); }
testFindSuperCall
291,851
String () { System.out.println(); if (false) { toString(); this.toString(); } return super.toString(); }
toString
291,852
boolean (Object o) { return super.equals(o); }
equals
291,853
void () { String source1 = """ class Two { Two x; void f() { Two a = x.x.x; Two b = x.x.x.x; } }"""; assertEquals(1, findMatchesCount(source1, "x.x.x.'_x")); String source2 = """ import static java.lang.String.*; class One { void f() { valueOf(1); String.valueOf(1); java.lang.String.valueOf(1); Integer.valueOf(1); } }"""; assertEquals(3, findMatchesCount(source2, "java.lang.String.valueOf(1)")); assertEquals(3, findMatchesCount(source2, "String.valueOf(1)")); assertEquals(3, findMatchesCount(source2, "'_a?:[regex( String )].valueOf(1)")); assertEquals(4, findMatchesCount(source2, "valueOf(1)")); String source3 = """ class Three { Three t$; void f() { Three a = t$.t$.t$; } }"""; assertEquals(2, findMatchesCount(source3, "t$.'_t")); String source4 = """ import java.util.*; class Four {{ System.out.println(Calendar.YEAR); }}"""; assertEquals(1, findMatchesCount(source4, "System.out.println(Calendar.YEAR)")); assertEquals(1, findMatchesCount(source4, "System.out.println(java.util.Calendar.YEAR)")); assertEquals(1, findMatchesCount(source4, "System.out.println(YEAR)")); }
testFindWithQualifiers
291,854
void () { String source1 = """ import java.util.*; class X { void x() { ArrayList<String> fooList = new ArrayList<>(); ArrayList<Integer> barList = new ArrayList<>(); someStuff(fooList); // find this! someStuff(barList); // don't find this one someStuff(Collections.singletonList(1)); // also match this one } void someStuff(Iterable<?> param) {} }"""; assertEquals(3, findMatchesCount(source1, "'_Instance?.'_MethodCall:[regex( someStuff )]('_Parameter:[exprtype( *List )])")); assertEquals(3, findMatchesCount(source1, "'_Instance?.'_MethodCall:[regex( someStuff )]('_Parameter:[exprtype( *java\\.util\\.List )])")); assertEquals(1, findMatchesCount(source1, "'_Instance?.'_MethodCall:[regex( someStuff )]('_Parameter:[exprtype( *List<String> )])")); assertEquals(1, findMatchesCount(source1, "'_Instance?.'_MethodCall:[regex( someStuff )]('_Parameter:[exprtype( *java\\.util\\.List<java\\.lang\\.String> )])")); assertEquals(2, findMatchesCount(source1, "'_Instance?.'_MethodCall:[regex( someStuff )]('_Parameter:[exprtype( *List<Integer> )])")); assertEquals(2, findMatchesCount(source1, "'_Instance?.'_MethodCall:[regex( someStuff )]('_Parameter:[exprtype( *java\\.util\\.List<java\\.lang\\.Integer> )])")); String source2 = """ class X { String sss[][]; String ss[]; void x() { System.out.println(sss); } }"""; assertEquals(1, findMatchesCount(source2, "'_x:[exprtype( String\\[\\]\\[\\] )]")); assertEquals(1, findMatchesCount(source2, "'_x:[exprtype( java\\.lang\\.String\\[\\]\\[\\] )]")); String source3 = """ import java.util.*; class X { void x(Map.Entry<String, Integer> map) { System.out.println(map); } }"""; assertEquals(1, findMatchesCount(source3, "'_x:[exprtype( Map\\.Entry<String,Integer> )]")); assertEquals(1, findMatchesCount(source3, "'_x:[exprtype( Entry<String,Integer> )]")); assertEquals(1, findMatchesCount(source3, "'_x:[exprtype( Map\\.Entry )]")); assertEquals(1, findMatchesCount(source3, "'_x:[exprtype( Entry )]")); assertEquals(1, findMatchesCount(source3, "'_x:[exprtype( java\\.util\\.Map\\.Entry )]")); assertEquals(1, findMatchesCount(source3, "'_x:[exprtype( java\\.util\\.Map\\.Entry<java\\.lang\\.String,java\\.lang\\.Integer> )]")); String source4 = """ import java.util.*; class X { void x() { new AbstractList<String>() { @Override public int size() { return 0; } @Override public String get(int index) { return null; } }; } }"""; assertEquals(1, findMatchesCount(source4, "'x:[exprtype( *List )]")); assertEquals(1, findMatchesCount(source4, "'x:[exprtype( *List<String> )]")); assertEquals(1, findMatchesCount(source4, "'x:[exprtype( AbstractList )]")); assertEquals(1, findMatchesCount(source4, "'x:[exprtype( AbstractList<String> )]")); assertEquals(0, findMatchesCount(source4, "'x:[exprtype( AbstractList<Integer> )]")); String source5 = """ class X { void x() { new UnknownStranger<Johnny5>() {}; } }"""; assertEquals(1, findMatchesCount(source5, "'x:[exprtype( UnknownStranger )]")); assertEquals(1, findMatchesCount(source5, "'x:[exprtype( UnknownStranger<Johnny5> )]")); String source6 = """ class X { List<List<String>> list; List<Garbage> list2; List<Garbage> list3; void x() { System.out.println(list); System.out.println(list2); System.out.println(list3); } }"""; assertEquals(3, findMatchesCount(source6, "'x:[exprtype( List )]")); assertEquals(1, findMatchesCount(source6, "'x:[exprtype( List<List<String>> )]")); assertEquals(2, findMatchesCount(source6, "'x:[exprtype( List<Garbage> )]")); String source7 = """ class X {{ System.out.println(1.0 * 2 + 3 * 4); }}"""; assertEquals(1, findMatchesCount(source7, "[exprtype( int )]'_a * '_b")); }
testSearchTypes
291,855
int () { return 0; }
size
291,856
String (int index) { return null; }
get
291,857
void () { String source = """ class X { @Deprecated void a() {} void b() {} void c() { a(); b(); b(); } }"""; assertEquals("find calls to deprecated methods", 1, findMatchesCount(source, "'_instance?.'_call:[ref( \"@Deprecated void '_x();\" )] ()")); assertEquals("find calls to non-deprecated methods", 2, findMatchesCount(source, "'_instance?.'_call:[ref( \"@'_Anno{0,0} void '_x();\" )] ()")); }
testSearchReferences
291,858
void () { String source = """ class ExampleTest { void m(String example) { synchronized (ExampleTest.class) { // comment if (example == null) { } } } }"""; assertEquals("find code ignoring comments", 1, findMatchesCount(source, "synchronized ('_a.class) { if ('_b == null) {}}")); String source2 = """ class X { int[] is = new int/*1*/[10]; int[] js = new int[1]; }"""; assertEquals("find code ignoring comments 2", 2, findMatchesCount(source2, "new int['_a]")); String source3 = """ class X {{ new java.util.ArrayList(/**/1); }}"""; assertEquals("find code ignoring comments 3", 1, findMatchesCount(source3, "new ArrayList(1)")); String source4 = """ class X { void m(int i, /**/String s) {} }"""; assertEquals("find code ignoring comments 4", 1, findMatchesCount(source4, "void m(int i, String s);")); assertEquals("find code ignoring comments 4a", 1, findMatchesCount(source4, "void m('_T '_p*);")); String source5 = """ class X {{ new String(/*nothing*/); }}"""; assertEquals("find code ignoring comments 5", 1, findMatchesCount(source5, "new String()")); assertEquals("find code ignored comments 5a", 1, findMatchesCount(source5, "new String('_a{0,0})")); String source6 = """ class X { void x() { final int x; // ok } }"""; assertEquals("find code while ignoring comments 6", 1, findMatchesCount(source6, """ '_ReturnType? '_Method('_BeforeType '_BeforeParameter*) { '_Expression1*; final '_Type? '_Var+; '_Expression2*; }""")); }
testSearchIgnoreComments
291,859
void () { final String s = """ class X { void x() { String x = null; x: System.out.println(); y: System.out.println(); } }"""; assertEquals("Find statement labels", 4, findMatchesCount(s, "x")); assertEquals("Find statement label variable", 2, findMatchesCount(s, "'_l : '_s;")); }
testFindLabeledStatements
291,860
void () { final String s = """ class X { void m() { outer: for (int i = 0; i < 10; i++) { if (i == 1) break outer; if (i == 2) break; if (i == 3) break nowhere; } } }"""; assertEquals("Find break statements", 3, findMatchesCount(s, "break;")); assertEquals("Find labeled break statements", 2, findMatchesCount(s, "break '_label;")); assertEquals("Find outer break statement", 1, findMatchesCount(s, "break outer;")); assertEquals("Find break statements without label", 1, findMatchesCount(s, "break '_label{0,0};")); final String s2 = """ class X { void m() { outer: for (int i = 0; i < 10; i++) { if (i == 3) continue outer; if (i == 4) continue; if (i == 5) continue nowhere; } } }"""; assertEquals("Find continue statements", 3, findMatchesCount(s2, "continue;")); assertEquals("Find labeled continue statements", 2, findMatchesCount(s2, "continue '_label;")); assertEquals("Find outer continue statement", 1, findMatchesCount(s2, "continue outer;")); assertEquals("Find continue statements without label", 1, findMatchesCount(s2, "continue '_label{0,0};")); }
testFindBreakContinue
291,861
void () { final String s = """ class X { void m() { var s = "hi"; String t = "bye"; } }"""; assertEquals("find var statement", 1, findMatchesCount(s, "var '_x;")); assertEquals("find String variables", 2, findMatchesCount(s, "String '_x;")); assertEquals("find String variables 2", 2, findMatchesCount(s, "var '_x = \"'_y\";")); }
testFindVarStatement
291,862
void () { final String s = """ class X { void a() { return; } int b() { return 1; } Object c() { return new Object(); } }"""; assertEquals("find return without value", 1, findMatchesCount(s, "return '_x{0,0};")); assertEquals("find return with value", 2, findMatchesCount(s, "return '_x;")); assertEquals("find returns", 3, findMatchesCount(s, "return;")); }
testFindReturn
291,863
void () { final String s = """ class X { void m() throws RuntimeException, IllegalStateException, IllegalArgumentException {} void n() throws RuntimeException {} void o() throws RuntimeException {} }"""; assertEquals("find method throwing only RuntimeException", 2, findMatchesCount(s, "'_T '_m() throws '_RE:RuntimeException , '_Other{0,0};")); assertEquals("find method throwing RuntimeException and others", 1, findMatchesCount(s, "'_T '_m() throws '_RE:RuntimeException , '_Other{1,100};")); }
testMatchInAnyOrderWithMultipleVars
291,864
void () { final String in = """ import java.util.List; class X { List a; List<String> b; List<?> c; List<? extends Object> d; List<? extends Number> e; List<? extends Number> f; List<? extends Integer> g; }"""; assertEquals("List<?> should match List<? extends Object>", 2, findMatchesCount(in, "'_A<?>")); assertEquals("List<? extends Object> should match List<?>", 2, findMatchesCount(in, "'_A<? extends Object>")); assertEquals("should match wildcards with extends bound", 4, findMatchesCount(in, "'_A<? extends '_B>")); assertEquals("should match wildcards with extends bound extending Number", 3, findMatchesCount(in, "'_A<? extends '_B:*Number >")); assertEquals("should match wildcards with or without extends bound", 5, findMatchesCount(in, "'_A<? extends '_B?>")); assertEquals("should match any generic type", 6, findMatchesCount(in, "'_A<'_B>")); assertEquals("should match generic and raw types", 7, findMatchesCount(in, "List '_x;")); assertEquals("should match generic and raw types 2", 7, findMatchesCount(in, "'_A:List <'_B? >")); }
testMatchWildcards
291,865
void () { String in = """ class X { void x(boolean b) { if (b) { System.out.println(); System.out.println(); } if (b) { System.out.println(); } else { System.out.println(); } } }"""; assertEquals("Should find if without else", 1, findMatchesCount(in, "if ('_a) '_b; else '_c{0,0};")); }
testIfStatements
291,866
void () { final String in = """ class X { void x(int i) { switch (i) { case 10: System.out.println(10); } switch (i) { case 1: default: } switch (i) { case 1: default: } switch (i) { case 1: case 2: default: } } }"""; assertEquals("Should find switch with one case", 1, findMatchesCount(in, """ switch ('_a) { case '_c : '_st*; }""")); assertEquals("should find switch with 2 cases", 2, findMatchesCount(in, """ switch ('_a) { case '_c1 : case '_c2? : }""")); assertEquals("should find swith with one case and default", 2, findMatchesCount(in, """ switch ('_a) { case '_c : '_st1*; default: '_st2*; }""")); assertEquals("should find defaults", 3, findMatchesCount(in, "default:")); assertEquals("should find cases", 5, findMatchesCount(in, "case '_a :")); assertEquals("should find cases & defaults", 8, findMatchesCount(in, "case '_a? :")); assertEquals("should match switch containing 2 statements", 3, findMatchesCount(in, """ switch ('_x) { '_st{2,2}; }""")); }
testSwitchStatements
291,867
void () { final String in = """ class X { void dummy(int i) { int j = switch (i) { case 10 -> { System.out.println(10); } default -> {} }; int k = switch (i) { case 10 -> { yield 1; } default -> 0; }; int l = switch (i) { case 1,2,3: break; case 5: break; }; } }"""; assertEquals("find expressions & statements", 2, findMatchesCount(in, """ switch (i) { case 10 -> { '_st; } default -> '_X; }""")); assertEquals("find yield statement", 1, findMatchesCount(in, "yield '_x;")); }
testFindSwitchExpressions
291,868
void () { String in = """ class SomePageObject { @FindBy(name = "first-name") private WebElement name; @FindBy(name = "first-name") private WebElement firstName; } class SomePageObject2 { @FindBy(name = "last-name") private WebElement name; @FindBy(name = "first-name") private WebElement firstName; }"""; assertEquals("find repeated annotation value", 1, findMatchesCount(in, """ class '_Class { @FindBy(name='_value) '_FieldType '_field = '_init?; @FindBy(name='_value) '_FieldType2 'field2 = '_init2?; }""")); in = """ class X {{ int[] newQueue = new int[queue.length * 2 - fwd]; System.arraycopy(queue, fwd, newQueue, 0, queue.length - fwd); }}"""; assertEquals("should not match because the p var differs", 0, findMatchesCount(in, "int[] '_params = new int['_p - '_i];\n" + "System.arraycopy('_a, '_i, '_params, 0, '_p - '_i);")); assertEquals(1, findMatchesCount(in, "int[] '_params = new int['_p * 2 - '_i];\n" + "System.arraycopy('_a, '_i, '_params, 0, '_p - '_i);")); in = """ class X { @Test(expected=IllegalArgumentException.class) public void testIt() throws IllegalArgumentException { System.out.println(); System.out.println(); } @Test(expected=IllegalArgumentException.class) public void testIt() throws NullPointerException { System.out.println(); System.out.println(); } } """; assertEquals(1, findMatchesCount(in, """ @Test(expected='_E.class) public void '_m() throws '_E { '_st*; } """)); }
testRepeatedVars
291,869
void () { String in = """ class X {{ for (int i = 0; i < 10; i++) {} for (int i = 0; i < 10; i++) {} for (int i = 0; i < 10; i++) {} for (int i = 0; i < 10; i++) {} for (;;) {} for (int i = 0; ;) {} for (int i = 0; true; ) {} }}"""; assertEquals("find all for loops", 7, findMatchesCount(in, "for(;;) '_st;")); assertEquals("find loops without initializers", 1, findMatchesCount(in, "for('_init{0,0};;) '_st;")); assertEquals("find loops without condition", 2, findMatchesCount(in, "for(;'_cond{0,0};) '_st;")); assertEquals("find loops without update", 3, findMatchesCount(in, "for(;;'_update{0,0}) '_st;")); assertEquals("find all for loops 2", 7, findMatchesCount(in, "for('_init?;;) '_st;")); assertEquals("find all for loops 3", 7, findMatchesCount(in, "for(;;'_update?) '_st;")); assertEquals("find all for loops 4", 7, findMatchesCount(in, "for(;'_cond?;) '_st;")); assertEquals("find loops with initializer, condition and update", 4, findMatchesCount(in, "for ('_init; '_cond; '_update) '_st;")); String in2 = """ class X {{ int i = 0, j = 0; for (i=1, j=1;; i++, j++) {} for (;; i++, j++) {} for (i=1;;i++){} }}"""; assertEquals("find for loops with 2 initializer expressions", 1, findMatchesCount(in2, "for ('_init{2,2};;) '_st;")); assertEquals("find for loops with 2 initializer expressions 2", 1, findMatchesCount(in2, "for ('_init1, '_init2;;) '_st;")); assertEquals("find for loops with 2 update expressions", 2, findMatchesCount(in2, "for (;;'_update{2,2}) '_st;")); assertEquals("find for loops with 2 update expressions 2", 2, findMatchesCount(in2, "for (;;'_update1, '_update2) '_st;")); }
testForStatement
291,870
void () { String in = """ class X { public String toString(X this) { return "x"; } void f() {} void g() {} }"""; assertEquals("find methods with receiver parameter", 3, findMatchesCount(in, "'_RT '_m();")); assertEquals("find methods with explicit receiver parameter", 1, findMatchesCount(in, "'_RT '_m('_T this);")); assertEquals("find methods without receiver parameter", 2, findMatchesCount(in, "'_RT '_m('_T '_this{0,0}:(\\w*\\.)?this );")); assertEquals("find methods with receiver parameter 2", 1, findMatchesCount(in, "'_RT '_m('_T '_this:(\\w*\\.)?this );")); }
testReceiverParameter
291,871
String (X this) { return "x"; }
toString
291,872
void () { String in = """ class X {} class Y {} class Z {} record R() {} record T(int i, int j) {} record S(double x, double y) {}"""; assertEquals("find empty record", 1, findMatchesCount(in, "record '_X() {}")); assertEquals("find two component records", 2, findMatchesCount(in, "record '_X('_T '_t{2,2}) {}")); assertEquals("find all classes including records", 6, findMatchesCount(in, "class '_X {}")); }
testRecords
291,873
void () { String in = """ class X { void x(Object o) { if (o instanceof String) {} if (o instanceof String s) {} if (o instanceof String s) {} } }"""; assertEquals("find instanceof", 3, findMatchesCount(in, "'_operand instanceof '_Type")); assertEquals("find pattern matching instanceof", 2, findMatchesCount(in, "'_operand instanceof '_Type '_var")); assertEquals("find plain instanceof", 1, findMatchesCount(in, "'_operand instanceof '_Type '_var{0,0}")); String in2 = """ class X { void x(Object o) { if (0 instanceof String s) {} if (0 instanceof (String s)) {} if (0 instanceof (String s)) {} } }"""; assertEquals("find parenthesized test pattern", 2, findMatchesCount(in2, "'_operand instanceof ('_Type '_var)")); assertEquals("find all pattern variables", 3, findMatchesCount(in2, "'_operand instanceof '_Type '_var")); }
testPatternMatchingInstanceof
291,874
void () { String s1 = "<a/>"; String s2 = "<a/>"; String s3 = "<a><b/></a>"; String expectedResult = "<a><b/></a>"; assertEquals("First tag replacement", expectedResult, replace(s1, s2, s3)); String s4 = """ <group id="EditorTabPopupMenu"> <reference id="Compile"/> <reference id="RunContextPopupGroup"/> <reference id="ValidateXml"/> <separator/> <reference id="VersionControlsGroup"/> <separator/> <reference id="ExternalToolsGroup"/> </group>"""; String s5 = "<reference id=\"'_Value\"/>"; String s6 = "<reference ref=\"$Value$\"/>"; expectedResult = """ <group id="EditorTabPopupMenu"> <reference ref="Compile"/> <reference ref="RunContextPopupGroup"/> <reference ref="ValidateXml"/> <separator/> <reference ref="VersionControlsGroup"/> <separator/> <reference ref="ExternalToolsGroup"/> </group>"""; assertEquals("Replace tag", expectedResult, replace(s4, s5, s6)); String s7 = "<h4 class=\"a\">My title<aaa>ZZZZ</aaa> My title 3</h4>\n" + "<h4>My title 2</h4>"; String s8 = "<h4 class=\"a\">'_Content*</h4>"; String s9 = "<h5>$Content$</h5>"; expectedResult = "<h5>My title <aaa>ZZZZ</aaa> My title 3</h5>\n" + "<h4>My title 2</h4>"; assertEquals("Replace tag saving content", expectedResult, replace(s7, s8, s9)); expectedResult = "\n" + "<h4>My title 2</h4>"; assertEquals("Delete tag", expectedResult, replace(s7, s8, "")); String what = "<'_H:h4 class=\"a\">'_Content*</'_H>"; String by = "<$H$>$Content$</$H$>"; expectedResult = "<h4>My title <aaa>ZZZZ</aaa> My title 3</h4>\n" + "<h4>My title 2</h4>"; assertEquals("Replace with variable", expectedResult, replace(s7, what, by)); String in = "<b>Cry 'Havoc!', and <i>let slip the<br> dogs of war</i></b>"; what = "<'_Tag:b >'_Content2*</'_Tag>"; by = "<$Tag$ id=\"unique\">$Content2$</$Tag$>"; expectedResult = "<b id=\"unique\">Cry 'Havoc!', and <i>let slip the<br> dogs of war</i></b>"; assertEquals("Replace complex content with variable", expectedResult, replace(in, what, by)); }
testReplaceXmlAndHtml
291,875
void () { String in = "<input class=\"other\" type=\"text\" ng-model=\"someModel\" placeholder=\"Some placeholder\" />"; String what = "<input '_a* />"; String by = "<input $a$ id=\"someId1\" />"; String expected = "<input class=\"other\" type=\"text\" ng-model=\"someModel\" placeholder=\"Some placeholder\" id=\"someId1\" />"; assertEquals(expected, replace(in, what, by)); }
testHtmlAddAttribute
291,876
void () { String in = "<input class=\"other\" placeholder=\"Some placeholder\">"; String what = "<input 'a:[regex( placeholder )]>"; String by = ""; String expected = "<input class=\"other\">"; assertEquals(expected, replace(in, what, by)); String in2 = "<img src=\"foobar.jpg\" alt=\"alt\" width=\"108\" height=\"71\" style=\"display:block\" >"; String what2 = "<img alt '_other*>"; String by2 = "<img $other$>"; assertEquals("<img src=\"foobar.jpg\" width=\"108\" height=\"71\" style=\"display:block\">", replace(in2, what2, by2)); }
testRemoveAttribute
291,877
void () { String in = """ <a> <b>liberation</b> <c>remuneration</c> </a>"""; String what = "<'tag:[regex( c )]>'_text</'tag>"; String by = ""; String expected = """ <a> <b>liberation</b> </a>"""; assertEquals(expected, replace(in, what, by)); }
testRemoveTag
291,878
void () { final ReplacementVariableDefinition definition = new ReplacementVariableDefinition("result"); definition.setScriptCodeConstraint("value.getText().toInteger() + 1"); options.addVariableDefinition(definition); String in = """ <!doctype html> <html> <head> <title class="EXAMPLE">Structural Replace Example</title> <body> <ul> <li class="EXAMPLE">2<!--comment--></li> <li class="example">3</li> <li class="EXAMPLE">4</li> <li class="example">Example line a</li> <li id="EXAMPLE">6</li> </ul> </body> </html> """; String what = "<li>'value:[regex( \\d+ )]</li>"; String by = "$result$"; final String expected = """ <!doctype html> <html> <head> <title class="EXAMPLE">Structural Replace Example</title> <body> <ul> <li class="EXAMPLE">3<!--comment--></li> <li class="example">4</li> <li class="EXAMPLE">5</li> <li class="example">Example line a</li> <li id="EXAMPLE">7</li> </ul> </body> </html> """; assertEquals(expected, replace(in, what, by)); }
testReplaceTargetText
291,879
void () { String in = "<input id=\"one\" class=\"no\">"; String what = "<'_tag '_attr:[regex( id )]=\\''value\\'>"; String by = "\"two\""; String expected = "<input id=\"two\" class=\"no\">"; assertEquals(expected, replace(in, what, by)); }
testReplaceAttributeValue
291,880
String () { return PlatformTestUtil.getCommunityPath() + "/platform/structuralsearch/testData/"; }
getTestDataPath
291,881
void () { String html = "<HTML><HEAD><TITLE>Hello Worlds</TITLE></HEAD><body><img src='test.gif'></body></HTML>"; String pattern = "<title>'_a</title>"; options.setCaseSensitiveMatch(false); assertEquals("case insensitive search", 1, findMatchesCount(html, pattern, HtmlFileType.INSTANCE)); String pattern2 = "<'t SRC=\"'_v\"/>"; assertEquals("case insensitive attribute", 1, findMatchesCount(html, pattern2, HtmlFileType.INSTANCE)); String pattern3 = "<'t '_a=\"TEST.gif\">"; assertEquals("case insensitive attribute value", 1, findMatchesCount(html, pattern3, HtmlFileType.INSTANCE)); }
testHtmlSearchCaseInsensitive
291,882
void () { String html = "<HTML><HEAD><TITLE>Hello Worlds</TITLE></HEAD><body><img src='test.gif'><body></HTML>"; String pattern = "<title>'_a</title>"; options.setCaseSensitiveMatch(true); assertEquals("case sensitive search", 0, findMatchesCount(html, pattern, HtmlFileType.INSTANCE)); }
testHtmlSearchCaseSensitive
291,883
void () { String s1 = "<aaa><bbb class=\"11\"></bbb></aaa><bbb class=\"22\"></bbb>"; String s2 = "<bbb></bbb>"; String s2_2 = "<bbb/>"; String s2_3 = "<'t:[ regex( aaa ) ] />"; String s2_4 = "<'_ 't:[ regex( class ) ]=\"'_\" />"; String s2_5 = "<'_ '_=\"'t:[ regex( 11 ) ]\" />"; assertEquals("Simple xml find", 2, findMatchesCount(s1, s2, XmlFileType.INSTANCE)); assertEquals("Simple xml find with empty tag", 2, findMatchesCount(s1, s2_2, XmlFileType.INSTANCE)); assertEquals("Simple xml find with typed var", 1, findMatchesCount(s1, s2_3, XmlFileType.INSTANCE)); assertEquals("Simple xml find with typed attr", 2, findMatchesCount(s1, s2_4, HtmlFileType.INSTANCE)); assertEquals("Simple xml find with typed attr value", 1, findMatchesCount(s1, s2_5, HtmlFileType.INSTANCE)); assertEquals("Simple xml find with attr without value", 2, findMatchesCount(s1, "<'_ '_+ />", HtmlFileType.INSTANCE)); String s3 = """ <a> content </a> <b> another content </b> <c>another <aaa>zzz</aaa>content </c>"""; String s4 = "<'_tag>'Content+</'_tag>"; assertEquals("Content match", 6, findMatchesCount(s3, s4, HtmlFileType.INSTANCE)); assertEquals("Content match", 6, findMatchesCount(s3, s4, XmlFileType.INSTANCE)); }
testXmlSearch
291,884
void () { String source = "<html><title>title</title></html>"; try { findMatchesCount(source, "<'_tag>", XmlFileType.INSTANCE); } catch (MalformedPatternException e) { fail(); } try { findMatchesCount(source, "<'_tag '_attr>", XmlFileType.INSTANCE); } catch (MalformedPatternException e) { fail(); } }
testNoUnexpectedException
291,885
void () { String source = "<x>z</x>"; try { findMatchesCount(source, "<title>$A$$</title>", HtmlFileType.INSTANCE); fail(); } catch (MalformedPatternException ignore) {} try { findMatchesCount(source, "<x>1<3</x>", XmlFileType.INSTANCE); fail(); } catch (MalformedPatternException ignore) {} try { findMatchesCount(source, "<x'_tag>", XmlFileType.INSTANCE); fail(); } catch (MalformedPatternException ignore) {} }
testInvalidPatternWarnings
291,886
void () { String source = "<ul><li>one</li></ul><li>two</li><li>three</li>"; String pattern1 = "[within( \"<ul>'content*</ul>\" )]<'li />"; assertEquals("within predicate", 1, findMatchesCount(source, pattern1, XmlFileType.INSTANCE)); String pattern1a = "[within( \"<ul>'_content*</ul>\" )]<'li />"; assertEquals("within predicate", 1, findMatchesCount(source, pattern1a, XmlFileType.INSTANCE)); String pattern2 = "[!within( \"<ul>'content*</ul>\" )]<'li />"; assertEquals("not within predicate", 3, findMatchesCount(source, pattern2, XmlFileType.INSTANCE)); String pattern2a = "[!within( \"<ul>'_content*</ul>\" )]<'li />"; assertEquals("not within predicate", 3, findMatchesCount(source, pattern2a, XmlFileType.INSTANCE)); }
testWithinPredicate
291,887
void () { String source = """ <html> <style type="text/css"> .stretchFormElement { width: auto; } </style> <img src="madonna.jpg" alt='Foligno Madonna, by Raphael' one="tro"/> </html>"""; String pattern = "<'_a type=\"text/css\">'_content*</'_a>"; assertEquals("find tag with css content", 1, findMatchesCount(source, pattern, HtmlFileType.INSTANCE)); }
testCssStyleTag
291,888
void () { String source = """ <user id="1"> <first_name>Max</first_name> <!-- asdf --> <last_name>Headroom</last_name> </user>"""; String pattern = "<first_name>$A$</first_name><last_name>$B$</last_name>"; assertEquals("find tag ignoring comments", 1, findMatchesCount(source, pattern, XmlFileType.INSTANCE)); }
testSearchIgnoreComments
291,889
void () { String in = "<blockquote>one two <!-- and I cannot emphasize this enough --> three</blockquote>"; assertEquals("find comment", 1, findMatchesCount(in, "<!-- '_x -->", HtmlFileType.INSTANCE)); assertEquals("find comment 2", 1, findMatchesCount(in, "<!-- and I cannot emphasize this enough -->", HtmlFileType.INSTANCE)); assertEquals("find partial text", 1, findMatchesCount(in, "two", HtmlFileType.INSTANCE)); assertEquals("find text ignoring comments & whitespace", 1, findMatchesCount(in, " one two three ", HtmlFileType.INSTANCE)); assertEquals("find text with comments, ignoring whitespace", 1, findMatchesCount(in, " one two <!-- and I cannot emphasize this enough --> three ", HtmlFileType.INSTANCE)); assertEquals("find text & var with comments, ignoring whitespace", 1, findMatchesCount(in, " one two <!-- and I cannot emphasize this enough --> '_x+ ", HtmlFileType.INSTANCE)); assertEquals("should find nothing, comment doesn't match", 0, findMatchesCount(in, " one two <!-- I can emphasize this enough --> three ", HtmlFileType.INSTANCE)); }
testComments
291,890
String () { return PlatformTestUtil.getCommunityPath() + "/platform/structuralsearch/testData/html/"; }
getTestDataPath
291,891
void () { String s1 = "<body><p class=\"11\"> AAA </p><p class=\"22\"></p> <p> ZZZ </p> <p/> <p/> <p/> </body>"; String s2 = "<p '_a{0,0}=\"'_t:[ regex( 11 ) ]\"> '_content? </p>"; assertEquals(5, findMatchesCount(s1, s2, XmlFileType.INSTANCE)); }
testXmlSearch2
291,892
void () { try { findMatchesCount("", "<H", HtmlFileType.INSTANCE); fail(); } catch (MalformedPatternException ignore) {} findMatchesCount("", "<H>", HtmlFileType.INSTANCE); // although invalid HTML, should not report an error findMatchesCount("", "<A href>", XmlFileType.INSTANCE); // although missing attribute value, should not report an error }
testErroneousPatterns
291,893
void () { final Configuration[] templates = JavaPredefinedConfigurations.createPredefinedTemplates(); final Map<String, Configuration> configurationMap = Stream.of(templates).collect(Collectors.toMap(Configuration::getName, x -> x)); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.logging.without.if")), """ /** @noinspection ALL*/ class X { void x(String s) { LOG.debug("s1: " + s); if (LOG.isDebug()) { LOG.debug("s2: " + s); } } }""", "LOG.debug(\"s1: \" + s);"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.method.calls")), """ /** @noinspection ALL*/ class X { void x() { System.out.println(); System.out.println(1); x(); } }""", "System.out.println()", "System.out.println(1)", "x()"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.constructors.of.the.class")), """ class X { X() {} X(int i) { System.out.println(i); } X(String... ss) {} void m() {} }""", "X() {}", """ X(int i) { System.out.println(i); }""", "X(String... ss) {}"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.class.with.parameterless.constructors")), """ class X { X() {} } class Y { Y() {} Y(String name) {} } class Z { Z(String name) {} } class A { void x(String names) {} }""", """ class X { X() {} }""", """ class A { void x(String names) {} }"""); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.try.without.resources")), """ /** @noinspection ALL*/ class X {{ try {} finally {} try { ; } catch (RuntimeException e) {} try (resourceRef) {} try (AutoCloseable ac = null) {} }}""", "try {} finally {}"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.switch.with.branches")), """ /** @noinspection ALL*/ class X {{ switch (1) { case 1: break; case 2: System.out.println(); case 3: default: } switch (1) { case 1: break; case 2: System.out.println(); case 3: case 4: default: } }}""", """ switch (1) { case 1: break; case 2: System.out.println(); case 3: default: }"""); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.string.concatenations")), """ class X { String s = "1" + "2" + "3" + "4" + "5" + "6" + "7" + "8" + "9" + "10" + "11"; String t = "1" + "2" + "3" + "4" + "5" + "6" + "7" + "8" + "9"+ "10"; }""", "\"1\" + \"2\" + \"3\" + \"4\" + \"5\" + \"6\" + \"7\" + \"8\" + \"9\" + \"10\" + \"11\""); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.assert.without.description")), """ /** @noinspection ALL*/ class X {{ assert true; assert false : false; assert false : "reason"; }}""", "assert true;"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.labeled.break")), """ /** @noinspection ALL*/ class X {{ break one; break; continue; continue here; }}""", "break one;"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.method.returns.bounded.wildcard")), """ /** @noinspection ALL*/ abstract class X { List<? extends Number> one() { return null; } abstract List<? extends Number> ignore(); List<?> two() { return null; } <T extends Number> T three() { return null; } }""", """ List<? extends Number> one() { return null; }"""); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.generic.constructors")), """ class X<U> { X() {} <T> X(String s) {} <T extends U, V> X(int i) {} }""", "<T> X(String s) {}", "<T extends U, V> X(int i) {}"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.all.methods.of.the.class.within.hierarchy")), "class X {}\ninterface I { void x(); }", JavaFileType.INSTANCE, PsiElement::getText, "registerNatives", "getClass", "hashCode", "equals", "clone", "toString", "notify", "notifyAll", "wait", "wait", "wait", "finalize"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.methods.with.final.parameters")), """ /** @noinspection ALL*/ class X { int myI; X(final int i) { myI = i; } public void m(final int i, int j, int k) { System.out.println(i); } void n() {} void o(String s) {} }""", """ X(final int i) { myI = i; }""", """ public void m(final int i, int j, int k) { System.out.println(i); }"""); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.methods.of.the.class")), """ abstract class X { X() {} X(String s) {} abstract void x(); int x(int i) {} boolean x(double d, Object o) {} }""", "X() {}", "X(String s) {}", "abstract void x();", "int x(int i) {}", "boolean x(double d, Object o) {}"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.class.static.blocks")), """ /** @noinspection ALL*/ class X { static {} static { System.out.println(); } { {} } }""", "static {}", """ static { System.out.println(); }"""); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.class.any.initialization.blocks")), """ /** @noinspection ALL*/ class X { static {} static { System.out.println(); } { {} } }""", "static {}", """ static { System.out.println(); }""", """ { {} }"""); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.static.fields.without.final")), """ class X { int i1 = 1; static int i2 = 2; static final int i3 = 3; }""", "static int i2 = 2;"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.annotated.fields")), """ class X { @SuppressWarnings("All") @Deprecated private static final int YES = 0; @Deprecated String text = null; public static final int NO = 1; }""", "@SuppressWarnings(\"All\") @Deprecated\n" + " private static final int YES = 0;", "@Deprecated\n" + " String text = null;"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.javadoc.annotated.methods")), """ /** @noinspection ALL*/ class X { /** constructor */ X() {} /** */ void x() {} /** @deprecated */ void y() {} /** * important * method * @param i the value that will be returned */ int z(int i) { return i; } void a() {} }""", "/** constructor */\n" + " X() {}", "/** */\n" + " void x() {}", "/** @deprecated */\n" + " void y() {}", """ /** * important * method * @param i the value that will be returned */ int z(int i) { return i; }"""); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.switches")), """ /** @noinspection ALL*/ class X {{ int i = switch (1) { default -> {} }; switch (2) { case 1,2: break; default: } }}""", """ switch (1) { default -> {} }""", """ switch (2) { case 1,2: break; default: }"""); //noinspection DanglingJavadoc doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.comments.containing.word")), """ // bug /* bugs are here */ /** * may * contain * one bug */ /* buggy */ // bug?""", "// bug", """ /** * may * contain * one bug */""", "// bug?"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.all.fields.of.the.class")), """ /** @noinspection ALL*/ interface I { public static final String S = ""; } enum E { A, B } /** @noinspection ALL*/ class C extends ThreadLocal { private int i = 0; } """, "private int i = 0;", "private final int threadLocalHashCode = nextHashCode();", "private static AtomicInteger nextHashCode = new AtomicInteger();", "private static final int HASH_INCREMENT = 1640531527;"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.fields.of.the.class")), """ /** @noinspection ALL*/ interface I { public static final String S = ""; } enum E { A, B } /** @noinspection ALL*/ record R(int i) { private static final int X = 1;} /** @noinspection ALL*/ class C extends ThreadLocal { private int i = 0; } """, "private int i = 0;"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.records")), """ class X {} interface I {} record R1(int i, int j) {} record R2(double a, double b) {}""", "record R1(int i, int j) {}", "record R2(double a, double b) {}"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.double.checked.locking")), """ /** @noinspection ALL*/ class X { private static Object o = null; static Object get() { if (o == null) { synchronized (X.class) { if (o == null) { return o; } } } } }""", """ if (o == null) { synchronized (X.class) { if (o == null) { return o; } } }"""); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.pattern.matching.instanceof")), """ /** @noinspection ALL*/ class X { void x(Object o) { if (o instanceof String) { String s = (String)s; System.out.println(s); } if (o instanceof String s) { System.out.println(s); } } }""", "o instanceof String s"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.local.classes")), """ /** @noinspection ALL*/ class X { void x() { System.out.println(); System.out.println(); class Y { int i; } System.out.println(); System.out.println(); } }""", """ class Y { int i; }"""); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.instance.fields.of.the.class")), """ class X { int a = 1; int b = 2; static int c = 3; }""", "int a = 1;", "int b = 2;"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.inner.classes")), """ class X { class Inner1 {} static class Inner2 {} }""", "class Inner1 {}", "static class Inner2 {}"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.all.inner.classes.within.hierarchy")), """ class X { class Inner {} } class Y extends X {}""", "class Inner {}"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.type.var.substitutions.in.instanceof.with.generic.types")), """ /** @noinspection ALL*/ class X<T, U, V> { void x(Object o) { System.out.println(o instanceof X<Integer, Boolean, String>); } }""", "Integer", "Boolean", "String"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.javadoc.annotated.fields")), """ class X { /** comment */ int i; int j; }""", "/** comment */\n int i;"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.javadoc.tags")), """ /** @noinspection ALL*/ class X { /** * comment * @version 1 */ int i; int j; }""", "@noinspection", "@version"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.any.boxing")), """ class X { Number n = 1; } """, "1"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.any.unboxing")), """ class X { int n = Integer.valueOf(1); } """, "Integer.valueOf(1)"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.boxing.in.method.calls")), """ class X { void x(Number n) { } void y() { x(1); } } """, "x(1)"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.unboxing.in.method.calls")), """ class X { void x(int n) { } void y(Integer i) { x(i); } } """, "x(i)"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.unboxing.in.declarations")), """ /** @noinspection ALL*/ class X { private int x = Integer.valueOf(1); private Integer y = 1; } """, "private int x = Integer.valueOf(1);"); doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.boxing.in.declarations")), """ /** @noinspection ALL*/ class X { private int x = Integer.valueOf(1); private Integer y = 1; } """, "private Integer y = 1;"); //assertTrue((templates.length - configurationMap.size()) + " of " + templates.length + // " existing templates tested. Untested templates: " + configurationMap.keySet(), configurationMap.isEmpty()); }
testAll
291,894
void (final int i, int j, int k) { System.out.println(i); }
m
291,895
void (final int i, int j, int k) { System.out.println(i); }
m
291,896
Object () { if (o == null) { synchronized (X.class) { if (o == null) { return o; } } } }
get
291,897
LanguageLevel () { return LanguageLevel.JDK_16; }
getLanguageLevel
291,898
void () { final Configuration[] templates = new XmlStructuralSearchProfile().getPredefinedTemplates(); final Map<String, Configuration> configurationMap = Stream.of(templates).collect(Collectors.toMap(Configuration::getName, x -> x)); doTest(configurationMap.remove(SSRBundle.message("predefined.template.li.not.contained.in.ul.or.ol")), """ <html> <ul><li>one</li></ul><li>two</li><li>three</li> </html>""", HtmlFileType.INSTANCE, "<li>two</li>", "<li>three</li>"); doTest(configurationMap.remove(SSRBundle.message("predefined.template.xml.tag.without.specific.attribute")), """ <one attributeName="1"> <two attributeName="value"></two> <three attributeName="value"/> <four/> <five></five> </one> """, XmlFileType.INSTANCE, "<four/>", "<five></five>"); }
testAll
291,899
void () { doTest("class A {<EOLError descr=\"'}' expected\"></EOLError>"); }
testSimpleError