Java Code Examples for com.google.javascript.rhino.jstype.ObjectType#isUnknownType()

The following examples show how to use com.google.javascript.rhino.jstype.ObjectType#isUnknownType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Closure_90_FunctionTypeBuilder_s.java    From coming with MIT License 6 votes vote down vote up
@Override
public boolean apply(JSType type) {
  ObjectType objectType = ObjectType.cast(type);
  if (objectType == null) {
    reportWarning(EXTENDS_NON_OBJECT, fnName, type.toString());
  } else if (objectType.isUnknownType() &&
      // If this has a supertype that hasn't been resolved yet,
      // then we can assume this type will be ok once the super
      // type resolves.
      (objectType.getImplicitPrototype() == null ||
       objectType.getImplicitPrototype().isResolved())) {
    reportWarning(RESOLVED_TAG_EMPTY, "@extends", fnName);
  } else {
    return true;
  }
  return false;
}
 
Example 2
Source File: Closure_66_TypeCheck_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 3
Source File: Closure_66_TypeCheck_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 4
Source File: Closure_125_TypeCheck_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 5
Source File: Closure_125_TypeCheck_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 6
Source File: Closure_90_FunctionTypeBuilder_t.java    From coming with MIT License 6 votes vote down vote up
@Override
public boolean apply(JSType type) {
  ObjectType objectType = ObjectType.cast(type);
  if (objectType == null) {
    reportError(BAD_IMPLEMENTED_TYPE, fnName);
  } else if (objectType.isUnknownType() &&
      // If this has a supertype that hasn't been resolved yet,
      // then we can assume this type will be ok once the super
      // type resolves.
      (objectType.getImplicitPrototype() == null ||
       objectType.getImplicitPrototype().isResolved())) {
    reportWarning(RESOLVED_TAG_EMPTY, "@implements", fnName);
  } else {
    return true;
  }
  return false;
}
 
Example 7
Source File: InlineProperties.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Returns true if properties on this type should not be renamed. */
private boolean isInvalidatingType(JSType type) {
  if (type.isUnionType()) {
    type = type.restrictByNotNullOrUndefined();
    if (type.isUnionType()) {
      for (JSType alt : type.toMaybeUnionType().getAlternates()) {
        if (isInvalidatingType(alt)) {
          return true;
        }
      }
      return false;
    }
  }
  ObjectType objType = ObjectType.cast(type);
  return objType == null
      || invalidatingTypes.contains(objType)
      || !objType.hasReferenceName()
      || objType.isUnknownType()
      || objType.isEmptyType() /* unresolved types */
      || objType.isEnumType()
      || objType.autoboxesTo() != null;
}
 
Example 8
Source File: FunctionTypeBuilder.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean apply(JSType type) {
  ObjectType objectType = ObjectType.cast(type);
  if (objectType == null) {
    reportError(BAD_IMPLEMENTED_TYPE, fnName);
    return false;
  } else if (objectType.isEmptyType()) {
    reportWarning(RESOLVED_TAG_EMPTY, "@implements", fnName);
    return false;
  } else if (objectType.isUnknownType()) {
    if (hasMoreTagsToResolve(objectType)) {
      return true;
    } else {
      reportWarning(RESOLVED_TAG_EMPTY, "@implements", fnName);
      return false;
    }
  } else {
    return true;
  }
}
 
Example 9
Source File: Closure_69_TypeCheck_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 10
Source File: Closure_41_FunctionTypeBuilder_t.java    From coming with MIT License 6 votes vote down vote up
@Override
public boolean apply(JSType type) {
  ObjectType objectType = ObjectType.cast(type);
  if (objectType == null) {
    reportWarning(EXTENDS_NON_OBJECT, fnName, type.toString());
    return false;
  } else if (objectType.isEmptyType()) {
    reportWarning(RESOLVED_TAG_EMPTY, "@extends", fnName);
    return false;
  } else if (objectType.isUnknownType()) {
    if (hasMoreTagsToResolve(objectType)) {
      return true;
    } else {
      reportWarning(RESOLVED_TAG_EMPTY, "@extends", fnName);
      return false;
    }
  } else {
    return true;
  }
}
 
Example 11
Source File: Closure_41_FunctionTypeBuilder_t.java    From coming with MIT License 6 votes vote down vote up
@Override
public boolean apply(JSType type) {
  ObjectType objectType = ObjectType.cast(type);
  if (objectType == null) {
    reportError(BAD_IMPLEMENTED_TYPE, fnName);
    return false;
  } else if (objectType.isEmptyType()) {
    reportWarning(RESOLVED_TAG_EMPTY, "@implements", fnName);
    return false;
  } else if (objectType.isUnknownType()) {
    if (hasMoreTagsToResolve(objectType)) {
      return true;
    } else {
      reportWarning(RESOLVED_TAG_EMPTY, "@implements", fnName);
      return false;
    }
  } else {
    return true;
  }
}
 
Example 12
Source File: Nopol2017_0029_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 13
Source File: AmbiguateProperties.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Returns true if properties on this type should not be renamed. */
private boolean isInvalidatingType(JSType type) {
  if (type.isUnionType()) {
    type = type.restrictByNotNullOrUndefined();
    if (type.isUnionType()) {
      for (JSType alt : type.toMaybeUnionType().getAlternates()) {
        if (isInvalidatingType(alt)) {
          return true;
        }
      }
      return false;
    }
  }
  ObjectType objType = ObjectType.cast(type);
  return objType == null
      || invalidatingTypes.contains(objType)
      || !objType.hasReferenceName()
      || objType.isUnknownType()
      || objType.isEmptyType() /* unresolved types */
      || objType.isEnumType()
      || objType.autoboxesTo() != null;
}
 
