use of com.google.javascript.jscomp.newtypes.DeclaredFunctionType in project closure-compiler by google.
the class NewTypeInference method getTypeEnvFromDeclaredTypes.
private TypeEnv getTypeEnvFromDeclaredTypes() {
TypeEnv env = new TypeEnv();
Set<String> varNames = this.currentScope.getOuterVars();
Set<String> locals = this.currentScope.getLocals();
varNames.addAll(locals);
varNames.addAll(this.currentScope.getExterns());
if (this.currentScope.hasThis()) {
varNames.add(THIS_ID);
}
if (this.currentScope.isFunction()) {
Node fn = this.currentScope.getRoot();
if (!this.currentScope.hasThis() && // a function.
NodeUtil.containsType(fn.getLastChild(), Token.SUPER, NodeUtil.MATCH_NOT_FUNCTION)) {
// This function is a static method on some class. To do lookups of the
// class name, we add the root of the qualified name to the environment.
Node funNameNode = NodeUtil.getBestLValue(fn);
Node qnameRoot = NodeUtil.getRootOfQualifiedName(funNameNode);
checkState(qnameRoot.isName());
varNames.add(qnameRoot.getString());
}
if (this.currentScope.getName() != null) {
varNames.add(this.currentScope.getName());
}
varNames.addAll(this.currentScope.getFormals());
// In the rare case when there is a local variable named "arguments",
// this entry will be overwritten in the foreach loop below.
JSType argumentsType;
DeclaredFunctionType dft = this.currentScope.getDeclaredTypeForOwnBody();
if (dft.getOptionalArity() == 0 && dft.hasRestFormals()) {
argumentsType = dft.getRestFormalsType();
} else {
argumentsType = UNKNOWN;
}
env = envPutType(env, "arguments", commonTypes.getArgumentsArrayType(argumentsType));
}
for (String varName : varNames) {
if (!this.currentScope.isLocalFunDef(varName)) {
JSType declType = this.currentScope.getDeclaredTypeOf(varName);
if (declType == null) {
declType = UNKNOWN;
} else if (areTypeVariablesUnknown) {
declType = declType.substituteGenericsWithUnknown();
}
env = envPutType(env, varName, declType);
}
}
for (String fnName : this.currentScope.getLocalFunDefs()) {
env = envPutType(env, fnName, getSummaryOfLocalFunDef(fnName));
}
return env;
}
Aggregations