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


Java Node.getString方法代码示例

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


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

示例1: processMemberFunctionDef

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void processMemberFunctionDef(Component cmp, Node n) throws Exception {
    if (n.getString() != null && n.getString().equals("constructor")) {
        System.out.println("Found constructor");
        cmp = createComponent(ComponentType.CONSTRUCTOR, n);
        cmp.setComponentName(generateComponentName("constructor"));
        cmp.setName("constructor");
        cmp.setPackageName(currPackage);
        pointParentsToGivenChild(cmp);
        componentStack.push(cmp);
    } else {
        System.out.println("Found instance method: " + n.getString());
        cmp = createComponent(ComponentType.METHOD, n);
        cmp.setComponentName(generateComponentName(n.getString()));
        cmp.setName(n.getString());
        cmp.setPackageName(currPackage);
        if (n.isStaticMember()) {
            cmp.insertAccessModifier("static");
        }
        cmp.insertAccessModifier("public");
        pointParentsToGivenChild(cmp);
        componentStack.push(cmp);
    }

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

示例2: isImmutableValue

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Returns true if this is an immutable value.
 */
static boolean isImmutableValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
    case Token.NUMBER:
    case Token.NULL:
    case Token.TRUE:
    case Token.FALSE:
    case Token.VOID:
      return true;
    case Token.NEG:
      return isImmutableValue(n.getFirstChild());
    case Token.NAME:
      String name = n.getString();
      // We assume here that programs don't change the value of the keyword
      // undefined to something other than the value undefined.
      return "undefined".equals(name)
          || "Infinity".equals(name)
          || "NaN".equals(name);
  }

  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:NodeUtil.java

