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


Java VariableDeclarationExpr类代码示例

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


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

示例1: removeVariable

import org.walkmod.javalang.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
public void removeVariable(Symbol<?> symbol, SymbolTable table, VariableDeclarationExpr vd) {

        List<VariableDeclarator> vds = vd.getVars();
        if (vds.size() == 1) {
            Expression init = vds.get(0).getInit();
            if (isReadOnlyExpression(init)) {
                remove(vd.getParentNode());
            }
        } else {
            Iterator<VariableDeclarator> it = vds.iterator();
            boolean finish = false;
            while (it.hasNext() && !finish) {
                VariableDeclarator current = it.next();
                if (current.getId().getName().equals(symbol.getName())) {
                    if (isReadOnlyExpression(current.getInit())) {
                        finish = true;
                        it.remove();
                    }
                }
            }
        }
    }
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:23,代码来源:RemoveUnusedSymbolsAction.java

示例2: replaceChildNode

import org.walkmod.javalang.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
@Override
public boolean replaceChildNode(Node oldChild, Node newChild) {
    boolean updated = false;
    if (oldChild == iterable) {
        setIterable((Expression) newChild);
        updated = true;
    }
    if (!updated) {
        if (oldChild == var) {
            setVariable((VariableDeclarationExpr) newChild);
            updated = true;
        }
        if (!updated) {
            if (oldChild == body) {
                setBody((Statement) newChild);
                updated = true;
            }
        }
    }
    return updated;
}
 
开发者ID:rpau,项目名称:javalang,代码行数:22,代码来源:ForeachStmt.java

示例3: getVariableDefinitions

import org.walkmod.javalang.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
@Override
public Map<String, SymbolDefinition> getVariableDefinitions() {
    Map<String, SymbolDefinition> result = ScopeAwareUtil.getVariableDefinitions(this);
    if (stmts != null) {
        for (Statement stmt : stmts) {
            if (stmt instanceof ExpressionStmt) {
                ExpressionStmt exprStmt = (ExpressionStmt) stmt;
                Expression expr = exprStmt.getExpression();
                if (expr instanceof VariableDeclarationExpr) {
                    VariableDeclarationExpr vde = (VariableDeclarationExpr) expr;
                    List<VariableDeclarator> vars = vde.getVars();
                    if (vars != null) {
                        for (VariableDeclarator vd : vars) {
                            result.put(vd.getSymbolName(), vd);
                        }
                    }
                }
            }
        }
    }
    return result;
}
 
开发者ID:rpau,项目名称:javalang,代码行数:23,代码来源:BlockStmt.java

示例4: visit

import org.walkmod.javalang.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
public Boolean visit(VariableDeclarationExpr n1, Node arg) {
    VariableDeclarationExpr n2 = (VariableDeclarationExpr) arg;
    if (n1.getModifiers() != n2.getModifiers()) {
        return Boolean.FALSE;
    }
    if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) {
        return Boolean.FALSE;
    }
    if (!nodeEquals(n1.getType(), n2.getType())) {
        return Boolean.FALSE;
    }
    if (!nodesEquals(n1.getVars(), n2.getVars())) {
        return Boolean.FALSE;
    }
    return Boolean.TRUE;
}
 
开发者ID:rpau,项目名称:javalang,代码行数:17,代码来源:EqualsVisitor.java

示例5: visit

import org.walkmod.javalang.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
public void visit(TryStmt n, A arg) {
    List<VariableDeclarationExpr> resources = n.getResources();
    if (resources != null) {
        for (VariableDeclarationExpr resource : resources) {
            resource.accept(this, arg);
        }
    }
    n.getTryBlock().accept(this, arg);
    if (n.getCatchs() != null) {
        for (CatchClause c : n.getCatchs()) {
            c.accept(this, arg);
        }
    }
    if (n.getFinallyBlock() != null) {
        n.getFinallyBlock().accept(this, arg);
    }
}
 
开发者ID:rpau,项目名称:javalang,代码行数:18,代码来源:VoidVisitorAdapter.java

示例6: visit

