use of com.google.devtools.j2objc.ast.CompilationUnit in project j2objc by google.
the class ElementReferenceMapperTest method testMethodInvocation.
public void testMethodInvocation() throws IOException {
String source = "class A {\n" + " private static void foo(String s) {final int bro = 1;}\n" + " private static void bar(String s) {foo(\"boo\");}\n" + " static { bar(\"bro\"); }\n" + "}\n";
CompilationUnit unit = compileType("test", source);
final HashMap<String, ReferenceNode> elementReferenceMap = new HashMap<>();
final HashMap<String, Set<String>> overrideMap = new HashMap<>();
final Set<String> staticSet = new HashSet<>();
ElementReferenceMapper mapper = new ElementReferenceMapper(unit, elementReferenceMap, staticSet, overrideMap);
mapper.run();
Set<String> elementSet = elementReferenceMap.keySet();
assertTrue(elementSet.contains(ElementReferenceMapper.stitchClassIdentifier("A")));
assertTrue(elementSet.contains(ElementReferenceMapper.stitchMethodIdentifier("A", "foo", "(Ljava/lang/String;)V")));
assertTrue(elementSet.contains(ElementReferenceMapper.stitchMethodIdentifier("A", "bar", "(Ljava/lang/String;)V")));
assertTrue(((MethodReferenceNode) elementReferenceMap.get(ElementReferenceMapper.stitchMethodIdentifier("A", "bar", "(Ljava/lang/String;)V"))).invokedMethods.contains(ElementReferenceMapper.stitchMethodIdentifier("A", "foo", "(Ljava/lang/String;)V")));
}
use of com.google.devtools.j2objc.ast.CompilationUnit 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.CompilationUnit in project j2objc by google.
the class NameTableTest method testTypeVariableWithTypeVariableBounds.
public void testTypeVariableWithTypeVariableBounds() {
String source = "class A<T> { <E extends T> void foo(E e) {} }";
CompilationUnit unit = translateType("A", source);
NameTable nameTable = unit.getEnv().nameTable();
final ExecutableElement[] methodElement = new ExecutableElement[1];
unit.accept(new TreeVisitor() {
@Override
public void endVisit(MethodDeclaration node) {
ExecutableElement element = node.getExecutableElement();
if (ElementUtil.getName(element).equals("foo")) {
methodElement[0] = element;
}
}
});
assertNotNull(methodElement[0]);
TypeMirror paramType = methodElement[0].getParameters().get(0).asType();
assertEquals("id", nameTable.getObjCType(paramType));
}
use of com.google.devtools.j2objc.ast.CompilationUnit 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.CompilationUnit 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()));
}
Aggregations