本文整理汇总了Java中org.mozilla.javascript.Token类的典型用法代码示例。如果您正苦于以下问题:Java Token类的具体用法?Java Token怎么用?Java Token使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Token类属于org.mozilla.javascript包,在下文中一共展示了Token类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toSource
import org.mozilla.javascript.Token; //导入依赖的package包/类
@Override
public String toSource(int depth) {
StringBuilder sb = new StringBuilder();
sb.append(makeIndent(depth));
sb.append("for ");
if (isForEach()) {
sb.append("each ");
}
sb.append("(");
sb.append(iterator.toSource(0));
if (isForOf) {
sb.append(" of ");
} else {
sb.append(" in ");
}
sb.append(iteratedObject.toSource(0));
sb.append(") ");
if (body.getType() == Token.BLOCK) {
sb.append(body.toSource(depth).trim()).append("\n");
} else {
sb.append("\n").append(body.toSource(depth+1));
}
return sb.toString();
}
示例2: toSource
import org.mozilla.javascript.Token; //导入依赖的package包/类
@Override
public String toSource(int depth) {
StringBuilder sb = new StringBuilder();
sb.append(makeIndent(depth));
int type = getType();
if (!isPostfix) {
sb.append(operatorToString(type));
if (type == Token.TYPEOF || type == Token.DELPROP || type == Token.VOID) {
sb.append(" ");
}
}
sb.append(operand.toSource());
if (isPostfix) {
sb.append(operatorToString(type));
}
return sb.toString();
}
示例3: toSource
import org.mozilla.javascript.Token; //导入依赖的package包/类
@Override
public String toSource(int depth) {
StringBuilder sb = new StringBuilder();
sb.append(makeIndent(depth));
switch (getType()) {
case Token.THIS:
sb.append("this");
break;
case Token.NULL:
sb.append("null");
break;
case Token.TRUE:
sb.append("true");
break;
case Token.FALSE:
sb.append("false");
break;
case Token.DEBUGGER:
sb.append("debugger;\n");
break;
default:
throw new IllegalStateException("Invalid keyword literal type: "
+ getType());
}
return sb.toString();
}
示例4: toSource
import org.mozilla.javascript.Token; //导入依赖的package包/类
@Override
public String toSource(int depth) {
StringBuilder sb = new StringBuilder();
sb.append("\n");
sb.append(makeIndent(depth+1));
if (isGetterMethod()) {
sb.append("get ");
} else if (isSetterMethod()) {
sb.append("set ");
}
sb.append(left.toSource(getType()==Token.COLON ? 0 : depth));
if (type == Token.COLON) {
sb.append(": ");
}
sb.append(right.toSource(getType()==Token.COLON ? 0 : depth+1));
return sb.toString();
}
示例5: toSource
import org.mozilla.javascript.Token; //导入依赖的package包/类
@Override
public String toSource(int depth) {
StringBuilder sb = new StringBuilder();
sb.append(makeIndent(depth));
sb.append("for (");
sb.append(initializer.toSource(0));
sb.append("; ");
sb.append(condition.toSource(0));
sb.append("; ");
sb.append(increment.toSource(0));
sb.append(") ");
if (body.getType() == Token.BLOCK) {
sb.append(body.toSource(depth).trim()).append("\n");
} else {
sb.append("\n").append(body.toSource(depth+1));
}
return sb.toString();
}
示例6: toSource
import org.mozilla.javascript.Token; //导入依赖的package包/类
@Override
public String toSource(int depth) {
StringBuilder sb = new StringBuilder();
sb.append(makeIndent(depth));
if (!isPostfix) {
sb.append(operatorToString(getType()));
if (getType() == Token.TYPEOF
|| getType() == Token.DELPROP) {
sb.append(" ");
}
}
sb.append(operand.toSource());
if (isPostfix) {
sb.append(operatorToString(getType()));
}
return sb.toString();
}
示例7: toSource
import org.mozilla.javascript.Token; //导入依赖的package包/类
@Override
public String toSource(int depth) {
StringBuilder sb = new StringBuilder();
sb.append(makeIndent(depth));
switch (getType()) {
case Token.THIS:
sb.append("this");
break;
case Token.NULL:
sb.append("null");
break;
case Token.TRUE:
sb.append("true");
break;
case Token.FALSE:
sb.append("false");
break;
case Token.DEBUGGER:
sb.append("debugger");
break;
default:
throw new IllegalStateException("Invalid keyword literal type: "
+ getType());
}
return sb.toString();
}
示例8: toSource
import org.mozilla.javascript.Token; //导入依赖的package包/类
@Override
public String toSource(int depth) {
StringBuilder sb = new StringBuilder();
sb.append(makeIndent(depth));
if (isGetter()) {
sb.append("get ");
} else if (isSetter()) {
sb.append("set ");
}
sb.append(left.toSource(0));
if (type == Token.COLON) {
sb.append(": ");
}
sb.append(right.toSource(0));
return sb.toString();
}
示例9: testLinenoGetProp
import org.mozilla.javascript.Token; //导入依赖的package包/类
public void testLinenoGetProp() {
AstRoot root = parse("\nfoo.bar");
ExpressionStatement st = (ExpressionStatement) root.getFirstChild();
AstNode n = st.getExpression();
assertTrue(n instanceof PropertyGet);
assertEquals(Token.GETPROP, n.getType());
assertEquals(1, n.getLineno());
PropertyGet getprop = (PropertyGet) n;
AstNode m = getprop.getRight();
assertTrue(m instanceof Name);
assertEquals(Token.NAME, m.getType()); // used to be Token.STRING!
assertEquals(1, m.getLineno());
}
示例10: checkJS
import org.mozilla.javascript.Token; //导入依赖的package包/类
/**
* Checks the parsed file against the API Map.
*
* @param p
* an instance of {@link JavaScriptParser} to get the tree representation of it
* @param jsFileName
* the JavaScript file name that is being checked
* @throws IOException
*/
private void checkJS(JavaScriptParser p, String jsFileName) throws IOException {
ScriptOrFnNode nodeTree = p.parse();
for (Node cursor = nodeTree.getFirstChild(); cursor != null; cursor = cursor.getNext()) {
StringBuffer sb = new StringBuffer();
if (cursor.getType() == Token.FUNCTION) {
int fnIndex = cursor.getExistingIntProp(Node.FUNCTION_PROP);
FunctionNode fn = nodeTree.getFunctionNode(fnIndex);
sb.append("FUNCTION: " + fn.getFunctionName());
} else if (cursor.getType() == Token.VAR) {
Node vn = cursor.getFirstChild();
sb.append("VAR: " + vn.getString());
}
apiMap.remove(jsFileName + sb);
}
}
示例11: getStringDetails
import org.mozilla.javascript.Token; //导入依赖的package包/类
/**
* @return a string with the global variables and function definitions
*/
public String getStringDetails() {
if (jsFile == null) {
throw new RuntimeException("You need to specify the file to parse");
}
if (details == null) {
details = new StringBuffer();
try {
parse();
} catch (IOException e) {
e.printStackTrace();
}
for (Node cursor = nodeTree.getFirstChild(); cursor != null; cursor = cursor.getNext()) {
if (cursor.getType() == Token.FUNCTION) {
int fnIndex = cursor.getExistingIntProp(Node.FUNCTION_PROP);
FunctionNode fn = nodeTree.getFunctionNode(fnIndex);
details.append("FUNCTION: " + fn.getFunctionName() + "\n");
} else if (cursor.getType() == Token.VAR) {
Node vn = cursor.getFirstChild();
details.append("VAR: " + vn.getString() + "\n");
}
}
}
return details.toString();
}
示例12: binaryOperatorMisuse
import org.mozilla.javascript.Token; //导入依赖的package包/类
public static TypeErrorMessage binaryOperatorMisuse(InfixExpression node, Type t1, Type t2, Type outType) {
TypeErrorMessage msg = genericTypeError("misuse of binary operator " + AstNode.operatorToString(node.getOperator()) + " in \"" + shortSrc(node) + '"',
locationOf(node));
if (node.getOperator() == Token.IN) {
if (!unconstrained(t1) && !Types.isEqual(t1, StringType.make())) {
msg = msg.withNote("left operand has type " + describeType(t1) + " instead of " + StringType.make());
}
if (!unconstrained(t2) && !Types.isMapType(t2)) {
msg = msg.withNote("right operand has type " + describeType(t2) + " instead of " + new MapType(new DefaultType()));
}
} else {
if (!unconstrained(t1)) {
msg = msg.withNote("left operand has type " + describeType(t1));
}
if (!unconstrained(t2)) {
msg = msg.withNote("right operand has type " + describeType(t2));
}
}
if (!unconstrained(outType)) {
msg = msg.withNote("result type is " + describeType(outType));
}
return msg;
}
示例13: checkParentLinks
import org.mozilla.javascript.Token; //导入依赖的package包/类
/**
* Debugging function to check that the parser has set the parent
* link for every node in the tree.
* @throws IllegalStateException if a parent link is missing
*/
public void checkParentLinks() {
this.visit(new NodeVisitor() {
@Override
public boolean visit(AstNode node) {
int type = node.getType();
if (type == Token.SCRIPT)
return true;
if (node.getParent() == null)
throw new IllegalStateException
("No parent for node: " + node
+ "\n" + node.toSource(0));
return true;
}
});
}
示例14: isTrivial
import org.mozilla.javascript.Token; //导入依赖的package包/类
public static boolean isTrivial (String formula) {
// No formulas, just one constant or one variable.
final ArrayList<AstNode> result = new ArrayList<AstNode>();
parseIntoTree(formula).visit(new NodeVisitor(){
@Override
public boolean visit(AstNode node) {
if(node.depth()>1){
result.add(node);
return false;
}
return true;
}
});
if(result.size()>0){
switch (result.get(0).getType()) {
case Token.NUMBER: return true;
case Token.NAME: return true;
case Token.STRING: return true;
default: return false;
}
}
return false;
}
示例15: getScriptObjectName
import org.mozilla.javascript.Token; //导入依赖的package包/类
/**
*
* @param n
* @param objectName
* @return
*/
private static void getScriptObjectName( Node n, String objectName, Set nameSet )
{
if ( n == null )
return;
String result = null;
if ( n.getType( ) == Token.NAME )
{
if ( objectName.equals( n.getString( ) ) )
{
Node dimNameNode = n.getNext( );
if ( dimNameNode == null
|| dimNameNode.getType( ) != Token.STRING )
return;
nameSet.add( dimNameNode.getString( ) );
}
}
getScriptObjectName( n.getFirstChild( ), objectName, nameSet );
getScriptObjectName( n.getNext( ), objectName, nameSet );
getScriptObjectName( n.getLastChild( ), objectName, nameSet );
}