import org.walkmod.javalang.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
public Node visit(VariableDeclarationExpr n, A arg) {
    List<AnnotationExpr> annotations = n.getAnnotations();
    if (annotations != null) {
        for (int i = 0; i < annotations.size(); i++) {
            annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg));
        }
        removeNulls(annotations);
    }
    n.setType((Type) n.getType().accept(this, arg));
    List<VariableDeclarator> vars = n.getVars();
    for (int i = 0; i < vars.size(); i++) {
        vars.set(i, (VariableDeclarator) vars.get(i).accept(this, arg));
    }
    removeNulls(vars);
    return n;
}
 
开发者ID:rpau,项目名称:javalang,代码行数:17,代码来源:ModifierVisitorAdapter.java

示例7: Resources

import org.walkmod.javalang.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
final public List Resources() throws ParseException {
    List vars = new LinkedList();
    VariableDeclarationExpr var;
    /*this is a bit more lenient than we need to be, eg allowing access modifiers like private*/
    var = VariableDeclarationExpression();
    vars.add(var);
    label_68: while (true) {
        if (jj_2_43(2)) {
            ;
        } else {
            break label_68;
        }
        jj_consume_token(SEMICOLON);
        var = VariableDeclarationExpression();
        vars.add(var);
    }
    {
        if (true)
            return vars;
    }
    throw new Error("Missing return statement in function");
}
 
开发者ID:rpau,项目名称:javalang,代码行数:23,代码来源:ASTParser.java

示例8: visit

import org.walkmod.javalang.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
public void visit(VariableDeclarationExpr n, A arg) {

        Type type = n.getType();
        SymbolType st = (SymbolType) type.getSymbolData();
        if (st == null) {
            type.accept(expressionTypeAnalyzer, arg);
            st = (SymbolType) type.getSymbolData();
            if (st == null) {
                throw new NoSuchExpressionTypeException(
                        "The type of " + type.toString() + "(" + type.getClass().getName() + ") at ["
                                + type.getBeginLine() + "," + type.getBeginColumn() + "] is not found.");
            }
        }
        List<SymbolAction> actions = null;
        if (actionProvider != null) {
            actions = actionProvider.getActions(n);
        }
        List<VariableDeclarator> vars = n.getVars();
        for (VariableDeclarator vd : vars) {
            SymbolType aux = st.clone();
            if (vd.getId().getArrayCount() > 0) {
                aux.setArrayCount(vd.getId().getArrayCount());
            }
            symbolTable.pushSymbol(vd.getId().getName(), ReferenceType.VARIABLE, aux, vd, actions);
            Expression expr = vd.getInit();
            if (expr != null && !(n.getParentNode() instanceof ExpressionStmt)) { // e.g
                // TryStmt
                expr.accept(expressionTypeAnalyzer, arg);
            }
        }
    }
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:32,代码来源:SymbolVisitorAdapter.java

示例9: getActions

