Skip to content

Commit

Permalink
Use Immutable collections for static final CONSTANT_CASE fields.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=149063770
  • Loading branch information
dorireuv authored and brad4d committed Mar 3, 2017
1 parent 0e94c8a commit a28045f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 20 deletions.
Expand Up @@ -17,7 +17,6 @@


import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;


import java.util.Set;


/** /**
* Abstract message formatter providing default behavior for implementations * Abstract message formatter providing default behavior for implementations
Expand All @@ -43,11 +42,8 @@ protected final SourceExcerptProvider getSource() {
return source; return source;
} }


private static final Set<String> SUPPORTED_COLOR_TERMINALS = private static final ImmutableSet<String> SUPPORTED_COLOR_TERMINALS =
ImmutableSet.of("xterm", ImmutableSet.of("xterm", "xterm-color", "xterm-256color", "screen-bce");
"xterm-color",
"xterm-256color",
"screen-bce");


static boolean termSupportsColor(String term) { static boolean termSupportsColor(String term) {
return SUPPORTED_COLOR_TERMINALS.contains(term); return SUPPORTED_COLOR_TERMINALS.contains(term);
Expand Down
Expand Up @@ -23,10 +23,8 @@
import com.google.javascript.rhino.IR; import com.google.javascript.rhino.IR;
import com.google.javascript.rhino.Node; import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.Token; import com.google.javascript.rhino.Token;

import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;


/** /**
* Callback that gathers subexpressions that may have side effects * Callback that gathers subexpressions that may have side effects
Expand Down Expand Up @@ -186,8 +184,8 @@ private Node simplifyShortCircuitBranch(Node node) {
} }
} }


private static final Set<Token> FORBIDDEN_TYPES = ImmutableSet.of( private static final ImmutableSet<Token> FORBIDDEN_TYPES =
Token.BLOCK, Token.SCRIPT, Token.VAR, Token.EXPR_RESULT, Token.RETURN); ImmutableSet.of(Token.BLOCK, Token.SCRIPT, Token.VAR, Token.EXPR_RESULT, Token.RETURN);
private final AbstractCompiler compiler; private final AbstractCompiler compiler;
private final SideEffectAccumulator accumulator; private final SideEffectAccumulator accumulator;


Expand Down
3 changes: 1 addition & 2 deletions src/com/google/javascript/jscomp/NameAnalyzer.java
Expand Up @@ -121,8 +121,7 @@ final class NameAnalyzer implements CompilerPass {
private static final String FUNCTION = "Function"; private static final String FUNCTION = "Function";


/** All of these refer to global scope. These can be moved to config */ /** All of these refer to global scope. These can be moved to config */
static final Set<String> DEFAULT_GLOBAL_NAMES = ImmutableSet.of( static final ImmutableSet<String> DEFAULT_GLOBAL_NAMES = ImmutableSet.of("window", "goog.global");
"window", "goog.global");


/** Whether to remove unreferenced variables in main pass */ /** Whether to remove unreferenced variables in main pass */
private final boolean removeUnreferenced; private final boolean removeUnreferenced;
Expand Down
3 changes: 2 additions & 1 deletion src/com/google/javascript/jscomp/VariableReferenceCheck.java
Expand Up @@ -16,6 +16,7 @@


package com.google.javascript.jscomp; package com.google.javascript.jscomp;


import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.javascript.jscomp.NodeTraversal.AbstractShallowCallback; import com.google.javascript.jscomp.NodeTraversal.AbstractShallowCallback;
import com.google.javascript.jscomp.ReferenceCollectingCallback.BasicBlock; import com.google.javascript.jscomp.ReferenceCollectingCallback.BasicBlock;
Expand Down Expand Up @@ -79,7 +80,7 @@ class VariableReferenceCheck implements HotSwapCompilerPass {


// These types do not permit a block-scoped declaration inside them without an explicit block. // These types do not permit a block-scoped declaration inside them without an explicit block.
// e.g. if (b) let x; // e.g. if (b) let x;
private static final Set<Token> BLOCKLESS_DECLARATION_FORBIDDEN_STATEMENTS = private static final ImmutableSet<Token> BLOCKLESS_DECLARATION_FORBIDDEN_STATEMENTS =
Sets.immutableEnumSet(Token.IF, Token.FOR, Token.FOR_IN, Token.FOR_OF, Token.WHILE); Sets.immutableEnumSet(Token.IF, Token.FOR, Token.FOR_IN, Token.FOR_OF, Token.WHILE);


public VariableReferenceCheck(AbstractCompiler compiler) { public VariableReferenceCheck(AbstractCompiler compiler) {
Expand Down
Expand Up @@ -19,17 +19,12 @@
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;


import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;

import junit.framework.TestCase;

import java.util.Collections; import java.util.Collections;
import java.util.Set; import junit.framework.TestCase;


public final class DefaultNameGeneratorTest extends TestCase { public final class DefaultNameGeneratorTest extends TestCase {


private static final Set<String> RESERVED_NAMES = ImmutableSet.of( private static final ImmutableSet<String> RESERVED_NAMES = ImmutableSet.of("ba", "xba");
"ba",
"xba");


private static String[] generate( private static String[] generate(
DefaultNameGenerator ng, String prefix, int num) throws Exception { DefaultNameGenerator ng, String prefix, int num) throws Exception {
Expand Down

0 comments on commit a28045f

Please sign in to comment.