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


Java Node类代码示例

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


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

示例1: visitParameter

import com.google.javascript.rhino.Node; //导入依赖的package包/类
@Override
protected boolean visitParameter(Node parameter, FunctionType owner, int index) {
  String ownerName;
  String paramName;
  if (isAnonymousFunctionType(owner)) {
    // FunctionType case. There is only one method called "onInvoke" and adding method name
    // doesn't make it unique.
    ownerName = "";
    // The java method name will be onInvoke and we need to use it in order to find the parameter
    // name replacement if provided.
    paramName = getParameterNameByMethodName(owner, index, "onInvoke");
  } else {
    // Extract method name as the owner from the fully qualified method name.
    ownerName = extractName(owner.getDisplayName());
    paramName = getParameterNameByMethodName(owner, index, ownerName);
  }

  String baseName = ownerName + toCamelUpperCase(paramName);
  initNameForRecordType(baseName, "Type");
  initNameForFunctionType(baseName);
  return true;
}
 
开发者ID:google,项目名称:jsinterop-generator,代码行数:23,代码来源:AnonymousTypeCollector.java

示例2: shouldTraverse

import com.google.javascript.rhino.Node; //导入依赖的package包/类
/**
 * shouldTraverse is call when descending into the Node tree, so it is used
 * here to build the context for label renames.
 *
 * {@inheritDoc}
 */
