Search in sources :

Example 11 with CodeReferenceMap

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

Example 12 with CodeReferenceMap

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

Example 13 with CodeReferenceMap

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

Example 14 with CodeReferenceMap

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

Example 15 with CodeReferenceMap

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");
}
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