Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic code cleanup. #344

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,983 changes: 989 additions & 994 deletions javatests/com/google/turbine/binder/BinderErrorTest.java

Large diffs are not rendered by default.

204 changes: 127 additions & 77 deletions javatests/com/google/turbine/deps/DependenciesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ public void excluded() throws Exception {
new LibraryBuilder()
.setClasspath(liba)
.addSourceLines(
"B.java", //
"class B {",
" public static final A a = new A();",
"}")
"B.java",
"""
class B {
public static final A a = new A();
}
""")
.compileToJar("libb.jar");
DepsProto.Dependencies deps =
new DepsBuilder()
Expand All @@ -167,10 +169,12 @@ public void transitive() throws Exception {
Path liba =
new LibraryBuilder()
.addSourceLines(
"A.java", //
"class A {",
" public static final class Y {}",
"}")
"A.java",
"""
class A {
public static final class Y {}
}
""")
.compileToJar("liba.jar");
Path libb =
new LibraryBuilder()
Expand All @@ -181,10 +185,12 @@ public void transitive() throws Exception {
new DepsBuilder()
.setClasspath(liba, libb)
.addSourceLines(
"Test.java", //
"class Test extends B {",
" public static class X extends Y {}",
"}")
"Test.java",
"""
class Test extends B {
public static class X extends Y {}
}
""")
.run();
assertThat(depsMap(deps))
.containsExactly(
Expand All @@ -197,35 +203,49 @@ public void closure() throws Exception {
new LibraryBuilder()
.addSourceLines(
"i/I.java",
"package i;", //
"public interface I {}")
"""
package i;

public interface I {}
""")
.compileToJar("libi.jar");
Path liba =
new LibraryBuilder()
.setClasspath(libi)
.addSourceLines(
"a/A.java", //
"package a;",
"import i.I;",
"public class A implements I {}")
"a/A.java",
"""
package a;

import i.I;

public class A implements I {}
""")
.compileToJar("liba.jar");
Path libb =
new LibraryBuilder()
.setClasspath(liba, libi)
.addSourceLines(
"b/B.java", //
"package b;",
"import a.A;",
"public class B extends A {}")
"b/B.java",
"""
package b;

import a.A;

public class B extends A {}
""")
.compileToJar("libb.jar");
{
DepsProto.Dependencies deps =
new DepsBuilder()
.setClasspath(liba, libb, libi)
.addSourceLines(
"Test.java", //
"import b.B;",
"class Test extends B {}")
"Test.java",
"""
import b.B;

class Test extends B {}
""")
.run();
assertThat(depsMap(deps))
.containsExactly(
Expand All @@ -242,9 +262,12 @@ public void closure() throws Exception {
new DepsBuilder()
.setClasspath(liba, libb)
.addSourceLines(
"Test.java", //
"import b.B;",
"class Test extends B {}")
"Test.java",
"""
import b.B;

class Test extends B {}
""")
.run();
assertThat(depsMap(deps))
.containsExactly(
Expand Down Expand Up @@ -298,34 +321,46 @@ public void packageInfo() throws Exception {
new LibraryBuilder()
.addSourceLines(
"p/Anno.java",
"package p;",
"import java.lang.annotation.Retention;",
"import static java.lang.annotation.RetentionPolicy.RUNTIME;",
"@Retention(RUNTIME)",
"@interface Anno {}")
"""
package p;

import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Retention(RUNTIME)
@interface Anno {}
""")
.addSourceLines(
"p/package-info.java", //
"@Anno",
"package p;")
"p/package-info.java",
"""
@Anno
package p;
""")
.compileToJar("libpackage-info.jar");
Path libp =
new LibraryBuilder()
.setClasspath(libpackageInfo)
.addSourceLines(
"p/P.java", //
"package p;",
"public class P {}")
"p/P.java",
"""
package p;

public class P {}
""")
.compileToJar("libp.jar");
{
DepsProto.Dependencies deps =
new DepsBuilder()
.setClasspath(libp, libpackageInfo)
.addSourceLines(
"Test.java", //
"import p.P;",
"class Test {",
" P p;",
"}")
"Test.java",
"""
import p.P;

class Test {
P p;
}
""")
.run();
assertThat(depsMap(deps))
.containsExactly(
Expand All @@ -345,12 +380,14 @@ public void annotations_recursive() throws Exception {
new DepsBuilder()
.setClasspath(libA, libB)
.addSourceLines(
"Test.java", //
"import a.A;",
"import b.B;",
"@A(B.class)",
"class Test {",
"}")
"Test.java",
"""
import a.A;
import b.B;

@A(B.class)
class Test {}
""")
.run();
assertThat(depsMap(deps))
.containsExactly(
Expand All @@ -365,13 +402,16 @@ public void annotations_field() throws Exception {
new DepsBuilder()
.setClasspath(libA, libB)
.addSourceLines(
"Test.java", //
"import a.A;",
"import b.B;",
"class Test {",
" @A(B.class)",
" int x;",
"}")
"Test.java",
"""
import a.A;
import b.B;

class Test {
@A(B.class)
int x;
}
""")
.run();
assertThat(depsMap(deps))
.containsExactly(
Expand All @@ -386,13 +426,16 @@ public void annotations_method() throws Exception {
new DepsBuilder()
.setClasspath(libA, libB)
.addSourceLines(
"Test.java", //
"import a.A;",
"import b.B;",
"class Test {",
" @A(B.class)",
" void f() {}",
"}")
"Test.java",
"""
import a.A;
import b.B;

class Test {
@A(B.class)
void f() {}
}
""")
.run();
assertThat(depsMap(deps))
.containsExactly(
Expand All @@ -403,26 +446,33 @@ private Path libB() throws Exception {
return new LibraryBuilder()
.addSourceLines(
"b/B.java",
"package b;",
"import java.lang.annotation.Retention;",
"import static java.lang.annotation.RetentionPolicy.RUNTIME;",
"@Retention(RUNTIME)",
"public @interface B {",
"}")
"""
package b;

import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Retention(RUNTIME)
public @interface B {}
""")
.compileToJar("libb.jar");
}

private Path libA() throws Exception {
return new LibraryBuilder()
.addSourceLines(
"a/A.java",
"package a;",
"import java.lang.annotation.Retention;",
"import static java.lang.annotation.RetentionPolicy.RUNTIME;",
"@Retention(RUNTIME)",
"public @interface A {",
" Class<?> value() default Object.class;",
"}")
"""
package a;

import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Retention(RUNTIME)
public @interface A {
Class<?> value() default Object.class;
}
""")
.compileToJar("liba.jar");
}

Expand Down
Loading
Loading