Skip to content

Commit

Permalink
Annotation support: update scenelib library version used.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 274174426
  • Loading branch information
antonio-cortes-perez authored and copybara-github committed Oct 11, 2019
1 parent 8fa592d commit 8a358be
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,9 @@ public ExternalAnnotations externalAnnotations() {
return externalAnnotations;
}

private void addExternalAnnotationFile(String file) throws IOException {
externalAnnotations.addExternalAnnotationFile(file);
}

@VisibleForTesting
public void addExternalAnnotationFileContents(String fileContents) throws IOException {
externalAnnotations.addExternalAnnotationFileContents(fileContents);
public void addExternalAnnotationFile(String file) throws IOException {
externalAnnotations.addExternalAnnotationFile(file);
}

public void addPlatformModuleSystemOptions(String... flags) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public void testInnerClassWithExternalWeakOuter() throws Exception {
+ "public class A { class B { int test() { return o.hashCode(); }} B o; }";
addSourceFile("A.java", source);
Options options = new Options();
options.addExternalAnnotationFileContents(externalWeakOuterAnnotation);
addExternalAnnotationFileContents(options, externalWeakOuterAnnotation);
findCycles(options);
assertNoCycles();
}
Expand All @@ -430,7 +430,7 @@ public void testFieldWithExternalWeak() throws Exception {
addSourceFile("A.java", "package p; class A { B b; }");
addSourceFile("B.java", "package p; class B { A a; }");
Options options = new Options();
options.addExternalAnnotationFileContents(externalWeakAnnotation);
addExternalAnnotationFileContents(options, externalWeakAnnotation);
findCycles(options);
assertNoCycles();
}
Expand All @@ -447,7 +447,7 @@ public void testFieldWithExternalRetainedWith() throws Exception {
addSourceFile("A.java", "package p; class A { B b; }");
addSourceFile("B.java", "package p; class B { A a; }");
Options options = new Options();
options.addExternalAnnotationFileContents(externalRetainedWithAnnotation);
addExternalAnnotationFileContents(options, externalRetainedWithAnnotation);
findCycles(options);
assertNoCycles();
}
Expand Down Expand Up @@ -525,11 +525,20 @@ private void findCycles(Options options) throws IOException {
}
}

