Skip to content

Commit

Permalink
Mark more return types with immutable interface types.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177341012
  • Loading branch information
blickly authored and brad4d committed Nov 30, 2017
1 parent 1f06fd5 commit 9e3f399
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 44 deletions.
3 changes: 1 addition & 2 deletions src/com/google/javascript/jscomp/CompilerInput.java
Expand Up @@ -37,7 +37,6 @@
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;


/** /**
Expand Down Expand Up @@ -499,7 +498,7 @@ public boolean isModule() {
return "goog".equals(getLoadFlags().get("module")); return "goog".equals(getLoadFlags().get("module"));
} }


private static <T> Set<T> concat(Iterable<T> first, Iterable<T> second) { private static <T> ImmutableSet<T> concat(Iterable<T> first, Iterable<T> second) {
return ImmutableSet.<T>builder().addAll(first).addAll(second).build(); return ImmutableSet.<T>builder().addAll(first).addAll(second).build();
} }


Expand Down
7 changes: 2 additions & 5 deletions src/com/google/javascript/jscomp/CompilerOptions.java
Expand Up @@ -1405,11 +1405,8 @@ public Map<String, Node> getTweakReplacements() {
return getReplacementsHelper(tweakReplacements); return getReplacementsHelper(tweakReplacements);
} }


/** /** Creates a map of String->Node from a map of String->Number/String/Boolean. */
* Creates a map of String->Node from a map of String->Number/String/Boolean. private static ImmutableMap<String, Node> getReplacementsHelper(Map<String, Object> source) {
*/
private static Map<String, Node> getReplacementsHelper(
Map<String, Object> source) {
ImmutableMap.Builder<String, Node> map = ImmutableMap.builder(); ImmutableMap.Builder<String, Node> map = ImmutableMap.builder();
for (Map.Entry<String, Object> entry : source.entrySet()) { for (Map.Entry<String, Object> entry : source.entrySet()) {
String name = entry.getKey(); String name = entry.getKey();
Expand Down
6 changes: 2 additions & 4 deletions src/com/google/javascript/jscomp/EmptyMessageBundle.java
Expand Up @@ -42,11 +42,9 @@ public JsMessage getMessage(String id) {
return null; return null;
} }


/** /** Returns an empty list of messages. */
* Returns an empty list of messages.
*/
@Override @Override
public Iterable<JsMessage> getAllMessages() { public ImmutableList<JsMessage> getAllMessages() {
return ImmutableList.of(); return ImmutableList.of();
} }
} }
4 changes: 2 additions & 2 deletions src/com/google/javascript/jscomp/JSModule.java
Expand Up @@ -81,12 +81,12 @@ public void setName(String name) {
} }


@Override @Override
public List<String> getProvides() { public ImmutableList<String> getProvides() {
return ImmutableList.of(name); return ImmutableList.of(name);
} }


