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


Java NodeUtil.getName方法代码示例

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


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

示例1: getClassName

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
private static String getClassName(Node functionNode) {
  checkArgument(functionNode.isFunction());
  if (isClassMethod(functionNode)) {
    Node parent = functionNode.getParent();
    if (parent.isMemberFunctionDef()) {
      // ES6 class
      Node classNode = functionNode.getGrandparent().getParent();
      checkState(classNode.isClass());
      return NodeUtil.getName(classNode);
    }
    // goog.defineClass
    checkState(parent.isStringKey());
    Node defineClassCall = parent.getGrandparent();
    checkState(defineClassCall.isCall());
    return NodeUtil.getBestLValue(defineClassCall).getQualifiedName();
  }
  return NodeUtil.getName(functionNode);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:19,代码来源:ClassUtil.java

示例2: addClassToScope

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
/**
 * Adds a class node to the top level scope.
 *
 * <p>This determines the classname using the nearest available name node.
 */
void addClassToScope(Node n) {
  Preconditions.checkState(n.isClass());
  String className = NodeUtil.getName(n);
  if (className == null) {
    // We do not emit an error here as there can be anonymous classes without names.
    return;
  }
  addTypeToScope(n, className);
}
 
开发者ID:angular,项目名称:clutz,代码行数:15,代码来源:TypeConversionPass.java

示例3: getEnclosingFunctionName

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
private String getEnclosingFunctionName(Node fnNode) {
  if (fnNode.isArrowFunction()) {
    return null;
  }

  // Use the QualifiedName if the function is on an object/namespace: `foo.moreFoo()`;
  // otherwise, use the string on the node: `foo` for `function foo()`
  Node fnParent = fnNode.getParent();
  if (fnParent.isGetProp() || fnParent.isCall()) {
    return NodeUtil.getName(fnNode);
  }

  return fnParent.getString();
}
 
开发者ID:angular,项目名称:clutz,代码行数:15,代码来源:TypeConversionPass.java

示例4: checkMissingJsDoc

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
private void checkMissingJsDoc(NodeTraversal t, Node function) {
  if (isFunctionThatShouldHaveJsDoc(t, function)) {
    String name = NodeUtil.getName(function);
    // Don't warn for test functions, setUp, tearDown, etc.
    if (name == null || !ExportTestFunctions.isTestFunction(name)) {
      t.report(function, MISSING_JSDOC);
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:10,代码来源:CheckJSDocStyle.java

示例5: convertConstructorToClass

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
/** Converts @constructor annotated functions into class definitions. */
void convertConstructorToClass(Node n, JSDocInfo jsDoc) {
  Preconditions.checkState(n.isFunction());
  Preconditions.checkState(n.getFirstChild().isName());
  Preconditions.checkState(n.getSecondChild().isParamList());
  Preconditions.checkState(n.getLastChild().isNormalBlock());
  String typeName = NodeUtil.getName(n);
  // Break up function
  Node name = n.getFirstChild();
  Node params = n.getSecondChild();
  Node body = n.getLastChild();
  n.detachChildren();

  // The empty name corresponds to anonymous constructors.
  // The name is usually located in the surrounding context.
  // ie. /** @constructor */ var A = function() {};
  // is converted to: var A = class {};
  if (name.getString().isEmpty()) {
    name = IR.empty();
  }

  // Superclass defaults to empty
  Node superClass = IR.empty();
  if (jsDoc.getBaseType() != null) {
    // Fullname of superclass
    // Closure Compiler generates non-nullable base classes:
    // ie. A.B.C is parsed as !A.B.C
    String superClassName =
        jsDoc
            .getBaseType()
            .getRoot()
            .getFirstChild() // ignore the ! node as we always output non nullable types
            .getString();
    superClass = NodeUtil.newQName(compiler, superClassName);
    superClass.useSourceInfoFrom(n);
  }

  Node typeNode;
  if (jsDoc.isInterface()) {
    List<JSTypeExpression> interfaces = jsDoc.getExtendedInterfaces();
    if (!interfaces.isEmpty()) {
      Node superInterfaces = new Node(Token.INTERFACE_EXTENDS);
      for (JSTypeExpression type : interfaces) {
        superInterfaces.addChildToBack(type.getRoot());
      }
      superClass = superInterfaces;
    }
    typeNode = new Node(Token.INTERFACE, name, superClass, new Node(Token.INTERFACE_MEMBERS));
    typeNode.useSourceInfoFromForTree(n);
    // Must be registered here, as JSCompiler cannot extract names from INTERFACE nodes.
    addTypeToScope(typeNode, typeName);
  } else {
    // Generate new class node with only a constructor method
    Node constructor =
        IR.memberFunctionDef("constructor", IR.function(IR.name(""), params, body));
    constructor.useSourceInfoFrom(n);
    // Sets jsdoc info to preserve type declarations on method
    constructor.setJSDocInfo(jsDoc);
    Node classMembers = new Node(Token.CLASS_MEMBERS, constructor);
    typeNode = new Node(Token.CLASS, name, superClass, classMembers);
  }

  typeNode.setJSDocInfo(n.getJSDocInfo());
  nodeComments.replaceWithComment(n, typeNode);
}
 
开发者ID:angular,项目名称:clutz,代码行数:66,代码来源:TypeConversionPass.java


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