Skip to content

Commit

Permalink
[NTI] Clean up lint errors and add JavaDoc in ObjectType.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=157182146
  • Loading branch information
shicks authored and blickly committed May 26, 2017
1 parent d4169c1 commit 1f7eaf4
Show file tree
Hide file tree
Showing 5 changed files with 366 additions and 157 deletions.
37 changes: 26 additions & 11 deletions src/com/google/javascript/jscomp/newtypes/JSType.java
Expand Up @@ -1365,8 +1365,14 @@ public final JSType withLoose() {
Preconditions.checkState(!getEnums().isEmpty());
return this;
}
return makeType(this.commonTypes, getMask(),
ObjectType.withLooseObjects(getObjs()), getTypeVar(), getEnums());
// TODO(dimvar): here, a lot of the time the set of objects will only contain objects for which
// withLoose is a no-op. Worth it to detect it and return `this` in that case, to avoid
// unnecessary creation of types?
ImmutableSet.Builder<ObjectType> looseObjs = ImmutableSet.builder();
for (ObjectType obj : getObjs()) {
looseObjs.add(obj.withLoose());
}
return makeType(this.commonTypes, getMask(), looseObjs.build(), getTypeVar(), getEnums());
}

public final JSType getProp(QualifiedName qname) {
Expand Down Expand Up @@ -1437,8 +1443,11 @@ public final JSType withProperty(QualifiedName qname, JSType type) {
if (isUnknown() || isBottom() || getObjs().isEmpty()) {
return this;
}
return makeType(this.commonTypes, getMask(),
ObjectType.withProperty(getObjs(), qname, type), getTypeVar(), getEnums());
ImmutableSet.Builder<ObjectType> newObjs = ImmutableSet.builder();
for (ObjectType obj : getObjs()) {
newObjs.add(obj.withProperty(qname, type));
}
return makeType(this.commonTypes, getMask(), newObjs.build(), getTypeVar(), getEnums());
}

public final JSType withDeclaredProperty(
Expand All @@ -1447,16 +1456,22 @@ public final JSType withDeclaredProperty(
if (type == null && isConstant) {
type = this.commonTypes.UNKNOWN;
}
return makeType(this.commonTypes,
getMask(),
ObjectType.withDeclaredProperty(getObjs(), qname, type, isConstant), getTypeVar(), getEnums());
ImmutableSet.Builder<ObjectType> newObjs = ImmutableSet.builder();
for (ObjectType obj : getObjs()) {
newObjs.add(obj.withDeclaredProperty(qname, type, isConstant));
}
return makeType(this.commonTypes, getMask(), newObjs.build(), getTypeVar(), getEnums());
}

public final JSType withPropertyRequired(String pname) {
return (isUnknown() || getObjs().isEmpty()) ?
this :
makeType(this.commonTypes, getMask(),
ObjectType.withPropertyRequired(getObjs(), pname), getTypeVar(), getEnums());
if (isUnknown() || getObjs().isEmpty()) {
return this;
}
ImmutableSet.Builder<ObjectType> newObjs = ImmutableSet.builder();
for (ObjectType obj : getObjs()) {
newObjs.add(obj.withPropertyRequired(pname));
}
return makeType(this.commonTypes, getMask(), newObjs.build(), getTypeVar(), getEnums());
}

// For a type A, this method tries to return the greatest subtype of A that
Expand Down
5 changes: 5 additions & 0 deletions src/com/google/javascript/jscomp/newtypes/JSTypes.java
Expand Up @@ -546,4 +546,9 @@ public boolean isNumStrScalarOrObj(JSType t) {
}
return t.isSubtypeOf(anyNumOrStr);
}

@SuppressWarnings("ReferenceEquality")
boolean isBottomPropertyMap(PersistentMap<String, Property> map) {
return map == BOTTOM_PROPERTY_MAP;
}
}

0 comments on commit 1f7eaf4

Please sign in to comment.