Search in sources :

Example 66 with CompilationUnit

use of com.google.devtools.j2objc.ast.CompilationUnit 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 67 with CompilationUnit

use of com.google.devtools.j2objc.ast.CompilationUnit 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 68 with CompilationUnit

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

the class PackageInfoLookupTest method testReflectionSupportAnnotation.

public void testReflectionSupportAnnotation() throws IOException {
    addSourceFile("@ReflectionSupport(value = ReflectionSupport.Level.FULL) package foo;" + "import com.google.j2objc.annotations.ReflectionSupport;", "foo/package-info.java");
    CompilationUnit unit = translateType("foo.A", "package foo; public class A {}");
    PackageInfoLookup packageInfoLookup = unit.getEnv().options().getPackageInfoLookup();
    assert packageInfoLookup.getReflectionSupportLevel("foo") == ReflectionSupport.Level.FULL;
    addSourceFile("@ReflectionSupport(ReflectionSupport.Level.FULL) package bar;" + "import com.google.j2objc.annotations.*;", "bar/package-info.java");
    unit = translateType("bar.A", "package bar; public class A {}");
    packageInfoLookup = unit.getEnv().options().getPackageInfoLookup();
    assert packageInfoLookup.getReflectionSupportLevel("bar") == ReflectionSupport.Level.FULL;
    addSourceFile("@com.google.j2objc.annotations.ReflectionSupport" + "(com.google.j2objc.annotations.ReflectionSupport.Level.NATIVE_ONLY) package baz;", "baz/package-info.java");
    unit = translateType("baz.A", "package baz; public class A {}");
    packageInfoLookup = unit.getEnv().options().getPackageInfoLookup();
    assert packageInfoLookup.getReflectionSupportLevel("baz") == ReflectionSupport.Level.NATIVE_ONLY;
    // Verify that ReflectionSupport annotation can be parsed from class files
    String jarFilePath = getResourceAsFile("packageInfoLookupTest.jar");
    options.fileUtil().getClassPathEntries().add(jarFilePath);
    unit = translateType("com.google.test.packageInfoLookupTest.A", "package com.google.test.packageInfoLookupTest; public class A {}");
    packageInfoLookup = unit.getEnv().options().getPackageInfoLookup();
    assert packageInfoLookup.getReflectionSupportLevel(unit.getPackage().getName().toString()) == ReflectionSupport.Level.FULL;
}
Also used : CompilationUnit(com.google.devtools.j2objc.ast.CompilationUnit)

Example 69 with CompilationUnit

use of com.google.devtools.j2objc.ast.CompilationUnit 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)

Example 70 with CompilationUnit

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

the class PackagePrefixesTest method testGetFullNameWithInnerClassAndPrefix.

// Verify inner class name with prefix.
public void testGetFullNameWithInnerClassAndPrefix() {
    String source = "package foo.bar; public class SomeClass { static class Inner {}}";
    options.getPackagePrefixes().addPrefix("foo.bar", "FB");
    CompilationUnit unit = translateType("SomeClass", source);
    NameTable nameTable = unit.getEnv().nameTable();
    AbstractTypeDeclaration decl = unit.getTypes().get(1);
    assertEquals("FBSomeClass_Inner", nameTable.getFullName(decl.getTypeElement()));
}
Also used : CompilationUnit(com.google.devtools.j2objc.ast.CompilationUnit) AbstractTypeDeclaration(com.google.devtools.j2objc.ast.AbstractTypeDeclaration)

Aggregations

CompilationUnit (com.google.devtools.j2objc.ast.CompilationUnit)71 AbstractTypeDeclaration (com.google.devtools.j2objc.ast.AbstractTypeDeclaration)24 HashSet (java.util.HashSet)24 ReferenceNode (com.google.devtools.treeshaker.ElementReferenceMapper.ReferenceNode)23 HashMap (java.util.HashMap)23 Set (java.util.Set)23 CodeReferenceMap (com.google.devtools.j2objc.util.CodeReferenceMap)9 MethodDeclaration (com.google.devtools.j2objc.ast.MethodDeclaration)7 MethodReferenceNode (com.google.devtools.treeshaker.ElementReferenceMapper.MethodReferenceNode)7 TypeElement (javax.lang.model.element.TypeElement)5 TreeVisitor (com.google.devtools.j2objc.ast.TreeVisitor)4 NameTable (com.google.devtools.j2objc.util.NameTable)4 TreeNode (com.google.devtools.j2objc.ast.TreeNode)3 VariableDeclarationFragment (com.google.devtools.j2objc.ast.VariableDeclarationFragment)3 RegularInputFile (com.google.devtools.j2objc.file.RegularInputFile)3 ExecutableElement (javax.lang.model.element.ExecutableElement)3 TypeMirror (javax.lang.model.type.TypeMirror)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 BodyDeclaration (com.google.devtools.j2objc.ast.BodyDeclaration)2 ReturnStatement (com.google.devtools.j2objc.ast.ReturnStatement)2