Lines 75-81
Link Here
|
75 |
|
75 |
|
76 |
|
76 |
|
77 |
this.sourceFolder = getPackageFragmentRoot("P", "src"); |
77 |
this.sourceFolder = getPackageFragmentRoot("P", "src"); |
78 |
|
78 |
this.sourceFolder.createPackageFragment("java.util", false, null); |
|
|
79 |
this.sourceFolder.createPackageFragment("java.net", false, null); |
80 |
this.sourceFolder.createPackageFragment("java.awt", false, null); |
81 |
|
79 |
waitUntilIndexesReady(); |
82 |
waitUntilIndexesReady(); |
80 |
} |
83 |
} |
81 |
|
84 |
|
Lines 572-577
Link Here
|
572 |
assertEqualString(cu.getSource(), buf.toString()); |
575 |
assertEqualString(cu.getSource(), buf.toString()); |
573 |
} |
576 |
} |
574 |
|
577 |
|
|
|
578 |
/** |
579 |
* Test that the Inner class import comes in the right order (i.e. after the enclosing type's import) when re-organized |
580 |
* |
581 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=194358" |
582 |
*/ |
583 |
public void testBug194358() throws Exception { |
584 |
|
585 |
StringBuffer buf= new StringBuffer(); |
586 |
buf.append("package pack1;\n"); |
587 |
buf.append("\n"); |
588 |
buf.append("import pack2.A;\n"); |
589 |
buf.append("import pack2.A.Inner;\n"); |
590 |
buf.append("import pack2.B;\n"); |
591 |
buf.append("\n"); |
592 |
buf.append("public class C {\n"); |
593 |
buf.append("}\n"); |
594 |
|
595 |
IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null); |
596 |
ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); |
597 |
|
598 |
// We need to actually make some state in the AST for the classes, to test that we can |
599 |
// disambiguate between packages and inner classes (see the bug for details). |
600 |
IPackageFragment pack2= this.sourceFolder.createPackageFragment("pack2", false, null); |
601 |
ICompilationUnit aUnit= pack2.createCompilationUnit("A.java", "", false, null); |
602 |
ICompilationUnit bUnit= pack2.createCompilationUnit("B.java", "", false, null); |
603 |
bUnit.createType("class B {}", null, false, null); |
604 |
|
605 |
IType aType= aUnit.createType("class A {}", null, false, null); |
606 |
aType.createType("class Inner {}", null, false, null); |
607 |
String[] order= new String[] { "java" }; |
608 |
|
609 |
ImportRewrite imports= newImportsRewrite(cu, order, 99, 99, false); |
610 |
imports.addImport("pack2.A"); |
611 |
imports.addImport("pack2.B"); |
612 |
imports.addImport("pack2.A.Inner"); |
613 |
|
614 |
apply(imports); |
615 |
|
616 |
buf= new StringBuffer(); |
617 |
buf.append("package pack1;\n"); |
618 |
buf.append("\n"); |
619 |
buf.append("import pack2.A;\n"); |
620 |
buf.append("import pack2.A.Inner;\n"); |
621 |
buf.append("import pack2.B;\n"); |
622 |
buf.append("\n"); |
623 |
buf.append("public class C {\n"); |
624 |
buf.append("}\n"); |
625 |
assertEqualString(cu.getSource(), buf.toString()); |
626 |
} |
627 |
|
628 |
/** |
629 |
* Test that a valid inner class import is not removed even when the container |
630 |
* class is implicitly available. This tests the case where the classes are in |
631 |
* different compilation units. |
632 |
* |
633 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=194358" |
634 |
*/ |
635 |
public void testBug194358a() throws Exception { |
636 |
StringBuffer buf= new StringBuffer(); |
637 |
buf.append("package com.pack1;\n"); |
638 |
buf.append("\n"); |
639 |
buf.append("import com.pack1.A;\n"); |
640 |
buf.append("import com.pack1.A.Inner;\n"); |
641 |
buf.append("import com.pack2.B;\n"); |
642 |
buf.append("\n"); |
643 |
buf.append("public class C {\n"); |
644 |
buf.append("}\n"); |
645 |
|
646 |
IPackageFragment pack1= this.sourceFolder.createPackageFragment("com.pack1", false, null); |
647 |
ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); |
648 |
ICompilationUnit aUnit= pack1.createCompilationUnit("A.java", "", false, null); |
649 |
|
650 |
IPackageFragment pack2= this.sourceFolder.createPackageFragment("com.pack2", false, null); |
651 |
ICompilationUnit bUnit= pack2.createCompilationUnit("B.java", "", false, null); |
652 |
bUnit.createType("class B {}", null, false, null); |
653 |
IType aType= aUnit.createType("class A {}", null, false, null); |
654 |
aType.createType("class Inner {}", null, false, null); |
655 |
String[] order= new String[] { "java" }; |
656 |
|
657 |
ImportRewrite imports= newImportsRewrite(cu, order, 99, 99, false); |
658 |
imports.addImport("com.pack1.A"); |
659 |
imports.addImport("com.pack1.A.Inner"); |
660 |
imports.addImport("com.pack2.B"); |
661 |
|
662 |
apply(imports); |
663 |
|
664 |
buf= new StringBuffer(); |
665 |
buf.append("package com.pack1;\n"); |
666 |
buf.append("\n"); |
667 |
buf.append("import com.pack1.A.Inner;\n"); |
668 |
buf.append("import com.pack2.B;\n"); |
669 |
buf.append("\n"); |
670 |
buf.append("public class C {\n"); |
671 |
buf.append("}\n"); |
672 |
assertEqualString(cu.getSource(), buf.toString()); |
673 |
} |
674 |
/** |
675 |
* Test that the Inner type imports are not removed while organizing even though the |
676 |
* containing class is implicitly available - for the case when both the classes are |
677 |
* in the same compilation unit |
678 |
* |
679 |
* see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=235253" |
680 |
*/ |
681 |
public void testBug235253() throws Exception { |
682 |
StringBuffer buf= new StringBuffer(); |
683 |
buf.append("package bug;\n"); |
684 |
buf.append("\n"); |
685 |
buf.append("class Bug {\n"); |
686 |
buf.append("public void addFile(File file) {}\n"); |
687 |
buf.append("\tinterface Proto{};\n"); |
688 |
buf.append("}\n"); |
689 |
buf.append("class Foo implements Proto{}"); |
690 |
|
691 |
IPackageFragment pack1= this.sourceFolder.createPackageFragment("bug", false, null); |
692 |
ICompilationUnit cu= pack1.createCompilationUnit("Bug.java", buf.toString(), false, null); |
693 |
String[] order= new String[] { "bug" , "java" }; |
694 |
ImportRewrite imports= newImportsRewrite(cu, order, 99, 99, false); |
695 |
imports.addImport("bug.Bug.Proto"); |
696 |
imports.addImport("java.io.File"); |
697 |
|
698 |
apply(imports); |
699 |
buf = new StringBuffer(); |
700 |
buf.append("package bug;\n"); |
701 |
buf.append("\n"); |
702 |
buf.append("import bug.Bug.Proto;\n"); |
703 |
buf.append("\n"); |
704 |
buf.append("import java.io.File;\n"); |
705 |
buf.append("\n"); |
706 |
buf.append("class Bug {\n"); |
707 |
buf.append("public void addFile(File file) {}\n"); |
708 |
buf.append("\tinterface Proto{};\n"); |
709 |
buf.append("}\n"); |
710 |
buf.append("class Foo implements Proto{}"); |
711 |
assertEqualString(cu.getSource(), buf.toString()); |
712 |
} |
713 |
|
575 |
public void testAddStaticImports1() throws Exception { |
714 |
public void testAddStaticImports1() throws Exception { |
576 |
|
715 |
|
577 |
IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null); |
716 |
IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null); |