Ejemplo n.º 1
0
  public void testConflictingImplicitJavaImport() {
    importManager.addImport("a.b.c.String");

    assertEquals("a.b.c.String", importManager.getImportedName("a.b.c.String"));
    assertEquals("String", importManager.getImportedName("java.lang.String"));
    assertEquals(0, importManager.getImports().size());
    assertFalse(importManager.hasImport("String"));
  }
Ejemplo n.º 2
0
  public void testMasterImport() {
    importManager.addImport("a.b.c.GeneratingClass");

    assertEquals(0, importManager.getImports().size());
    assertTrue(importManager.hasImport("GeneratingClass"));
    assertEquals(
        "GeneratingClass",
        importManager.getImportedName("org.eclipse.example.test.GeneratingClass"));
    assertEquals("a.b.c.GeneratingClass", importManager.getImportedName("a.b.c.GeneratingClass"));
  }
Ejemplo n.º 3
0
  public void testGenericTypeImport() {
    importManager.addImport("a.b.c.MyClass");
    importManager.addImport("java.util.Map");

    assertEquals(
        "MyClass<Map<String,a.Baz>>",
        importManager.getImportedName("a.b.c.MyClass<java.util.Map<java.lang.String,a.Baz>>"));
    assertEquals(
        "MyClass<Map<a.Baz, String>>",
        importManager.getImportedName("a.b.c.MyClass<java.util.Map<a.Baz, java.lang.String>>"));
    assertEquals(
        "MyClass <Map <a.Baz, String> >",
        importManager.getImportedName("a.b.c.MyClass <java.util.Map <a.Baz, java.lang.String> >"));
    assertEquals(
        "Map  < MyClass < a.Baz > , String >",
        importManager.getImportedName(
            "java.util.Map  < a.b.c.MyClass < a.Baz > , java.lang.String >"));
    assertEquals(
        "  Map  <   MyClass < a .  Baz > ,   String >",
        importManager.getImportedName(
            "java . util .  Map  < a . b . c .  MyClass < a .  Baz > , java . lang .  String >"));
    assertEquals(
        "Map<String, ?>", importManager.getImportedName("java.util.Map<java.lang.String, ?>"));
    assertEquals(
        "Map<String, ? extends MyClass & a.Baz>",
        importManager.getImportedName(
            "java.util.Map<java.lang.String, ? extends a.b.c.MyClass & a.Baz>"));
    assertEquals(
        "Map<String, ? super MyClass & a.Baz>",
        importManager.getImportedName(
            "java.util.Map<java.lang.String, ? super a.b.c.MyClass & a.Baz>"));
  }
Ejemplo n.º 4
0
 public void testAutoGenericTypeImport() {
   assertEquals(
       "MyClass<Map<String,Baz>>",
       importManager.getImportedName(
           "a.b.c.MyClass<java.util.Map<java.lang.String,a.b.Baz>>", true));
   assertEquals(
       "MyClass<Map<a.Baz, String>>",
       importManager.getImportedName(
           "a.b.c.MyClass<java.util.Map<a.Baz, java.lang.String>>", true));
   assertEquals(
       "Map  < MyClass < a.Baz > , String >",
       importManager.getImportedName(
           "java.util.Map  < a.b.c.MyClass < a.Baz > , java.lang.String >", true));
 }
Ejemplo n.º 5
0
 public void testAutoGenericTypeWhitespaceImport() {
   assertEquals(
       "  Map  <   MyClass <   Baz > ,   String >",
       importManager.getImportedName(
           "java . util .  Map  < a . b . c .  MyClass < a .  Baz > , java . lang .  String >",
           true));
 }
Ejemplo n.º 6
0
  public void testPseudoImport() {
    importManager.addPseudoImport("a.b.c.Foo");
    importManager.addImport("d.e.Foo");
    importManager.addImport("a.Foo");

    assertEquals(0, importManager.getImports().size());
    assertTrue(importManager.hasImport("Foo"));
    assertEquals("Foo", importManager.getImportedName("a.b.c.Foo"));
    assertEquals("d.e.Foo", importManager.getImportedName("d.e.Foo"));
    assertEquals("a.Foo", importManager.getImportedName("a.Foo"));
  }
