View | Details | Raw Unified | Return to bug 235253 | Differences between
and this patch

Collapse All | Expand All

(-)a/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java (+90 lines)
Lines 572-577 public class ImportRewriteTest extends AbstractJavaModelTests { Link Here
572
		assertEqualString(cu.getSource(), buf.toString());
572
		assertEqualString(cu.getSource(), buf.toString());
573
	}
573
	}
574
574
575
	/**
576
	 * Test that a valid inner class glob import is not removed even if it's in the same package.
577
	 * 
578
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=235253"
579
	 */
580
	public void testAddImports_bug235253_glob() throws Exception {
581
		StringBuffer buf= new StringBuffer();
582
		buf.append("package com.pack1;\n");
583
		buf.append("\n");
584
		buf.append("import com.pack1.A;\n");
585
		buf.append("import com.pack1.A.*;\n");
586
		buf.append("import com.pack2.B;\n");
587
		buf.append("\n");
588
		buf.append("public class C {\n");
589
		buf.append("}\n");
590
591
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("com.pack1", false, null);
592
		ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null);
593
		ICompilationUnit aUnit= pack1.createCompilationUnit("A.java", "", false, null);
594
595
		IPackageFragment pack2= this.sourceFolder.createPackageFragment("com.pack2", false, null);
596
		ICompilationUnit bUnit= pack2.createCompilationUnit("B.java", "", false, null);
597
		bUnit.createType("class B {}", null, false, null);
598
		IType aType= aUnit.createType("class A {}", null, false, null);
599
		aType.createType("class Inner {}", null, false, null);
600
		String[] order= new String[] { "java" };
601
602
		ImportRewrite imports= newImportsRewrite(cu, order, 99, 99, false);
603
		imports.addImport("com.pack1.A");
604
		imports.addImport("com.pack1.A.*");
605
		imports.addImport("com.pack2.B");
606
607
		apply(imports);
608
609
		buf= new StringBuffer();
610
		buf.append("package com.pack1;\n");
611
		buf.append("\n");
612
		buf.append("import com.pack1.A.*;\n");
613
		buf.append("import com.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
	}
619
620
	/**
621
	 * Test that a valid inner class import is not removed even if it's in the same package.
622
	 * 
623
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=235253"
624
	 */
625
	public void testAddImports_bug235253_noglob() throws Exception {
626
		StringBuffer buf= new StringBuffer();
627
		buf.append("package com.pack1;\n");
628
		buf.append("\n");
629
		buf.append("import com.pack1.A;\n");
630
		buf.append("import com.pack1.A.Inner;\n");
631
		buf.append("import com.pack2.B;\n");
632
		buf.append("\n");
633
		buf.append("public class C {\n");
634
		buf.append("}\n");
635
636
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("com.pack1", false, null);
637
		ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null);
638
		ICompilationUnit aUnit= pack1.createCompilationUnit("A.java", "", false, null);
639
640
		IPackageFragment pack2= this.sourceFolder.createPackageFragment("com.pack2", false, null);
641
		ICompilationUnit bUnit= pack2.createCompilationUnit("B.java", "", false, null);
642
		bUnit.createType("class B {}", null, false, null);
643
		IType aType= aUnit.createType("class A {}", null, false, null);
644
		aType.createType("class Inner {}", null, false, null);
645
		String[] order= new String[] { "java" };
646
647
		ImportRewrite imports= newImportsRewrite(cu, order, 99, 99, false);
648
		imports.addImport("com.pack1.A");
649
		imports.addImport("com.pack1.A.Inner");
650
		imports.addImport("com.pack2.B");
651
652
		apply(imports);
653
654
		buf= new StringBuffer();
655
		buf.append("package com.pack1;\n");
656
		buf.append("\n");
657
		buf.append("import com.pack1.A.Inner;\n");
658
		buf.append("import com.pack2.B;\n");
659
		buf.append("\n");
660
		buf.append("public class C {\n");
661
		buf.append("}\n");
662
		assertEqualString(cu.getSource(), buf.toString());
663
	}
664
575
	public void testAddStaticImports1() throws Exception {
665
	public void testAddStaticImports1() throws Exception {
576
666
577
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null);
667
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null);

Return to bug 235253