use of com.google.devtools.j2objc.ast.AbstractTypeDeclaration in project j2objc by google.
the class AnonymousClassConverterTest method testMethodVarInAnonymousClass.
public void testMethodVarInAnonymousClass() throws IOException {
String source = "class Test { " + " boolean debug;" + " void foo() { " + " if (true) {" + " if (debug) {" + " final Integer i = 1;" + " Runnable r = new Runnable() { " + " public void run() { int j = i + 1; } }; }}}}";
// Verify method var in r1.run() isn't mistakenly made a field in r1.
CompilationUnit unit = translateType("Test", source);
NameTable nameTable = unit.getEnv().nameTable();
List<AbstractTypeDeclaration> types = unit.getTypes();
AbstractTypeDeclaration r1 = types.get(1);
assertEquals("Test_1", nameTable.getFullName(r1.getTypeElement()));
boolean found = false;
for (VariableDeclarationFragment var : TreeUtil.getAllFields(r1)) {
if (ElementUtil.getName(var.getVariableElement()).equals("val$i")) {
found = true;
}
}
assertTrue("required field not found", found);
// Verify method var is passed to constructor.
String translation = generateFromUnit(unit, "Test.m");
assertTranslation(translation, "r = create_Test_1_initWithJavaLangInteger_(i)");
}
use of com.google.devtools.j2objc.ast.AbstractTypeDeclaration in project j2objc by google.
the class ElementUtilTest method testGetAnnotationValue.
public void testGetAnnotationValue() throws IOException {
CompilationUnit unit = translateType("Example", "@com.google.j2objc.annotations.ObjectiveCName(\"E\") class Example {}");
AbstractTypeDeclaration decl = unit.getTypes().get(0);
TypeElement element = decl.getTypeElement();
AnnotationMirror annotation = ElementUtil.getAnnotation(element, ObjectiveCName.class);
Object value = ElementUtil.getAnnotationValue(annotation, "value");
assertEquals("E", value);
}
use of com.google.devtools.j2objc.ast.AbstractTypeDeclaration in project j2objc by google.
the class NameTableTest method testGetFullNameWithLocalClass.
// Verify local class name.
public void testGetFullNameWithLocalClass() {
String source = "package foo.bar; class SomeClass { void test() { " + // This matches JVM naming, once '$' is substituted for the '_' characters.
"{ class Foo {}} { class Foo {}}}}";
CompilationUnit unit = translateType("SomeClass", source);
NameTable nameTable = unit.getEnv().nameTable();
AbstractTypeDeclaration decl = unit.getTypes().get(1);
assertEquals("FooBarSomeClass_1Foo", nameTable.getFullName(decl.getTypeElement()));
decl = unit.getTypes().get(2);
assertEquals("FooBarSomeClass_2Foo", nameTable.getFullName(decl.getTypeElement()));
}
use of com.google.devtools.j2objc.ast.AbstractTypeDeclaration in project j2objc by google.
the class NameTableTest method testGetFullNameWithPackage.
// Verify class name with package is camel-cased.
public void testGetFullNameWithPackage() {
String source = "package foo.bar; public class SomeClass {}";
CompilationUnit unit = translateType("SomeClass", source);
NameTable nameTable = unit.getEnv().nameTable();
AbstractTypeDeclaration decl = unit.getTypes().get(0);
assertEquals("FooBarSomeClass", nameTable.getFullName(decl.getTypeElement()));
}
use of com.google.devtools.j2objc.ast.AbstractTypeDeclaration in project j2objc by google.
the class PackagePrefixesTest method testGetFullNameWithPrefix.
// Verify class name with prefix.
public void testGetFullNameWithPrefix() {
String source = "package foo.bar; public class SomeClass {}";
options.getPackagePrefixes().addPrefix("foo.bar", "FB");
CompilationUnit unit = translateType("SomeClass", source);
NameTable nameTable = unit.getEnv().nameTable();
AbstractTypeDeclaration decl = unit.getTypes().get(0);
assertEquals("FBSomeClass", nameTable.getFullName(decl.getTypeElement()));
}
Aggregations