public boolean shouldTraverse(NodeTraversal nodeTraversal, Node node,
    Node parent) {
  if (node.getType() == Token.LABEL) {
    // Determine the new name for this label.
    LabelNamespace current = namespaceStack.peek();
    int currentDepth = current.renameMap.size() + 1;
    String name = node.getFirstChild().getString();

    // Store the context for this label name.
    LabelInfo li = new LabelInfo(currentDepth);
    Preconditions.checkState(!current.renameMap.containsKey(name));
    current.renameMap.put(name, li);

    // Create a new name, if needed, for this depth.
    if (names.size() < currentDepth) {
      names.add(nameGenerator.generateNextName());
    }

    String newName = getNameForId(currentDepth);
    compiler.addToDebugLog("label renamed: " + name + " => " + newName);
  }

  return true;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:31,代码来源:RenameLabels.java

示例3: getAddingRoot

import com.google.javascript.rhino.Node; //导入依赖的package包/类
/**
 * Gets a Node at the top of the current scope where we can add new var
 * declarations as children.
 */
private static Node getAddingRoot(Node n) {
  Node addingRoot = null;
  Node ancestor = n;
  while (null != (ancestor = ancestor.getParent())) {
    int type = ancestor.getType();
    if (type == Token.SCRIPT) {
      addingRoot = ancestor;
      break;
    } else if (type == Token.FUNCTION) {
      addingRoot = ancestor.getLastChild();
      break;
    }
  }

  // make sure that the adding root looks ok
  Preconditions.checkState(addingRoot.getType() == Token.BLOCK ||
      addingRoot.getType() == Token.SCRIPT);
  Preconditions.checkState(addingRoot.getFirstChild() == null ||
      addingRoot.getFirstChild().getType() != Token.SCRIPT);
  return addingRoot;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:NodeUtil.java

示例4: runVariableRenaming

import com.google.javascript.rhino.Node; //导入依赖的package包/类
private VariableMap runVariableRenaming(
    AbstractCompiler compiler, VariableMap prevVariableMap,
    Node externs, Node root) {
  char[] reservedChars =
      options.anonymousFunctionNaming.getReservedCharacters();
  boolean preserveAnonymousFunctionNames =
      options.anonymousFunctionNaming != AnonymousFunctionNamingPolicy.OFF;
  RenameVars rn = new RenameVars(
      compiler,
      options.renamePrefix,
      options.variableRenaming == VariableRenamingPolicy.LOCAL,
      preserveAnonymousFunctionNames,
      options.generatePseudoNames,
      prevVariableMap,
      reservedChars,
      exportedNames);
  rn.process(externs, root);
  return rn.getVariableMap();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:DefaultPassConfig.java

示例5: processClass

import com.google.javascript.rhino.Node; //导入依赖的package包/类
private void processClass(Component cmp, Node n) throws Exception {
    cmp = createComponent(ComponentType.CLASS, n);
    String name = "";
    if (n.getParent().isExport() && n.getParent().getBooleanProp(Node.EXPORT_DEFAULT)) {
        String fileName = new TrimmedString(this.file.name(), "/").value();
        if (fileName.contains("/")) {
            name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.lastIndexOf("."));
        } else {
            name = fileName.substring(0, fileName.lastIndexOf("."));
        }
    } else if (n.hasChildren()) {
        name = n.getFirstChild().getString();
    }
    name = name.replaceAll("/", ".");
    cmp.setComponentName(generateComponentName(name));
    cmp.setName(name);
    cmp.setPackageName(currPackage);
    pointParentsToGivenChild(cmp);
    if (n.getSecondChild().isName()) {
        // this class extends another class
        System.out.println("this class extends " + n.getSecondChild().getString());
        cmp.insertComponentInvocation(new TypeExtension(n.getSecondChild().getString()));
    }
    componentStack.push(cmp);

}
 
开发者ID:Zir0-93,项目名称:clarpse,代码行数:27,代码来源:JavaScriptListener.java

示例6: visitBreakOrContinue

import com.google.javascript.rhino.Node; //导入依赖的package包/类
/**
 * Rename label references in breaks and continues.
 * @param node The break or continue node.
 */
private void visitBreakOrContinue(Node node) {
  Node nameNode = node.getFirstChild();
  if (nameNode != null) {
    // This is a named break or continue;
    String name = nameNode.getString();
    Preconditions.checkState(name.length() != 0);
    LabelInfo li = getLabelInfo(name);
    if (li != null) {
      String newName = getNameForId(li.id);
      // Mark the label as referenced so it isn't removed.
      li.referenced = true;
      if (!name.equals(newName)) {
        // Give it the short name.
        nameNode.setString(newName);
        compiler.reportCodeChange();
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:24,代码来源:RenameLabels.java

示例7: computeDefUse

import com.google.javascript.rhino.Node; //导入依赖的package包/类
/**
 * Computes reaching definition on given source.
 */
private void computeDefUse(String src) {
  Compiler compiler = new Compiler();
  src = "function _FUNCTION(param1, param2){" + src + "}";
  Node externs = compiler.parseTestCode(EXTERNS);
  Node root = compiler.parseTestCode(src).getFirstChild();
  assertEquals(0, compiler.getErrorCount());
  Scope scope = new SyntacticScopeCreator(compiler).createScope(root, null);
  ControlFlowAnalysis cfa = new ControlFlowAnalysis(compiler, false);
  cfa.process(null, root);
  ControlFlowGraph<Node> cfg = cfa.getCfg();
  defUse = new MustBeReachingVariableDef(cfg, scope, compiler);
  defUse.analyze();
  def = null;
  use = null;
  new NodeTraversal(compiler,new LabelFinder()).traverse(root);
  assertNotNull("Code should have an instruction labeled D", def);
  assertNotNull("Code should have an instruction labeled U", use);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:MustBeReachingVariableDefTest.java

示例8: isStatement

import com.google.javascript.rhino.Node; //导入依赖的package包/类
/**
 * @return Whether the node is used as a statement.
 */
static boolean isStatement(Node n) {
  Node parent = n.getParent();
  // It is not possible to determine definitely if a node is a statement
  // or not if it is not part of the AST.  A FUNCTION node, for instance,
  // is either part of an expression (as a anonymous function) or as
  // a statement.
  Preconditions.checkState(parent != null);
  switch (parent.getType()) {
    case Token.SCRIPT:
    case Token.BLOCK:
    case Token.LABEL:
      return true;
    default:
      return false;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:NodeUtil.java

示例9: caseAndOrMaybeShortCircuiting

import com.google.javascript.rhino.Node; //导入依赖的package包/类
private FlowScope caseAndOrMaybeShortCircuiting(Node left, Node right,
    FlowScope blindScope, boolean condition) {
  FlowScope leftScope = firstPreciserScopeKnowingConditionOutcome(
      left, blindScope, !condition);
  StaticSlot<JSType> leftVar = leftScope.findUniqueRefinedSlot(blindScope);
  if (leftVar == null) {
    return blindScope;
  }
  FlowScope rightScope = firstPreciserScopeKnowingConditionOutcome(
      left, blindScope, condition);
  rightScope = firstPreciserScopeKnowingConditionOutcome(
      right, rightScope, !condition);
  StaticSlot<JSType> rightVar = rightScope.findUniqueRefinedSlot(blindScope);
  if (rightVar == null || !leftVar.getName().equals(rightVar.getName())) {
    return blindScope;
  }
  JSType type = leftVar.getType().getLeastSupertype(rightVar.getType());
  FlowScope informed = blindScope.createChildFlowScope();
  informed.inferSlotType(leftVar.getName(), type);
  return informed;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:SemanticReverseAbstractInterpreter.java

示例10: process

import com.google.javascript.rhino.Node; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public void process(Node externs, Node root) {
  new NodeTraversal(compiler, this).traverse(root);

  for (ProvidedName pn : providedNames.values()) {
    pn.replace();
  }

  if (requiresLevel.isOn()) {
    for (UnrecognizedRequire r : unrecognizedRequires) {
      DiagnosticType error;
      ProvidedName expectedName = providedNames.get(r.namespace);
      if (expectedName != null && expectedName.firstNode != null) {
        // The namespace ended up getting provided after it was required.
        error = LATE_PROVIDE_ERROR;
      } else {
        error = MISSING_PROVIDE_ERROR;
      }

      compiler.report(JSError.make(
          r.inputName, r.requireNode, requiresLevel, error, r.namespace));
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:ProcessClosurePrimitives.java

示例11: handleSymbolExport

import com.google.javascript.rhino.Node; //导入依赖的package包/类
private void handleSymbolExport(Node parent) {
  // Ensure that we only check valid calls with the 2 arguments
  // (plus the GETPROP node itself).
  if (parent.getChildCount() != 3) {
    return;
  }

  Node thisNode = parent.getFirstChild();
  Node nameArg = thisNode.getNext();
  Node valueArg = nameArg.getNext();

  // Confirm the arguments are the expected types. If they are not,
  // then we have an export that we cannot statically identify.
  if (nameArg.getType() != Token.STRING) {
    return;
  }

  // Add the export to the list.
  this.exports.add(new SymbolExport(nameArg.getString(), valueArg));
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:21,代码来源:ExternExportsPass.java

示例12: parse

import com.google.javascript.rhino.Node; //导入依赖的package包/类
private Node parse(String[] original) {
  String[] argStrings = args.toArray(new String[] {});
  CommandLineRunner runner = null;
  try {
    runner = new CommandLineRunner(argStrings);
  } catch (CmdLineException e) {
    throw new RuntimeException(e);
  }
  Compiler compiler = runner.createCompiler();
  JSSourceFile[] inputs = new JSSourceFile[original.length];
  for (int i = 0; i < inputs.length; i++) {
    inputs[i] = JSSourceFile.fromCode("input" + i, original[i]);
  }
  compiler.init(externs, inputs, new CompilerOptions());
  Node all = compiler.parseInputs();
  Node n = all.getLastChild();
  return n;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:CommandLineRunnerTest.java

示例13: convertParameter

import com.google.javascript.rhino.Node; //导入依赖的package包/类
private Parameter convertParameter(Node jsParameter, String parameterName) {
  return new Parameter(
      parameterName,
      getJavaTypeRegistry().createTypeReference(jsParameter.getJSType()),
      jsParameter.isVarArgs(),
      jsParameter.isOptionalArg());
}
 
开发者ID:google,项目名称:jsinterop-generator,代码行数:8,代码来源:MemberCollector.java

示例14: getBooleanValue

import com.google.javascript.rhino.Node; //导入依赖的package包/类
/**
 * Gets the boolean value of a node that represents a literal. This method
 * effectively emulates the <code>Boolean()</code> JavaScript cast function.
 *
 * @throws IllegalArgumentException If {@code n} is not a literal value
 */
static boolean getBooleanValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
      return n.getString().length() > 0;

    case Token.NUMBER:
      return n.getDouble() != 0;

    case Token.NULL:
    case Token.FALSE:
    case Token.VOID:
      return false;

    case Token.NAME:
      String name = n.getString();
      if ("undefined".equals(name)
          || "NaN".equals(name)) {
        // We assume here that programs don't change the value of the keyword
        // undefined to something other than the value undefined.
        return false;
      } else if ("Infinity".equals(name)) {
        return true;
      }
      break;

    case Token.TRUE:
    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
    case Token.REGEXP:
      return true;
  }
  throw new IllegalArgumentException("Non-literal value: " + n);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:40,代码来源:NodeUtil.java

示例15: DefineInfo

import com.google.javascript.rhino.Node; //导入依赖的package包/类
/**
 * Initializes a define.
 */
public DefineInfo(Node initialValue, Node initialValueParent) {
  this.initialValueParent = initialValueParent;
  this.initialValue = initialValue;
  lastValue = initialValue;
  isAssignable = true;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:10,代码来源:ProcessDefines.java


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