Ejemplo n.º 7
0
  public void testExplicitJavaImport() {
    importManager.addJavaLangImports(Collections.singletonList("String"));
    importManager.addImport("a.b.c.String");

    assertEquals("a.b.c.String", importManager.getImportedName("a.b.c.String"));
    assertEquals("String", importManager.getImportedName("java.lang.String"));
    assertEquals(1, importManager.getImports().size());
    assertFalse(importManager.hasImport("String"));
  }
Ejemplo n.º 8
0
  private void assertWhitespaceImport() {
    assertEquals(1, importManager.getImports().size());
    assertTrue(importManager.hasImport("MyThirdClass"));

    assertEquals("MyThirdClass", importManager.getImportedName("a.b.c.MyThirdClass"));
    assertEquals(" MyThirdClass", importManager.getImportedName("a. b. c. MyThirdClass"));
    assertEquals("a.b . Foo", importManager.getImportedName("a.b . Foo"));

    assertEquals(NL + "import a.b.c.MyThirdClass;", importManager.computeSortedImports());
  }
Ejemplo n.º 9
0
 public void testAutoImport() {
   assertEquals("Foo", importManager.getImportedName("a.b.c.Foo", true));
   assertEquals("d.e.f.Foo", importManager.getImportedName("d.e.f.Foo", true));
   assertEquals("Bar", importManager.getImportedName("d.e.f.Bar", true));
 }
Ejemplo n.º 10
0
 public void testNestedImport() {
   importManager.addImport("a.b.c.OuterClass$InnerClass");
   importManager.addImport("a.b.c.C1$C2$C3");
   assertNestedImport();
 }
Ejemplo n.º 11
0
  public void testWildcardImport() {
    importManager.addImport("a.b.c.Foo");
    importManager.addImport("a.b.c.*");
    importManager.addImport("a.b.c.Bar");

    assertTrue(importManager.hasImport("Foo"));
    assertTrue(importManager.hasImport("Bar"));
    assertFalse(importManager.hasImport("Baz"));
    assertEquals(1, importManager.getImports().size());
    assertEquals("Baz", importManager.getImportedName("a.b.c.Baz"));

    importManager.addImport("a.b.Baz");
    assertTrue(importManager.hasImport("Baz"));
    assertEquals(2, importManager.getImports().size());
    assertEquals("a.b.c.Baz", importManager.getImportedName("a.b.c.Baz"));
    assertEquals("Baz", importManager.getImportedName("a.b.Baz"));
  }
Ejemplo n.º 12
0
 public void testNestedImport2() {
   importManager.addImport("a.b.c", "OuterClass");
   importManager.addImport("a.b.c", "C1");
   assertNestedImport();
 }
Ejemplo n.º 13
0
 public void testWhitespaceImport2() {
   importManager.addImport("a. b. c", " MyThirdClass");
   assertWhitespaceImport();
 }
Ejemplo n.º 14
0
 public void testImplicitJavaImport() {
   assertEquals("String", importManager.getImportedName("java.lang.String"));
 }
Ejemplo n.º 15
0
 public void testSimpleImport2() {
   importManager.addImport("a", "MyClass");
   importManager.addImport("a.b.c", "MyOtherClass");
   importManager.addImport("a.b.c", "ItemClass[]");
   assertSimpleImport();
 }
Ejemplo n.º 16
0
 public void testUnqualifiedTypeImport() {
   assertEquals("Foo", importManager.getImportedName("Foo"));
 }
Ejemplo n.º 17
0
 public void testNestedWildcardImport() {
   importManager.addImport("a.b.c.Foo.Bar.*");
   assertEquals("Baz", importManager.getImportedName("a.b.c.Foo$Bar$Baz"));
 }
