Search in sources :

Example 1 with StaticRef

use of com.google.javascript.rhino.StaticRef in project closure-compiler by google.

the class SymbolTable method addSymbolsFrom.

/**
 * Make sure all the symbols and references in {@code otherSymbolTable} are in this symbol table.
 *
 * <p>Uniqueness of symbols and references is determined by the associated node.
 *
 * <p>If multiple symbol tables are mixed in, we do not check for consistency between symbol
 * tables. The first symbol we see dictates the type information for that symbol.
 */
<S extends StaticSlot, R extends StaticRef> void addSymbolsFrom(StaticSymbolTable<S, R> otherSymbolTable) {
    for (S otherSymbol : otherSymbolTable.getAllSymbols()) {
        String name = otherSymbol.getName();
        SymbolScope myScope = createScopeFrom(otherSymbolTable.getScope(otherSymbol));
        StaticRef decl = findBestDeclToAdd(otherSymbolTable, otherSymbol);
        Symbol mySymbol = null;
        if (decl != null) {
            Node declNode = decl.getNode();
            // If we have a declaration node, we can ensure the symbol is declared.
            mySymbol = isAnySymbolDeclared(name, declNode, myScope);
            if (mySymbol == null) {
                mySymbol = copySymbolTo(otherSymbol, declNode, myScope);
            }
        } else {
            // If we don't have a declaration node, we won't be able to declare
            // a symbol in this symbol table. But we may be able to salvage the
            // references if we already have a symbol.
            mySymbol = myScope.getOwnSlot(name);
        }
        if (mySymbol != null) {
            for (R otherRef : otherSymbolTable.getReferences(otherSymbol)) {
                if (isGoodRefToAdd(otherRef)) {
                    mySymbol.defineReferenceAt(otherRef.getNode());
                }
            }
        }
    }
}
Also used : Node(com.google.javascript.rhino.Node) StaticRef(com.google.javascript.rhino.StaticRef)

Example 2 with StaticRef

use of com.google.javascript.rhino.StaticRef in project closure-compiler by google.

the class AstFactory method getVarDefinitionNode.

private Node getVarDefinitionNode(StaticScope scope, String name) {
    StaticSlot var = checkNotNull(scope.getSlot(name), "Missing var %s in scope %s", name, scope);
    StaticRef declaration = checkNotNull(var.getDeclaration(), "Cannot find type for var with missing declaration %s", var);
    return checkNotNull(declaration.getNode(), "Missing node for declaration %s", declaration);
}
Also used : StaticSlot(com.google.javascript.rhino.StaticSlot) StaticRef(com.google.javascript.rhino.StaticRef)

Aggregations

StaticRef (com.google.javascript.rhino.StaticRef)2 Node (com.google.javascript.rhino.Node)1 StaticSlot (com.google.javascript.rhino.StaticSlot)1