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"));
  }
  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"));
  }
  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>"));
  }
  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"));
  }
  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"));
  }
  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"));
  }
  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"));
  }
 public void testSimpleImport2() {
   importManager.addImport("a", "MyClass");
   importManager.addImport("a.b.c", "MyOtherClass");
   importManager.addImport("a.b.c", "ItemClass[]");
   assertSimpleImport();
 }
 public void testNestedWildcardImport() {
   importManager.addImport("a.b.c.Foo.Bar.*");
   assertEquals("Baz", importManager.getImportedName("a.b.c.Foo$Bar$Baz"));
 }
Exemplo n.º 10
0
 public void testNestedImport2() {
   importManager.addImport("a.b.c", "OuterClass");
   importManager.addImport("a.b.c", "C1");
   assertNestedImport();
 }
Exemplo n.º 11
0
 public void testNestedImport() {
   importManager.addImport("a.b.c.OuterClass$InnerClass");
   importManager.addImport("a.b.c.C1$C2$C3");
   assertNestedImport();
 }
Exemplo n.º 12
0
 public void testWhitespaceImport2() {
   importManager.addImport("a. b. c", " MyThirdClass");
   assertWhitespaceImport();
 }
 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);
 }