@Override @Override
public List<String> getRequires() { public ImmutableList<String> getRequires() {
ImmutableList.Builder<String> builder = ImmutableList.builder(); ImmutableList.Builder<String> builder = ImmutableList.builder();
for (JSModule m : deps) { for (JSModule m : deps) {
builder.add(m.getName()); builder.add(m.getName());
Expand Down
17 changes: 7 additions & 10 deletions src/com/google/javascript/jscomp/JSModuleGraph.java
Expand Up @@ -426,19 +426,16 @@ public List<CompilerInput> manageDependencies(
} }


/** /**
* Apply the dependency options to the list of sources, returning a new * Apply the dependency options to the list of sources, returning a new source list re-ordering
* source list re-ordering and dropping files as necessary. * and dropping files as necessary. This module graph will be updated to reflect the new list.
* This module graph will be updated to reflect the new list.
* *
* @param inputs The original list of sources. Used to ensure that the sort * @param inputs The original list of sources. Used to ensure that the sort is stable.
* is stable. * @throws MissingProvideException if an entry point was not provided by any of the inputs.
* @throws MissingProvideException if an entry point was not provided
* by any of the inputs.
* @see DependencyOptions for more info on how this works. * @see DependencyOptions for more info on how this works.
*/ */
public List<CompilerInput> manageDependencies( public ImmutableList<CompilerInput> manageDependencies(
DependencyOptions depOptions, DependencyOptions depOptions, List<CompilerInput> inputs)
List<CompilerInput> inputs) throws MissingProvideException, MissingModuleException { throws MissingProvideException, MissingModuleException {


SortedDependencies<CompilerInput> sorter = new Es6SortedDependencies<>(inputs); SortedDependencies<CompilerInput> sorter = new Es6SortedDependencies<>(inputs);


Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/NodeUtil.java
Expand Up @@ -5468,7 +5468,7 @@ public static boolean isCallTo(Node n, String qualifiedName) {
return n.isCall() && n.getFirstChild().matchesQualifiedName(qualifiedName); return n.isCall() && n.getFirstChild().matchesQualifiedName(qualifiedName);
} }


static Set<String> collectExternVariableNames(AbstractCompiler compiler, Node externs) { static ImmutableSet<String> collectExternVariableNames(AbstractCompiler compiler, Node externs) {
ReferenceCollectingCallback externsRefs = ReferenceCollectingCallback externsRefs =
new ReferenceCollectingCallback( new ReferenceCollectingCallback(
compiler, compiler,
Expand Down
15 changes: 5 additions & 10 deletions src/com/google/javascript/jscomp/VariableMap.java
Expand Up @@ -26,7 +26,6 @@
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;
import com.google.common.io.Files; import com.google.common.io.Files;

import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
Expand Down Expand Up @@ -76,17 +75,13 @@ public String lookupSourceName(String newName) {
return map.inverse().get(newName); return map.inverse().get(newName);
} }


/** /** Returns an unmodifiable mapping from original names to new names. */
* Returns an unmodifiable mapping from original names to new names. public ImmutableMap<String, String> getOriginalNameToNewNameMap() {
*/
public Map<String, String> getOriginalNameToNewNameMap() {
return ImmutableSortedMap.copyOf(map); return ImmutableSortedMap.copyOf(map);
} }


/** /** Returns an unmodifiable mapping from new names to original names. */
* Returns an unmodifiable mapping from new names to original names. public ImmutableMap<String, String> getNewNameToOriginalNameMap() {
*/
public Map<String, String> getNewNameToOriginalNameMap() {
return map.inverse(); return map.inverse();
} }


Expand Down Expand Up @@ -206,7 +201,7 @@ public static VariableMap fromMap(Map<String, String> map) {
} }


@VisibleForTesting @VisibleForTesting
Map<String, String> toMap() { ImmutableMap<String, String> toMap() {
return map; return map;
} }
} }
5 changes: 3 additions & 2 deletions src/com/google/javascript/jscomp/newtypes/JSType.java
Expand Up @@ -24,6 +24,7 @@
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -1874,7 +1875,7 @@ public final Node getSource() {
} }


@Override @Override
public final Collection<FunctionTypeI> getDirectSubTypes() { public final ImmutableCollection<FunctionTypeI> getDirectSubTypes() {
Preconditions.checkState(this.isConstructor() || this.isInterface()); Preconditions.checkState(this.isConstructor() || this.isInterface());
ImmutableList.Builder<FunctionTypeI> result = ImmutableList.builder(); ImmutableList.Builder<FunctionTypeI> result = ImmutableList.builder();
NominalType nt = NominalType nt =
Expand Down Expand Up @@ -2105,7 +2106,7 @@ public final boolean hasProperty(String propertyName) {
} }


@Override @Override
public final Iterable<JSType> getUnionMembers() { public final ImmutableCollection<JSType> getUnionMembers() {
if (!isUnion()) { if (!isUnion()) {
return ImmutableList.of(this); return ImmutableList.of(this);
} }
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/newtypes/NominalType.java
Expand Up @@ -98,7 +98,7 @@ ObjectKind getObjectKind() {
return this.rawType.getObjectKind(); return this.rawType.getObjectKind();
} }


Map<String, JSType> getTypeMap() { ImmutableMap<String, JSType> getTypeMap() {
return typeMap; return typeMap;
} }


Expand Down
14 changes: 7 additions & 7 deletions src/com/google/javascript/jscomp/newtypes/TypeParameters.java
Expand Up @@ -54,15 +54,15 @@ static TypeParameters make(List<String> ordinaryTypeParams, Map<String, Node> tt
return new TypeParameters(builder.build()); return new TypeParameters(builder.build());
} }


List<String> asList() { ImmutableList<String> asList() {
return this.typeParams.keySet().asList(); return this.typeParams.keySet().asList();
} }


/** /**
* Returns a non-null list of type variables, by filtering out the TTL variables * Returns a non-null list of type variables, by filtering out the TTL variables from
* from this.typeParams. * this.typeParams.
*/ */
List<String> getOrdinaryTypeParams() { ImmutableList<String> getOrdinaryTypeParams() {
boolean foundTtlVariable = false; boolean foundTtlVariable = false;
for (Map.Entry<String, Node> entry : this.typeParams.entrySet()) { for (Map.Entry<String, Node> entry : this.typeParams.entrySet()) {
if (!entry.getValue().isEmpty()) { if (!entry.getValue().isEmpty()) {
Expand All @@ -83,10 +83,10 @@ List<String> getOrdinaryTypeParams() {
} }


/** /**
* Returns a non-null map from TTL variables to their ASTs, by filtering out the non-TTL * Returns a non-null map from TTL variables to their ASTs, by filtering out the non-TTL variables
* variables from this.typeParams. * from this.typeParams.
*/ */
public Map<String, Node> getTypeTransformations() { public ImmutableMap<String, Node> getTypeTransformations() {
boolean foundOrdinaryTypeVariable = false; boolean foundOrdinaryTypeVariable = false;
for (Map.Entry<String, Node> entry : this.typeParams.entrySet()) { for (Map.Entry<String, Node> entry : this.typeParams.entrySet()) {
if (entry.getValue().isEmpty()) { if (entry.getValue().isEmpty()) {
Expand Down

0 comments on commit 9e3f399

Please sign in to comment.