private void addSourceFile(String fileName, String source) throws IOException {
private File addFile(String fileName, String source) throws IOException {
File file = new File(tempDir, fileName);
file.getParentFile().mkdirs();
Files.asCharSink(file, Charset.defaultCharset()).write(source);
inputFiles.add(file.getAbsolutePath());
return file;
}

private void addSourceFile(String fileName, String source) throws IOException {
inputFiles.add(addFile(fileName, source).getAbsolutePath());
}

private void addExternalAnnotationFileContents(Options options, String content)
throws IOException {
options.addExternalAnnotationFile(addFile("annotations.jaif", content).getPath());
}

private File createTempDir() throws IOException {
Expand Down
8 changes: 4 additions & 4 deletions java_deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ $(BUILD_DIR)/$(JAVAC_JAR): | $(BUILD_DIR)
@cp -f $(JAVA_HOME)/lib/$(JAVAC_JAR) $@

$(BUILD_DIR)/$(SCENELIB_JAR): | $(BUILD_DIR)
@curl -s -o $@.zip https://checkerframework.org/annotation-file-utilities/annotation-tools-3.8.0.zip
@unzip -qq -d $(BUILD_DIR) $@.zip annotation-tools/annotation-file-utilities/annotation-file-utilities.jar
@unzip -qq -d $(BUILD_DIR) $(BUILD_DIR)/annotation-tools/annotation-file-utilities/annotation-file-utilities.jar "scenelib/*"
@curl -s -o $@.zip https://checkerframework.org/annotation-file-utilities/annotation-tools-3.9.1.zip
@unzip -qq -d $(BUILD_DIR) $@.zip annotation-file-utilities/annotation-file-utilities.jar
@unzip -qq -d $(BUILD_DIR) $(BUILD_DIR)/annotation-file-utilities/annotation-file-utilities.jar "scenelib/*"
@cd $(BUILD_DIR) && zip -q -r $(SCENELIB_JAR) scenelib/
@rm -rf $(BUILD_DIR)/annotation-tools/ $(BUILD_DIR)/scenelib/
@rm -rf $(BUILD_DIR)/annotation-file-utilities/ $(BUILD_DIR)/scenelib/

$(BUILD_DIR)/$(JARJAR_JAR): | $(BUILD_DIR)
@cp -f $(JARJAR_HOME)/$(JARJAR_JAR) $@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1009,11 +1009,6 @@ public void addExternalAnnotationFile(String file) throws IOException {
externalAnnotations.addExternalAnnotationFile(file);
}

@VisibleForTesting
public void addExternalAnnotationFileContents(String fileContents) throws IOException {
externalAnnotations.addExternalAnnotationFileContents(fileContents);
}

// Unreleased experimental project.
public boolean translateClassfiles() {
return translateClassfiles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ public void addExternalAnnotationFile(String file) throws IOException {
IndexFileParser.parseFile(file, scene);
}

/** Useful for testing. */
public void addExternalAnnotationFileContents(String fileContents) throws IOException {
IndexFileParser.parseString(fileContents, scene);
}

/**
* {@link com.google.devtools.j2objc.translate.ExternalAnnotationInjector} should use this method
* to retrieve external annotations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ public class ExternalAnnotationInjectorTest extends GenerationTest {
+ " method qux()Ljava/lang/String;:"
+ " return: @p.Nullable";

private void addExternalAnnotationFileContents(String content) throws IOException {
options.addExternalAnnotationFile(addSourceFile(content, "annotations.jaif"));
}

// In order to test different paths, the non-null version is a type annotation and the nullable
// version is a declaration annotation.
private void setupNullabilityAnnotations(String externalAnnotations) throws IOException {
options.setNullability(true);
options.addExternalAnnotationFileContents(
addExternalAnnotationFileContents(
"package p: "
+ "annotation @NonNull: @java.lang.annotation.Target(value={TYPE_USE}) "
+ "annotation @Nullable: "
Expand Down Expand Up @@ -155,7 +159,7 @@ public void testVisitingConstructor() throws IOException {
+ "annotation @AnAnnotation: "
+ "class Test: "
+ " method <init>()V: @p.AnAnnotation";
options.addExternalAnnotationFileContents(externalNullabilityAnnotations);
addExternalAnnotationFileContents(externalNullabilityAnnotations);
addSourceFile("package p; public @interface AnAnnotation {}", "p/AnAnnotation.java");
String source = "package p; public class Test { public Test() {} }";
String translation = translateSourceFile(source, "p.Test", "p/Test.h");
Expand All @@ -175,7 +179,7 @@ public void testForwardDeclaration() throws IOException {
+ "class Test: "
+ " method foo(Ljava/lang/Thread;)V: @p.AnAnnotation";
addSourceFile("package p; public @interface AnAnnotation {}", "p/AnAnnotation.java");
options.addExternalAnnotationFileContents(externalNullabilityAnnotations);
addExternalAnnotationFileContents(externalNullabilityAnnotations);
String source =
"package p;"
+ "public class Test { "
Expand All @@ -193,7 +197,7 @@ public void testFunctionizer() throws IOException {
+ "annotation @AnAnnotation: "
+ "class Test: "
+ " method foo()V: @p.AnAnnotation";
options.addExternalAnnotationFileContents(externalAnnotations);
addExternalAnnotationFileContents(externalAnnotations);
addSourceFile("package p; public @interface AnAnnotation {}", "p/AnAnnotation.java");
String source =
"package p;"
Expand All @@ -216,7 +220,7 @@ public void testInjectReflectionSupport_type_keepReflection() throws IOException
REFLECTION_SUPPORT_ANNOTATION
+ "package p: "
+ "class Test: @ReflectionSupport(FULL) ";
options.addExternalAnnotationFileContents(externalReflectionSupportAnnotations);
addExternalAnnotationFileContents(externalReflectionSupportAnnotations);
options.setStripReflection(true);
String source = "package p; public class Test {}";
String translation = translateSourceFile(source, "p.Test", "p/Test.m");
Expand All @@ -228,7 +232,7 @@ public void testInjectReflectionSupport_type_stripReflection() throws IOExceptio
REFLECTION_SUPPORT_ANNOTATION
+ "package p: "
+ "class Test: @ReflectionSupport(NATIVE_ONLY) ";
options.addExternalAnnotationFileContents(externalReflectionSupportAnnotations);
addExternalAnnotationFileContents(externalReflectionSupportAnnotations);
options.setStripReflection(false);
String source = "package p; public class Test {}";
String translation = translateSourceFile(source, "p.Test", "p/Test.m");
Expand All @@ -243,7 +247,7 @@ public void testInjectRuntimeAnnotation() throws IOException {
+ "package p: "
+ "class Test: "
+ " method test()V: @Ignore";
options.addExternalAnnotationFileContents(externalReflectionSupportAnnotations);
addExternalAnnotationFileContents(externalReflectionSupportAnnotations);
String source = "package p; public class Test { public void test() {} }";
String translation = translateSourceFile(source, "p.Test", "p/Test.m");
assertTranslation(translation, "#include \"org/junit/Ignore.h\"");
Expand All @@ -256,7 +260,7 @@ public void testInjectToPackageInfo() throws IOException {
+ " public void test(String s) {} "
+ "}", "p/Test.java");
addSourceFile("package p;", "p/package-info.java");
options.addExternalAnnotationFileContents("package com.google.j2objc.annotations: "
addExternalAnnotationFileContents("package com.google.j2objc.annotations: "
+ "annotation @ObjectiveCName: "
+ " String value "
+ "annotation @ReflectionSupport: "
Expand All @@ -278,7 +282,7 @@ public void testInjectToPackageInfo() throws IOException {
}

private void setupObjectiveCNameAnnotations(String additionalAnnotations) throws IOException {
options.addExternalAnnotationFileContents(
addExternalAnnotationFileContents(
"package com.google.j2objc.annotations: "
+ "annotation @ObjectiveCName: @java.lang.annotation.Retention(value=CLASS) "
+ " @java.lang.annotation.Target(value={TYPE,METHOD,CONSTRUCTOR,PACKAGE}) "
Expand Down Expand Up @@ -331,7 +335,7 @@ public void testWeakOuter() throws IOException {
+ " int bar() { return i; } "
+ " } "
+ "}";
options.addExternalAnnotationFileContents(
addExternalAnnotationFileContents(
"package com.google.j2objc.annotations: "
+ "annotation @WeakOuter: "
+ "package p: "
Expand All @@ -350,7 +354,7 @@ public void testWeak() throws IOException {
+ " t = otherT;"
+ " }"
+ "}";
options.addExternalAnnotationFileContents(
addExternalAnnotationFileContents(
"package com.google.j2objc.annotations: "
+ "annotation @Weak: "
+ "package p: "
Expand All @@ -368,7 +372,7 @@ public void testRetainedWith() throws IOException {
+ " private Object o; "
+ " public void setO(Object o) { this.o = o; } "
+ "}";
options.addExternalAnnotationFileContents(
addExternalAnnotationFileContents(
"package com.google.j2objc.annotations: "
+ "annotation @RetainedWith: "
+ "package p: "
Expand All @@ -385,7 +389,7 @@ public void testAutoreleasePool() throws IOException {
+ "public class A { "
+ " public void test() {} "
+ "}";
options.addExternalAnnotationFileContents(
addExternalAnnotationFileContents(
"package com.google.j2objc.annotations: "
+ "annotation @AutoreleasePool: "
+ "package p: "
Expand Down

0 comments on commit 8a358be

Please sign in to comment.