Skip to content

Commit

Permalink
Replace j2clPassMode.ON and j2clPassMode.TRUE with AUTO semantics and…
Browse files Browse the repository at this point in the history
… make it the default.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=169485608
  • Loading branch information
gkdn authored and blickly committed Sep 21, 2017
1 parent c0d5759 commit 9fb5248
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 67 deletions.
6 changes: 1 addition & 5 deletions src/com/google/javascript/jscomp/CompilerOptions.java
Expand Up @@ -1296,7 +1296,7 @@ public CompilerOptions() {
angularPass = false; angularPass = false;
polymerVersion = null; polymerVersion = null;
dartPass = false; dartPass = false;
j2clPassMode = J2clPassMode.OFF; j2clPassMode = J2clPassMode.AUTO;
removeAbstractMethods = false; removeAbstractMethods = false;
removeSuperMethods = false; removeSuperMethods = false;
removeClosureAsserts = false; removeClosureAsserts = false;
Expand Down Expand Up @@ -3354,10 +3354,6 @@ public static enum J2clPassMode {
boolean shouldAddJ2clPasses() { boolean shouldAddJ2clPasses() {
return this == TRUE || this == ON || this == AUTO; return this == TRUE || this == ON || this == AUTO;
} }

boolean isExplicitlyOn() {
return this == TRUE || this == ON;
}
} }


public boolean expectStrictModeInput() { public boolean expectStrictModeInput() {
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/DefaultPassConfig.java
Expand Up @@ -465,7 +465,7 @@ private void addNonTranspilationCheckPasses(List<PassFactory> checks) {
addNewTypeCheckerPasses(checks, options); addNewTypeCheckerPasses(checks, options);
} }


if (options.j2clPassMode.equals(CompilerOptions.J2clPassMode.AUTO)) { if (options.j2clPassMode.shouldAddJ2clPasses()) {
checks.add(j2clSourceFileChecker); checks.add(j2clSourceFileChecker);
} }


Expand Down
21 changes: 12 additions & 9 deletions src/com/google/javascript/jscomp/J2clSourceFileChecker.java
Expand Up @@ -33,29 +33,32 @@ final class J2clSourceFileChecker implements CompilerPass {
this.compiler = compiler; this.compiler = compiler;
} }


private static Boolean hasJ2cl(Node root) { private static boolean hasJ2cl(Node root) {
for (Node script : root.children()) { for (Node script : root.children()) {
checkState(script.isScript()); checkState(script.isScript());
if (script.getSourceFileName() != null if (script.getSourceFileName() != null && script.getSourceFileName().endsWith(".java.js")) {
&& script.getSourceFileName().endsWith(".java.js") return true;
&& script.getSourceFileName().contains(".js.zip!")) {
return Boolean.TRUE;
} }
} }
return Boolean.FALSE; return false;
} }


@Override @Override
public void process(Node externs, Node root) { public void process(Node externs, Node root) {
compiler.setAnnotation(HAS_J2CL_ANNOTATION_KEY, hasJ2cl(root)); if (hasJ2cl(root)) {
markToRunJ2clPasses(compiler);
}
}

static void markToRunJ2clPasses(AbstractCompiler compiler) {
compiler.setAnnotation(HAS_J2CL_ANNOTATION_KEY, true);
} }


/** /**
* Indicates whether it should run future J2CL passes with information from the compiler. For * Indicates whether it should run future J2CL passes with information from the compiler. For
* example, if the compiler's HAS_J2CL annotation is false, it should. * example, if the compiler's HAS_J2CL annotation is false, it should.
*/ */
static boolean shouldRunJ2clPasses(AbstractCompiler compiler) { static boolean shouldRunJ2clPasses(AbstractCompiler compiler) {
return compiler.getOptions().j2clPassMode.isExplicitlyOn() return Boolean.TRUE.equals(compiler.getAnnotation(HAS_J2CL_ANNOTATION_KEY));
|| Boolean.TRUE.equals(compiler.getAnnotation(HAS_J2CL_ANNOTATION_KEY));
} }
} }
2 changes: 0 additions & 2 deletions test/com/google/javascript/jscomp/IntegrationTest.java
Expand Up @@ -26,7 +26,6 @@
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.primitives.Chars; import com.google.common.primitives.Chars;
import com.google.javascript.jscomp.CompilerOptions.DevMode; import com.google.javascript.jscomp.CompilerOptions.DevMode;
import com.google.javascript.jscomp.CompilerOptions.J2clPassMode;
import com.google.javascript.jscomp.CompilerOptions.LanguageMode; import com.google.javascript.jscomp.CompilerOptions.LanguageMode;
import com.google.javascript.jscomp.CompilerOptions.Reach; import com.google.javascript.jscomp.CompilerOptions.Reach;
import com.google.javascript.jscomp.testing.NodeSubject; import com.google.javascript.jscomp.testing.NodeSubject;
Expand Down Expand Up @@ -2073,7 +2072,6 @@ public void testPreservesCastInformation() {
"var x = /** @type {!Foo} */ (Arrays.$create()).myprop;"); "var x = /** @type {!Foo} */ (Arrays.$create()).myprop;");


