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


Java NodeUtil类代码示例

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


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

示例1: moveAllFollowing

import com.google.javascript.jscomp.NodeUtil; //导入依赖的package包/类
/**
 * Move all the child nodes following start in srcParent to the end of
 * destParent's child list.
 * @param start The start point in the srcParent child list.
 * @param srcParent The parent node of start.
 * @param destParent The destination node.
 */
static private void moveAllFollowing(
    Node start, Node srcParent, Node destParent) {
  for (Node n = start.getNext(); n != null; n = start.getNext()) {
    boolean isFunctionDeclaration =
        NodeUtil.isFunctionDeclaration(n);

    srcParent.removeChild(n);

    if (isFunctionDeclaration) {
      destParent.addChildToFront(n);
    } else {
      destParent.addChildToBack(n);
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:23,代码来源:MinimizeExitPoints.java

示例2: processVariableAssignment

import com.google.javascript.jscomp.NodeUtil; //导入依赖的package包/类
private void processVariableAssignment(Component cmp, Node assignmentNode) {
    if (NodeUtil.isLiteralValue(assignmentNode, false)) {
        cmp.setCodeFragment(cmp.name() + " : " + NodeUtil.getStringValue(assignmentNode));
        cmp.setCodeFragment(declarationSnippet(assignmentNode.getToken()));
    } else if (assignmentNode.hasChildren() && assignmentNode.isNew()
            && (assignmentNode.getFirstChild().isName() || assignmentNode.getFirstChild().isGetProp())) {
        String invokedType;
        if (assignmentNode.getFirstChild().isGetProp()) {
            invokedType = assignmentNode.getFirstChild().getFirstChild().getString();
            cmp.insertComponentInvocation(new TypeDeclaration(invokedType));
        } else {
            invokedType = assignmentNode.getFirstChild().getString();
            cmp.insertComponentInvocation(new TypeInstantiation(invokedType));
        }
        cmp.setCodeFragment(invokedType);
    }
}
 
开发者ID:Zir0-93,项目名称:clarpse,代码行数:18,代码来源:JavaScriptListener.java

示例3: createTypeAlias

import com.google.javascript.jscomp.NodeUtil; //导入依赖的package包/类
private void createTypeAlias(Node n, Node parent) {
  JSDocInfo bestJSDocInfo = NodeUtil.getBestJSDocInfo(n);
  if (bestJSDocInfo != null && bestJSDocInfo.hasTypedefType()) {
    String name;
    switch (n.getToken()) {
      case NAME:
        name = n.getString();
        break;
      case GETPROP:
        // Inner typedef
        name = n.getSecondChild().getString();
        break;
      default:
        name = n.getFirstChild().getString();
        break;
    }
    Node typeDef = Node.newString(Token.TYPE_ALIAS, name);
    types.put(name, typeDef);
    typeDef.setJSDocInfo(bestJSDocInfo);
    replaceExpressionOrAssignment(n, parent, typeDef);
  }
}
 
开发者ID:angular,项目名称:clutz,代码行数:23,代码来源:TypeConversionPass.java

示例4: canPromoteFieldInitializer

import com.google.javascript.jscomp.NodeUtil; //导入依赖的package包/类
/**
 * Check if we can safely generate a field initializer. We don't do this if the assignment rhs is
 * not a literal or the enclosing function is not a constructor.
 */
private boolean canPromoteFieldInitializer(ClassMemberDeclaration declaration) {
  if (!NodeUtil.isLiteralValue(declaration.rhs, false)) {
    return false;
  }

  Node fnNode = NodeUtil.getEnclosingFunction(declaration.exprRoot);
  if (fnNode != null) {
    String fnName = getEnclosingFunctionName(fnNode);
    if (!"constructor".equals(fnName)) {
      return false;
    }
  }

  return true;
}
 
开发者ID:angular,项目名称:clutz,代码行数:20,代码来源:TypeConversionPass.java

示例5: newDeclarationOnThis

import com.google.javascript.jscomp.NodeUtil; //导入依赖的package包/类
/**
 * Factory method for creating a new ClassMemberDeclarationOnThis on a declaration internal to a
 * class via the "this" keyword.
 *
 * <ul>
 *   <li>{@code this.a = 5}
 *   <li>{@code this.b}
 * </ul>
 *
 * Returns null if the expression node is an invalid member declaration.
 */
@Nullable
static ClassMemberDeclaration newDeclarationOnThis(Node n) {
  Node fullName = getFullName(n);
  // Node MUST start with "this." and be shallow, i.e. "this.foo".
  // "this.foo.bar" and other nestings are not declarations and are ignored.
  // fullName is a binary tree and multiple parts are represented by GETPROP
  // nodes recursively on the left (first) child, so a first child of THIS is
  // sufficient to ensure the name is of the form "this.foo".
  if (!fullName.isGetProp() || !fullName.getFirstChild().isThis()) {
    return null;
  }

  Node classNode = NodeUtil.getEnclosingClass(n);
  String memberName = fullName.getLastChild().getString();
  if (classNode == null) {
    return null;
  }

  return new ClassMemberDeclaration(n, false, classNode, memberName);
}
 
开发者ID:angular,项目名称:clutz,代码行数:32,代码来源:TypeConversionPass.java

示例6: maybeAddProvidesExport

import com.google.javascript.jscomp.NodeUtil; //导入依赖的package包/类
private void maybeAddProvidesExport(Node exportsName) {
  String fullname = exportsName.getQualifiedName();

  if (providesObjectChildren.containsKey(fullname)) {
    googProvideNamespaceToNode.put(fullname, exportsName);
    addExport(fullname, fullname, nameUtil.lastStepOfName(exportsName));

  } else if (exportsName.isGetProp()
      && providesObjectChildren.containsKey(exportsName.getFirstChild().getQualifiedName())) {
    googProvideNamespaceToNode.put(fullname, exportsName);

    // functions declared on functions should be exported.
    // static functions on classes should not be exported.
    String parentName = exportsName.getFirstChild().getQualifiedName();
    @Nullable Node parentNode = googProvideNamespaceToNode.get(parentName);
    JSDocInfo jsDoc = parentNode != null ? NodeUtil.getBestJSDocInfo(parentNode) : null;

    if (providesObjectChildren.containsKey(parentName)
        && (jsDoc == null || !jsDoc.isConstructor())) {
      addExport(fullname, fullname, nameUtil.lastStepOfName(exportsName));
    }
  }
}
 
开发者ID:angular,项目名称:clutz,代码行数:24,代码来源:CollectModuleMetadata.java

示例7: visit

import com.google.javascript.jscomp.NodeUtil; //导入依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  JSDocInfo bestJSDocInfo = NodeUtil.getBestJSDocInfo(n);
  if (bestJSDocInfo == null) {
    return;
  }

  // Add visibility for private and protected.
  if (Visibility.PRIVATE.equals(bestJSDocInfo.getVisibility())) {
    n.putProp(Node.ACCESS_MODIFIER, Visibility.PRIVATE);
  } else if (Visibility.PROTECTED.equals(bestJSDocInfo.getVisibility())) {
    n.putProp(Node.ACCESS_MODIFIER, Visibility.PROTECTED);
  }

  // Change variable declarations to constants
  if (bestJSDocInfo.isConstant() && (n.isVar() || n.isLet())) {
    n.setToken(Token.CONST);
  }
}
 
开发者ID:angular,项目名称:clutz,代码行数:20,代码来源:TypeAnnotationPass.java

示例8: 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

示例9: getJSDocForRhs

import com.google.javascript.jscomp.NodeUtil; //导入依赖的package包/类
static JSDocInfo getJSDocForRhs(Node rhs, JSDocInfo oldJSDoc) {
  switch (NodeUtil.getKnownValueType(rhs)) {
    case BOOLEAN:
      return getConstJSDoc(oldJSDoc, "boolean");
    case NUMBER:
      return getConstJSDoc(oldJSDoc, "number");
    case STRING:
      return getConstJSDoc(oldJSDoc, "string");
    case NULL:
      return getConstJSDoc(oldJSDoc, "null");
    case VOID:
      return getConstJSDoc(oldJSDoc, "void");
    case OBJECT:
      if (rhs.isRegExp()) {
        return getConstJSDoc(oldJSDoc, new Node(Token.BANG, IR.string("RegExp")));
      }
      break;
    case UNDETERMINED:
      if (oldJSDoc != null && oldJSDoc.getDescription() != null) {
        return getConstJSDoc(oldJSDoc, "string");
      }
      break;
  }
  return null;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:26,代码来源:JsdocUtil.java

示例10: splitNameDeclarationsAndRemoveDestructuring

import com.google.javascript.jscomp.NodeUtil; //导入依赖的package包/类
/**
 * Does two simplifications to const/let/var nodes.
 * 1. Splits them so that each declaration is a separate statement.
 * 2. Removes non-import destructuring statements, which we assume are not type declarations.
 */
static void splitNameDeclarationsAndRemoveDestructuring(Node n, NodeTraversal t) {
  checkArgument(NodeUtil.isNameDeclaration(n));
  while (n.hasChildren()) {
    Node lhsToSplit = n.getLastChild();
    if (lhsToSplit.isDestructuringLhs() && !isImportRhs(lhsToSplit.getLastChild())) {
      // Remove destructuring statements, which we assume are not type declarations
      NodeUtil.markFunctionsDeleted(lhsToSplit, t.getCompiler());
      NodeUtil.removeChild(n, lhsToSplit);
      t.reportCodeChange();
      continue;
    }
    if (n.hasOneChild()) {
      return;
    }
    // A name declaration with more than one LHS is split into separate declarations.
    Node rhs = lhsToSplit.hasChildren() ? lhsToSplit.removeFirstChild() : null;
    Node newDeclaration =
        NodeUtil.newDeclaration(lhsToSplit.detach(), rhs, n.getToken()).srcref(n);
    n.getParent().addChildAfter(newDeclaration, n);
    t.reportCodeChange();
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:28,代码来源:ConvertToTypedInterface.java

示例11: propagateJsdocAtName

import com.google.javascript.jscomp.NodeUtil; //导入依赖的package包/类
private void propagateJsdocAtName(NodeTraversal t, Node nameNode) {
  checkArgument(
      nameNode.isQualifiedName() || nameNode.isStringKey() || nameNode.isDestructuringLhs(),
      nameNode);
  Node jsdocNode = NodeUtil.getBestJSDocInfoNode(nameNode);
  JSDocInfo originalJsdoc = jsdocNode.getJSDocInfo();
  if (!isConstToBeInferred(originalJsdoc, nameNode)) {
    return;
  }
  Node rhs = NodeUtil.getRValueOfLValue(nameNode);
  if (rhs == null) {
    return;
  }
  JSDocInfo newJsdoc = JsdocUtil.getJSDocForRhs(rhs, originalJsdoc);
  if (newJsdoc == null && ClassUtil.isThisProp(nameNode)) {
    Var decl = findNameDeclaration(t.getScope(), rhs);
    newJsdoc = JsdocUtil.getJSDocForName(decl, originalJsdoc);
  }
  if (newJsdoc != null) {
    jsdocNode.setJSDocInfo(newJsdoc);
    t.reportCodeChange();
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:24,代码来源:ConvertToTypedInterface.java

示例12: 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

示例13: isReturnTypeNullable

import com.google.javascript.jscomp.NodeUtil; //导入依赖的package包/类
/**
 * @return True if n is a function node which is explicitly annotated
 * as returning a nullable type, other than {?}.
 */
private static boolean isReturnTypeNullable(Node n) {
  if (n == null || !n.isFunction()) {
    return false;
  }
  FunctionTypeI functionType = n.getTypeI().toMaybeFunctionType();
  if (functionType == null) {
    // If the JSDoc declares a non-function type on a function node, we still shouldn't crash.
    return false;
  }
  TypeI returnType = functionType.getReturnType();
  if (returnType == null
      || returnType.isUnknownType() || !returnType.isNullable()) {
    return false;
  }
  JSDocInfo info = NodeUtil.getBestJSDocInfo(n);
  return info != null && info.hasReturnType();
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:22,代码来源:CheckNullableReturn.java

示例14: visitFunction

import com.google.javascript.jscomp.NodeUtil; //导入依赖的package包/类
private void visitFunction(NodeTraversal t, Node function, Node parent) {
  JSDocInfo jsDoc = NodeUtil.getBestJSDocInfo(function);

  if (jsDoc == null && !hasAnyInlineJsDoc(function)) {
    checkMissingJsDoc(t, function);
  } else {
    if (t.inGlobalScope()
        || hasAnyInlineJsDoc(function)
        || !jsDoc.getParameterNames().isEmpty()
        || jsDoc.hasReturnType()) {
      checkParams(t, function, jsDoc);
    }
    checkReturn(t, function, jsDoc);
  }

  if (parent.isMemberFunctionDef()
      && "constructor".equals(parent.getString())
      && jsDoc != null
      && !jsDoc.getVisibility().equals(Visibility.INHERITED)) {
    t.report(function, CONSTRUCTOR_DISALLOWED_JSDOC);
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:23,代码来源:CheckJSDocStyle.java

示例15: checkInlineParams

import com.google.javascript.jscomp.NodeUtil; //导入依赖的package包/类
/**
 * Checks that the inline type annotations are correct.
 */
private void checkInlineParams(NodeTraversal t, Node function) {
  Node paramList = NodeUtil.getFunctionParameters(function);

  for (Node param : paramList.children()) {
    JSDocInfo jsDoc = param.getJSDocInfo();
    if (jsDoc == null) {
      t.report(param, MISSING_PARAMETER_JSDOC);
      return;
    } else {
      JSTypeExpression paramType = jsDoc.getType();
      checkNotNull(paramType, "Inline JSDoc info should always have a type");
      checkParam(t, param, null, paramType);
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:19,代码来源:CheckJSDocStyle.java


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