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


Java AstNode类代码示例

本文整理汇总了Java中org.mozilla.javascript.ast.AstNode的典型用法代码示例。如果您正苦于以下问题:Java AstNode类的具体用法?Java AstNode怎么用?Java AstNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: transformNewExpr

import org.mozilla.javascript.ast.AstNode; //导入依赖的package包/类
private Node transformNewExpr(NewExpression node) {
    decompiler.addToken(Token.NEW);
    Node nx = createCallOrNew(Token.NEW, transform(node.getTarget()));
    nx.setLineno(node.getLineno());
    List<AstNode> args = node.getArguments();
    decompiler.addToken(Token.LP);
    for (int i = 0; i < args.size(); i++) {
        AstNode arg = args.get(i);
        nx.addChildToBack(transform(arg));
        if (i < args.size() - 1) {
            decompiler.addToken(Token.COMMA);
        }
    }
    decompiler.addToken(Token.RP);
    if (node.getInitializer() != null) {
        nx.addChildToBack(transformObjectLiteral(node.getInitializer()));
    }
    return nx;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:20,代码来源:IRFactory.java

示例2: transformParenExpr

import org.mozilla.javascript.ast.AstNode; //导入依赖的package包/类
private Node transformParenExpr(ParenthesizedExpression node) {
    AstNode expr = node.getExpression();
    decompiler.addToken(Token.LP);
    int count = 1;
    while (expr instanceof ParenthesizedExpression) {
        decompiler.addToken(Token.LP);
        count++;
        expr = ((ParenthesizedExpression)expr).getExpression();
    }
    Node result = transform(expr);
    for (int i = 0; i < count; i++) {
        decompiler.addToken(Token.RP);
    }
    result.putProp(Node.PARENTHESIZED_PROP, Boolean.TRUE);
    return result;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:17,代码来源:IRFactory.java

示例3: transformReturn

import org.mozilla.javascript.ast.AstNode; //导入依赖的package包/类
private Node transformReturn(ReturnStatement node) {
    boolean expClosure = Boolean.TRUE.equals(node.getProp(Node.EXPRESSION_CLOSURE_PROP));
    boolean isArrow = Boolean.TRUE.equals(node.getProp(Node.ARROW_FUNCTION_PROP));
    if (expClosure) {
        if (!isArrow) {
            decompiler.addName(" ");
        }
    } else {
        decompiler.addToken(Token.RETURN);
    }
    AstNode rv = node.getReturnValue();
    Node value = rv == null ? null : transform(rv);
    if (!expClosure) decompiler.addEOL(Token.SEMI);
    return rv == null
        ? new Node(Token.RETURN, node.getLineno())
        : new Node(Token.RETURN, value, node.getLineno());
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:18,代码来源:IRFactory.java

示例4: autoInsertSemicolon

import org.mozilla.javascript.ast.AstNode; //导入依赖的package包/类
private void autoInsertSemicolon(AstNode pn) throws IOException {
    int ttFlagged = peekFlaggedToken();
    int pos = pn.getPosition();
    switch (ttFlagged & CLEAR_TI_MASK) {
      case Token.SEMI:
          // Consume ';' as a part of expression
          consumeToken();
          // extend the node bounds to include the semicolon.
          pn.setLength(ts.tokenEnd - pos);
          break;
      case Token.ERROR:
      case Token.EOF:
      case Token.RC:
          // Autoinsert ;
          warnMissingSemi(pos, nodeEnd(pn));
          break;
      default:
          if ((ttFlagged & TI_AFTER_EOL) == 0) {
              // Report error if no EOL or autoinsert ; otherwise
              reportError("msg.no.semi.stmt");
          } else {
              warnMissingSemi(pos, nodeEnd(pn));
          }
          break;
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:27,代码来源:Parser.java

示例5: ifStatement

import org.mozilla.javascript.ast.AstNode; //导入依赖的package包/类
private IfStatement ifStatement()
    throws IOException
{
    if (currentToken != Token.IF) codeBug();
    consumeToken();
    int pos = ts.tokenBeg, lineno = ts.lineno, elsePos = -1;
    ConditionData data = condition();
    AstNode ifTrue = statement(), ifFalse = null;
    if (matchToken(Token.ELSE)) {
        elsePos = ts.tokenBeg - pos;
        ifFalse = statement();
    }
    int end = getNodeEnd(ifFalse != null ? ifFalse : ifTrue);
    IfStatement pn = new IfStatement(pos, end - pos);
    pn.setCondition(data.condition);
    pn.setParens(data.lp - pos, data.rp - pos);
    pn.setThenPart(ifTrue);
    pn.setElsePart(ifFalse);
    pn.setElsePosition(elsePos);
    pn.setLineno(lineno);
    return pn;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:23,代码来源:Parser.java

示例6: whileLoop

import org.mozilla.javascript.ast.AstNode; //导入依赖的package包/类
private WhileLoop whileLoop()
    throws IOException
{
    if (currentToken != Token.WHILE) codeBug();
    consumeToken();
    int pos = ts.tokenBeg;
    WhileLoop pn = new WhileLoop(pos);
    pn.setLineno(ts.lineno);
    enterLoop(pn);
    try {
        ConditionData data = condition();
        pn.setCondition(data.condition);
        pn.setParens(data.lp - pos, data.rp - pos);
        AstNode body = statement();
        pn.setLength(getNodeEnd(body) - pos);
        pn.setBody(body);
    } finally {
        exitLoop();
    }
    return pn;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:22,代码来源:Parser.java

示例7: throwStatement

import org.mozilla.javascript.ast.AstNode; //导入依赖的package包/类
private ThrowStatement throwStatement()
    throws IOException
{
    if (currentToken != Token.THROW) codeBug();
    consumeToken();
    int pos = ts.tokenBeg, lineno = ts.lineno;
    if (peekTokenOrEOL() == Token.EOL) {
        // ECMAScript does not allow new lines before throw expression,
        // see bug 256617
        reportError("msg.bad.throw.eol");
    }
    AstNode expr = expr();
    ThrowStatement pn = new ThrowStatement(pos, getNodeEnd(expr), expr);
    pn.setLineno(lineno);
    return pn;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:17,代码来源:Parser.java

示例8: attributeAccess

import org.mozilla.javascript.ast.AstNode; //导入依赖的package包/类
/**
 * Xml attribute expression:<p>
 *   {@code @attr}, {@code @ns::attr}, {@code @ns::*}, {@code @ns::*},
 *   {@code @*}, {@code @*::attr}, {@code @*::*}, {@code @ns::[expr]},
 *   {@code @*::[expr]}, {@code @[expr]} <p>
 * Called if we peeked an '@' token.
 */
private AstNode attributeAccess()
    throws IOException
{
    int tt = nextToken(), atPos = ts.tokenBeg;

    switch (tt) {
      // handles: @name, @ns::name, @ns::*, @ns::[expr]
      case Token.NAME:
          return propertyName(atPos, ts.getString(), 0);

      // handles: @*, @*::name, @*::*, @*::[expr]
      case Token.MUL:
          saveNameTokenData(ts.tokenBeg, "*", ts.lineno);
          return propertyName(atPos, "*", 0);

      // handles @[expr]
      case Token.LB:
          return xmlElemRef(atPos, null, -1);

      default:
          reportError("msg.no.name.after.xmlAttr");
          return makeErrorNode();
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:32,代码来源:Parser.java

示例9: xmlElemRef

import org.mozilla.javascript.ast.AstNode; //导入依赖的package包/类
/**
 * Parse the [expr] portion of an xml element reference, e.g.
 * @[expr], @*::[expr], or ns::[expr].
 */
private XmlElemRef xmlElemRef(int atPos, Name namespace, int colonPos)
    throws IOException
{
    int lb = ts.tokenBeg, rb = -1, pos = atPos != -1 ? atPos : lb;
    AstNode expr = expr();
    int end = getNodeEnd(expr);
    if (mustMatchToken(Token.RB, "msg.no.bracket.index")) {
        rb = ts.tokenBeg;
        end = ts.tokenEnd;
    }
    XmlElemRef ref = new XmlElemRef(pos, end - pos);
    ref.setNamespace(namespace);
    ref.setColonPos(colonPos);
    ref.setAtPos(atPos);
    ref.setExpression(expr);
    ref.setBrackets(lb, rb);
    return ref;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:23,代码来源:Parser.java

示例10: name

import org.mozilla.javascript.ast.AstNode; //导入依赖的package包/类
private AstNode name(int ttFlagged, int tt) throws IOException {
    String nameString = ts.getString();
    int namePos = ts.tokenBeg, nameLineno = ts.lineno;
    if (0 != (ttFlagged & TI_CHECK_LABEL) && peekToken() == Token.COLON) {
        // Do not consume colon.  It is used as an unwind indicator
        // to return to statementHelper.
        Label label = new Label(namePos, ts.tokenEnd - namePos);
        label.setName(nameString);
        label.setLineno(ts.lineno);
        return label;
    }
    // Not a label.  Unfortunately peeking the next token to check for
    // a colon has biffed ts.tokenBeg, ts.tokenEnd.  We store the name's
    // bounds in instance vars and createNameNode uses them.
    saveNameTokenData(namePos, nameString, nameLineno);

    if (compilerEnv.isXmlAvailable()) {
        return propertyName(-1, nameString, 0);
    } else {
        return createNameNode(true, Token.NAME);
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:23,代码来源:Parser.java

示例11: getPropertyNames

import org.mozilla.javascript.ast.AstNode; //导入依赖的package包/类
public List<String> getPropertyNames(){
	List<String> propNames = new ArrayList<String>();
	ObjectLiteral ol = (ObjectLiteral)this.getNode();
	for (ObjectProperty op : ol.getElements()){
		AstNode left = op.getLeft();
		if (left instanceof Name){
			propNames.add(((Name)left).getIdentifier());
		} else if (left instanceof StringLiteral){
			String identifier = ConstraintGenUtil.removeQuotes(((StringLiteral)left).toSource());
			propNames.add(identifier);
		} else {
			System.err.println(left.getClass().getName() + " " + left.toSource());
			throw new Error("unsupported case in getPropertyNames()");
		}
	}
	return propNames;
}
 
开发者ID:Samsung,项目名称:SJS,代码行数:18,代码来源:MapLiteralTerm.java

示例12: findOrCreateFunctionTerm

import org.mozilla.javascript.ast.AstNode; //导入依赖的package包/类
/**
 * Find or create a term representing a FunctionNode (function definition). The
 * created FunctionTerm provides methods for accessing the terms corresponding to the
 * function's parameters and return type. The boolean flag isMethod indicates whether
 * the function is a method.
 */
public FunctionTerm findOrCreateFunctionTerm(FunctionNode fun, FunctionTerm.FunctionKind funType) {
    if (!functionTerms.containsKey(fun)){
        FunctionTerm var = new FunctionTerm(fun, funType);
        var.setReturnVariable(this.findOrCreateFunctionReturnTerm(var, fun.getParamCount()));
        List<AstNode> params = fun.getParams();
        List<NameDeclarationTerm> paramVars = new ArrayList<NameDeclarationTerm>();
        for (int i=0; i < params.size(); i++){
            AstNode param = params.get(i);
            if (param instanceof Name){
                NameDeclarationTerm paramCV = this.findOrCreateNameDeclarationTerm((Name)param);
                paramVars.add(paramCV);
            } else {
                throw new Error("unimplemented case in findOrCreateFunctionVariable");
            }
        }
        var.setParamVariables(paramVars);
        functionTerms.put(fun, var);
    }
    return functionTerms.get(fun);
}
 
开发者ID:Samsung,项目名称:SJS,代码行数:27,代码来源:ConstraintFactory.java

示例13: visit

import org.mozilla.javascript.ast.AstNode; //导入依赖的package包/类
@Override
public boolean visit(AstNode node) {
	if (node instanceof PropertyGet){
		PropertyGet pg = (PropertyGet)node;
		AstNode target = pg.getTarget();
		String propName = pg.getProperty().getIdentifier();
		if (target instanceof KeywordLiteral && ConstraintGenUtil.isThis(target)){
			if (node.getParent() instanceof Assignment){
				Assignment a = (Assignment)node.getParent();
				if (a.getLeft() == node){
					writtenProperties.add(propName);
				} else {
					readProperties.add(propName);
				}
			} else {
				readProperties.add(propName);
			}
			readProperties.removeAll(writtenProperties); // if something is read and written, it should only be in the written set
		}
	} else if (node instanceof FunctionNode) {
	    // don't recurse into nested function body
	    return false;
	}
	return true;
}
 
开发者ID:Samsung,项目名称:SJS,代码行数:26,代码来源:ConstraintGenUtil.java

示例14: getPropertyNames

import org.mozilla.javascript.ast.AstNode; //导入依赖的package包/类
public static List<String> getPropertyNames(ObjectLiteral ol){
	List<String> propNames = new ArrayList<String>();
	for (ObjectProperty op : ol.getElements()){
		AstNode left = op.getLeft();
		if (left instanceof Name){
			propNames.add(((Name)left).getIdentifier());
		} else if (left instanceof StringLiteral){
			String identifier = ConstraintGenUtil.removeQuotes(((StringLiteral)left).toSource());
			propNames.add(identifier);
		} else {
			System.err.println(left.getClass().getName() + " " + left.toSource());
			throw new Error("unsupported case in getPropertyNames()");
		}
	}
	return propNames;
}
 
开发者ID:Samsung,项目名称:SJS,代码行数:17,代码来源:ConstraintGenUtil.java

示例15: createFunctionNodeConstraints

import org.mozilla.javascript.ast.AstNode; //导入依赖的package包/类
/**
 * For a function definition (FunctionNode), create constraints equating its
 * parameters to param(.) variables, and equate the type of the function name
 * to the type of the entire function definition.
 */
private void createFunctionNodeConstraints(FunctionNode node, ITypeTerm funTerm){
	// if the function has a name, equate the types of the function node and the function name
	Name funName = node.getFunctionName();
	if (funName != null){
		ITypeTerm nameTerm = findOrCreateNameDeclarationTerm(funName);
		addSubTypeConstraint(funTerm, nameTerm, node.getLineno(), null);
	}

	// for a function f with params v1, v2, ... generate param(|f|,i) = |v_i|
	for (int i=0; i < node.getParamCount(); i++){
		AstNode param = node.getParams().get(i);
		if (param instanceof Name){
			Name name = (Name)param;
			ITypeTerm nameVar = findOrCreateNameDeclarationTerm(name);
			ITypeTerm paramVar = findOrCreateFunctionParamTerm(funTerm, i, node.getParamCount(), node.getLineno());
			addTypeEqualityConstraint(paramVar, nameVar, param.getLineno(), null);
		} else {
			error("createFunctionNodeConstraints: unexpected parameter type", node);
		}
	}

}
 
开发者ID:Samsung,项目名称:SJS,代码行数:28,代码来源:ConstraintVisitor.java


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