Search in sources :

Example 26 with AbstractTypeDeclaration

use of com.google.devtools.j2objc.ast.AbstractTypeDeclaration in project j2objc by google.

the class ElementUtilTest method testHasAnnotation.

public void testHasAnnotation() throws IOException {
    CompilationUnit unit = translateType("Example", "@com.google.j2objc.annotations.ObjectiveCName(\"E\") class Example {}");
    AbstractTypeDeclaration decl = unit.getTypes().get(0);
    TypeElement element = decl.getTypeElement();
    assertTrue(ElementUtil.hasAnnotation(element, ObjectiveCName.class));
}
Also used : CompilationUnit(com.google.devtools.j2objc.ast.CompilationUnit) ObjectiveCName(com.google.j2objc.annotations.ObjectiveCName) TypeElement(javax.lang.model.element.TypeElement) AbstractTypeDeclaration(com.google.devtools.j2objc.ast.AbstractTypeDeclaration)

Example 27 with AbstractTypeDeclaration

use of com.google.devtools.j2objc.ast.AbstractTypeDeclaration in project j2objc by google.

the class NameTableTest method testGetFullNameNoPackage.

// Verify class name without package is unchanged.
public void testGetFullNameNoPackage() {
    String source = "public class SomeClass {}";
    CompilationUnit unit = translateType("SomeClass", source);
    NameTable nameTable = unit.getEnv().nameTable();
    AbstractTypeDeclaration decl = unit.getTypes().get(0);
    assertEquals("SomeClass", nameTable.getFullName(decl.getTypeElement()));
}
Also used : CompilationUnit(com.google.devtools.j2objc.ast.CompilationUnit) AbstractTypeDeclaration(com.google.devtools.j2objc.ast.AbstractTypeDeclaration)

Example 28 with AbstractTypeDeclaration

use of com.google.devtools.j2objc.ast.AbstractTypeDeclaration in project j2objc by google.

the class NameTableTest method testGetFullNameEnumWithInnerClasses.

// Verify the name of an inner class of an enum.
public void testGetFullNameEnumWithInnerClasses() {
    String source = "package foo.bar; " + "public enum SomeClass { A; static class Inner {} static enum Inner2 { B; }}";
    CompilationUnit unit = translateType("SomeClass", source);
    NameTable nameTable = unit.getEnv().nameTable();
    AbstractTypeDeclaration decl = unit.getTypes().get(1);
    // Outer type should not have "Enum" added to name.
    assertEquals("FooBarSomeClass_Inner", nameTable.getFullName(decl.getTypeElement()));
    // Inner enum should have "Enum" added to name.
    decl = unit.getTypes().get(2);
    assertEquals("FooBarSomeClass_Inner2", nameTable.getFullName(decl.getTypeElement()));
}
Also used : CompilationUnit(com.google.devtools.j2objc.ast.CompilationUnit) AbstractTypeDeclaration(com.google.devtools.j2objc.ast.AbstractTypeDeclaration)

Example 29 with AbstractTypeDeclaration

use of com.google.devtools.j2objc.ast.AbstractTypeDeclaration in project j2objc by google.

the class NameTableTest method testGetFullNameWithInnerClass.

// Verify inner class name with package is camel-cased.
public void testGetFullNameWithInnerClass() {
    String source = "package foo.bar; public class SomeClass { static class Inner {}}";
    CompilationUnit unit = translateType("SomeClass", source);
    NameTable nameTable = unit.getEnv().nameTable();
    AbstractTypeDeclaration decl = unit.getTypes().get(1);
    assertEquals("FooBarSomeClass_Inner", nameTable.getFullName(decl.getTypeElement()));
}
Also used : CompilationUnit(com.google.devtools.j2objc.ast.CompilationUnit) AbstractTypeDeclaration(com.google.devtools.j2objc.ast.AbstractTypeDeclaration)

Example 30 with AbstractTypeDeclaration

use of com.google.devtools.j2objc.ast.AbstractTypeDeclaration in project j2objc by google.

the class PackagePrefixesTest method testPackageWildcards.

public void testPackageWildcards() throws IOException {
    String source = "package foo.bar; public class SomeClass {}";
    options.getPackagePrefixes().addPrefix("foo.*", "FB");
    CompilationUnit unit = translateType("SomeClass", source);
    NameTable nameTable = unit.getEnv().nameTable();
    AbstractTypeDeclaration decl = unit.getTypes().get(0);
    assertEquals("FBSomeClass", nameTable.getFullName(decl.getTypeElement()));
}
Also used : CompilationUnit(com.google.devtools.j2objc.ast.CompilationUnit) AbstractTypeDeclaration(com.google.devtools.j2objc.ast.AbstractTypeDeclaration)

Aggregations

AbstractTypeDeclaration (com.google.devtools.j2objc.ast.AbstractTypeDeclaration)31 CompilationUnit (com.google.devtools.j2objc.ast.CompilationUnit)23 TypeElement (javax.lang.model.element.TypeElement)6 TypeMirror (javax.lang.model.type.TypeMirror)4 BodyDeclaration (com.google.devtools.j2objc.ast.BodyDeclaration)3 VariableDeclarationFragment (com.google.devtools.j2objc.ast.VariableDeclarationFragment)3 NameTable (com.google.devtools.j2objc.util.NameTable)3 MethodDeclaration (com.google.devtools.j2objc.ast.MethodDeclaration)2 ReturnStatement (com.google.devtools.j2objc.ast.ReturnStatement)2 TreeNode (com.google.devtools.j2objc.ast.TreeNode)2 TypeDeclaration (com.google.devtools.j2objc.ast.TypeDeclaration)2 AnnotationMirror (javax.lang.model.element.AnnotationMirror)2 ExecutableElement (javax.lang.model.element.ExecutableElement)2 Annotation (com.google.devtools.j2objc.ast.Annotation)1 AnnotationTypeDeclaration (com.google.devtools.j2objc.ast.AnnotationTypeDeclaration)1 Block (com.google.devtools.j2objc.ast.Block)1 Comment (com.google.devtools.j2objc.ast.Comment)1 EnumDeclaration (com.google.devtools.j2objc.ast.EnumDeclaration)1 Expression (com.google.devtools.j2objc.ast.Expression)1 ExpressionStatement (com.google.devtools.j2objc.ast.ExpressionStatement)1