Skip to content

Commit

Permalink
Automated cleanups
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=148280587
  • Loading branch information
tbreisacher committed Feb 27, 2017
1 parent 2575059 commit e648a64
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 40 deletions.
23 changes: 10 additions & 13 deletions src/com/google/javascript/jscomp/CommandLineRunner.java
Expand Up @@ -131,9 +131,9 @@ private static class Flags {
// Some clients run a few copies of the compiler through CommandLineRunner // Some clients run a few copies of the compiler through CommandLineRunner
// on parallel threads (thankfully, with the same flags), // on parallel threads (thankfully, with the same flags),
// so the access to these lists should be synchronized. // so the access to these lists should be synchronized.
private static List<FlagEntry<CheckLevel>> guardLevels = private static final List<FlagEntry<CheckLevel>> guardLevels =
Collections.synchronizedList(new ArrayList<FlagEntry<CheckLevel>>()); Collections.synchronizedList(new ArrayList<FlagEntry<CheckLevel>>());
private static List<FlagEntry<JsSourceType>> mixedJsSources = private static final List<FlagEntry<JsSourceType>> mixedJsSources =
Collections.synchronizedList(new ArrayList<FlagEntry<JsSourceType>>()); Collections.synchronizedList(new ArrayList<FlagEntry<JsSourceType>>());


@Option( @Option(
Expand Down Expand Up @@ -741,7 +741,7 @@ private static class Flags {
private List<String> arguments = new ArrayList<>(); private List<String> arguments = new ArrayList<>();
private final CmdLineParser parser; private final CmdLineParser parser;


private static final Map<String, CompilationLevel> COMPILATION_LEVEL_MAP = private static final ImmutableMap<String, CompilationLevel> COMPILATION_LEVEL_MAP =
ImmutableMap.of( ImmutableMap.of(
"WHITESPACE_ONLY", "WHITESPACE_ONLY",
CompilationLevel.WHITESPACE_ONLY, CompilationLevel.WHITESPACE_ONLY,
Expand Down Expand Up @@ -940,7 +940,7 @@ private void printStringLineWrapped(String input, OutputStreamWriter outputStrea
" " + input.substring(foundMatch ? endIndex + 1 : endIndex), outputStream); " " + input.substring(foundMatch ? endIndex + 1 : endIndex), outputStream);
} }


private void printShortUsageAfterErrors(PrintStream ps) { private static void printShortUsageAfterErrors(PrintStream ps) {
ps.print("Sample usage: "); ps.print("Sample usage: ");
ps.println("--compilation_level (-O) VAL --externs VAL --js VAL" ps.println("--compilation_level (-O) VAL --externs VAL --js VAL"
+ " --js_output_file VAL" + " --js_output_file VAL"
Expand Down Expand Up @@ -1047,10 +1047,8 @@ private ImmutableMap<String, String> splitPipeParts(Iterable<String> input,
// Our own option parser to be backwards-compatible. // Our own option parser to be backwards-compatible.
// It needs to be public because of the crazy reflection that args4j does. // It needs to be public because of the crazy reflection that args4j does.
public static class BooleanOptionHandler extends OptionHandler<Boolean> { public static class BooleanOptionHandler extends OptionHandler<Boolean> {
private static final Set<String> TRUES = private static final ImmutableSet<String> TRUES = ImmutableSet.of("true", "on", "yes", "1");
ImmutableSet.of("true", "on", "yes", "1"); private static final ImmutableSet<String> FALSES = ImmutableSet.of("false", "off", "no", "0");
private static final Set<String> FALSES =
ImmutableSet.of("false", "off", "no", "0");


public BooleanOptionHandler( public BooleanOptionHandler(
CmdLineParser parser, OptionDef option, CmdLineParser parser, OptionDef option,
Expand Down Expand Up @@ -1400,8 +1398,7 @@ private void initConfigFromFlags(String[] args, PrintStream out, PrintStream err


if (flags.outputWrapperFile != null && !flags.outputWrapperFile.isEmpty()) { if (flags.outputWrapperFile != null && !flags.outputWrapperFile.isEmpty()) {
try { try {
flags.outputWrapper = Files.toString( flags.outputWrapper = Files.asCharSource(new File(flags.outputWrapperFile), UTF_8).read();
new File(flags.outputWrapperFile), UTF_8);
} catch (Exception e) { } catch (Exception e) {
reportError("ERROR - invalid output_wrapper_file specified."); reportError("ERROR - invalid output_wrapper_file specified.");
} }
Expand All @@ -1422,7 +1419,7 @@ private void initConfigFromFlags(String[] args, PrintStream out, PrintStream err
} }


if (errors) { if (errors) {
flags.printShortUsageAfterErrors(errorStream); Flags.printShortUsageAfterErrors(errorStream);
} else if (flags.displayHelp) { } else if (flags.displayHelp) {
flags.printUsage(out); flags.printUsage(out);
} else if (flags.version) { } else if (flags.version) {
Expand Down Expand Up @@ -1735,7 +1732,7 @@ protected List<SourceFile> createExterns(CompilerOptions options) throws IOExcep
} }
} }


private ImmutableList<ConformanceConfig> loadConformanceConfigs(List<String> configPaths) { private static ImmutableList<ConformanceConfig> loadConformanceConfigs(List<String> configPaths) {
ImmutableList.Builder<ConformanceConfig> configs = ImmutableList.Builder<ConformanceConfig> configs =
ImmutableList.builder(); ImmutableList.builder();


Expand All @@ -1752,7 +1749,7 @@ private ImmutableList<ConformanceConfig> loadConformanceConfigs(List<String> con


private static ConformanceConfig loadConformanceConfig(String configFile) private static ConformanceConfig loadConformanceConfig(String configFile)
throws IOException { throws IOException {
String textProto = Files.toString(new File(configFile), UTF_8); String textProto = Files.asCharSource(new File(configFile), UTF_8).read();


ConformanceConfig.Builder builder = ConformanceConfig.newBuilder(); ConformanceConfig.Builder builder = ConformanceConfig.newBuilder();


Expand Down
3 changes: 1 addition & 2 deletions src/com/google/javascript/jscomp/JSModule.java
Expand Up @@ -181,8 +181,7 @@ public Set<JSModule> getAllDependencies() {
while (!stack.isEmpty()) { while (!stack.isEmpty()) {
JSModule module = stack.pop(); JSModule module = stack.pop();
List<JSModule> moduleDeps = module.deps; List<JSModule> moduleDeps = module.deps;
for (int i = 0; i < moduleDeps.size(); i++) { for (JSModule dep : moduleDeps) {
JSModule dep = moduleDeps.get(i);
if (allDeps.add(dep)) { if (allDeps.add(dep)) {
stack.push(dep); stack.push(dep);
} }
Expand Down
8 changes: 4 additions & 4 deletions src/com/google/javascript/jscomp/JSModuleGraph.java
Expand Up @@ -53,13 +53,13 @@
*/ */
public final class JSModuleGraph { public final class JSModuleGraph {


private List<JSModule> modules; private final List<JSModule> modules;


/** /**
* Lists of modules at each depth. <code>modulesByDepth.get(3)</code> is a * Lists of modules at each depth. <code>modulesByDepth.get(3)</code> is a list of the modules at
* list of the modules at depth 3, for example. * depth 3, for example.
*/ */
private List<List<JSModule>> modulesByDepth; private final List<List<JSModule>> modulesByDepth;


/** /**
* dependencyMap is a cache of dependencies that makes the dependsOn function faster. Each map * dependencyMap is a cache of dependencies that makes the dependsOn function faster. Each map
Expand Down
6 changes: 3 additions & 3 deletions src/com/google/javascript/jscomp/JsAst.java
Expand Up @@ -35,9 +35,9 @@
public class JsAst implements SourceAst { public class JsAst implements SourceAst {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;


private transient InputId inputId; private final transient InputId inputId;
private transient SourceFile sourceFile; private transient SourceFile sourceFile;
private String fileName; private final String fileName;
private Node root; private Node root;
private FeatureSet features; private FeatureSet features;


Expand Down Expand Up @@ -119,7 +119,7 @@ public static class ParseResult implements Serializable {
private static class RecordingReporterProxy implements ErrorReporter { private static class RecordingReporterProxy implements ErrorReporter {
final ArrayList<RhinoError> errors = new ArrayList<>(); final ArrayList<RhinoError> errors = new ArrayList<>();
final ArrayList<RhinoError> warnings = new ArrayList<>(); final ArrayList<RhinoError> warnings = new ArrayList<>();
private ErrorReporter delegateReporter; private final ErrorReporter delegateReporter;


RecordingReporterProxy(ErrorReporter delegateReporter) { RecordingReporterProxy(ErrorReporter delegateReporter) {
this.delegateReporter = delegateReporter; this.delegateReporter = delegateReporter;
Expand Down
9 changes: 4 additions & 5 deletions src/com/google/javascript/jscomp/JsMessage.java
Expand Up @@ -277,9 +277,8 @@ public String toString() {


@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
return o == this || return o == this
o instanceof PlaceholderReference && || (o instanceof PlaceholderReference && name.equals(((PlaceholderReference) o).name));
name.equals(((PlaceholderReference) o).name);
} }


@Override @Override
Expand Down Expand Up @@ -317,8 +316,8 @@ private static String getExternalMessageId(String identifier) {
private String desc; private String desc;
private boolean hidden; private boolean hidden;


private List<CharSequence> parts = new LinkedList<>(); private final List<CharSequence> parts = new LinkedList<>();
private Set<String> placeholders = new HashSet<>(); private final Set<String> placeholders = new HashSet<>();


private String sourceName; private String sourceName;


Expand Down
Expand Up @@ -30,7 +30,7 @@
* *
*/ */
public final class LightweightMessageFormatter extends AbstractMessageFormatter { public final class LightweightMessageFormatter extends AbstractMessageFormatter {
private SourceExcerpt excerpt; private final SourceExcerpt excerpt;
private static final ExcerptFormatter excerptFormatter = private static final ExcerptFormatter excerptFormatter =
new LineNumberingFormatter(); new LineNumberingFormatter();
private boolean includeLocation = true; private boolean includeLocation = true;
Expand Down
3 changes: 1 addition & 2 deletions src/com/google/javascript/jscomp/NameAnonymousFunctions.java
Expand Up @@ -17,7 +17,6 @@
package com.google.javascript.jscomp; package com.google.javascript.jscomp;


import com.google.javascript.rhino.Node; import com.google.javascript.rhino.Node;

import java.util.logging.Logger; import java.util.logging.Logger;


/** /**
Expand Down Expand Up @@ -65,7 +64,7 @@ public void process(Node externs, Node root) {
*/ */
private class AnonymousFunctionNamer private class AnonymousFunctionNamer
implements AnonymousFunctionNamingCallback.FunctionNamer { implements AnonymousFunctionNamingCallback.FunctionNamer {
private NodeNameExtractor nameExtractor; private final NodeNameExtractor nameExtractor;


AnonymousFunctionNamer() { AnonymousFunctionNamer() {
this.nameExtractor = new NodeNameExtractor(DELIMITER); this.nameExtractor = new NodeNameExtractor(DELIMITER);
Expand Down
Expand Up @@ -42,8 +42,8 @@
*/ */
class NameAnonymousFunctionsMapped implements CompilerPass { class NameAnonymousFunctionsMapped implements CompilerPass {


private static Logger logger = Logger.getLogger( private static final Logger logger =
NameAnonymousFunctionsMapped.class.getName()); Logger.getLogger(NameAnonymousFunctionsMapped.class.getName());


static final char PREFIX = '$'; static final char PREFIX = '$';
static final String PREFIX_STRING = "$"; static final String PREFIX_STRING = "$";
Expand Down
16 changes: 12 additions & 4 deletions src/com/google/javascript/jscomp/ReferenceCollectingCallback.java
Expand Up @@ -21,6 +21,7 @@
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.javascript.jscomp.NodeTraversal.ScopedCallback; import com.google.javascript.jscomp.NodeTraversal.ScopedCallback;
import com.google.javascript.rhino.InputId; import com.google.javascript.rhino.InputId;
import com.google.javascript.rhino.Node; import com.google.javascript.rhino.Node;
Expand Down Expand Up @@ -294,7 +295,7 @@ private static <T> T pop(List<T> list) {
} }


private static <T> T peek(List<T> list) { private static <T> T peek(List<T> list) {
return list.get(list.size() - 1); return Iterables.getLast(list);
} }


/** /**
Expand Down Expand Up @@ -592,9 +593,16 @@ public String toString() {
*/ */
public static final class Reference implements StaticRef { public static final class Reference implements StaticRef {


private static final Set<Token> DECLARATION_PARENTS = private static final ImmutableSet<Token> DECLARATION_PARENTS =
ImmutableSet.of(Token.VAR, Token.LET, Token.CONST, Token.PARAM_LIST, ImmutableSet.of(
Token.FUNCTION, Token.CLASS, Token.CATCH, Token.REST); Token.VAR,
Token.LET,
Token.CONST,
Token.PARAM_LIST,
Token.FUNCTION,
Token.CLASS,
Token.CATCH,
Token.REST);


private final Node nameNode; private final Node nameNode;
private final BasicBlock basicBlock; private final BasicBlock basicBlock;
Expand Down
5 changes: 3 additions & 2 deletions src/com/google/javascript/jscomp/SourceFile.java
Expand Up @@ -42,6 +42,7 @@
import java.util.Arrays; import java.util.Arrays;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;


Expand Down Expand Up @@ -588,7 +589,7 @@ public synchronized String getCode() throws IOException {


if (cachedCode == null) { if (cachedCode == null) {
cachedCode = Files.toString(file, this.getCharset()); cachedCode = Files.toString(file, this.getCharset());
super.setCode(cachedCode, this.getCharset() == StandardCharsets.UTF_8); super.setCode(cachedCode, Objects.equals(this.getCharset(), StandardCharsets.UTF_8));
// Byte Order Mark can be removed by setCode // Byte Order Mark can be removed by setCode
cachedCode = super.getCode(); cachedCode = super.getCode();
} }
Expand Down Expand Up @@ -691,7 +692,7 @@ public synchronized String getCode() throws IOException {
// Must close the stream or else the cache won't be cleared. // Must close the stream or else the cache won't be cleared.
inputStream.close(); inputStream.close();


super.setCode(cachedCode, this.getCharset() == StandardCharsets.UTF_8); super.setCode(cachedCode, Objects.equals(this.getCharset(), StandardCharsets.UTF_8));
// Byte Order Mark can be removed by setCode // Byte Order Mark can be removed by setCode
cachedCode = super.getCode(); cachedCode = super.getCode();
} }
Expand Down
3 changes: 1 addition & 2 deletions src/com/google/javascript/jscomp/SourceMapInput.java
Expand Up @@ -18,7 +18,6 @@


import com.google.debugging.sourcemap.SourceMapConsumerV3; import com.google.debugging.sourcemap.SourceMapConsumerV3;
import com.google.debugging.sourcemap.SourceMapParseException; import com.google.debugging.sourcemap.SourceMapParseException;

import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
Expand All @@ -31,7 +30,7 @@ public final class SourceMapInput {
private static final Logger logger = private static final Logger logger =
Logger.getLogger(SourceMapInput.class.getName()); Logger.getLogger(SourceMapInput.class.getName());


private SourceFile sourceFile; private final SourceFile sourceFile;
private volatile SourceMapConsumerV3 parsedSourceMap = null; private volatile SourceMapConsumerV3 parsedSourceMap = null;


public SourceMapInput(SourceFile sourceFile) { public SourceMapInput(SourceFile sourceFile) {
Expand Down

0 comments on commit e648a64

Please sign in to comment.