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


Java NodeUtil.newQName方法代码示例

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


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

示例1: maybeReassignAlias

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
private void maybeReassignAlias(Node assign) {
  Node lhs = assign.getFirstChild();
  if (!lhs.isGetProp()) {
    // TODO(dpurpura): Add support for GET_ELEM.  (e.g. Foo['abc'])
    return;
  }

  // Find the name of the deepest first child.
  String alias = null;
  for (Node child = lhs; child != null; child = child.getFirstChild()) {
    if (child.isName()) {
      alias = child.getQualifiedName();
    }
  }

  checkNotNull(alias, "Missing name for alias");
  if (aliasToProvidedNamespace.containsKey(alias)) {
    String providedNamespace = aliasToProvidedNamespace.get(alias);

    String suffix = lhs.getQualifiedName().substring(alias.length());
    Node fullName = NodeUtil.newQName(compiler, providedNamespace + suffix);
    assign.replaceChild(lhs, fullName);
  }
  return;
}
 
开发者ID:angular,项目名称:clutz,代码行数:26,代码来源:RemoveGoogScopePass.java

示例2: replacePrefixInName

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
/**
 * Returns the new name string with a prefix replaced with the new prefix. Returns input name if
 * prefix does not exist.
 */
String replacePrefixInName(String name, String prefix, String newPrefix) {
  Node nameNode = NodeUtil.newQName(compiler, name);
  // Placeholder node to ensure name has a parent
  Node placeholder = new Node(Token.EMPTY, nameNode);
  replacePrefixInName(nameNode, prefix, newPrefix);
  return placeholder.getFirstChild().getQualifiedName();
}
 
开发者ID:angular,项目名称:clutz,代码行数:12,代码来源:NameUtil.java

示例3: addExport

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
private void addExport(String exportName, String importName, String identifier) {
  exportedNamespacesToSymbols.put(exportName, identifier);
  importedNamespacesToSymbols.put(importName, identifier);

  Node namespace = NodeUtil.newQName(compiler, importName);
  if (namespace.isGetProp()) {
    String parentName = namespace.getFirstChild().getQualifiedName();
    if (providesObjectChildren.containsKey(parentName)) {
      providesObjectChildren.get(parentName).add(identifier);
    }
  }
}
 
开发者ID:angular,项目名称:clutz,代码行数:13,代码来源:CollectModuleMetadata.java

示例4: getPropsTypedefNode

import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
private Node getPropsTypedefNode(String name, boolean forValidator) {
  Node lb = new Node(Token.LB);
  for (Prop prop : props) {
    PropType propType = prop.propType;
    Node colon = new Node(Token.COLON);
    Node member = prop.propTypeKeyNode.cloneNode();
    colon.addChildToBack(member);
    Node typeNode;
    if (forValidator && propType.isRequired && prop.hasDefaultValue) {
      typeNode = propType.optionalTypeNode;
    } else if (!forValidator && !propType.isRequired &&
        prop.hasDefaultValue) {
      // If a prop is not required but it has a default value then its type
      // inside the component can be treated as required.
      typeNode = propType.requiredTypeNode;
    } else {
      typeNode = propType.typeNode;
    }
    if (typeNode.getParent() != null) {
      // We have already used this node in the regular typedef, so we now
      // need to use a copy.
      typeNode = typeNode.cloneTree();
    }
    colon.addChildToBack(typeNode);
    colon.useSourceInfoFromForTree(prop.propTypeKeyNode);
    lb.addChildToBack(colon);
  }
  Node propsRecordTypeNode = new Node(Token.LC, lb);
  JSDocInfoBuilder jsDocBuilder = new JSDocInfoBuilder(true);
  jsDocBuilder.recordTypedef(new JSTypeExpression(
      propsRecordTypeNode, sourceFileName));
  Node propsTypedefNode = NodeUtil.newQName(compiler, name);
  propsTypedefNode.setJSDocInfo(jsDocBuilder.build());
  propsTypedefNode = IR.exprResult(propsTypedefNode);
  return propsTypedefNode;
}
 
开发者ID:mihaip,项目名称:react-closure-compiler,代码行数:37,代码来源:PropTypesExtractor.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.newQName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。