Search in sources :

Example 16 with CodeReferenceMap

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;");
}
Also used : CodeReferenceMap(com.google.devtools.j2objc.util.CodeReferenceMap)

Example 17 with CodeReferenceMap

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");
}
Also used : CodeReferenceMap(com.google.devtools.j2objc.util.CodeReferenceMap)

Example 18 with CodeReferenceMap

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;");
}
Also used : CodeReferenceMap(com.google.devtools.j2objc.util.CodeReferenceMap)

Example 19 with CodeReferenceMap

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");
}
Also used : CodeReferenceMap(com.google.devtools.j2objc.util.CodeReferenceMap)

Example 20 with CodeReferenceMap

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");
}
Also used : CodeReferenceMap(com.google.devtools.j2objc.util.CodeReferenceMap)

Aggregations

CodeReferenceMap (com.google.devtools.j2objc.util.CodeReferenceMap)32 CompilationUnit (com.google.devtools.j2objc.ast.CompilationUnit)9 ReferenceNode (com.google.devtools.treeshaker.ElementReferenceMapper.ReferenceNode)9 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 Set (java.util.Set)9 Builder (com.google.devtools.j2objc.util.CodeReferenceMap.Builder)3 ImmutableSet (com.google.common.collect.ImmutableSet)1 RegularInputFile (com.google.devtools.j2objc.file.RegularInputFile)1 Parser (com.google.devtools.j2objc.util.Parser)1 ProGuardUsageParser (com.google.devtools.j2objc.util.ProGuardUsageParser)1 File (java.io.File)1 IOException (java.io.IOException)1