diff --git a/src/com/google/javascript/jscomp/CompilerInput.java b/src/com/google/javascript/jscomp/CompilerInput.java index 97c394b4db3..c8754ca634f 100644 --- a/src/com/google/javascript/jscomp/CompilerInput.java +++ b/src/com/google/javascript/jscomp/CompilerInput.java @@ -37,7 +37,6 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.TreeMap; /** @@ -499,7 +498,7 @@ public boolean isModule() { return "goog".equals(getLoadFlags().get("module")); } - private static Set concat(Iterable first, Iterable second) { + private static ImmutableSet concat(Iterable first, Iterable second) { return ImmutableSet.builder().addAll(first).addAll(second).build(); } diff --git a/src/com/google/javascript/jscomp/CompilerOptions.java b/src/com/google/javascript/jscomp/CompilerOptions.java index 82d01b4b76f..5b7c3c4e36f 100644 --- a/src/com/google/javascript/jscomp/CompilerOptions.java +++ b/src/com/google/javascript/jscomp/CompilerOptions.java @@ -1405,11 +1405,8 @@ public Map getTweakReplacements() { return getReplacementsHelper(tweakReplacements); } - /** - * Creates a map of String->Node from a map of String->Number/String/Boolean. - */ - private static Map getReplacementsHelper( - Map source) { + /** Creates a map of String->Node from a map of String->Number/String/Boolean. */ + private static ImmutableMap getReplacementsHelper(Map source) { ImmutableMap.Builder map = ImmutableMap.builder(); for (Map.Entry entry : source.entrySet()) { String name = entry.getKey(); diff --git a/src/com/google/javascript/jscomp/EmptyMessageBundle.java b/src/com/google/javascript/jscomp/EmptyMessageBundle.java index a03d433ba38..2715f7f3715 100644 --- a/src/com/google/javascript/jscomp/EmptyMessageBundle.java +++ b/src/com/google/javascript/jscomp/EmptyMessageBundle.java @@ -42,11 +42,9 @@ public JsMessage getMessage(String id) { return null; } - /** - * Returns an empty list of messages. - */ + /** Returns an empty list of messages. */ @Override - public Iterable getAllMessages() { + public ImmutableList getAllMessages() { return ImmutableList.of(); } } diff --git a/src/com/google/javascript/jscomp/JSModule.java b/src/com/google/javascript/jscomp/JSModule.java index 32c93861e7c..e73a941b79a 100644 --- a/src/com/google/javascript/jscomp/JSModule.java +++ b/src/com/google/javascript/jscomp/JSModule.java @@ -81,12 +81,12 @@ public void setName(String name) { } @Override - public List getProvides() { + public ImmutableList getProvides() { return ImmutableList.of(name); } @Override - public List getRequires() { + public ImmutableList getRequires() { ImmutableList.Builder builder = ImmutableList.builder(); for (JSModule m : deps) { builder.add(m.getName()); diff --git a/src/com/google/javascript/jscomp/JSModuleGraph.java b/src/com/google/javascript/jscomp/JSModuleGraph.java index 6e50d1d1df7..c10ba35c79d 100644 --- a/src/com/google/javascript/jscomp/JSModuleGraph.java +++ b/src/com/google/javascript/jscomp/JSModuleGraph.java @@ -426,19 +426,16 @@ public List manageDependencies( } /** - * Apply the dependency options to the list of sources, returning a new - * source list re-ordering and dropping files as necessary. - * This module graph will be updated to reflect the new list. + * Apply the dependency options to the list of sources, returning a new source list re-ordering + * and dropping files as necessary. This module graph will be updated to reflect the new list. * - * @param inputs The original list of sources. Used to ensure that the sort - * is stable. - * @throws MissingProvideException if an entry point was not provided - * by any of the inputs. + * @param inputs The original list of sources. Used to ensure that the sort is stable. + * @throws MissingProvideException if an entry point was not provided by any of the inputs. * @see DependencyOptions for more info on how this works. */ - public List manageDependencies( - DependencyOptions depOptions, - List inputs) throws MissingProvideException, MissingModuleException { + public ImmutableList manageDependencies( + DependencyOptions depOptions, List inputs) + throws MissingProvideException, MissingModuleException { SortedDependencies sorter = new Es6SortedDependencies<>(inputs); diff --git a/src/com/google/javascript/jscomp/NodeUtil.java b/src/com/google/javascript/jscomp/NodeUtil.java index c3919b98e9e..e8e8133c39c 100644 --- a/src/com/google/javascript/jscomp/NodeUtil.java +++ b/src/com/google/javascript/jscomp/NodeUtil.java @@ -5468,7 +5468,7 @@ public static boolean isCallTo(Node n, String qualifiedName) { return n.isCall() && n.getFirstChild().matchesQualifiedName(qualifiedName); } - static Set collectExternVariableNames(AbstractCompiler compiler, Node externs) { + static ImmutableSet collectExternVariableNames(AbstractCompiler compiler, Node externs) { ReferenceCollectingCallback externsRefs = new ReferenceCollectingCallback( compiler, diff --git a/src/com/google/javascript/jscomp/VariableMap.java b/src/com/google/javascript/jscomp/VariableMap.java index 56bd6e96fae..07494264de3 100644 --- a/src/com/google/javascript/jscomp/VariableMap.java +++ b/src/com/google/javascript/jscomp/VariableMap.java @@ -26,7 +26,6 @@ import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedSet; import com.google.common.io.Files; - import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -76,17 +75,13 @@ public String lookupSourceName(String newName) { return map.inverse().get(newName); } - /** - * Returns an unmodifiable mapping from original names to new names. - */ - public Map getOriginalNameToNewNameMap() { + /** Returns an unmodifiable mapping from original names to new names. */ + public ImmutableMap getOriginalNameToNewNameMap() { return ImmutableSortedMap.copyOf(map); } - /** - * Returns an unmodifiable mapping from new names to original names. - */ - public Map getNewNameToOriginalNameMap() { + /** Returns an unmodifiable mapping from new names to original names. */ + public ImmutableMap getNewNameToOriginalNameMap() { return map.inverse(); } @@ -206,7 +201,7 @@ public static VariableMap fromMap(Map map) { } @VisibleForTesting - Map toMap() { + ImmutableMap toMap() { return map; } } diff --git a/src/com/google/javascript/jscomp/newtypes/JSType.java b/src/com/google/javascript/jscomp/newtypes/JSType.java index 5e611dc1897..ae5d98dd280 100644 --- a/src/com/google/javascript/jscomp/newtypes/JSType.java +++ b/src/com/google/javascript/jscomp/newtypes/JSType.java @@ -24,6 +24,7 @@ import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -1874,7 +1875,7 @@ public final Node getSource() { } @Override - public final Collection getDirectSubTypes() { + public final ImmutableCollection getDirectSubTypes() { Preconditions.checkState(this.isConstructor() || this.isInterface()); ImmutableList.Builder result = ImmutableList.builder(); NominalType nt = @@ -2105,7 +2106,7 @@ public final boolean hasProperty(String propertyName) { } @Override - public final Iterable getUnionMembers() { + public final ImmutableCollection getUnionMembers() { if (!isUnion()) { return ImmutableList.of(this); } diff --git a/src/com/google/javascript/jscomp/newtypes/NominalType.java b/src/com/google/javascript/jscomp/newtypes/NominalType.java index e41948f7e69..5e1a619ffab 100644 --- a/src/com/google/javascript/jscomp/newtypes/NominalType.java +++ b/src/com/google/javascript/jscomp/newtypes/NominalType.java @@ -98,7 +98,7 @@ ObjectKind getObjectKind() { return this.rawType.getObjectKind(); } - Map getTypeMap() { + ImmutableMap getTypeMap() { return typeMap; } diff --git a/src/com/google/javascript/jscomp/newtypes/TypeParameters.java b/src/com/google/javascript/jscomp/newtypes/TypeParameters.java index 36edadfef4f..f18ce25e8b7 100644 --- a/src/com/google/javascript/jscomp/newtypes/TypeParameters.java +++ b/src/com/google/javascript/jscomp/newtypes/TypeParameters.java @@ -54,15 +54,15 @@ static TypeParameters make(List ordinaryTypeParams, Map tt return new TypeParameters(builder.build()); } - List asList() { + ImmutableList asList() { return this.typeParams.keySet().asList(); } /** - * Returns a non-null list of type variables, by filtering out the TTL variables - * from this.typeParams. + * Returns a non-null list of type variables, by filtering out the TTL variables from + * this.typeParams. */ - List getOrdinaryTypeParams() { + ImmutableList getOrdinaryTypeParams() { boolean foundTtlVariable = false; for (Map.Entry entry : this.typeParams.entrySet()) { if (!entry.getValue().isEmpty()) { @@ -83,10 +83,10 @@ List getOrdinaryTypeParams() { } /** - * Returns a non-null map from TTL variables to their ASTs, by filtering out the non-TTL - * variables from this.typeParams. + * Returns a non-null map from TTL variables to their ASTs, by filtering out the non-TTL variables + * from this.typeParams. */ - public Map getTypeTransformations() { + public ImmutableMap getTypeTransformations() { boolean foundOrdinaryTypeVariable = false; for (Map.Entry entry : this.typeParams.entrySet()) { if (entry.getValue().isEmpty()) {