32
32
import spoon .reflect .code .CtTypeAccess ;
33
33
import spoon .reflect .cu .CompilationUnit ;
34
34
import spoon .reflect .declaration .CtClass ;
35
+ import spoon .reflect .declaration .CtConstructor ;
35
36
import spoon .reflect .declaration .CtElement ;
36
37
import spoon .reflect .declaration .CtField ;
37
38
import spoon .reflect .declaration .CtImport ;
@@ -1534,6 +1535,7 @@ public void testBug2369_autoimports() {
1534
1535
" }" + nl +
1535
1536
"}" , launcher .getFactory ().Type ().get ("spoon.test.imports.testclasses.JavaLongUse" ).toString ());
1536
1537
}
1538
+
1537
1539
@ Test
1538
1540
public void testImportReferenceIsFullyQualifiedAndNoGeneric () {
1539
1541
//contract: the reference of CtImport is always fully qualified and contains no actual type arguments
@@ -1556,4 +1558,26 @@ public void testImportReferenceIsFullyQualifiedAndNoGeneric() {
1556
1558
assertTrue (typeRef .isImplicit ());
1557
1559
assertTrue (typeRef .getPackage ().isImplicit ());
1558
1560
}
1561
+
1562
+ @ Test
1563
+ public void testMethodChainAutoImports () {
1564
+ // contract: A chain of unknown methods in noclasspath mode with enabled auto-imports should not corrupt argument
1565
+ // https://github.com/INRIA/spoon/issues/2996
1566
+ Launcher launcher = new Launcher ();
1567
+ launcher .getEnvironment ().setNoClasspath (true );
1568
+ launcher .getEnvironment ().setShouldCompile (false );
1569
+ launcher .getEnvironment ().setAutoImports (true );
1570
+ launcher .addInputResource ("./src/test/resources/import-resources/fr/inria/PageButtonNoClassPath.java" );
1571
+ launcher .buildModel ();
1572
+
1573
+ CtClass <?> clazz = (CtClass <?>) launcher .getFactory ().Type ().get ("fr.inria.PageButtonNoClassPath" );
1574
+ CtConstructor <?> ctor = clazz .getConstructors ().stream ().findFirst ().get ();
1575
+ List <CtStatement > statements = ctor .getBody ().getStatements ();
1576
+
1577
+ assertEquals ("super(context, attributeSet)" , statements .get (0 ).toString ());
1578
+ assertEquals ("mButton = ((Button) (findViewById(R.id.page_button_button)))" , statements .get (1 ).toString ());
1579
+ assertEquals ("mCurrentActiveColor = getColor(R.color.c4_active_button_color)" , statements .get (2 ).toString ());
1580
+ assertEquals ("mCurrentActiveColor = getResources().getColor(R.color.c4_active_button_color)" , statements .get (3 ).toString ());
1581
+ assertEquals ("mCurrentActiveColor = getData().getResources().getColor(R.color.c4_active_button_color)" , statements .get (4 ).toString ());
1582
+ }
1559
1583
}
0 commit comments