本文整理汇总了Java中com.google.javascript.jscomp.NodeUtil.isLiteralValue方法的典型用法代码示例。如果您正苦于以下问题:Java NodeUtil.isLiteralValue方法的具体用法?Java NodeUtil.isLiteralValue怎么用?Java NodeUtil.isLiteralValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.jscomp.NodeUtil
的用法示例。
在下文中一共展示了NodeUtil.isLiteralValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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;
}
示例3: visit
import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getType()) {
case Token.LABEL:
tryMinimizeExits(
n.getLastChild(), Token.BREAK, n.getFirstChild().getString());
break;
case Token.FOR:
case Token.WHILE:
tryMinimizeExits(
NodeUtil.getLoopCodeBlock(n), Token.CONTINUE, null);
break;
case Token.DO:
tryMinimizeExits(
NodeUtil.getLoopCodeBlock(n), Token.CONTINUE, null);
Node cond = NodeUtil.getConditionExpression(n);
if (NodeUtil.isLiteralValue(cond) && !NodeUtil.getBooleanValue(cond)) {
// Normally, we wouldn't be able to optimize BREAKs inside a loop
// but as we know the condition will always false, we can treat them
// as we would a CONTINUE.
tryMinimizeExits(
n.getFirstChild(), Token.BREAK, null);
}
break;
case Token.FUNCTION:
tryMinimizeExits(
n.getLastChild(), Token.RETURN, null);
break;
}
}