当前位置: 首页>>代码示例>>Java>>正文


Java Name.getDeclaration方法代码示例

本文整理汇总了Java中com.google.javascript.jscomp.GlobalNamespace.Name.getDeclaration方法的典型用法代码示例。如果您正苦于以下问题:Java Name.getDeclaration方法的具体用法?Java Name.getDeclaration怎么用?Java Name.getDeclaration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.javascript.jscomp.GlobalNamespace.Name的用法示例。


在下文中一共展示了Name.getDeclaration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateGlobalNameDeclarationAtClassNode

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
 * Updates the first initialization (a.k.a "declaration") of a global name that occurs at a CLASS
 * node. See comment for {@link #updateGlobalNameDeclaration}.
 *
 * @param n An object representing a global name (e.g. "a")
 */
private void updateGlobalNameDeclarationAtClassNode(Name n, boolean canCollapseChildNames) {
  if (!canCollapseChildNames || !canCollapse(n)) {
    return;
  }

  Ref ref = n.getDeclaration();
  String className = ref.node.getString();
  addStubsForUndeclaredProperties(
      n, className, ref.node.getAncestor(2), ref.node.getParent());
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:17,代码来源:CollapseProperties.java

示例2: checkNamespaces

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
 * Runs through all namespaces (prefixes of classes and enums), and checks if
 * any of them have been used in an unsafe way.
 */
private void checkNamespaces() {
  for (Name name : nameMap.values()) {
    if (name.isNamespace() &&
        (name.aliasingGets > 0 || name.localSets + name.globalSets > 1 ||
         name.deleteProps > 0)) {
      boolean initialized = name.getDeclaration() != null;
      for (Ref ref : name.getRefs()) {
        if (ref == name.getDeclaration()) {
          continue;
        }

        if (ref.type == Ref.Type.DELETE_PROP) {
          if (initialized) {
            warnAboutNamespaceRedefinition(name, ref);
          }
        } else if (
            ref.type == Ref.Type.SET_FROM_GLOBAL ||
            ref.type == Ref.Type.SET_FROM_LOCAL) {
          if (initialized) {
            warnAboutNamespaceRedefinition(name, ref);
          }

          initialized = true;
        } else if (ref.type == Ref.Type.ALIASING_GET) {
          warnAboutNamespaceAliasing(name, ref);
        }
      }
    }
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:35,代码来源:CollapseProperties.java

示例3: flattenPrefixes

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
 * Flattens all occurrences of a name as a prefix of subnames beginning
 * with a particular subname.
 *
 * @param n A global property name (e.g. "a.b.c.d")
 * @param alias A flattened prefix name (e.g. "a$b")
 * @param depth The difference in depth between the property name and
 *    the prefix name (e.g. 2)
 */
private void flattenPrefixes(String alias, Name n, int depth) {
  // Only flatten the prefix of a name declaration if the name being
  // initialized is fully qualified (i.e. not an object literal key).
  String originalName = n.getFullName();
  Ref decl = n.getDeclaration();
  if (decl != null && decl.node != null &&
      decl.node.isGetProp()) {
    flattenNameRefAtDepth(alias, decl.node, depth, originalName);
  }

  for (Ref r : n.getRefs()) {
    if (r == decl) {
      // Declarations are handled separately.
      continue;
    }

    // References inside a complex assign (a = x.y = 0)
    // have twins. We should only flatten one of the twins.
    if (r.getTwin() == null || r.isSet()) {
      flattenNameRefAtDepth(alias, r.node, depth, originalName);
    }
  }

  if (n.props != null) {
    for (Name p : n.props) {
      flattenPrefixes(alias, p, depth + 1);
    }
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:39,代码来源:CollapseProperties.java

示例4: collapseDeclarationOfNameAndDescendants

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
 * Collapses definitions of the collapsible properties of a global name.
 * Recurses on subnames that also represent JavaScript objects with
 * collapsible properties.
 *
 * @param n A node representing a global name
 * @param alias The flattened name for {@code n}
 */
private void collapseDeclarationOfNameAndDescendants(Name n, String alias) {
  boolean canCollapseChildNames = n.canCollapseUnannotatedChildNames();

  // Handle this name first so that nested object literals get unrolled.
  if (n.canCollapse()) {
    updateObjLitOrFunctionDeclaration(n, alias, canCollapseChildNames);
  }

  if (n.props != null) {
    for (Name p : n.props) {
      // Recurse first so that saved node ancestries are intact when needed.
      collapseDeclarationOfNameAndDescendants(
          p, appendPropForAlias(alias, p.getBaseName()));

      if (!p.inExterns && canCollapseChildNames &&
          p.getDeclaration() != null &&
          p.canCollapse() &&
          p.getDeclaration().node != null &&
          p.getDeclaration().node.getParent() != null &&
          p.getDeclaration().node.getParent().isAssign()) {
        updateSimpleDeclaration(
            appendPropForAlias(alias, p.getBaseName()), p, p.getDeclaration());
      }
    }
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:35,代码来源:CollapseProperties.java

示例5: updateObjLitOrFunctionDeclaration

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
 * Updates the first initialization (a.k.a "declaration") of a global name.
 * This involves flattening the global name (if it's not just a global
 * variable name already), collapsing object literal keys into global
 * variables, declaring stub global variables for properties added later
 * in a local scope.
 *
 * It may seem odd that this function also takes care of declaring stubs
 * for direct children. The ultimate goal of this function is to eliminate
 * the global name entirely (when possible), so that "middlemen" namespaces
 * disappear, and to do that we need to make sure that all the direct children
 * will be collapsed as well.
 *
 * @param n An object representing a global name (e.g. "a", "a.b.c")
 * @param alias The flattened name for {@code n} (e.g. "a", "a$b$c")
 * @param canCollapseChildNames Whether it's possible to collapse children of
 *     this name. (This is mostly passed for convenience; it's equivalent to
 *     n.canCollapseChildNames()).
 */
private void updateObjLitOrFunctionDeclaration(
    Name n, String alias, boolean canCollapseChildNames) {
  Ref decl = n.getDeclaration();
  if (decl == null) {
    // Some names do not have declarations, because they
    // are only defined in local scopes.
    return;
  }

  if (decl.getTwin() != null) {
    // Twin declarations will get handled when normal references
    // are handled.
    return;
  }

  switch (decl.node.getParent().getType()) {
    case Token.ASSIGN:
      updateObjLitOrFunctionDeclarationAtAssignNode(
          n, alias, canCollapseChildNames);
      break;
    case Token.VAR:
      updateObjLitOrFunctionDeclarationAtVarNode(n, canCollapseChildNames);
      break;
    case Token.FUNCTION:
      updateFunctionDeclarationAtFunctionNode(n, canCollapseChildNames);
      break;
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:48,代码来源:CollapseProperties.java

示例6: updateObjLitOrFunctionDeclarationAtVarNode

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
 * Updates the first initialization (a.k.a "declaration") of a global name
 * that occurs at a VAR node. See comment for
 * {@link #updateObjLitOrFunctionDeclaration}.
 *
 * @param n An object representing a global name (e.g. "a")
 */
private void updateObjLitOrFunctionDeclarationAtVarNode(
    Name n, boolean canCollapseChildNames) {
  if (!canCollapseChildNames) {
    return;
  }

  Ref ref = n.getDeclaration();
  String name = ref.node.getString();
  Node rvalue = ref.node.getFirstChild();
  Node varNode = ref.node.getParent();
  Node gramps = varNode.getParent();

  boolean isObjLit = rvalue.isObjectLit();
  int numChanges = 0;

  if (isObjLit) {
    numChanges += declareVarsForObjLitValues(
        n, name, rvalue, varNode, gramps.getChildBefore(varNode),
        gramps);
  }

  numChanges += addStubsForUndeclaredProperties(n, name, gramps, varNode);

  if (isObjLit && n.canEliminate()) {
    varNode.removeChild(ref.node);
    if (!varNode.hasChildren()) {
      gramps.removeChild(varNode);
    }
    numChanges++;

    // Clear out the object reference, since we've eliminated it from the
    // parse tree.
    ref.node = null;
  }

  if (numChanges > 0) {
    compiler.reportCodeChange();
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:47,代码来源:CollapseProperties.java

示例7: updateFunctionDeclarationAtFunctionNode

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
 * Updates the first initialization (a.k.a "declaration") of a global name
 * that occurs at a FUNCTION node. See comment for
 * {@link #updateObjLitOrFunctionDeclaration}.
 *
 * @param n An object representing a global name (e.g. "a")
 */
private void updateFunctionDeclarationAtFunctionNode(
    Name n, boolean canCollapseChildNames) {
  if (!canCollapseChildNames) {
    return;
  }

  Ref ref = n.getDeclaration();
  String fnName = ref.node.getString();
  addStubsForUndeclaredProperties(
      n, fnName, ref.node.getAncestor(2), ref.node.getParent());
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:CollapseProperties.java

示例8: CollectDefines

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
CollectDefines(AbstractCompiler compiler, List<Name> listOfDefines) {
  this.compiler = compiler;
  this.allDefines = new HashMap<>();

  assignableDefines = new HashMap<>();
  assignAllowed = new ArrayDeque<>();
  assignAllowed.push(1);

  // Create a map of references to defines keyed by node for easy lookup
  allRefInfo = new HashMap<>();
  for (Name name : listOfDefines) {
    Ref decl = name.getDeclaration();
    if (decl != null) {
      allRefInfo.put(decl.node,
                     new RefInfo(decl, name));
    }
    for (Ref ref : name.getRefs()) {
      if (ref == decl) {
        // Declarations were handled above.
        continue;
      }

      // If there's a TWIN def, only put one of the twins in.
      if (ref.getTwin() == null || !ref.getTwin().isSet()) {
        allRefInfo.put(ref.node, new RefInfo(ref, name));
      }
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:30,代码来源:ProcessDefines.java

示例9: checkNamespaces

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
 * Runs through all namespaces (prefixes of classes and enums), and checks if
 * any of them have been used in an unsafe way.
 */
private void checkNamespaces() {
  for (Name name : nameMap.values()) {
    if (name.isNamespaceObjectLit()
        && (name.aliasingGets > 0
            || name.localSets + name.globalSets > 1
            || name.deleteProps > 0)) {
      boolean initialized = name.getDeclaration() != null;
      for (Ref ref : name.getRefs()) {
        if (ref == name.getDeclaration()) {
          continue;
        }

        if (ref.type == Ref.Type.DELETE_PROP) {
          if (initialized) {
            warnAboutNamespaceRedefinition(name, ref);
          }
        } else if (
            ref.type == Ref.Type.SET_FROM_GLOBAL
            || ref.type == Ref.Type.SET_FROM_LOCAL) {
          if (initialized && !isSafeNamespaceReinit(ref)) {
            warnAboutNamespaceRedefinition(name, ref);
          }

          initialized = true;
        } else if (ref.type == Ref.Type.ALIASING_GET) {
          warnAboutNamespaceAliasing(name, ref);
        }
      }
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:36,代码来源:CollapseProperties.java

示例10: flattenReferencesTo

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
 * Flattens all references to a collapsible property of a global name except
 * its initial definition.
 *
 * @param n A global property name (e.g. "a.b" or "a.b.c.d")
 * @param alias The flattened name (e.g. "a$b" or "a$b$c$d")
 */
private void flattenReferencesTo(Name n, String alias) {
  String originalName = n.getFullName();
  for (Ref r : n.getRefs()) {
    if (r == n.getDeclaration()) {
      // Declarations are handled separately.
      continue;
    }
    Node rParent = r.node.getParent();
    // There are two cases when we shouldn't flatten a reference:
    // 1) Object literal keys, because duplicate keys show up as refs.
    // 2) References inside a complex assign. (a = x.y = 0). These are
    //    called TWIN references, because they show up twice in the
    //    reference list. Only collapse the set, not the alias.
    if (!NodeUtil.isObjectLitKey(r.node) && (r.getTwin() == null || r.isSet())) {
      flattenNameRef(alias, r.node, rParent, originalName);
    }
  }

  // Flatten all occurrences of a name as a prefix of its subnames. For
  // example, if {@code n} corresponds to the name "a.b", then "a.b" will be
  // replaced with "a$b" in all occurrences of "a.b.c", "a.b.c.d", etc.
  if (n.props != null) {
    for (Name p : n.props) {
      flattenPrefixes(alias, p, 1);
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:35,代码来源:CollapseProperties.java

示例11: updateGlobalNameDeclarationAtFunctionNode

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
 * Updates the first initialization (a.k.a "declaration") of a global name
 * that occurs at a FUNCTION node. See comment for
 * {@link #updateGlobalNameDeclaration}.
 *
 * @param n An object representing a global name (e.g. "a")
 */
private void updateGlobalNameDeclarationAtFunctionNode(
    Name n, boolean canCollapseChildNames) {
  if (!canCollapseChildNames || !canCollapse(n)) {
    return;
  }

  Ref ref = n.getDeclaration();
  String fnName = ref.node.getString();
  addStubsForUndeclaredProperties(n, fnName, ref.node.getAncestor(2), ref.node.getParent());
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:18,代码来源:CollapseProperties.java

示例12: updateGlobalNameDeclaration

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
 * Updates the first initialization (a.k.a "declaration") of a global name.
 * This involves flattening the global name (if it's not just a global
 * variable name already), collapsing object literal keys into global
 * variables, declaring stub global variables for properties added later
 * in a local scope.
 *
 * It may seem odd that this function also takes care of declaring stubs
 * for direct children. The ultimate goal of this function is to eliminate
 * the global name entirely (when possible), so that "middlemen" namespaces
 * disappear, and to do that we need to make sure that all the direct children
 * will be collapsed as well.
 *
 * @param n An object representing a global name (e.g. "a", "a.b.c")
 * @param alias The flattened name for {@code n} (e.g. "a", "a$b$c")
 * @param canCollapseChildNames Whether it's possible to collapse children of
 *     this name. (This is mostly passed for convenience; it's equivalent to
 *     n.canCollapseChildNames()).
 */
private void updateGlobalNameDeclaration(
    Name n, String alias, boolean canCollapseChildNames) {
  Ref decl = n.getDeclaration();
  if (decl == null) {
    // Some names do not have declarations, because they
    // are only defined in local scopes.
    return;
  }

  switch (decl.node.getParent().getToken()) {
    case ASSIGN:
      updateGlobalNameDeclarationAtAssignNode(
          n, alias, canCollapseChildNames);
      break;
    case VAR:
    case LET:
    case CONST:
      updateGlobalNameDeclarationAtVariableNode(n, canCollapseChildNames);
      break;
    case FUNCTION:
      updateGlobalNameDeclarationAtFunctionNode(n, canCollapseChildNames);
      break;
    case CLASS:
      updateGlobalNameDeclarationAtClassNode(n, canCollapseChildNames);
      break;
    default:
      break;
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:49,代码来源:CollapseProperties.java

示例13: updateGlobalNameDeclarationAtVariableNode

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
 * Updates the first initialization (a.k.a "declaration") of a global name that occurs at a VAR
 * node. See comment for {@link #updateGlobalNameDeclaration}.
 *
 * @param n An object representing a global name (e.g. "a")
 */
private void updateGlobalNameDeclarationAtVariableNode(
    Name n, boolean canCollapseChildNames) {
  if (!canCollapseChildNames) {
    return;
  }

  Ref ref = n.getDeclaration();
  String name = ref.node.getString();
  Node rvalue = ref.node.getFirstChild();
  Node variableNode = ref.node.getParent();
  Node grandparent = variableNode.getParent();

  boolean isObjLit = rvalue.isObjectLit();

  if (isObjLit) {
    declareVariablesForObjLitValues(
        n, name, rvalue, variableNode, variableNode.getPrevious(), grandparent);
  }

  addStubsForUndeclaredProperties(n, name, grandparent, variableNode);

  if (isObjLit && canEliminate(n)) {
    variableNode.removeChild(ref.node);
    compiler.reportChangeToEnclosingScope(variableNode);
    if (!variableNode.hasChildren()) {
      grandparent.removeChild(variableNode);
    }

    // Clear out the object reference, since we've eliminated it from the
    // parse tree.
    ref.node = null;
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:40,代码来源:CollapseProperties.java

示例14: CollectDefines

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
CollectDefines(AbstractCompiler compiler, List<Name> listOfDefines) {
  this.compiler = compiler;
  this.allDefines = Maps.newHashMap();

  assignableDefines = Maps.newHashMap();
  assignAllowed = new ArrayDeque<>();
  assignAllowed.push(1);

  // Create a map of references to defines keyed by node for easy lookup
  allRefInfo = Maps.newHashMap();
  for (Name name : listOfDefines) {
    Ref decl = name.getDeclaration();
    if (decl != null) {
      allRefInfo.put(decl.node,
                     new RefInfo(decl, name));
    }
    for (Ref ref : name.getRefs()) {
      if (ref == decl) {
        // Declarations were handled above.
        continue;
      }

      // If there's a TWIN def, only put one of the twins in.
      if (ref.getTwin() == null || !ref.getTwin().isSet()) {
        allRefInfo.put(ref.node, new RefInfo(ref, name));
      }
    }
  }
}
 
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:30,代码来源:ProcessDefines.java

示例15: flattenReferencesTo

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入方法依赖的package包/类
/**
 * Flattens all references to a collapsible property of a global name except
 * its initial definition.
 *
 * @param n A global property name (e.g. "a.b" or "a.b.c.d")
 * @param alias The flattened name (e.g. "a$b" or "a$b$c$d")
 */
private void flattenReferencesTo(Name n, String alias) {
  String originalName = n.getFullName();
  for (Ref r : n.getRefs()) {
    if (r == n.getDeclaration()) {
      // Declarations are handled separately.
      continue;
    }

    Node rParent = r.node.getParent();

    // There are two cases when we shouldn't flatten a reference:
    // 1) Object literal keys, because duplicate keys show up as refs.
    // 2) References inside a complex assign. (a = x.y = 0). These are
    //    called TWIN references, because they show up twice in the
    //    reference list. Only collapse the set, not the alias.
    if (!NodeUtil.isObjectLitKey(r.node) &&
        (r.getTwin() == null || r.isSet())) {
      flattenNameRef(alias, r.node, rParent, originalName);
    }
  }

  // Flatten all occurrences of a name as a prefix of its subnames. For
  // example, if {@code n} corresponds to the name "a.b", then "a.b" will be
  // replaced with "a$b" in all occurrences of "a.b.c", "a.b.c.d", etc.
  if (n.props != null) {
    for (Name p : n.props) {
      flattenPrefixes(alias, p, 1);
    }
  }
}
 
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:38,代码来源:CollapseProperties.java


注:本文中的com.google.javascript.jscomp.GlobalNamespace.Name.getDeclaration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。