options.setCheckTypes(true); options.setCheckTypes(true);
options.setJ2clPass(J2clPassMode.TRUE);
options.setDisambiguateProperties(true); options.setDisambiguateProperties(true);


test(options, code, test(options, code,
Expand Down
Expand Up @@ -23,10 +23,10 @@ protected CompilerPass getProcessor(final Compiler compiler) {
} }


@Override @Override
protected CompilerOptions getOptions() { protected Compiler createCompiler() {
CompilerOptions options = super.getOptions(); Compiler compiler = super.createCompiler();
options.setJ2clPass(CompilerOptions.J2clPassMode.ON); J2clSourceFileChecker.markToRunJ2clPasses(compiler);
return options; return compiler;
} }


public void testRemoveAssert() { public void testRemoveAssert() {
Expand Down
8 changes: 4 additions & 4 deletions test/com/google/javascript/jscomp/J2clCheckPassTest.java
Expand Up @@ -36,10 +36,10 @@ protected CompilerPass getProcessor(Compiler compiler) {
} }


@Override @Override
protected CompilerOptions getOptions() { protected Compiler createCompiler() {
CompilerOptions options = super.getOptions(); Compiler compiler = super.createCompiler();
options.setJ2clPass(CompilerOptions.J2clPassMode.ON); J2clSourceFileChecker.markToRunJ2clPasses(compiler);
return options; return compiler;
} }


public void testReferenceEquality_noWarning_other() { public void testReferenceEquality_noWarning_other() {
Expand Down
Expand Up @@ -26,11 +26,12 @@ protected CompilerPass getProcessor(Compiler compiler) {
} }


@Override @Override
protected CompilerOptions getOptions() { protected Compiler createCompiler() {
CompilerOptions options = super.getOptions(); Compiler compiler = super.createCompiler();
options.setJ2clPass(CompilerOptions.J2clPassMode.ON); J2clSourceFileChecker.markToRunJ2clPasses(compiler);
return options; return compiler;
} }

@Override @Override
protected int getNumRepetitions() { protected int getNumRepetitions() {
// A single run should be sufficient. // A single run should be sufficient.
Expand Down
Expand Up @@ -23,10 +23,10 @@ protected CompilerPass getProcessor(final Compiler compiler) {
} }


@Override @Override
protected CompilerOptions getOptions() { protected Compiler createCompiler() {
CompilerOptions options = super.getOptions(); Compiler compiler = super.createCompiler();
options.setJ2clPass(CompilerOptions.J2clPassMode.ON); J2clSourceFileChecker.markToRunJ2clPasses(compiler);
return options; return compiler;
} }


public void testHoistClinitConstantAssignments() { public void testHoistClinitConstantAssignments() {
Expand Down
Expand Up @@ -32,12 +32,14 @@ protected void setUp() throws Exception {
protected CompilerPass getProcessor(final Compiler compiler) { protected CompilerPass getProcessor(final Compiler compiler) {
return new PeepholeOptimizationsPass(compiler, getName(), new J2clEqualitySameRewriterPass()); return new PeepholeOptimizationsPass(compiler, getName(), new J2clEqualitySameRewriterPass());
} }

@Override @Override
protected CompilerOptions getOptions() { protected Compiler createCompiler() {
CompilerOptions options = super.getOptions(); Compiler compiler = super.createCompiler();
options.setJ2clPass(CompilerOptions.J2clPassMode.ON); J2clSourceFileChecker.markToRunJ2clPasses(compiler);
return options; return compiler;
} }

public void testRewriteEqualitySame() { public void testRewriteEqualitySame() {
test( test(
LINE_JOINER.join( LINE_JOINER.join(
Expand Down
8 changes: 6 additions & 2 deletions test/com/google/javascript/jscomp/J2clIntegrationTest.java
Expand Up @@ -15,7 +15,6 @@
*/ */
package com.google.javascript.jscomp; package com.google.javascript.jscomp;


import com.google.javascript.jscomp.CompilerOptions.J2clPassMode;
import com.google.javascript.jscomp.CompilerOptions.LanguageMode; import com.google.javascript.jscomp.CompilerOptions.LanguageMode;




Expand Down Expand Up @@ -58,13 +57,18 @@ public void testFoldJ2clClinits() {
test(createCompilerOptions(), code, ""); test(createCompilerOptions(), code, "");
} }


@Override
public void setUp() {
super.setUp();
inputFileNameSuffix = ".java.js";
}

@Override @Override
CompilerOptions createCompilerOptions() { CompilerOptions createCompilerOptions() {
CompilerOptions options = new CompilerOptions(); CompilerOptions options = new CompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options); CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
options.setLanguageIn(LanguageMode.ECMASCRIPT6_TYPED); options.setLanguageIn(LanguageMode.ECMASCRIPT6_TYPED);
options.setLanguageOut(LanguageMode.ECMASCRIPT5); options.setLanguageOut(LanguageMode.ECMASCRIPT5);
options.setJ2clPass(J2clPassMode.ON);
return options; return options;
} }
} }
8 changes: 4 additions & 4 deletions test/com/google/javascript/jscomp/J2clPassTest.java
Expand Up @@ -41,10 +41,10 @@ protected CompilerPass getProcessor(final Compiler compiler) {
} }


@Override @Override
protected CompilerOptions getOptions() { protected Compiler createCompiler() {
CompilerOptions options = super.getOptions(); Compiler compiler = super.createCompiler();
options.setJ2clPass(CompilerOptions.J2clPassMode.ON); J2clSourceFileChecker.markToRunJ2clPasses(compiler);
return options; return compiler;
} }


public void testUtilGetDefine() { public void testUtilGetDefine() {
Expand Down
Expand Up @@ -33,10 +33,10 @@ protected CompilerPass getProcessor(Compiler compiler) {
} }


@Override @Override
protected CompilerOptions getOptions() { protected Compiler createCompiler() {
CompilerOptions options = super.getOptions(); Compiler compiler = super.createCompiler();
options.setJ2clPass(CompilerOptions.J2clPassMode.ON); J2clSourceFileChecker.markToRunJ2clPasses(compiler);
return options; return compiler;
} }


@Override @Override
Expand Down
22 changes: 2 additions & 20 deletions test/com/google/javascript/jscomp/J2clSourceFileCheckerTest.java
Expand Up @@ -22,12 +22,6 @@


/** Tests for {@link J2clSourceFileChecker}. */ /** Tests for {@link J2clSourceFileChecker}. */
public class J2clSourceFileCheckerTest extends CompilerTestCase { public class J2clSourceFileCheckerTest extends CompilerTestCase {
private static final SourceFile NO_J2CL_SOURCE_FILE =
SourceFile.fromCode(
"noJ2cl.js", "goog.provide('noJ2cl'); /** @constructor */ function noJ2cl(){};");
private static final SourceFile NO_J2CL_SOURCE_FILE2 =
SourceFile.fromCode(
"noJ2cl2.js", "goog.provide('noJ2cl2'); /** @constructor */ function noJ2cl2(){};");
private static final SourceFile J2CL_SOURCE_FILE = private static final SourceFile J2CL_SOURCE_FILE =
SourceFile.fromCode( SourceFile.fromCode(
"jar:file://foo.js.zip!foo/bar.impl.java.js", "jar:file://foo.js.zip!foo/bar.impl.java.js",
Expand All @@ -48,26 +42,14 @@ protected CompilerPass getProcessor(final Compiler compiler) {
return checkContainingJ2cl; return checkContainingJ2cl;
} }


public void testHasJ2cl() {
testSame(ImmutableList.of(NO_J2CL_SOURCE_FILE, J2CL_SOURCE_FILE, NO_J2CL_SOURCE_FILE2));
assertThat(compiler.getAnnotation(J2clSourceFileChecker.HAS_J2CL_ANNOTATION_KEY))
.isEqualTo(Boolean.TRUE);
}

public void testHasNoJ2cl() {
testSame(ImmutableList.of(NO_J2CL_SOURCE_FILE, NO_J2CL_SOURCE_FILE2));
assertThat(compiler.getAnnotation(J2clSourceFileChecker.HAS_J2CL_ANNOTATION_KEY))
.isEqualTo(Boolean.FALSE);
}

public void testShouldRunJ2clPassesWithoutJ2clSources() { public void testShouldRunJ2clPassesWithoutJ2clSources() {
testSame(""); testSame("");
assertThat(J2clSourceFileChecker.shouldRunJ2clPasses(compiler)).isFalse(); assertThat(J2clSourceFileChecker.shouldRunJ2clPasses(compiler)).isFalse();


compiler.getOptions().setJ2clPass(J2clPassMode.ON); compiler.getOptions().setJ2clPass(J2clPassMode.ON);
assertThat(J2clSourceFileChecker.shouldRunJ2clPasses(compiler)).isTrue(); assertThat(J2clSourceFileChecker.shouldRunJ2clPasses(compiler)).isFalse();
compiler.getOptions().setJ2clPass(J2clPassMode.TRUE); compiler.getOptions().setJ2clPass(J2clPassMode.TRUE);
assertThat(J2clSourceFileChecker.shouldRunJ2clPasses(compiler)).isTrue(); assertThat(J2clSourceFileChecker.shouldRunJ2clPasses(compiler)).isFalse();
compiler.getOptions().setJ2clPass(J2clPassMode.AUTO); compiler.getOptions().setJ2clPass(J2clPassMode.AUTO);
assertThat(J2clSourceFileChecker.shouldRunJ2clPasses(compiler)).isFalse(); assertThat(J2clSourceFileChecker.shouldRunJ2clPasses(compiler)).isFalse();
} }
Expand Down

0 comments on commit 9fb5248

Please sign in to comment.