本文整理汇总了Java中org.mozilla.javascript.Token类的典型用法代码示例。如果您正苦于以下问题:Java Token类的具体用法?Java Token怎么用?Java Token使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Token类属于org.mozilla.javascript包,在下文中一共展示了Token类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:25,代码来源:ForInLoop.java
示例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();
}
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:18,代码来源:UnaryExpression.java
示例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();
}
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:27,代码来源:KeywordLiteral.java
示例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();
}
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:18,代码来源:ObjectProperty.java
示例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();
}
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:19,代码来源:ForLoop.java
示例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();
}
开发者ID:middle2tw,项目名称:whackpad,代码行数:18,代码来源:UnaryExpression.java
示例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();
}
开发者ID:middle2tw,项目名称:whackpad,代码行数:27,代码来源:KeywordLiteral.java
示例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();
}
开发者ID:middle2tw,项目名称:whackpad,代码行数:17,代码来源:ObjectProperty.java
示例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());
}
开发者ID:middle2tw,项目名称:whackpad,代码行数:17,代码来源:ParserTest.java
示例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);
}
}
开发者ID:mauyr,项目名称:openbravo-brazil,代码行数:26,代码来源:JavaScriptAPIChecker.java
示例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();
}
开发者ID:mauyr,项目名称:openbravo-brazil,代码行数:28,代码来源:JavaScriptParser.java
示例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;
}
开发者ID:Samsung,项目名称:SJS,代码行数:24,代码来源:TypeErrorMessage.java
示例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;
}
});
}
开发者ID:tiffit,项目名称:TaleCraft,代码行数:21,代码来源:AstRoot.java
示例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;
}
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:26,代码来源:FormulaInfo.java
示例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 );
}
开发者ID:eclipse,项目名称:birt,代码行数:29,代码来源:OlapExpressionCompiler.java
示例16: 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));
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();
}
开发者ID:WolframG,项目名称:Rhino-Prov-Mod,代码行数:21,代码来源:ForInLoop.java
示例17: getScriptObjectName
import org.mozilla.javascript.Token; //导入依赖的package包/类
/**
*
* @param n
* @param objectName
* @return
*/
private static String getScriptObjectName( Node n, String objectName )
{
if ( n == null )
return null;
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 null;
return dimNameNode.getString( );
}
}
result = getScriptObjectName( n.getFirstChild( ), objectName );
if ( result == null )
result = getScriptObjectName( n.getLastChild( ), objectName );
return result;
}
开发者ID:eclipse,项目名称:birt,代码行数:31,代码来源:CubeQueryUtil.java
示例18: compileAggregateExpr
import org.mozilla.javascript.Token; //导入依赖的package包/类
protected AggregateExpression compileAggregateExpr( Context context, Node parent, Node callNode ) throws DataException
{
assert( callNode.getType() == Token.CALL );
IAggrFunction aggregation = getAggregationFunction( callNode );
// not an aggregation function being called, then it's considered
// a complex expression
if( aggregation == null )
return null;
AggregateExpression aggregateExpression =
new AggregateExpression( aggregation );
extractArguments( context, aggregateExpression, callNode );
replaceAggregateNode( aggregateExpression, parent, callNode );
return aggregateExpression;
}
开发者ID:eclipse,项目名称:birt,代码行数:19,代码来源:ExpressionCompiler.java
示例19: visit
import org.mozilla.javascript.Token; //导入依赖的package包/类
public boolean visit(AstNode node) {
int tt = node.getType();
String name = Token.typeToName(tt);
buffer.append(node.getAbsolutePosition()).append("\t");
buffer.append(makeIndent(node.depth()));
buffer.append(name).append(" ");
buffer.append(node.getPosition()).append(" ");
buffer.append(node.getLength());
if (tt == Token.NAME) {
buffer.append(" ").append(((Name)node).getIdentifier());
}
buffer.append("\n");
return true; // process kids
}
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:15,代码来源:AstNode.java
示例20: toSource
import org.mozilla.javascript.Token; //导入依赖的package包/类
@Override
public String toSource(int depth) {
StringBuilder sb = new StringBuilder();
sb.append(makeIndent(depth));
sb.append("while (");
sb.append(condition.toSource(0));
sb.append(") ");
if (body.getType() == Token.BLOCK) {
sb.append(body.toSource(depth).trim());
sb.append("\n");
} else {
sb.append("\n").append(body.toSource(depth+1));
}
return sb.toString();
}
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:16,代码来源:WhileLoop.java
注:本文中的org.mozilla.javascript.Token类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论