use of com.google.devtools.j2objc.util.CodeReferenceMap in project j2objc by google.
the class DeadCodeEliminatorTest method testDeadClass_DeadInnerClassConstructor.
public void testDeadClass_DeadInnerClassConstructor() throws IOException {
CodeReferenceMap map = CodeReferenceMap.builder().addField("Foo$A", "z").addField("Foo$A", "this$0").addMethod("Foo$A", "Foo$A", "(LFoo;I)V").addMethod("Foo$A", "f", "()I").build();
setDeadCodeMap(map);
String source = "public class Foo {\n" + " int y;\n" + " public Foo(int x) { y = x; }\n" + "\n" + " class A {\n" + " int z;\n" + " A(int x) { z = x; }\n" + " int f() { return z + y; }\n" + " }\n" + "}\n";
String translation = translateSourceFile(source, "Foo", "Foo.h");
assertTranslation(translation, "@interface Foo_A");
assertNotInTranslation(translation, "z_;");
translation = getTranslatedFile("Foo.m");
assertNotInTranslation(translation, "Foo *this$0_;");
assertNotInTranslation(translation, "JreStrongAssign(&self->this$0_, outer$");
assertNotInTranslation(translation, "self->z_ = x;");
assertNotInTranslation(translation, "- (jint)f");
}
use of com.google.devtools.j2objc.util.CodeReferenceMap in project j2objc by google.
the class DeadCodeEliminatorTest method testDeadMethod_AnonymousClassMember.
public void testDeadMethod_AnonymousClassMember() throws IOException {
String source = "abstract class B {}\n" + "class A {\n" + " private B b = new B() {\n" + " public void foo() {}\n" + " };\n" + "}\n";
CodeReferenceMap map = CodeReferenceMap.builder().addMethod("A$1", "foo", "()V").build();
setDeadCodeMap(map);
String translation = translateSourceFile(source, "A", "A.m");
assertNotInTranslation(translation, "foo");
}
use of com.google.devtools.j2objc.util.CodeReferenceMap in project j2objc by google.
the class DeadCodeEliminatorTest method testDeadAnnotation.
// Verify that annotation bodies aren't stripped when specified in a dead code report.
public void testDeadAnnotation() throws IOException {
CodeReferenceMap map = CodeReferenceMap.builder().addClass("Foo").build();
setDeadCodeMap(map);
String source = "import java.lang.annotation.Retention;\n" + "import java.lang.annotation.RetentionPolicy;\n" + "@Retention(RetentionPolicy.RUNTIME)\n" + "public @interface Foo {\n" + " String value() default \"\";\n" + "}\n";
String translation = translateSourceFile(source, "Foo", "Foo.h");
assertTranslation(translation, "@property (readonly) NSString *value;");
}
use of com.google.devtools.j2objc.util.CodeReferenceMap in project j2objc by google.
the class DeadCodeEliminatorTest method testDeadFastEnumerationImplementation.
public void testDeadFastEnumerationImplementation() throws IOException {
String source = "import java.util.Iterator;\n" + "interface SomeInterface extends Iterable<String> {}\n" + "class Base {}\n" + "class Foo extends Base implements SomeInterface {\n" + " @Override\n" + " public Iterator<String> iterator() { return null; }\n" + "}";
CodeReferenceMap map = CodeReferenceMap.builder().addClass("Foo").build();
setDeadCodeMap(map);
String header = translateSourceFile(source, "Foo", "Foo.h");
String impl = getTranslatedFile("Foo.m");
assertNotInTranslation(header, "@interface Foo : Base < SomeInterface >");
assertTranslation(header, "@interface Foo : NSObject");
assertNotInTranslation(impl, "countByEnumeratingWithState:");
}
use of com.google.devtools.j2objc.util.CodeReferenceMap in project j2objc by google.
the class DeadCodeEliminatorTest method testDeadMethod.
public void testDeadMethod() throws IOException {
String source = "class A {\n" + " private static interface B {\n" + " String bar();\n" + " }\n" + " private void baz() {\n" + " // nothing\n" + " }\n" + "}\n";
CodeReferenceMap map = CodeReferenceMap.builder().addMethod("A$B", "bar", "()Ljava/lang/String;").build();
setDeadCodeMap(map);
String translation = translateSourceFile(source, "A", "A.m");
assertTranslation(translation, "@interface A_B");
assertNotInTranslation(translation, "bar");
assertTranslation(translation, "baz");
}
Aggregations