Ejemplo n.º 18
0
  public void testFullNestedImport() {
    importManager.addImport("a.b.c.Foo.Bar.Baz");
    assertTrue(importManager.hasImport("Baz"));
    assertFalse(importManager.hasImport("Bar"));
    assertFalse(importManager.hasImport("Foo"));
    assertEquals("Baz", importManager.getImportedName("a.b.c.Foo$Bar$Baz"));
    assertEquals("Baz", importManager.getImportedName("a.b.c.Foo.Bar.Baz"));
    assertEquals("a.b.c.Foo.Bar", importManager.getImportedName("a.b.c.Foo$Bar"));
    assertEquals("a.b.c.Foo.Bar", importManager.getImportedName("a.b.c.Foo.Bar"));
    assertEquals("a.b.c.Foo", importManager.getImportedName("a.b.c.Foo"));

    importManager.addImport("a.b.c.Foo.Bar$Baz");
    assertTrue(importManager.hasImport("Baz"));
    assertTrue(importManager.hasImport("Bar"));
    assertFalse(importManager.hasImport("Foo"));
    assertEquals("Bar.Baz", importManager.getImportedName("a.b.c.Foo$Bar$Baz"));
    assertEquals("Baz", importManager.getImportedName("a.b.c.Foo.Bar.Baz"));
    assertEquals("Bar", importManager.getImportedName("a.b.c.Foo$Bar"));
    assertEquals("Bar", importManager.getImportedName("a.b.c.Foo.Bar"));
    assertEquals("a.b.c.Foo", importManager.getImportedName("a.b.c.Foo"));

    importManager.addImport("a.b.c.Foo$Bar$Baz");
    assertTrue(importManager.hasImport("Baz"));
    assertTrue(importManager.hasImport("Bar"));
    assertTrue(importManager.hasImport("Foo"));
    assertEquals("Foo.Bar.Baz", importManager.getImportedName("a.b.c.Foo$Bar$Baz"));
    assertEquals("Baz", importManager.getImportedName("a.b.c.Foo.Bar.Baz"));
    assertEquals("Foo.Bar", importManager.getImportedName("a.b.c.Foo$Bar"));
    assertEquals("Bar", importManager.getImportedName("a.b.c.Foo.Bar"));
    assertEquals("Foo", importManager.getImportedName("a.b.c.Foo"));
  }
Ejemplo n.º 19
0
  private void assertNestedImport() {
    assertEquals(2, importManager.getImports().size());
    assertTrue(importManager.hasImport("OuterClass"));
    assertFalse(importManager.hasImport("InnerClass"));
    assertTrue(importManager.hasImport("C1"));
    assertFalse(importManager.hasImport("C2"));
    assertFalse(importManager.hasImport("C3"));

    assertEquals("OuterClass", importManager.getImportedName("a.b.c.OuterClass"));
    assertEquals(
        "OuterClass.InnerClass", importManager.getImportedName("a.b.c.OuterClass$InnerClass"));
    assertEquals("C1", importManager.getImportedName("a.b.c.C1"));
    assertEquals("C1.C2", importManager.getImportedName("a.b.c.C1$C2"));
    assertEquals("C1.C2.C3", importManager.getImportedName("a.b.c.C1$C2$C3"));

    assertEquals(
        NL + "import a.b.c.C1;" + NL + "import a.b.c.OuterClass;",
        importManager.computeSortedImports());
  }
Ejemplo n.º 20
0
  private void assertSimpleImport() {
    assertEquals(3, importManager.getImports().size());
    assertTrue(importManager.hasImport("MyClass"));
    assertTrue(importManager.hasImport("MyOtherClass"));
    assertTrue(importManager.hasImport("ItemClass"));

    assertEquals("MyClass", importManager.getImportedName("a.MyClass"));
    assertEquals("MyOtherClass", importManager.getImportedName("a.b.c.MyOtherClass"));
    assertEquals("ItemClass", importManager.getImportedName("a.b.c.ItemClass"));
    assertEquals("ItemClass[]", importManager.getImportedName("a.b.c.ItemClass[]"));
    assertEquals("ItemClass[][]", importManager.getImportedName("a.b.c.ItemClass[][]"));
    assertEquals("a.b.Foo", importManager.getImportedName("a.b.Foo"));

    assertEquals(
        NL
            + "import a.MyClass;"
            + NL
            + NL
            + "import a.b.c.ItemClass;"
            + NL
            + "import a.b.c.MyOtherClass;",
        importManager.computeSortedImports());
  }
 protected static String getImportedName(String qualifiedName, ImportManager importManager) {
   int index = qualifiedName.indexOf("$");
   importManager.addImport(index == -1 ? qualifiedName : qualifiedName.substring(0, index));
   return importManager.getImportedName(qualifiedName);
 }