use of com.google.devtools.j2objc.util.CodeReferenceMap in project j2objc by google.
the class DeadCodeEliminatorTest method testDeadMethodInBaseClassNotShowingInChildClasses.
public void testDeadMethodInBaseClassNotShowingInChildClasses() throws IOException {
String source = "class Base<T> { \n" + " T someDeadMethod() { return null; }\n" + "}\n" + "class Foo extends Base<String> {}";
CodeReferenceMap map = CodeReferenceMap.builder().addMethod("Base", "someDeadMethod", "()Ljava/lang/Object;").build();
setDeadCodeMap(map);
String header = translateSourceFile(source, "Foo", "Foo.h");
assertNotInTranslation(header, "- (id)someDeadMethod;");
assertNotInTranslation(header, "- (NSString *)someDeadMethod;");
}
use of com.google.devtools.j2objc.util.CodeReferenceMap in project j2objc by google.
the class DeadCodeEliminatorTest method testDeadClass_StaticNestedClass.
public void testDeadClass_StaticNestedClass() throws IOException {
CodeReferenceMap map = CodeReferenceMap.builder().addClass("Foo").build();
setDeadCodeMap(map);
String source = "class Foo {\n" + " static class Bar {}\n" + "}\n" + "class Baz extends Foo.Bar {\n" + "}\n";
String translation = translateSourceFile(source, "Foo", "Foo.h");
assertTranslation(translation, "@interface Foo_Bar : NSObject");
translation = getTranslatedFile("Foo.m");
assertTranslation(translation, "Foo_Bar_init");
}
use of com.google.devtools.j2objc.util.CodeReferenceMap in project j2objc by google.
the class DeadCodeEliminatorTest method testDeadMethodInBaseClassNotShowingInDeadChildClasses.
public void testDeadMethodInBaseClassNotShowingInDeadChildClasses() throws IOException {
String source = "class Base<T> { \n" + " T someDeadMethod() { return null; }\n" + "}\n" + "class Foo extends Base<String> {}";
CodeReferenceMap map = CodeReferenceMap.builder().addClass("Foo").addMethod("Base", "someDeadMethod", "()Ljava/lang/Object;").build();
setDeadCodeMap(map);
String header = translateSourceFile(source, "Foo", "Foo.h");
assertNotInTranslation(header, "- (id)someDeadMethod;");
assertNotInTranslation(header, "- (NSString *)someDeadMethod;");
}
use of com.google.devtools.j2objc.util.CodeReferenceMap in project j2objc by google.
the class DeadCodeEliminatorTest method testDeadFields.
public void testDeadFields() throws IOException {
String source = "import static java.lang.System.out;\n" + "import static java.lang.System.in;\n" + "class A {\n" + " private static final int foo = 1;\n" + " public static final String bar = \"bar\";\n" + " static final double pi = 3.2; // in Indiana only\n" + " final String baz = null, bah = \"123\";\n" + " private int abc = 9;\n" + "}\n";
CodeReferenceMap map = CodeReferenceMap.builder().addField("A", "foo").addField("A", "baz").addField("java.lang.System", "in").build();
setDeadCodeMap(map);
String translation = translateSourceFile(source, "A", "A.h");
assertTranslation(translation, "#define A_pi 3.2");
assertTranslation(translation, "NSString *bah_;");
assertNotInTranslation(translation, "baz");
translation = getTranslatedFile("A.m");
assertTranslation(translation, "#define A_foo 1");
assertTranslation(translation, "NSString *A_bar = @\"bar\";");
assertTranslation(translation, "abc_ = 9;");
assertTranslation(translation, "JreStrongAssign(&self->bah_, @\"123\");");
assertNotInTranslation(translation, "baz");
}
use of com.google.devtools.j2objc.util.CodeReferenceMap in project j2objc by google.
the class DeadCodeEliminatorTest method testDeadDefaultConstructor.
public void testDeadDefaultConstructor() throws IOException {
CodeReferenceMap map = CodeReferenceMap.builder().addMethod("Test", "<init>", "()V").build();
setDeadCodeMap(map);
String translation = translateSourceFile("class Test {}", "Test", "Test.h");
// Make sure the default constructor is not added.
assertNotInTranslation(translation, "init");
}
Aggregations