import org.walkmod.javalang.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
@Override
public List<SymbolAction> getActions(VariableDeclarationExpr n) {
    RemoveUnusedSymbolsAction unusedSymbols = new RemoveUnusedSymbolsAction(siblings.peek());
    actions = new LinkedList<SymbolAction>();
    actions.add(unusedSymbols);
    siblings.push(n.getVars());
    return actions;
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:9,代码来源:RemoveUnusedSymbolsProvider.java

示例10: visit

import org.walkmod.javalang.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
public void visit(VariableDeclarationExpr n, A arg) {

        if (semanticVisitor != null) {
            n.accept(semanticVisitor, arg);
        }
        super.visit(n, arg);
    }
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:8,代码来源:TypeVisitorAdapter.java

示例11: doPop

import org.walkmod.javalang.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
@Override
public void doPop(Symbol<?> symbol, SymbolTable table) {

    Node n = symbol.getLocation();
    if (n != null) {
        Map<String, Object> attrs = symbol.getAttributes();

        Object reads = attrs.get(ReferencesCounterAction.READS);

        Object writes = attrs.get(ReferencesCounterAction.WRITES);

        if (reads == null && writes == null) {
            if (n instanceof MethodDeclaration) {
                removeMethod(symbol, table);
            } else if (n instanceof VariableDeclarator) {
                Node parentNode = n.getParentNode();
                if (parentNode != null) {
                    if (parentNode instanceof FieldDeclaration) {
                        removeField(symbol, table, (FieldDeclaration) parentNode);
                    } else {
                        removeVariable(symbol, table, (VariableDeclarationExpr) parentNode);
                    }
                }

            } else if (n instanceof TypeDeclaration) {
                Symbol<?> thisSymbol = table.findSymbol("this", ReferenceType.VARIABLE);
                if (symbol.getReferenceType().equals(ReferenceType.TYPE) && thisSymbol != null
                        && !thisSymbol.getType().equals(symbol.getType())) {
                    removeType(symbol, table);
                }
            } else if (n instanceof ImportDeclaration) {
                removeImport(symbol, table);
            }
        }
    }
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:37,代码来源:RemoveUnusedSymbolsAction.java

示例12: testAnnonymousClass

import org.walkmod.javalang.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
@Test
public void testAnnonymousClass() throws Exception {
    String code =
            "public class Foo{ public void bar() { Foo o = new Foo() { private String name; public void bar() { System.out.println(\"hello\"); }};}}";
    CompilationUnit cu = run(code);
    MethodDeclaration md = (MethodDeclaration) cu.getTypes().get(0).getMembers().get(0);
    ExpressionStmt stmt = (ExpressionStmt) md.getBody().getStmts().get(0);
    VariableDeclarationExpr expr = (VariableDeclarationExpr) stmt.getExpression();
    ObjectCreationExpr oce = (ObjectCreationExpr) expr.getVars().get(0).getInit();
    // The name attribute should be removed
    FieldDeclaration fd = (FieldDeclaration) oce.getAnonymousClassBody().get(0);

    Assert.assertNull(fd.getUsages());
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:15,代码来源:SymbolVisitorAdapterTest.java

示例13: testArrayInitExprType

import org.walkmod.javalang.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
@Test
public void testArrayInitExprType() throws Exception {
    String code = "public class A { void foo() { int[] c = new int[10];}} ";
    CompilationUnit cu = run(code);
    MethodDeclaration md = (MethodDeclaration) cu.getTypes().get(0).getMembers().get(0);
    ExpressionStmt stmt = (ExpressionStmt) md.getBody().getStmts().get(0);
    VariableDeclarationExpr expr = (VariableDeclarationExpr) stmt.getExpression();
    ArrayCreationExpr array = (ArrayCreationExpr) expr.getVars().get(0).getInit();
    Assert.assertNotNull(array.getDimensions().get(0).getSymbolData());
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:11,代码来源:SymbolVisitorAdapterTest.java

示例14: testArrayInitExprType2

import org.walkmod.javalang.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
@Test
public void testArrayInitExprType2() throws Exception {
    String code = "public class A { private int x = 10; void foo() { int[] c = new int[x];}} ";
    CompilationUnit cu = runRemoveUnusedMembers(code);
    MethodDeclaration md = (MethodDeclaration) cu.getTypes().get(0).getMembers().get(1);
    ExpressionStmt stmt = (ExpressionStmt) md.getBody().getStmts().get(0);
    VariableDeclarationExpr expr = (VariableDeclarationExpr) stmt.getExpression();
    Assert.assertNotNull(expr.getVars().get(0).getInit().getSymbolData());
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:10,代码来源:SymbolVisitorAdapterTest.java

示例15: testMethodsThatReturnsMatrixs

import org.walkmod.javalang.ast.expr.VariableDeclarationExpr; //导入依赖的package包/类
@Test
public void testMethodsThatReturnsMatrixs() throws Exception {
    CompilationUnit cu = run(
            "public class A { char[][] bar(){ return new char[0][0]; } void foo(String s) { int i = bar().length; }}");
    MethodDeclaration md = (MethodDeclaration) cu.getTypes().get(0).getMembers().get(1);
    ExpressionStmt stmt = (ExpressionStmt) md.getBody().getStmts().get(0);
    VariableDeclarationExpr vexpr = (VariableDeclarationExpr) stmt.getExpression();
    Expression expr = vexpr.getVars().get(0).getInit();
    SymbolData sd = expr.getSymbolData();
    Assert.assertNotNull(sd);
    Assert.assertEquals("int", sd.getName());
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:13,代码来源:SymbolVisitorAdapterTest.java


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