use of com.google.devtools.j2objc.ast.CompilationUnit 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()));
}
use of com.google.devtools.j2objc.ast.CompilationUnit in project j2objc by google.
the class OuterReferenceResolverTest method resolveSource.
private void resolveSource(String name, String source) {
CompilationUnit unit = compileType(name, source);
captureInfo = unit.getEnv().captureInfo();
new OuterReferenceResolver(unit).run();
findTypeDeclarations(unit);
}
use of com.google.devtools.j2objc.ast.CompilationUnit in project j2objc by google.
the class ElementUtilTest method testIsRuntimeAnnotation.
public void testIsRuntimeAnnotation() throws IOException {
// SuppressWarnings is a source-level annotation.
CompilationUnit unit = translateType("Example", "@SuppressWarnings(\"test\") class Example {}");
AbstractTypeDeclaration decl = unit.getTypes().get(0);
Annotation annotation = decl.getAnnotations().get(0);
assertFalse(ElementUtil.isRuntimeAnnotation(annotation.getAnnotationMirror()));
// Deprecated is a runtime annotation..
unit = translateType("Example", "@Deprecated class Example {}");
decl = unit.getTypes().get(0);
annotation = decl.getAnnotations().get(0);
assertTrue(ElementUtil.isRuntimeAnnotation(annotation.getAnnotationMirror()));
}
use of com.google.devtools.j2objc.ast.CompilationUnit in project j2objc by google.
the class SignatureGeneratorTest method testGenericMethodWithConcreteTypeArgument.
public void testGenericMethodWithConcreteTypeArgument() throws IOException {
CompilationUnit unit = translateType("MyList", "abstract class MyList extends java.util.AbstractList<String> { " + "public boolean add(String s) { return true; }}");
SignatureGenerator signatureGenerator = unit.getEnv().signatureGenerator();
List<ExecutableElement> methods = ElementUtil.getExecutables(unit.getTypes().get(0).getTypeElement());
// methods[0] is the default constructor.
assertEquals(2, methods.size());
// add(String) does not need a generic signature, even though it overrides a generic method.
assertNull(signatureGenerator.createMethodTypeSignature(methods.get(1)));
}
use of com.google.devtools.j2objc.ast.CompilationUnit in project j2objc by google.
the class SignatureGeneratorTest method testJniSignatures.
public void testJniSignatures() throws IOException {
CompilationUnit unit = translateType("D", "package foo.bar; class D {" + "native void foo(int i, float f, String s);" + "native void a_b$c();" + "native void 你好世界();" + "native void bar();" + "native void bar(String s);" + "native void bar(boolean b, String s);" + "native void bar(String[] s); " + "static class 测试 { native void mumble(); }}");
SignatureGenerator signatureGenerator = unit.getEnv().signatureGenerator();
List<AbstractTypeDeclaration> decls = unit.getTypes();
assertEquals(2, decls.size());
List<ExecutableElement> methods = Lists.newArrayList(ElementUtil.getMethods(decls.get(0).getTypeElement()));
assertEquals(7, methods.size());
Set<String> signatures = new HashSet<>(methods.size());
for (ExecutableElement method : methods) {
signatures.add(signatureGenerator.createJniFunctionSignature(method));
}
// Expected JNI signatures were copied from javah output.
// Verify no parameters, since foo isn't overloaded.
assertTrue(signatures.contains("Java_foo_bar_D_foo"));
// Verify underscores and dollar signs in names are mangled.
assertTrue(signatures.contains("Java_foo_bar_D_a_1b_00024c"));
// Verify Unicode characters are mangled.
assertTrue(signatures.contains("Java_foo_bar_D__04f60_0597d_04e16_0754c"));
// Verify overloaded methods have parameter suffixes.
assertTrue(signatures.contains("Java_foo_bar_D_bar__"));
assertTrue(signatures.contains("Java_foo_bar_D_bar__Ljava_lang_String_2"));
assertTrue(signatures.contains("Java_foo_bar_D_bar__ZLjava_lang_String_2"));
assertTrue(signatures.contains("Java_foo_bar_D_bar___3Ljava_lang_String_2"));
// Check Unicode class name mangling.
methods = Lists.newArrayList(ElementUtil.getMethods(decls.get(1).getTypeElement()));
assertEquals(1, methods.size());
assertEquals("Java_foo_bar_D_00024_06d4b_08bd5_mumble", signatureGenerator.createJniFunctionSignature(methods.get(0)));
}
Aggregations