use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class JsDocInfoParserTest method testTypedefType4.
// https://github.com/google/closure-compiler/issues/2543
public void testTypedefType4() {
JSDocInfo info = parse(LINE_JOINER.join("@typedef {{", " * boo: ?,", " * goo: ?", " * }}", " */"));
assertThat(info.hasTypedefType()).isTrue();
JSType recordType = createRecordTypeBuilder().addProperty("boo", UNKNOWN_TYPE, null).addProperty("goo", UNKNOWN_TYPE, null).build();
assertTypeEquals(recordType, info.getTypedefType());
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypedScopeCreator method createScopeInternal.
private TypedScope createScopeInternal(Node root, TypedScope typedParent) {
// 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.
TypedScope newScope = null;
AbstractScopeBuilder scopeBuilder = null;
if (typedParent == null) {
JSType globalThis = typeRegistry.getNativeObjectType(JSTypeNative.GLOBAL_THIS);
// Mark the main root, the externs root, and the src root
// with the global this type.
root.setJSType(globalThis);
root.getFirstChild().setJSType(globalThis);
root.getLastChild().setJSType(globalThis);
// Run a first-order analysis over the syntax tree.
new FirstOrderFunctionAnalyzer().process(root.getFirstChild(), root.getLastChild());
// Find all the classes in the global scope.
newScope = createInitialScope(root);
scopeBuilder = new GlobalScopeBuilder(newScope);
} else {
newScope = new TypedScope(typedParent, root);
scopeBuilder = new LocalScopeBuilder(newScope);
}
scopeBuilder.build();
scopeBuilder.resolveStubDeclarations();
if (typedParent == null) {
List<NominalTypeBuilder> delegateProxies = new ArrayList<>();
for (FunctionType delegateProxyCtor : delegateProxyCtors) {
delegateProxies.add(new NominalTypeBuilderOti(delegateProxyCtor, delegateProxyCtor.getInstanceType()));
}
codingConvention.defineDelegateProxyPrototypeProperties(typeRegistry, delegateProxies, delegateCallingConventions);
}
newScope.setTypeResolver(scopeBuilder);
return newScope;
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class TypeValidator method getFunctionType.
/**
* Utility function for getting a function type from a var.
*/
static FunctionType getFunctionType(@Nullable TypedVar v) {
JSType t = v == null ? null : v.getType();
ObjectType o = t == null ? null : t.dereference();
return JSType.toMaybeFunctionType(o);
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class Matchers method matchesPrototypeInstanceVar.
/**
* Checks to see if the node represents an access of an instance variable
* on an object given a prototype declaration of an object. For instance,
* {@code ns.AppContext.prototype.get} will match {@code appContext.get}
* or {@code this.get} when accessed from within the AppContext object.
*/
private static boolean matchesPrototypeInstanceVar(Node node, NodeMetadata metadata, String name) {
String[] parts = name.split(".prototype.");
String className = parts[0];
String propertyName = parts[1];
JSType providedJsType = getJsType(metadata, className);
if (providedJsType == null) {
return false;
}
JSType jsType = null;
if (node.hasChildren()) {
jsType = node.getFirstChild().getJSType();
}
if (jsType == null) {
return false;
}
jsType = jsType.restrictByNotNullOrUndefined();
if (!jsType.isUnknownType() && !jsType.isAllType() && jsType.isSubtypeOf(providedJsType)) {
if (node.isName() && propertyName.equals(node.getString())) {
return true;
} else if (node.isGetProp() && propertyName.equals(node.getLastChild().getString())) {
return true;
}
}
return false;
}
use of com.google.javascript.rhino.jstype.JSType in project closure-compiler by google.
the class JSTypeExpression method evaluate.
/**
* Evaluates the type expression into a {@code JSType} object.
*/
public JSType evaluate(StaticTypedScope<JSType> scope, TypeIRegistry registry) {
if (registry instanceof JSTypeRegistry) {
JSType type = ((JSTypeRegistry) registry).createTypeFromCommentNode(root, sourceName, scope);
root.setJSType(type);
return type;
}
return null;
}
Aggregations