Lines 572-577
Link Here
|
572 |
assertEqualString(cu.getSource(), buf.toString()); |
572 |
assertEqualString(cu.getSource(), buf.toString()); |
573 |
} |
573 |
} |
574 |
|
574 |
|
|
|
575 |
public void testAddImports_bug194358() throws Exception { |
576 |
|
577 |
IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null); |
578 |
StringBuffer buf= new StringBuffer(); |
579 |
buf.append("package pack1;\n"); |
580 |
buf.append("\n"); |
581 |
buf.append("import pack2.A;\n"); |
582 |
buf.append("import pack2.A.Inner;\n"); |
583 |
buf.append("import pack2.B;\n"); |
584 |
buf.append("\n"); |
585 |
buf.append("public class C {\n"); |
586 |
buf.append("}\n"); |
587 |
|
588 |
ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); |
589 |
|
590 |
// We need to actually make some state in the AST for the classes, to test that we can |
591 |
// disambiguate between packages and inner classes (see the bug for details). |
592 |
IPackageFragment pack2= this.sourceFolder.createPackageFragment("pack2", false, null); |
593 |
ICompilationUnit aUnit= pack2.createCompilationUnit("A.java", "", false, null); |
594 |
ICompilationUnit bUnit= pack2.createCompilationUnit("B.java", "", false, null); |
595 |
bUnit.createType("class B {}", null, false, null); |
596 |
|
597 |
IType aType= aUnit.createType("class A {}", null, false, null); |
598 |
aType.createType("class Inner {}", null, false, null); |
599 |
String[] order= new String[] { "java" }; |
600 |
|
601 |
ImportRewrite imports= newImportsRewrite(cu, order, 99, 99, false); |
602 |
imports.addImport("pack2.A"); |
603 |
imports.addImport("pack2.A.Inner"); |
604 |
imports.addImport("pack2.B"); |
605 |
|
606 |
apply(imports); |
607 |
|
608 |
buf= new StringBuffer(); |
609 |
buf.append("package pack1;\n"); |
610 |
buf.append("\n"); |
611 |
buf.append("import pack2.A;\n"); |
612 |
buf.append("import pack2.A.Inner;\n"); |
613 |
buf.append("import pack2.B;\n"); |
614 |
buf.append("\n"); |
615 |
buf.append("public class C {\n"); |
616 |
buf.append("}\n"); |
617 |
assertEqualString(cu.getSource(), buf.toString()); |
618 |
} |
575 |
public void testAddStaticImports1() throws Exception { |
619 |
public void testAddStaticImports1() throws Exception { |
576 |
|
620 |
|
577 |
IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null); |
621 |
IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null); |