Example 14
Source File: Closure_11_TypeCheck_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 15
Source File: Nopol2017_0051_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Given a constructor or an interface type, find out whether the unknown
 * type is a supertype of the current type.
 */
private static boolean hasUnknownOrEmptySupertype(FunctionType ctor) {
  Preconditions.checkArgument(ctor.isConstructor() || ctor.isInterface());
  Preconditions.checkArgument(!ctor.isUnknownType());

  // The type system should notice inheritance cycles on its own
  // and break the cycle.
  while (true) {
    ObjectType maybeSuperInstanceType =
        ctor.getPrototype().getImplicitPrototype();
    if (maybeSuperInstanceType == null) {
      return false;
    }
    if (maybeSuperInstanceType.isUnknownType() ||
        maybeSuperInstanceType.isEmptyType()) {
      return true;
    }
    ctor = maybeSuperInstanceType.getConstructor();
    if (ctor == null) {
      return false;
    }
    Preconditions.checkState(ctor.isConstructor() || ctor.isInterface());
  }
}
 
Example 16
Source File: TightenTypes.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public StaticScope<ConcreteType> createInstanceScope(
    ObjectType instanceType) {
  ConcreteScope parentScope = null;
  ObjectType implicitProto = instanceType.getImplicitPrototype();
  if (implicitProto != null && !implicitProto.isUnknownType()) {
    ConcreteInstanceType prototype = createConcreteInstance(implicitProto);
    parentScope = (ConcreteScope) prototype.getScope();
  }
  ConcreteScope scope = new ConcreteScope(parentScope);
  for (String propName : instanceType.getOwnPropertyNames()) {
    scope.declareSlot(propName, null);
  }
  return scope;
}
 
Example 17
Source File: Closure_54_TypedScopeCreator_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
@Override
public Scope createScope(Node root, Scope parent) {
  // Constructing the global scope is very different than constructing
  // inner scopes, because only global scopes can contain named classes that
  // show up in the type registry.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type.isFunctionType()) {
      FunctionType fnType = type.toMaybeFunctionType();
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes,
        delegateCallingConventions);
  }
  return newScope;
}
 
Example 18
Source File: Nopol2017_0027_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
@Override
public Scope createScope(Node root, Scope parent) {
  // Constructing the global scope is very different than constructing
  // inner scopes, because only global scopes can contain named classes that
  // show up in the type registry.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Run a first-order analysis over the syntax tree.
    (new FirstOrderFunctionAnalyzer(compiler, functionAnalysisResults))
        .process(root.getFirstChild(), root.getLastChild());

    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type.isFunctionType()) {
      FunctionType fnType = type.toMaybeFunctionType();
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes,
        delegateCallingConventions);
  }
  return newScope;
}
 
Example 19
Source File: Closure_43_TypedScopeCreator_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
@Override
public Scope createScope(Node root, Scope parent) {
  // Constructing the global scope is very different than constructing
  // inner scopes, because only global scopes can contain named classes that
  // show up in the type registry.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Run a first-order analysis over the syntax tree.
    (new FirstOrderFunctionAnalyzer(compiler, functionAnalysisResults))
        .process(root.getFirstChild(), root.getLastChild());

    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type.isFunctionType()) {
      FunctionType fnType = type.toMaybeFunctionType();
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes,
        delegateCallingConventions);
  }
  return newScope;
}
 
Example 20
Source File: Closure_43_TypedScopeCreator_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Creates a scope with all types declared. Declares newly discovered types
 * and type properties in the type registry.
 */
@Override
public Scope createScope(Node root, Scope parent) {
  // Constructing the global scope is very different than constructing
  // inner scopes, because only global scopes can contain named classes that
  // show up in the type registry.
  Scope newScope = null;
  AbstractScopeBuilder scopeBuilder = null;
  if (parent == null) {
    // Run a first-order analysis over the syntax tree.
    (new FirstOrderFunctionAnalyzer(compiler, functionAnalysisResults))
        .process(root.getFirstChild(), root.getLastChild());

    // Find all the classes in the global scope.
    newScope = createInitialScope(root);

    GlobalScopeBuilder globalScopeBuilder = new GlobalScopeBuilder(newScope);
    scopeBuilder = globalScopeBuilder;
    NodeTraversal.traverse(compiler, root, scopeBuilder);
  } else {
    newScope = new Scope(parent, root);
    LocalScopeBuilder localScopeBuilder = new LocalScopeBuilder(newScope);
    scopeBuilder = localScopeBuilder;
    localScopeBuilder.build();
  }

  scopeBuilder.resolveStubDeclarations();
  scopeBuilder.resolveTypes();

  // Gather the properties in each function that we found in the
  // global scope, if that function has a @this type that we can
  // build properties on.
  for (Node functionNode : scopeBuilder.nonExternFunctions) {
    JSType type = functionNode.getJSType();
    if (type != null && type.isFunctionType()) {
      FunctionType fnType = type.toMaybeFunctionType();
      ObjectType fnThisType = fnType.getTypeOfThis();
      if (!fnThisType.isUnknownType()) {
        NodeTraversal.traverse(compiler, functionNode.getLastChild(),
            scopeBuilder.new CollectProperties(fnThisType));
      }
    }
  }

  if (parent == null) {
    codingConvention.defineDelegateProxyPrototypeProperties(
        typeRegistry, newScope, delegateProxyPrototypes,
        delegateCallingConventions);
  }
  return newScope;
}