示例3: handleFunctionInputs

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/** Handle bleeding functions and function parameters. */
private void handleFunctionInputs(Node fnNode) {
  // Handle bleeding functions.
  Node fnNameNode = fnNode.getFirstChild();
  String fnName = fnNameNode.getString();
  if (!fnName.isEmpty()) {
    Scope.Var fnVar = scope.getVar(fnName);
    if (fnVar == null ||
        // Make sure we're not touching a native function. Native
        // functions aren't bleeding, but may not have a declaration
        // node.
        (fnVar.getNameNode() != null &&
            // Make sure that the function is actually bleeding by checking
            // if has already been declared.
            fnVar.getInitialValue() != fnNode)) {
      defineSlot(fnNameNode, fnNode, fnNode.getJSType(), false);
    }
  }

  declareArguments(fnNode);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:TypedScopeCreator.java

示例4: addRead

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Determines whether this is a potentially bad read, and remembers the
 * location of the code.  A read clears out all this property's bad writes.
 * @param nameNode  the name of the property (a STRING node)
 * @param t  where we are in the code, so we can generate a useful report
 */
private void addRead(Node nameNode, NodeTraversal t) {
  String name = nameNode.getString();
  Property prop = getProperty(name);
  prop.readCount++;
  if (prop.writeCount == 0 && !isExternallyDefined(name)) {
    // We don't know about any writes yet, so this might be a bad read.
    if (checkReads.isOn()) {
      if (prop.reads == null) {
        prop.reads = new ArrayList<Node>(MAX_REPORTS_PER_PROPERTY);
      }
      if (prop.reads.size() < MAX_REPORTS_PER_PROPERTY) {
        nameNode.putProp(Node.SOURCENAME_PROP, t.getSourceName());
        prop.reads.add(nameNode);
      }
    }
  } else {
    // There are writes, or this is an extern, so null out reads.
    prop.reads = null;
  }

  // There's at least this one read, so there are no invalid writes.
  prop.writes = null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:30,代码来源:SuspiciousPropertiesCheck.java

示例5: maybeMarkCandidate

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * If a property node is eligible for renaming, stashes a reference to it
 * and increments the property name's access count.
 *
 * @param n The STRING node for a property
 * @param t The traversal
 */
private void maybeMarkCandidate(Node n, JSType type, NodeTraversal t) {
  String name = n.getString();
  if (!externedNames.contains(name)) {
    stringNodesToRename.add(n);
    recordProperty(name, type);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:15,代码来源:AmbiguateProperties.java

示例6: visit

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {

    String fileName = null;
    try {
        fileName = new TrimmedString(this.file.name(), "/").value();
        String baseCmpName = null;

        if (n.isClass()) {
            if (n.getParent().isExport() && n.getParent().getBooleanProp(Node.EXPORT_DEFAULT)) {
                if (fileName.contains("/")) {
                    baseCmpName = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.lastIndexOf("."));
                } else {
                    baseCmpName = fileName.substring(0, fileName.lastIndexOf("."));
                }
            } else if (n.hasChildren()) {
                baseCmpName = n.getFirstChild().getString();
            }
            baseCmpName = new TrimmedString(baseCmpName, "/").value().replaceAll("/", ".");
        } else if (n.isMemberFunctionDef()) {
            baseCmpName = n.getString();
        } else if (n.isGetterDef()) {
            baseCmpName = "get_" + n.getString();
        } else if (n.isSetterDef()) {
            baseCmpName = "set_" + n.getString();
        }

        if (baseCmpName != null) {
            while (!componentStack.isEmpty() && (componentStack.peek().componentName().contains(baseCmpName + ".")
                    || componentStack.peek().componentName().endsWith(baseCmpName))) {
                completeComponent();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:Zir0-93,项目名称:clarpse,代码行数:38,代码来源:JavaScriptListener.java

示例7: getStringValue

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Gets the value of a node as a String, or null if it cannot be converted.
 * When it returns a non-null String, this method effectively emulates the
 * <code>String()</code> JavaScript cast function.
 */
static String getStringValue(Node n) {
  // TODO(user): Convert constant array, object, and regex literals as well.
  switch (n.getType()) {
    case Token.NAME:
    case Token.STRING:
      return n.getString();

    case Token.NUMBER:
      double value = n.getDouble();
      long longValue = (long) value;

      // Return "1" instead of "1.0"
      if (longValue == value) {
        return Long.toString(longValue);
      } else {
        return Double.toString(n.getDouble());
      }

    case Token.FALSE:
    case Token.TRUE:
    case Token.NULL:
      return Node.tokenToName(n.getType());

    case Token.VOID:
      return "undefined";
  }
  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:NodeUtil.java

示例8: getName

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/** {@inheritDoc} */
public final String getName(Node node) {
  switch (node.getType()) {
    case Token.NAME:
    case Token.STRING:
      return node.getString();
    default:
      return new CodePrinter.Builder(node).build();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:11,代码来源:NameAnonymousFunctionsMapped.java

示例9: shouldTraverse

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
  if (isPrototypePropertyAssign(n)) {
    symbolStack.push(getNameInfoForName(
            n.getFirstChild().getLastChild().getString(), PROPERTY));
  } else if (isGlobalFunctionDeclaration(t, n, parent)) {
    String name = parent.getType() == Token.NAME ?
        parent.getString() /* VAR */ :
        n.getFirstChild().getString() /* named function */;
    symbolStack.push(getNameInfoForName(name, VAR));
  }
  return true;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:13,代码来源:AnalyzePrototypeProperties.java

示例10: isGlobalThisObject

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private boolean isGlobalThisObject(NodeTraversal t, Node n) {
  if (n.getType() == Token.THIS) {
    return t.inGlobalScope();
  } else if (n.getType() == Token.NAME && !NodeUtil.isLabelName(n)) {
    String varName = n.getString();
    if (varName.equals(GLOBAL_THIS_NAME)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:12,代码来源:GatherRawExports.java

示例11: visit

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    // Function calls
    case Token.CALL:
      Node child = n.getFirstChild();
      String name = null;
      // NOTE: The normalization pass insures that local names do not
      // collide with global names.
      if (child.getType() == Token.NAME) {
        name = child.getString();
      } else if (child.getType() == Token.FUNCTION) {
        name = anonFunctionMap.get(child);
      } else if (NodeUtil.isFunctionObjectCall(n)) {
        Preconditions.checkState(NodeUtil.isGet(child));
        Node fnIdentifingNode = child.getFirstChild();
        if (fnIdentifingNode.getType() == Token.NAME) {
          name = fnIdentifingNode.getString();
        } else if (fnIdentifingNode.getType() == Token.FUNCTION) {
          name = anonFunctionMap.get(fnIdentifingNode);
        }
      }

      if (name != null) {
        FunctionState fs = functionMap.get(name);
        // Only visit call-sites for functions that can be inlined.
        if (fs != null) {
          callback.visitCallSite(t, n, parent, fs);
        }
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:33,代码来源:InlineFunctions.java

示例12: getNewGlobalName

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private String getNewGlobalName(Node n) {
  String oldName = n.getString();
  Assignment a = assignments.get(oldName);
  if (a.newName != null && !a.newName.equals(oldName)) {
    if (generatePseudoNames) {
      return getPseudoName(oldName);
    }
    return a.newName;
  } else {
    return null;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:13,代码来源:RenameVars.java

示例13: replaceGlobalUse

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Replace uses of a global with its aliased name.
 */
private void replaceGlobalUse(Node globalUse) {
  String globalName = globalUse.getString();
  if (globals.get(globalName).aliasAccessor) {
    globalUse.setString("GLOBAL_" + globalName);
    compiler.reportCodeChange();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:11,代码来源:AliasExternals.java

示例14: traverseName

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private FlowScope traverseName(Node n, FlowScope scope) {
  String varName = n.getString();
  Node value = n.getFirstChild();
  JSType type = n.getJSType();
  if (value != null) {
    scope = traverse(value, scope);
    updateScopeForTypeChange(scope, n, n.getJSType() /* could be null */,
        getJSType(value));
    return scope;
  } else {
    StaticSlot<JSType> var = scope.getSlot(varName);
    if (var != null) {
      // There are two situations where we don't want to use type information
      // from the scope, even if we have it.

      // 1) The var is escaped in a weird way, e.g.,
      // function f() { var x = 3; function g() { x = null } (x); }
      boolean isInferred = var.isTypeInferred();
      boolean unflowable =
          isInferred && unflowableVarNames.contains(varName);

      // 2) We're reading type information from another scope for an
      // inferred variable.
      // var t = null; function f() { (t); }
      boolean nonLocalInferredSlot =
          isInferred &&
          syntacticScope.getParent() != null &&
          var == syntacticScope.getParent().getSlot(varName);

      if (!unflowable && !nonLocalInferredSlot) {
        type = var.getType();
        if (type == null) {
          type = getNativeType(UNKNOWN_TYPE);
        }
      }
    }
  }
  n.setJSType(type);
  return scope;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:41,代码来源:TypeInference.java

示例15: visit

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.GETPROP:
    case Token.GETELEM:
      Node dest = n.getFirstChild().getNext();
      if (dest.getType() == Token.STRING) {
        String s = dest.getString();
        if (s.equals("prototype")) {
          processPrototypeParent(parent, t.getInput());
        } else {
          markPropertyAccessCandidate(dest, t.getInput());
        }
      }
      break;
    case Token.OBJECTLIT:
      if (!prototypeObjLits.contains(n)) {
        // Object literals have their property name/value pairs as a flat
        // list as their children. We want every other node in order to get
        // only the property names.
        for (Node child = n.getFirstChild();
             child != null;
             child = child.getNext().getNext()) {

          if (child.getType() == Token.STRING) {
            markObjLitPropertyCandidate(child, t.getInput());
          }
        }
      }
      break;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:32,代码来源:RenamePrototypes.java


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