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


Java VariableDeclaration类代码示例

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


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

示例1: print

import org.mozilla.javascript.ast.VariableDeclaration; //导入依赖的package包/类
private void print(VariableDeclaration node) throws IOException {
    switch (node.getType()) {
        case Token.VAR:
            writer.append("var ");
            break;
        case Token.LET:
            writer.append("let ");
            break;
        case Token.CONST:
            writer.append("const ");
            break;
        default:
            break;
    }
    print(node.getVariables().get(0));
    for (int i = 1; i < node.getVariables().size(); ++i) {
        writer.append(',').ws();
        print(node.getVariables().get(i));
    }
    if (node.isStatement()) {
        writer.append(';');
    }
}
 
开发者ID:konsoletyper,项目名称:teavm,代码行数:24,代码来源:AstWriter.java

示例2: transformForInLoop

import org.mozilla.javascript.ast.VariableDeclaration; //导入依赖的package包/类
private Node transformForInLoop(ForInLoop loop) {
    decompiler.addToken(Token.FOR);
    if (loop.isForEach())
        decompiler.addName("each ");
    decompiler.addToken(Token.LP);

    loop.setType(Token.LOOP);
    pushScope(loop);
    try {
        int declType = -1;
        AstNode iter = loop.getIterator();
        if (iter instanceof VariableDeclaration) {
            declType = ((VariableDeclaration)iter).getType();
        }
        Node lhs = transform(iter);
        if (loop.isForOf()) {
            decompiler.addName("of ");
        } else {
            decompiler.addToken(Token.IN);
        }
        Node obj = transform(loop.getIteratedObject());
        decompiler.addToken(Token.RP);
        decompiler.addEOL(Token.LC);
        Node body = transform(loop.getBody());
        decompiler.addEOL(Token.RC);
        return createForIn(declType, loop, lhs, obj, body,
                           loop.isForEach(), loop.isForOf());
    } finally {
        popScope();
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:32,代码来源:IRFactory.java

示例3: transformVariables

import org.mozilla.javascript.ast.VariableDeclaration; //导入依赖的package包/类
private Node transformVariables(VariableDeclaration node) {
    decompiler.addToken(node.getType());
    transformVariableInitializers(node);

    // Might be most robust to have parser record whether it was
    // a variable declaration statement, possibly as a node property.
    AstNode parent = node.getParent();
    if (!(parent instanceof Loop)
        && !(parent instanceof LetNode)) {
        decompiler.addEOL(Token.SEMI);
    }
    return node;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:14,代码来源:IRFactory.java

示例4: processForInLoop

import org.mozilla.javascript.ast.VariableDeclaration; //导入依赖的package包/类
/**
 * generate constraints for a for-in loop
 */
private void processForInLoop(ForInLoop loop) {
	AstNode it = loop.getIterator();
	AstNode obj = loop.getIteratedObject();
	ITypeTerm objTerm = processExpression(obj);
	MapType mapType = new MapType(factory.freshTypeVar());
       addSubTypeConstraint(
               objTerm,
               findOrCreateTypeTerm(mapType, loop.getLineno()),
               loop.getLineno(),
               (solution) -> typeEqualityError("for-in loop can only iterate over map objects; " + obj.toSource() + " is not a map",
                       solution.typeOfTerm(objTerm), mapType, locationOf(obj)));
	if (it instanceof VariableDeclaration){
		VariableDeclaration vd = (VariableDeclaration)it;
		for (VariableInitializer vi : vd.getVariables()){
			AstNode target = vi.getTarget();
			if (target instanceof Name){
				ITypeTerm leftTerm = findOrCreateNameDeclarationTerm((Name)target);
                   addSubTypeConstraint(
                           leftTerm,
                           findOrCreateTypeTerm(StringType.make(),
                                   loop.getLineno()),
                           loop.getLineno(),
                           (solution) -> typeEqualityError(
                                   "loop variable " + it.toSource() + " of for-in loop must have string type",
                                   solution.typeOfTerm(leftTerm),
                                   StringType.make(), locationOf(it)));
			}
		}
	} else {
		error("unhandled type of iterator in for-in loop: " + it.getClass().getName(), it);
	}
}
 
开发者ID:Samsung,项目名称:SJS,代码行数:36,代码来源:ConstraintVisitor.java

示例5: visit

import org.mozilla.javascript.ast.VariableDeclaration; //导入依赖的package包/类
@Override
public boolean visit(AstNode node) {

	if (node==null) {
		return false;
	}

	int nodeType = node.getType();
	switch (nodeType) {

		case Token.SCRIPT: // AstRoot
			curScopeTreeNode = root;
			return true;

		case Token.FUNCTION:
			FunctionNode fn = (FunctionNode)node;
			return visitFunction(fn);

		case Token.VAR:
			VariableDeclaration varDec = (VariableDeclaration)node;
			return visitVariableDeclaration(varDec);

		case Token.BLOCK:
			return true;

		case Token.EXPR_RESULT:
			ExpressionStatement exprStmt = (ExpressionStatement)node;
			return visitExpressionStatement(exprStmt);

	}

	return false; // Unhandled node type

}
 
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:35,代码来源:JavaScriptOutlineTreeGenerator.java

示例6: processVariableNode

import org.mozilla.javascript.ast.VariableDeclaration; //导入依赖的package包/类
/**
 * Extract variable from node and add to code block
 */
private void processVariableNode(Node child, CodeBlock block,
		Set<Completion> set, String entered, int offset) {
	//check block can resolve variable or is pre-processing variables
	if(block.contains(dot) || isPreProcessing())
	{
		VariableDeclaration varDec = (VariableDeclaration) child;
		List<VariableInitializer> vars = varDec.getVariables();
		for (VariableInitializer var : vars) {
			extractVariableFromNode(var, block, offset);
		}
	}
}
 
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:16,代码来源:JavaScriptAstParser.java

示例7: transformVariableInitializers

import org.mozilla.javascript.ast.VariableDeclaration; //导入依赖的package包/类
private Node transformVariableInitializers(VariableDeclaration node) {
    List<VariableInitializer> vars = node.getVariables();
    int size = vars.size(), i = 0;
    for (VariableInitializer var : vars) {
        AstNode target = var.getTarget();
        AstNode init = var.getInitializer();

        Node left = null;
        if (var.isDestructuring()) {
            decompile(target);  // decompile but don't transform
            left = target;
        } else {
            left = transform(target);
        }

        Node right = null;
        if (init != null) {
            decompiler.addToken(Token.ASSIGN);
            right = transform(init);
        }

        if (var.isDestructuring()) {
            if (right == null) {  // TODO:  should this ever happen?
                node.addChildToBack(left);
            } else {
                Node d = createDestructuringAssignment(node.getType(),
                                                       left, right);
                node.addChildToBack(d);
            }
        } else {
            if (right != null) {
                left.addChildToBack(right);
            }
            node.addChildToBack(left);
        }
        if (i++ < size-1) {
            decompiler.addToken(Token.COMMA);
        }
    }
    return node;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:42,代码来源:IRFactory.java

示例8: let

import org.mozilla.javascript.ast.VariableDeclaration; //导入依赖的package包/类
private AstNode let(boolean isStatement, int pos)
    throws IOException
{
    LetNode pn = new LetNode(pos);
    pn.setLineno(ts.lineno);
    if (mustMatchToken(Token.LP, "msg.no.paren.after.let"))
        pn.setLp(ts.tokenBeg - pos);
    pushScope(pn);
    try {
        VariableDeclaration vars = variables(Token.LET, ts.tokenBeg, isStatement);
        pn.setVariables(vars);
        if (mustMatchToken(Token.RP, "msg.no.paren.let")) {
            pn.setRp(ts.tokenBeg - pos);
        }
        if (isStatement && peekToken() == Token.LC) {
            // let statement
            consumeToken();
            int beg = ts.tokenBeg;  // position stmt at LC
            AstNode stmt = statements();
            mustMatchToken(Token.RC, "msg.no.curly.let");
            stmt.setLength(ts.tokenEnd - beg);
            pn.setLength(ts.tokenEnd - pos);
            pn.setBody(stmt);
            pn.setType(Token.LET);
        } else {
            // let expression
            AstNode expr = expr();
            pn.setLength(getNodeEnd(expr) - pos);
            pn.setBody(expr);
            if (isStatement) {
                // let expression in statement context
                ExpressionStatement es =
                        new ExpressionStatement(pn, !insideFunction());
                es.setLineno(pn.getLineno());
                return es;
            }
        }
    } finally {
        popScope();
    }
    return pn;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:43,代码来源:Parser.java

示例9: visit

import org.mozilla.javascript.ast.VariableDeclaration; //导入依赖的package包/类
/**
 * This method generates constraints for all relevant AstNodes. It delegates its work to various
 * processXXX() methods that handle AstNodes of type XXX.
 */
@Override
public boolean visit(AstNode node) {
	if (node instanceof VariableInitializer){
		processVariableInitializer(node);
	} else if (node instanceof ReturnStatement){
		processReturnStatement((ReturnStatement)node);
	} else if (node instanceof ExpressionStatement){
		processExpressionStatement((ExpressionStatement)node);
	} else if (node instanceof ForLoop){
		processForLoop((ForLoop)node);
	} else if (node instanceof ForInLoop){
		processForInLoop((ForInLoop)node);
	}else if (node instanceof WhileLoop){
		processWhileLoop((WhileLoop)node);
	} else if (node instanceof DoLoop){
		processDoLoop((DoLoop)node);
	} else if (node instanceof NewExpression){
		processNewExpression((NewExpression)node);
	} else if (node instanceof FunctionCall){
		processFunctionCall((FunctionCall)node);
	} else if (node instanceof ElementGet){
		processElementGet((ElementGet)node);
	} else if (node instanceof FunctionNode){
		processFunctionNode((FunctionNode)node);
	} else if (node instanceof IfStatement){
		processIfStatement((IfStatement)node);
	} else if (node instanceof KeywordLiteral){
		processKeywordLiteral((KeywordLiteral)node);
	} else if (node instanceof SwitchStatement){
		processSwitchStatement((SwitchStatement)node);
	} else if (node instanceof SwitchCase){
		processSwitchCase((SwitchCase)node);
	} else if ((node instanceof AstRoot) || //AstRoot: no constraints need to be generated
		(node instanceof BreakStatement) || //BreakStatement: no constraints need to be generated
		(node instanceof VariableDeclaration) || //VariableDeclaration: we generate constraints for its constituent VariableInitializer nodes
		(node instanceof Name) || //Name: generate constraints for complex expressions that refer to names
		(node instanceof NumberLiteral) || //NumberLiteral: generate constraints for complex expressions that refer to names
		(node instanceof StringLiteral) || //StringLiteral: generate constraints for complex expressions that refer to names
		(node instanceof Assignment) || // Assignment is a special case of InfixExpression
		(node instanceof ArrayLiteral) ||
		(node instanceof UnaryExpression) ||
		(node instanceof InfixExpression) ||
		(node instanceof ConditionalExpression) ||
		(node instanceof ParenthesizedExpression) ||
		(node instanceof EmptyExpression) ||
		(node instanceof ObjectLiteral) ||
		(node instanceof EmptyStatement) ||
		(node instanceof ContinueStatement) ||
		(node instanceof Scope) ||
		(node instanceof Block)){ // // occurs in programs with for loops -- nothing to be done here?
		/* nothing */
	} else {
		error("unsupported node " + node.toSource().trim() + " of type: " + node.getClass().getName(), node);
	}
	return true;
}
 
开发者ID:Samsung,项目名称:SJS,代码行数:61,代码来源:ConstraintVisitor.java


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