• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Name类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Name类属于com.google.javascript.jscomp.GlobalNamespace包,在下文中一共展示了Name类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: 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<Integer>();
  assignAllowed.push(1);

  // Create a map of references to defines keyed by node for easy lookup
  allRefInfo = Maps.newHashMap();
  for (Name name : listOfDefines) {
    if (name.declaration != null) {
      allRefInfo.put(name.declaration.node,
                     new RefInfo(name.declaration, name));
    }
    if (name.refs != null) {
      for (Ref ref : name.refs) {
        // 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:andyjko,项目名称:feedlack,代码行数:26,代码来源:ProcessDefines.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.refs != null &&
        (name.aliasingGets > 0 || name.localSets + name.globalSets > 1)) {
      boolean initialized = name.declaration != null;
      for (Ref ref : name.refs) {
        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:andyjko,项目名称:feedlack,代码行数:25,代码来源:CollapseProperties.java


示例3: 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() && canCollapseChildNames) {
    updateObjLitOrFunctionDeclaration(n, alias);
  }

  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.name));

      if (!p.inExterns && canCollapseChildNames && p.declaration != null &&
          p.declaration.node != null &&
          p.declaration.node.getParent() != null &&
          p.declaration.node.getParent().getType() == Token.ASSIGN) {
        updateSimpleDeclaration(
            appendPropForAlias(alias, p.name), p, p.declaration);
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:33,代码来源:CollapseProperties.java


示例4: checkForHosedThisReferences

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
/**
 * Warns about any references to "this" in the given FUNCTION. The function
 * is getting collapsed, so the references will change.
 */
private void checkForHosedThisReferences(Node function, JSDocInfo docInfo,
    final Name name) {
  // A function is getting collapsed. Make sure that if it refers to
  // "this", it must be a constructor or documented with @this.
  if (docInfo == null ||
      (!docInfo.isConstructor() && !docInfo.hasThisType())) {
    NodeTraversal.traverse(compiler, function.getLastChild(),
        new NodeTraversal.AbstractShallowCallback() {
          public void visit(NodeTraversal t, Node n, Node parent) {
            if (n.getType() == Token.THIS) {
              compiler.report(
                  JSError.make(name.declaration.sourceName, n,
                      UNSAFE_THIS, name.fullName()));
            }
          }
        });
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:23,代码来源:CollapseProperties.java


示例5: checkDescendantNames

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
/**
 * Checks to make sure all the descendants of a name are defined if they
 * are referenced.
 *
 * @param name A global name.
 * @param nameIsDefined If true, {@code name} is defined. Otherwise, it's
 *    undefined, and any references to descendant names should emit warnings.
 */
private void checkDescendantNames(Name name, boolean nameIsDefined) {
  if (name.props != null) {
    for (Name prop : name.props) {
      // if the ancestor of a property is not defined, then we should emit
      // warnings for all references to the property.
      boolean propIsDefined = false;
      if (nameIsDefined) {
        // if the ancestor of a property is defined, then let's check that
        // the property is also explicitly defined if it needs to be.
        propIsDefined = (!propertyMustBeInitializedByFullName(prop) ||
            prop.globalSets + prop.localSets > 0);
      }

      validateName(prop, propIsDefined);
      checkDescendantNames(prop, propIsDefined);
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:CheckGlobalNames.java


示例6: validateName

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
private void validateName(Name name, boolean isDefined) {
  // If the name is not defined, emit warnings for each reference. While
  // we're looking through each reference, check all the module dependencies.
  Ref declaration = name.declaration;
  if (!isDefined) {
    if (declaration != null) {
      reportRefToUndefinedName(name, declaration);
    }
  }

  if (name.refs != null) {
    JSModuleGraph moduleGraph = compiler.getModuleGraph();
    for (Ref ref : name.refs) {
      if (!isDefined) {
        reportRefToUndefinedName(name, ref);
      } else {
        if (declaration != null &&
            ref.module != declaration.module &&
            !moduleGraph.dependsOn(ref.module, declaration.module)) {
          reportBadModuleReference(name, ref);
        }
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:CheckGlobalNames.java


示例7: testRemoveDeclaration1

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
public void testRemoveDeclaration1() {
  Name n = new Name("a", null, false);
  Ref set1 = createNodelessRef(Ref.Type.SET_FROM_GLOBAL);
  Ref set2 = createNodelessRef(Ref.Type.SET_FROM_GLOBAL);

  n.addRef(set1);
  n.addRef(set2);

  assertEquals(set1, n.declaration);
  assertEquals(2, n.globalSets);
  assertEquals(1, n.refs.size());

  n.removeRef(set1);

  assertEquals(set2, n.declaration);
  assertEquals(1, n.globalSets);
  assertEquals(0, n.refs.size());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:GlobalNamespaceTest.java


示例8: testRemoveDeclaration2

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
public void testRemoveDeclaration2() {
  Name n = new Name("a", null, false);
  Ref set1 = createNodelessRef(Ref.Type.SET_FROM_GLOBAL);
  Ref set2 = createNodelessRef(Ref.Type.SET_FROM_LOCAL);

  n.addRef(set1);
  n.addRef(set2);

  assertEquals(set1, n.declaration);
  assertEquals(1, n.globalSets);
  assertEquals(1, n.localSets);
  assertEquals(1, n.refs.size());

  n.removeRef(set1);

  assertEquals(null, n.declaration);
  assertEquals(0, n.globalSets);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:GlobalNamespaceTest.java


示例9: flattenReferencesToCollapsibleDescendantNames

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
/**
 * Flattens all references to collapsible properties of a global name except
 * their initial definitions. Recurses on subnames.
 *
 * @param n An object representing a global name
 * @param alias The flattened name for {@code n}
 */
private void flattenReferencesToCollapsibleDescendantNames(
    Name n, String alias) {
  if (n.props == null) return;

  for (Name p : n.props) {
    String propAlias = appendPropForAlias(alias, p.getBaseName());

    if (p.canCollapse()) {
      flattenReferencesTo(p, propAlias);
    } else if (p.isSimpleStubDeclaration()) {
      flattenSimpleStubDeclaration(p, propAlias);
    }

    flattenReferencesToCollapsibleDescendantNames(p, propAlias);
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:24,代码来源:CollapseProperties.java


示例10: checkForHosedThisReferences

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
/**
 * Warns about any references to "this" in the given FUNCTION. The function
 * is getting collapsed, so the references will change.
 */
private void checkForHosedThisReferences(Node function, JSDocInfo docInfo,
    final Name name) {
  // A function is getting collapsed. Make sure that if it refers to
  // "this", it must be a constructor or documented with @this.
  if (docInfo == null ||
      (!docInfo.isConstructor() && !docInfo.hasThisType())) {
    NodeTraversal.traverse(compiler, function.getLastChild(),
        new NodeTraversal.AbstractShallowCallback() {
          @Override
          public void visit(NodeTraversal t, Node n, Node parent) {
            if (n.isThis()) {
              compiler.report(
                  JSError.make(name.getDeclaration().getSourceName(), n,
                      UNSAFE_THIS, name.getFullName()));
            }
          }
        });
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:24,代码来源:CollapseProperties.java


示例11: process

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
@Override
public void process(Node externs, Node root) {
  if (namespace == null) {
    namespace = new GlobalNamespace(compiler, externs, root);
  }

  // Find prototype properties that will affect our analysis.
  Preconditions.checkState(namespace.hasExternsRoot());
  findPrototypeProps("Object", objectPrototypeProps);
  findPrototypeProps("Function", functionPrototypeProps);
  objectPrototypeProps.addAll(
      convention.getIndirectlyDeclaredProperties());

  for (Name name : namespace.getNameForest()) {
    // Skip extern names. Externs are often not runnable as real code,
    // and will do things like:
    // var x;
    // x.method;
    // which this check forbids.
    if (name.inExterns) {
      continue;
    }

    checkDescendantNames(name, name.globalSets + name.localSets > 0);
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:CheckGlobalNames.java


示例12: testRemoveDeclaration1

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
public void testRemoveDeclaration1() {
  Name n = new Name("a", null, false);
  Ref set1 = createNodelessRef(Ref.Type.SET_FROM_GLOBAL);
  Ref set2 = createNodelessRef(Ref.Type.SET_FROM_GLOBAL);

  n.addRef(set1);
  n.addRef(set2);

  assertEquals(set1, n.getDeclaration());
  assertEquals(2, n.globalSets);
  assertEquals(2, n.getRefs().size());

  n.removeRef(set1);

  assertEquals(set2, n.getDeclaration());
  assertEquals(1, n.globalSets);
  assertEquals(1, n.getRefs().size());
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:GlobalNamespaceTest.java


示例13: testRemoveDeclaration2

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
public void testRemoveDeclaration2() {
  Name n = new Name("a", null, false);
  Ref set1 = createNodelessRef(Ref.Type.SET_FROM_GLOBAL);
  Ref set2 = createNodelessRef(Ref.Type.SET_FROM_LOCAL);

  n.addRef(set1);
  n.addRef(set2);

  assertEquals(set1, n.getDeclaration());
  assertEquals(1, n.globalSets);
  assertEquals(1, n.localSets);
  assertEquals(2, n.getRefs().size());

  n.removeRef(set1);

  assertEquals(null, n.getDeclaration());
  assertEquals(0, n.globalSets);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:GlobalNamespaceTest.java


示例14: referencesCollapsibleProperty

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
/**
 * Returns whether a ReferenceCollection for some aliasing variable references a property on the
 * original aliased variable that may be collapsed in CollapseProperties.
 *
 * <p>See {@link GlobalNamespace.Name#canCollapse} for what can/cannot be collapsed.
 */
private boolean referencesCollapsibleProperty(
    ReferenceCollection aliasRefs, Name aliasedName, GlobalNamespace namespace) {
  for (Reference ref : aliasRefs.references) {
    if (ref.getParent() == null) {
      continue;
    }
    if (ref.getParent().isGetProp()) {
      Node propertyNode = ref.getNode().getNext();
      // e.g. if the reference is "alias.b.someProp", this will be "b".
      String propertyName = propertyNode.getString();
      // e.g. if the aliased name is "originalName", this will be "originalName.b".
      String originalPropertyName = aliasedName.getName() + "." + propertyName;
      Name originalProperty = namespace.getOwnSlot(originalPropertyName);
      // If the original property isn't in the namespace or can't be collapsed, keep going.
      if (originalProperty == null || !originalProperty.canCollapse()) {
        continue;
      }
      return true;
    }
  }
  return false;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:29,代码来源:AggressiveInlineAliases.java


示例15: flattenReferencesToCollapsibleDescendantNames

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
/**
 * Flattens all references to collapsible properties of a global name except
 * their initial definitions. Recurs on subnames.
 *
 * @param n An object representing a global name
 * @param alias The flattened name for {@code n}
 */
private void flattenReferencesToCollapsibleDescendantNames(
    Name n, String alias) {
  if (n.props == null || n.isCollapsingExplicitlyDenied()) {
    return;
  }

  for (Name p : n.props) {
    String propAlias = appendPropForAlias(alias, p.getBaseName());

    boolean isAllowedToCollapse =
        propertyCollapseLevel != PropertyCollapseLevel.MODULE_EXPORT || p.isModuleExport();

    if (isAllowedToCollapse && p.canCollapse()) {
      flattenReferencesTo(p, propAlias);
    } else if (isAllowedToCollapse
        && p.isSimpleStubDeclaration()
        && !p.isCollapsingExplicitlyDenied()) {
      flattenSimpleStubDeclaration(p, propAlias);
    }

    flattenReferencesToCollapsibleDescendantNames(p, propAlias);
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:31,代码来源:CollapseProperties.java


示例16: collapseDeclarationOfNameAndDescendants

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
/**
 * Collapses definitions of the collapsible properties of a global name.
 * Recurs 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 (canCollapse(n)) {
    updateGlobalNameDeclaration(n, alias, canCollapseChildNames);
  }

  if (n.props == null) {
    return;
  }
  for (Name p : n.props) {
    collapseDeclarationOfNameAndDescendants(p, appendPropForAlias(alias, p.getBaseName()));
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:24,代码来源:CollapseProperties.java


示例17: checkForHosedThisReferences

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
/**
 * Warns about any references to "this" in the given FUNCTION. The function
 * is getting collapsed, so the references will change.
 */
private void checkForHosedThisReferences(Node function, JSDocInfo docInfo,
    final Name name) {
  // A function is getting collapsed. Make sure that if it refers to "this",
  // it must be a constructor, interface, record, arrow function, or documented with @this.
  boolean isAllowedToReferenceThis =
      (docInfo != null && (docInfo.isConstructorOrInterface() || docInfo.hasThisType()))
      || function.isArrowFunction();
  if (!isAllowedToReferenceThis) {
    NodeTraversal.traverseEs6(compiler, function.getLastChild(),
        new NodeTraversal.AbstractShallowCallback() {
          @Override
          public void visit(NodeTraversal t, Node n, Node parent) {
            if (n.isThis()) {
              compiler.report(
                  JSError.make(n, UNSAFE_THIS, name.getFullName()));
            }
          }
        });
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:25,代码来源:CollapseProperties.java


示例18: addStubsForUndeclaredProperties

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
/**
 * Adds global variable "stubs" for any properties of a global name that are only set in a local
 * scope or read but never set.
 *
 * @param n An object representing a global name (e.g. "a", "a.b.c")
 * @param alias The flattened name of the object whose properties we are adding stubs for (e.g.
 *     "a$b$c")
 * @param parent The node to which new global variables should be added as children
 * @param addAfter The child of after which new variables should be added
 */
private void addStubsForUndeclaredProperties(Name n, String alias, Node parent, Node addAfter) {
  checkState(n.canCollapseUnannotatedChildNames(), n);
  checkArgument(NodeUtil.isStatementBlock(parent), parent);
  checkNotNull(addAfter);
  if (n.props == null) {
    return;
  }
  for (Name p : n.props) {
    if (p.needsToBeStubbed()) {
      String propAlias = appendPropForAlias(alias, p.getBaseName());
      Node nameNode = IR.name(propAlias);
      Node newVar = IR.var(nameNode).useSourceInfoIfMissingFromForTree(addAfter);
      parent.addChildAfter(newVar, addAfter);
      addAfter = newVar;
      compiler.reportChangeToEnclosingScope(newVar);
      // Determine if this is a constant var by checking the first
      // reference to it. Don't check the declaration, as it might be null.
      if (p.getRefs().get(0).node.getLastChild().getBooleanProp(
          Node.IS_CONSTANT_NAME)) {
        nameNode.putBooleanProp(Node.IS_CONSTANT_NAME, true);
        compiler.reportChangeToEnclosingScope(nameNode);
      }
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:36,代码来源:CollapseProperties.java


示例19: process

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
@Override
public void process(Node externs, Node root) {
  if (namespace == null) {
    namespace = new GlobalNamespace(compiler, externs, root);
  }

  // Find prototype properties that will affect our analysis.
  checkState(namespace.hasExternsRoot());
  findPrototypeProps("Object", objectPrototypeProps);
  findPrototypeProps("Function", functionPrototypeProps);
  objectPrototypeProps.addAll(
      convention.getIndirectlyDeclaredProperties());

  for (Name name : namespace.getNameForest()) {
    // Skip extern names. Externs are often not runnable as real code,
    // and will do things like:
    // var x;
    // x.method;
    // which this check forbids.
    if (name.inExterns) {
      continue;
    }

    checkDescendantNames(name, name.globalSets + name.localSets > 0);
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:27,代码来源:CheckGlobalNames.java


示例20: testSimpleReassign2

import com.google.javascript.jscomp.GlobalNamespace.Name; //导入依赖的package包/类
public void testSimpleReassign2() {
  test(
      lines(
          "/** @fileoverview @suppress {newCheckTypes} */",
          "/** @define {number|boolean} */ var DEF=false;",
          "DEF=true;",
          "DEF=3"),
      lines(
          "/** @fileoverview @suppress {newCheckTypes} */",
          "/** @define {number|boolean} */ var DEF=3;",
          "true;3"));

  Name def = namespace.getNameIndex().get("DEF");
  assertThat(def.getRefs()).hasSize(1);
  assertEquals(1, def.globalSets);
  assertNotNull(def.getDeclaration());
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:18,代码来源:ProcessDefinesTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java VertexScoreTransformer类代码示例发布时间:2022-05-23
下一篇:
Java ReducerAggregatorImpl类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap