Skip to content

Commit

Permalink
[NTI] Give better names to some recently-added TypeI methods, plus so…
Browse files Browse the repository at this point in the history
…me cleanup.

Also changes isBottom to be the same as isEmptyType in OTI.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=130005422
  • Loading branch information
aravind-pg authored and blickly committed Aug 11, 2016
1 parent d89012e commit 9daec22
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 46 deletions.
36 changes: 18 additions & 18 deletions src/com/google/javascript/jscomp/ConformanceRules.java
Expand Up @@ -247,33 +247,33 @@ protected boolean isWhitelistedType(Node n) {


protected boolean isKnown(Node n) { protected boolean isKnown(Node n) {
return !isUnknown(n) return !isUnknown(n)
&& !isEmptyType(n) && !isBottom(n)
&& !isTemplateType(n); // TODO(johnlenz): Remove this restriction && !isTypeVariable(n); // TODO(johnlenz): Remove this restriction
} }


protected boolean isNativeObjectType(Node n) { protected boolean isNativeObjectType(Node n) {
TypeI type = n.getTypeI().restrictByNotNullOrUndefined(); TypeI type = n.getTypeI().restrictByNotNullOrUndefined();
return type.isEquivalentTo(nativeObjectType); return type.isEquivalentTo(nativeObjectType);
} }


protected boolean isAllType(Node n) { protected boolean isTop(Node n) {
TypeI type = n.getTypeI(); TypeI type = n.getTypeI();
return type != null && type.isAllType(); return type != null && type.isTop();
} }


protected boolean isUnknown(Node n) { protected boolean isUnknown(Node n) {
TypeI type = n.getTypeI(); TypeI type = n.getTypeI();
return (type == null || type.isUnknownType()); return (type == null || type.isUnknownType());
} }


protected boolean isTemplateType(Node n) { protected boolean isTypeVariable(Node n) {
TypeI type = n.getTypeI().restrictByNotNullOrUndefined(); TypeI type = n.getTypeI().restrictByNotNullOrUndefined();
return type.isTemplateType(); return type.isTypeVariable();
} }


private boolean isEmptyType(Node n) { private boolean isBottom(Node n) {
TypeI type = n.getTypeI().restrictByNotNullOrUndefined(); TypeI type = n.getTypeI().restrictByNotNullOrUndefined();
return type.isEmptyType(); return type.isBottom();
} }


protected TypeI union(List<String> typeNames) { protected TypeI union(List<String> typeNames) {
Expand Down Expand Up @@ -486,8 +486,8 @@ private ConformanceResult checkConformance(NodeTraversal t, Node n, Property pro
if (methodClassType != null && lhs.getTypeI() != null) { if (methodClassType != null && lhs.getTypeI() != null) {
TypeI targetType = lhs.getTypeI().restrictByNotNullOrUndefined(); TypeI targetType = lhs.getTypeI().restrictByNotNullOrUndefined();
if (targetType.isUnknownType() if (targetType.isUnknownType()
|| targetType.isEmptyType() || targetType.isBottom()
|| targetType.isAllType() || targetType.isTop()
|| targetType.isEquivalentTo( || targetType.isEquivalentTo(
registry.getNativeType(JSTypeNative.OBJECT_TYPE))) { registry.getNativeType(JSTypeNative.OBJECT_TYPE))) {
if (reportLooseTypeViolations) { if (reportLooseTypeViolations) {
Expand Down Expand Up @@ -825,8 +825,8 @@ private ConformanceResult checkConformance(
if (methodClassType != null && lhs.getTypeI() != null) { if (methodClassType != null && lhs.getTypeI() != null) {
TypeI targetType = lhs.getTypeI().restrictByNotNullOrUndefined(); TypeI targetType = lhs.getTypeI().restrictByNotNullOrUndefined();
if (targetType.isUnknownType() if (targetType.isUnknownType()
|| targetType.isNoResolvedType() || targetType.isUnresolved()
|| targetType.isAllType() || targetType.isTop()
|| targetType.isEquivalentTo( || targetType.isEquivalentTo(
registry.getNativeType(JSTypeNative.OBJECT_TYPE))) { registry.getNativeType(JSTypeNative.OBJECT_TYPE))) {
if (reportLooseTypeViolations if (reportLooseTypeViolations
Expand Down Expand Up @@ -1086,8 +1086,8 @@ protected ConformanceResult checkConformance(NodeTraversal t, Node n) {
if (thrown != null) { if (thrown != null) {
// Allow vague types, as is typical of re-throws of exceptions // Allow vague types, as is typical of re-throws of exceptions
if (!thrown.isUnknownType() if (!thrown.isUnknownType()
&& !thrown.isAllType() && !thrown.isTop()
&& !thrown.isEmptyType() && !thrown.isBottom()
&& !thrown.isSubtypeOf(errorObjType)) { && !thrown.isSubtypeOf(errorObjType)) {
return ConformanceResult.VIOLATION; return ConformanceResult.VIOLATION;
} }
Expand Down Expand Up @@ -1191,7 +1191,7 @@ protected ConformanceResult checkConformance(NodeTraversal t, Node n) {
if (n.isGetProp() if (n.isGetProp()
&& isKnownThis(n.getFirstChild()) // not a cascading unknown && isKnownThis(n.getFirstChild()) // not a cascading unknown
&& isUnknown(n) && isUnknown(n)
&& !isTemplateType(n) && !isTypeVariable(n)
&& isUsed(n) // skip most assignments, etc && isUsed(n) // skip most assignments, etc
&& !isTypeImmediatelyTightened(n)) { && !isTypeImmediatelyTightened(n)) {
return ConformanceResult.VIOLATION; return ConformanceResult.VIOLATION;
Expand Down Expand Up @@ -1235,7 +1235,7 @@ && isUnknown(n)
&& isUsed(n) // skip most assignments, etc && isUsed(n) // skip most assignments, etc
&& !isTypeImmediatelyTightened(n) && !isTypeImmediatelyTightened(n)
&& isCheckablePropertySource(n.getFirstChild()) // not a cascading unknown && isCheckablePropertySource(n.getFirstChild()) // not a cascading unknown
&& !isTemplateType(n) && !isTypeVariable(n)
&& !isDeclaredUnknown(n)) { && !isDeclaredUnknown(n)) {
String propName = n.getLastChild().getString(); String propName = n.getLastChild().getString();
String typeName = n.getFirstChild().getTypeI().toString(); String typeName = n.getFirstChild().getTypeI().toString();
Expand All @@ -1247,7 +1247,7 @@ && isCheckablePropertySource(n.getFirstChild()) // not a cascading unknown


private boolean isCheckablePropertySource(Node n) { private boolean isCheckablePropertySource(Node n) {
return isKnown(n) return isKnown(n)
&& !isAllType(n) && !isTop(n)
&& isClassType(n) && isClassType(n)
&& !isNativeObjectType(n) && !isNativeObjectType(n)
&& !isWhitelistedType(n); && !isWhitelistedType(n);
Expand Down Expand Up @@ -1319,7 +1319,7 @@ private boolean conforms(TypeI type) {
} }
return true; return true;
} else { } else {
return !type.isNoResolvedType(); return !type.isUnresolved();
} }
} }
} }
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/TypeMatchingStrategy.java
Expand Up @@ -65,7 +65,7 @@ public MatchResult match(TypeI templateType, TypeI type) {
return new MatchResult(true, false); return new MatchResult(true, false);
} }


if (type == null || type.isUnknownType() || type.isAllType()) { if (type == null || type.isUnknownType() || type.isTop()) {
return new MatchResult(allowLooseMatches, allowLooseMatches); return new MatchResult(allowLooseMatches, allowLooseMatches);
} }


Expand Down
19 changes: 3 additions & 16 deletions src/com/google/javascript/jscomp/newtypes/JSType.java
Expand Up @@ -29,7 +29,6 @@
import com.google.javascript.rhino.Node; import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.ObjectTypeI; import com.google.javascript.rhino.ObjectTypeI;
import com.google.javascript.rhino.TypeI; import com.google.javascript.rhino.TypeI;

import java.util.Collection; import java.util.Collection;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
Expand Down Expand Up @@ -272,6 +271,7 @@ && getEnums().isEmpty()) {
UNDEFINED_MASK | NON_SCALAR_MASK, UNDEFINED_MASK | NON_SCALAR_MASK,
ImmutableSet.of(ObjectType.TOP_OBJECT), null, NO_ENUMS); ImmutableSet.of(ObjectType.TOP_OBJECT), null, NO_ENUMS);


@Override
public boolean isTop() { public boolean isTop() {
return TOP_MASK == getMask(); return TOP_MASK == getMask();
} }
Expand Down Expand Up @@ -371,6 +371,7 @@ public boolean isNullable() {
return (getMask() & NULL_MASK) != 0; return (getMask() & NULL_MASK) != 0;
} }


@Override
public boolean isTypeVariable() { public boolean isTypeVariable() {
return getMask() == TYPEVAR_MASK; return getMask() == TYPEVAR_MASK;
} }
Expand Down Expand Up @@ -1545,13 +1546,9 @@ public boolean isUnknownType() {
return isUnknown(); return isUnknown();
} }


@Override
public boolean isAllType() {
throw new UnsupportedOperationException("isAllType not implemented yet");
}


@Override @Override
public boolean isNoResolvedType() { public boolean isUnresolved() {
throw new UnsupportedOperationException("isUnresolved not implemented yet"); throw new UnsupportedOperationException("isUnresolved not implemented yet");
} }


Expand All @@ -1570,16 +1567,6 @@ public boolean isVoidable() {
throw new UnsupportedOperationException("isVoidable not implemented yet"); throw new UnsupportedOperationException("isVoidable not implemented yet");
} }


@Override
public boolean isEmptyType() {
throw new UnsupportedOperationException("isEmpty not implemented yet");
}

@Override
public boolean isTemplateType() {
throw new UnsupportedOperationException("isGeneric not implemented yet");
}

@Override @Override
public TypeI restrictByNotNullOrUndefined() { public TypeI restrictByNotNullOrUndefined() {
return this.removeType(NULL_OR_UNDEF); return this.removeType(NULL_OR_UNDEF);
Expand Down
8 changes: 3 additions & 5 deletions src/com/google/javascript/rhino/TypeI.java
Expand Up @@ -50,13 +50,11 @@ public interface TypeI {


boolean isBottom(); boolean isBottom();


boolean isAllType(); boolean isTop();


boolean isTemplateType(); boolean isTypeVariable();


boolean isEmptyType(); boolean isUnresolved();

boolean isNoResolvedType();


// Hacky method to abstract away corner case handling of the way OTI // Hacky method to abstract away corner case handling of the way OTI
// represents unresolved types. // represents unresolved types.
Expand Down
23 changes: 17 additions & 6 deletions src/com/google/javascript/rhino/jstype/JSType.java
Expand Up @@ -157,11 +157,15 @@ public boolean isNoType() {
return false; return false;
} }


@Override
public boolean isNoResolvedType() { public boolean isNoResolvedType() {
return false; return false;
} }


@Override
public final boolean isUnresolved() {
return isNoResolvedType();
}

@Override @Override
public final boolean isUnresolvedOrResolvedUnknown() { public final boolean isUnresolvedOrResolvedUnknown() {
return isNoResolvedType() || isNamedType() && isUnknownType(); return isNoResolvedType() || isNamedType() && isUnknownType();
Expand All @@ -171,7 +175,6 @@ public boolean isNoObjectType() {
return false; return false;
} }


@Override
public final boolean isEmptyType() { public final boolean isEmptyType() {
return isNoType() || isNoObjectType() || isNoResolvedType() || return isNoType() || isNoObjectType() || isNoResolvedType() ||
(registry.getNativeFunctionType( (registry.getNativeFunctionType(
Expand Down Expand Up @@ -254,11 +257,15 @@ public boolean isVoidType() {
return false; return false;
} }


@Override
public boolean isAllType() { public boolean isAllType() {
return false; return false;
} }


@Override
public final boolean isTop() {
return isAllType();
}

@Override @Override
public boolean isUnknownType() { public boolean isUnknownType() {
return false; return false;
Expand Down Expand Up @@ -457,11 +464,15 @@ public TemplatizedType toMaybeTemplatizedType() {
return null; return null;
} }


@Override
public final boolean isTemplateType() { public final boolean isTemplateType() {
return toMaybeTemplateType() != null; return toMaybeTemplateType() != null;
} }


@Override
public final boolean isTypeVariable() {
return isTemplateType();
}

/** /**
* Downcasts this to a TemplateType, or returns null if this is not * Downcasts this to a TemplateType, or returns null if this is not
* a function. * a function.
Expand Down Expand Up @@ -1592,8 +1603,8 @@ public boolean isSubtypeOf(TypeI other) {
} }


@Override @Override
public boolean isBottom() { public final boolean isBottom() {
return isNoType() || isNoResolvedType() || isNoObjectType(); return isEmptyType();
} }


@Override @Override
Expand Down

0 comments on commit 9daec22

Please sign in to comment.