@Override public com.google.javascript.rhino.jstype.JSType getAssertedOldType(Node call, JSTypeRegistry registry) { return registry.getType(typeName); }
public JSType getGlobalType(String jsTypeName) { return getType(null, jsTypeName); }
/** * Looks up a type by name. To allow for forward references to types, an unrecognized string has * to be bound to a NamedType object that will be resolved later. * * @param scope A scope for doing type name resolution. * @param jsTypeName The name string. * @param sourceName The name of the source file where this reference appears. * @param lineno The line number of the reference. * @return a NamedType if the string argument is not one of the known types, otherwise the * corresponding JSType object. */ public JSType getType( StaticTypedScope scope, String jsTypeName, String sourceName, int lineno, int charno) { return getType(scope, jsTypeName, sourceName, lineno, charno, true); }
/** * Resolves a named type by looking it up in the registry. * @return True if we resolved successfully. */ private boolean resolveViaRegistry(ErrorReporter reporter) { JSType type = registry.getType(resolutionScope, reference); if (type != null) { setReferencedAndResolvedType(type, reporter); return true; } return false; }
/** * Resolves a named type by looking it up in the registry. * @return True if we resolved successfully. */ private boolean resolveViaRegistry(ErrorReporter reporter) { JSType type = registry.getType(reference); if (type != null) { setReferencedAndResolvedType(type, reporter); return true; } return false; }
private boolean isNonNullable(JSType type) { // TODO(lpino): Verify that nonNullableTypeNames is correct for (String s : nonNullableTypeNames) { JSType that = getType(s); if (that != null && type.isEquivalentTo(that)) { return true; } } return false; }
protected JSType union(List<String> typeNames) { JSTypeRegistry registry = compiler.getTypeRegistry(); List<JSType> types = new ArrayList<JSType>(); for (String typeName : typeNames) { JSType type = registry.getType(typeName); if (type != null) { types.add(type); } } if (types.isEmpty()) { return null; } else { JSType[] variants = types.toArray(new JSType[0]); return registry.createUnionType(variants); } }
private static JSType getJsType(NodeMetadata metadata, String type) { return metadata.getCompiler().getTypeRegistry().getType(type); }
private Symbol lookupPossiblyDottedName(SymbolScope scope, String dottedName) { // Try the dotted name to start. String[] names = dottedName.split("\\."); Symbol result = null; SymbolScope currentScope = scope; for (int i = 0; i < names.length; i++) { String name = names[i]; result = currentScope.getSlot(name); if (result == null) { break; } if (i < (names.length - 1)) { currentScope = result.getPropertyScope(); if (currentScope == null) { result = null; break; } } } if (result == null) { // If we can't find this type, it might be a reference to a // primitive type (like {string}). Autobox it to check. JSType type = typeRegistry.getType(dottedName); JSType autobox = type == null ? null : type.autoboxesTo(); result = autobox == null ? null : getSymbolForTypeHelper(autobox, true); } return result; } }
/** @return return an immutable list of template types of the given builtin. */ public ImmutableList<TemplateType> maybeGetTemplateTypesOfBuiltin(String fnName) { JSType type = getType(null, fnName); ObjectType objType = type == null ? null : type.toObjectType(); if (objType != null && objType.isNativeObjectType()) { ImmutableList<TemplateType> templateKeys = objType.getTemplateTypeMap().getUnfilledTemplateKeys(); return templateKeys; } return null; }
/** * Makes a new PolyfillInfo, including the correct Removable. Parses the name to determine whether * this is a global, static, or prototype polyfill. */ private PolyfillInfo createPolyfillInfo(Node call, Scope scope, String name) { checkState(scope.isGlobal()); checkState(call.getParent().isExprResult()); // Make the removable and polyfill info. Add continuations for all arguments. RemovableBuilder builder = new RemovableBuilder(); for (Node n = call.getFirstChild().getNext(); n != null; n = n.getNext()) { builder.addContinuation(new Continuation(n, scope)); } Polyfill removable = builder.buildPolyfill(call.getParent()); int lastDot = name.lastIndexOf("."); if (lastDot < 0) { return new GlobalPolyfillInfo(removable, name); } String owner = name.substring(0, lastDot); String prop = name.substring(lastDot + 1); boolean typed = call.getJSType() != null; if (owner.endsWith(DOT_PROTOTYPE)) { owner = owner.substring(0, owner.length() - DOT_PROTOTYPE.length()); return new PrototypePropertyPolyfillInfo( removable, prop, typed ? compiler.getTypeRegistry().getType(scope, owner) : null); } ObjectType ownerInstanceType = typed ? ObjectType.cast(compiler.getTypeRegistry().getType(scope, owner)) : null; JSType ownerCtorType = ownerInstanceType != null ? ownerInstanceType.getConstructor() : null; return new StaticPropertyPolyfillInfo(removable, prop, ownerCtorType, owner); }
/** * Resolve all the unresolved types in the given scope. */ public void resolveTypesInScope(StaticTypedScope<JSType> scope) { for (NamedType type : unresolvedNamedTypes.get(scope)) { type.resolve(reporter, scope); } resolvedNamedTypes.putAll(scope, unresolvedNamedTypes.removeAll(scope)); if (scope != null && scope.getParentScope() == null) { // By default, the global "this" type is just an anonymous object. // If the user has defined a Window type, make the Window the // implicit prototype of "this". PrototypeObjectType globalThis = (PrototypeObjectType) getNativeType( JSTypeNative.GLOBAL_THIS); JSType windowType = getType("Window"); if (globalThis.isUnknownType()) { ObjectType windowObjType = ObjectType.cast(windowType); if (windowObjType != null) { globalThis.setImplicitPrototype(windowObjType); } else { globalThis.setImplicitPrototype( getNativeObjectType(JSTypeNative.OBJECT_TYPE)); } } } }
globalScope.undeclare(var); globalScope.getTypeOfThis().toObjectType().removeProperty(typeName); if (typeRegistry.getType(globalScope, typeName) != null) { typeRegistry.removeType(globalScope, typeName);
DelegateRelationship delegateRelationship) { ObjectType delegatorObject = ObjectType.cast( typeRegistry.getType(delegateRelationship.delegator)); ObjectType delegateBaseObject = ObjectType.cast( typeRegistry.getType(delegateRelationship.delegateBase)); ObjectType delegateSuperObject = ObjectType.cast( typeRegistry.getType(codingConvention.getDelegateSuperclassName())); if (delegatorObject != null && delegateBaseObject != null &&
DelegateRelationship delegateRelationship) { ObjectType delegatorObject = ObjectType.cast(typeRegistry.getType(currentScope, delegateRelationship.delegator)); ObjectType delegateBaseObject = ObjectType.cast(typeRegistry.getType(currentScope, delegateRelationship.delegateBase)); ObjectType delegateSuperObject = ObjectType.cast( typeRegistry.getType(currentScope, codingConvention.getDelegateSuperclassName())); if (delegatorObject != null && delegateBaseObject != null
if (typeName.equals("null") || registry.getType(scope, typeName) == null) { return;
private FunctionType getOrCreateInterface() { FunctionType fnType = null; JSType type = typeRegistry.getType(getScopeDeclaredIn(), fnName); if (type != null && type.isInstanceType()) { FunctionType ctor = type.toMaybeObjectType().getConstructor(); if (ctor.isInterface()) { fnType = ctor; fnType.setSource(contents.getSourceNode()); } } if (fnType == null) { fnType = typeRegistry.createInterfaceType( fnName, contents.getSourceNode(), templateTypeNames, makesStructs); if (!fnName.isEmpty()) { typeRegistry.declareTypeForExactScope( getScopeDeclaredIn(), fnName, fnType.getInstanceType()); } maybeSetBaseType(fnType); } return fnType; } private void reportWarning(DiagnosticType warning, String ... args) {
} else if (rValue != null) { JSType rhsNamedType = typeRegistry.getType(currentScope, rValue.join()); if (rhsNamedType != null) { typeRegistry.declareType(currentScope, lValue.getQualifiedName(), rhsNamedType);
private JSType getType(String typeName) { JSType type = registry.getType(typeEnv, typeName); if (type != null) { return type; } StaticTypedSlot slot = typeEnv.getSlot(typeName); type = slot != null ? slot.getType() : null; if (type != null) { if (type.isConstructor() || type.isInterface()) { return type.toMaybeFunctionType().getInstanceType().getRawType(); } if (type.isEnumElementType()) { return type.getEnumeratedTypeOfEnumElement(); } return type; } JSDocInfo jsdoc = slot == null ? null : slot.getJSDocInfo(); if (jsdoc != null && jsdoc.hasTypedefType()) { return this.registry.evaluateTypeExpression(jsdoc.getTypedefType(), typeEnv); } return null; }
registry.getType(scope.getDeclarationScope(), qualifiedName)); if (regType != null) { propertyType = regType.getConstructor();