本文整理汇总了Java中com.google.javascript.rhino.Node.setString方法的典型用法代码示例。如果您正苦于以下问题:Java Node.setString方法的具体用法?Java Node.setString怎么用?Java Node.setString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.Node
的用法示例。
在下文中一共展示了Node.setString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
}
}
示例2: handleScopeVar
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* For the Var declared in the current scope determine if it is possible
* to revert the name to its orginal form without conflicting with other
* values.
*/
void handleScopeVar(Var v) {
String name = v.getName();
if (containsSeparator(name)) {
String newName = getOrginalName(name);
// Check if the new name is valid and if it would cause conflicts.
if (TokenStream.isJSIdentifier(newName) &&
!referencedNames.contains(newName) &&
!newName.equals(ARGUMENTS)) {
referencedNames.remove(name);
// Adding a reference to the new name to prevent either the parent
// scopes or the current scope renaming another var to this new name.
referencedNames.add(newName);
List<Node> references = nameMap.get(name);
Preconditions.checkState(references != null);
for (Node n : references) {
Preconditions.checkState(n.getType() == Token.NAME);
n.setString(newName);
}
compiler.reportCodeChange();
}
nameMap.remove(name);
}
}
示例3: processStringNode
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Processes a string argument to goog.getCssName(). The string will be
* renamed based off the symbol map. If there is no map or any part of the
* name can't be renamed, a warning is reported to the compiler and the node
* is left unchanged.
*
* If the type is unexpected then an error is reported to the compiler.
*
* @param t The node traversal.
* @param n The string node to process.
*/
private void processStringNode(NodeTraversal t, Node n) {
if (symbolMap != null || cssNames != null) {
String[] parts = n.getString().split("-");
for (int i = 0; i < parts.length; i++) {
if (cssNames != null) {
Integer count = cssNames.get(parts[i]);
if (count == null) {
count = Integer.valueOf(0);
}
cssNames.put(parts[i], count.intValue() + 1);
}
if (symbolMap != null) {
String replacement = symbolMap.get(parts[i]);
if (replacement == null) {
// If we can't encode all parts, don't encode any of it.
compiler.report(JSError.make(
t, n, UNKNOWN_SYMBOL_WARNING, parts[i], n.getString()));
return;
}
parts[i] = replacement;
}
}
if (symbolMap != null) {
n.setString(Joiner.on("-").join(parts));
}
}
}
示例4: setFunctionName
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/** {@inheritDoc} */
public final void setFunctionName(String name, Node fnNode) {
Node fnNameNode = fnNode.getFirstChild();
String newName = renameMap.get(name);
if (newName == null) {
newName = nameGenerator.generateNextName();
renameMap.put(name, newName);
}
fnNameNode.setString(newName);
namedCount++;
bytesUsed += newName.length();
}
示例5: 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();
}
}
示例6: visit
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.getType() != Token.VAR) {
return;
}
// It is only safe to collapse anonymous functions that appear
// at top-level blocks. In other cases the difference between
// variable and function declarations can lead to problems or
// expose subtle bugs in browser implementation as function
// definitions are added to scopes before the start of execution.
Node grandparent = parent.getParent();
if (!(parent.getType() == Token.SCRIPT ||
grandparent != null &&
grandparent.getType() == Token.FUNCTION &&
parent.getType() == Token.BLOCK)) {
return;
}
// Need to store the next name in case the current name is removed from
// the linked list.
Preconditions.checkState(n.hasOneChild());
Node name = n.getFirstChild();
Node value = name.getFirstChild();
if (value != null &&
value.getType() == Token.FUNCTION &&
!isRecursiveFunction(value)) {
Node fnName = value.getFirstChild();
fnName.setString(name.getString());
NodeUtil.copyNameAnnotations(name, fnName);
name.removeChild(value);
parent.replaceChild(n, value);
compiler.reportCodeChange();
}
}
示例7: visitLabel
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Rename or remove labels.
* @param node The label node.
* @param parent The parent of the label node.
*/
private void visitLabel(Node node, Node parent) {
Node nameNode = node.getFirstChild();
Preconditions.checkState(nameNode != null);
String name = nameNode.getString();
LabelInfo li = getLabelInfo(name);
// This is a label...
if (li.referenced) {
String newName = getNameForId(li.id);
if (!name.equals(newName)) {
// ... and it is used, give it the short name.
nameNode.setString(newName);
compiler.reportCodeChange();
}
} else {
// ... and it is not referenced, just remove it.
Node newChild = node.getLastChild();
node.removeChild(newChild);
parent.replaceChild(node, newChild);
if (newChild.getType() == Token.BLOCK) {
NodeUtil.tryMergeBlock(newChild);
}
compiler.reportCodeChange();
}
// Remove the label from the current stack of labels.
namespaceStack.peek().renameMap.remove(name);
}
示例8: visit
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getType()) {
case Token.NAME:
String newName = getReplacementName(n.getString());
if (newName != null) {
Renamer renamer = nameStack.peek();
if (renamer.stripConstIfReplaced()) {
// TODO(johnlenz): Do we need to do anything about the javadoc?
n.removeProp(Node.IS_CONSTANT_NAME);
}
n.setString(newName);
t.getCompiler().reportCodeChange();
}
break;
case Token.FUNCTION:
// Remove function recursive name (if any).
nameStack.pop();
break;
case Token.CATCH:
// Remove catch except name from the stack of names.
nameStack.pop();
break;
}
}
示例9: setFunctionName
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/** {@inheritDoc} */
public final void setFunctionName(String name, Node fnNode) {
Node fnNameNode = fnNode.getFirstChild();
String uniqueName = getLikelyNonConflictingName(name);
fnNameNode.setString(uniqueName);
compiler.reportCodeChange();
namedCount++;
bytesUsed += uniqueName.length();
}
示例10: renameProperties
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/** Renames all properties with references on more than one type. */
void renameProperties() {
int propsRenamed = 0, propsSkipped = 0, instancesRenamed = 0,
instancesSkipped = 0, singleTypeProps = 0;
for (Property prop : properties.values()) {
if (prop.shouldRename()) {
Map<T, String> propNames = buildPropNames(prop.getTypes(), prop.name);
++propsRenamed;
prop.expandTypesToSkip();
UnionFind<T> types = prop.getTypes();
for (Node node : prop.renameNodes) {
T rootType = prop.rootTypes.get(node);
if (prop.shouldRename(rootType)) {
String newName = propNames.get(rootType);
node.setString(newName);
compiler.reportCodeChange();
++instancesRenamed;
} else {
++instancesSkipped;
}
}
} else {
if (prop.skipRenaming) {
++propsSkipped;
} else {
++singleTypeProps;
}
}
}
logger.info("Renamed " + instancesRenamed + " instances of "
+ propsRenamed + " properties.");
logger.info("Skipped renaming " + instancesSkipped + " invalidated "
+ "properties, " + propsSkipped + " instances of properties "
+ "that were skipped for specific types and " + singleTypeProps
+ " properties that were referenced from only one type.");
}
示例11: visit
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
if (colorings.isEmpty() || !NodeUtil.isName(n) ||
NodeUtil.isFunction(parent)) {
// Don't rename named functions.
return;
}
Var var = t.getScope().getVar(n.getString());
GraphNode<Var, ?> vNode = colorings.peek().getGraph().getNode(var);
if (vNode == null) {
// This is not a local.
return;
}
Var coalescedVar = colorings.peek().getPartitionSuperNode(var);
if (!usePseudoNames) {
if (vNode.getValue().equals(coalescedVar)) {
// The coalesced name is itself, nothing to do.
return;
}
// Rename.
n.setString(coalescedVar.name);
compiler.reportCodeChange();
if (NodeUtil.isVar(parent)) {
removeVarDeclaration(n);
}
} else {
// This code block is slow but since usePseudoName is for debugging,
// we should not sacrifice performance for non-debugging compilation to
// make this fast.
String pseudoName = null;
Set<String> allMergedNames = Sets.newTreeSet();
for (Iterator<Var> i = t.getScope().getVars(); i.hasNext();) {
Var iVar = i.next();
// Look for all the variables that can be merged (in the graph by now)
// and it is merged with the current coalscedVar.
if (colorings.peek().getGraph().getNode(iVar) != null &&
coalescedVar.equals(colorings.peek().getPartitionSuperNode(iVar))) {
allMergedNames.add(iVar.name);
}
}
// Keep its original name.
if (allMergedNames.size() == 1) {
return;
}
pseudoName = Joiner.on("_").join(allMergedNames);
while (t.getScope().isDeclared(pseudoName, true)) {
pseudoName += "$";
}
n.setString(pseudoName);
compiler.reportCodeChange();
if (!vNode.getValue().equals(coalescedVar) && NodeUtil.isVar(parent)) {
removeVarDeclaration(n);
}
}
}
示例12: visit
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.getType() != Token.NAME) {
return;
}
String name = n.getString();
// Ignore anonymous functions
if (name.length() == 0) {
return;
}
// Is this local or Global?
Scope.Var var = t.getScope().getVar(name);
boolean local = (var != null) && var.isLocal();
// Are we renaming global variables?
if (!local && localRenamingOnly) {
reservedNames.add(name);
return;
}
// Are we renaming anonymous function names?
if (preserveAnonymousFunctionNames
&& var != null
&& NodeUtil.isAnonymousFunction(var.getParentNode())) {
reservedNames.add(name);
return;
}
// Check if we can rename this.
if (!okToRenameVar(name, local)) {
if (local) {
// Blindly de-uniquify for the Prototype library for issue 103.
String newName =
MakeDeclaredNamesUnique.ContextualRenameInverter.getOrginalName(
name);
if (!newName.equals(name)) {
n.setString(newName);
}
}
return;
}
if (isExternsPass_) {
// Keep track of extern globals.
if (!local) {
externNames.add(name);
}
return;
}
if (local) {
// Local var: assign a new name
String tempName = LOCAL_VAR_PREFIX + var.getLocalVarIndex();
incCount(tempName, null);
localNameNodes.add(n);
localTempNames.add(tempName);
} else if (var != null) { // Not an extern
// If it's global, increment global count
incCount(name, var.input);
globalNameNodes.add(n);
}
}