use of com.google.javascript.jscomp.newtypes.Namespace in project closure-compiler by google.
the class NTIScope method addFunNamespace.
void addFunNamespace(Node qnameNode) {
if (qnameNode.isName()) {
String varName = qnameNode.getString();
checkArgument(isDefinedLocally(varName, false));
checkState(!this.localNamespaces.containsKey(varName));
NTIScope s = checkNotNull(this.localFunDefs.get(varName));
this.localNamespaces.put(varName, new FunctionNamespace(this.commonTypes, varName, s, qnameNode));
} else {
checkArgument(!isNamespace(qnameNode));
QualifiedName qname = QualifiedName.fromNode(qnameNode);
Namespace ns = getNamespace(qname.getLeftmostName());
NTIScope s = (NTIScope) ns.getDeclaration(qname).getFunctionScope();
ns.addNamespace(qname.getAllButLeftmost(), new FunctionNamespace(this.commonTypes, qname.toString(), s, qnameNode));
}
}
use of com.google.javascript.jscomp.newtypes.Namespace in project closure-compiler by google.
the class NTIScope method getNamespaceAfterFreezing.
private Namespace getNamespaceAfterFreezing(String typeName) {
checkNotNull(preservedNamespaces, "Failed to preserve namespaces post-finalization");
QualifiedName qname = QualifiedName.fromQualifiedString(typeName);
Namespace ns = preservedNamespaces.get(qname.getLeftmostName());
if (ns != null && !qname.isIdentifier()) {
ns = ns.getSubnamespace(qname.getAllButLeftmost());
}
return ns;
}
use of com.google.javascript.jscomp.newtypes.Namespace in project closure-compiler by google.
the class NTIScope method addTypedef.
void addTypedef(Node qnameNode, Typedef td) {
if (qnameNode.isName()) {
checkState(!localTypedefs.containsKey(qnameNode.getString()));
localTypedefs.put(qnameNode.getString(), td);
} else {
checkState(!isDefined(qnameNode));
QualifiedName qname = QualifiedName.fromNode(qnameNode);
Namespace ns = getNamespace(qname.getLeftmostName());
ns.addTypedef(qname.getAllButLeftmost(), td);
namespaceTypedefs.add(td);
}
}
use of com.google.javascript.jscomp.newtypes.Namespace in project closure-compiler by google.
the class NTIScope method getLocalDeclaration.
private Declaration getLocalDeclaration(String name, boolean includeTypes) {
checkArgument(!name.contains("."));
if (!isDefinedLocally(name, includeTypes)) {
return null;
}
DeclaredFunctionType declaredType = getDeclaredTypeForOwnBody();
JSType type = null;
boolean isTypeVar = false;
if ("this".equals(name)) {
type = getDeclaredTypeOf("this");
} else if (locals.containsKey(name)) {
type = locals.get(name).getDeclaredType();
} else if (formals.contains(name)) {
int formalIndex = formals.indexOf(name);
if (declaredType != null && formalIndex != -1) {
JSType formalType = declaredType.getFormalType(formalIndex);
if (formalType != null && !formalType.isBottom()) {
type = formalType;
}
}
} else if (localFunDefs.containsKey(name)) {
// external function namespaces, don't rely on localFunDefs
if (isFrozen && externs.containsKey(name)) {
type = externs.get(name);
}
} else if (localTypedefs.containsKey(name) || localNamespaces.containsKey(name)) {
// Any further declarations are shadowed
} else if (declaredType != null && declaredType.isTypeVariableDefinedLocally(name)) {
isTypeVar = true;
type = JSType.fromTypeVar(this.commonTypes, declaredType.getTypeVariableDefinedLocally(name));
} else if (externs.containsKey(name)) {
type = externs.get(name);
}
Namespace ns = null;
if (localNamespaces.containsKey(name)) {
ns = localNamespaces.get(name);
} else if (preservedNamespaces != null) {
ns = preservedNamespaces.get(name);
}
return new Declaration(type, localTypedefs.get(name), ns, localFunDefs.get(name), isTypeVar, constVars.contains(name));
}
use of com.google.javascript.jscomp.newtypes.Namespace in project closure-compiler by google.
the class NTIScope method getDeclaration.
@Override
public Declaration getDeclaration(QualifiedName qname, boolean includeTypes) {
if (qname.isIdentifier()) {
return getDeclaration(qname.getLeftmostName(), includeTypes);
}
Namespace ns = getNamespace(qname.getLeftmostName());
if (ns == null) {
return maybeGetForwardDeclaration(qname.toString());
}
Declaration decl = ns.getDeclaration(qname.getAllButLeftmost());
return decl != null ? decl : maybeGetForwardDeclaration(qname.toString());
}
Aggregations