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