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


Java VariableDeclarator类代码示例

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


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

示例1: visit

import org.walkmod.javalang.ast.body.VariableDeclarator; //导入依赖的package包/类
@Override
public void visit(FieldDeclaration n, A arg) {
    List<VariableDeclarator> vds = n.getVariables();
    List<FieldSymbolData> result = new LinkedList<FieldSymbolData>();
    SymbolType thisType = symbolTable.getType("this", ReferenceType.VARIABLE);
    for (VariableDeclarator vd : vds) {
        String name = vd.getId().getName();
        SymbolType st = symbolTable.getType(name, ReferenceType.VARIABLE).clone();
        try {
            st.setField(thisType.getClazz().getDeclaredField(name));
        } catch (Exception e) {
            throw new NoSuchExpressionTypeException(
                    "Ops! We can't find the field " + name + " in " + thisType.getClazz().getName(), e);
        }
        result.add(st);
    }
    n.setFieldsSymbolData(result);
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:19,代码来源:TypeVisitorAdapter.java

示例2: removeVariable

import org.walkmod.javalang.ast.body.VariableDeclarator; //导入依赖的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

示例3: removeField

import org.walkmod.javalang.ast.body.VariableDeclarator; //导入依赖的package包/类
public void removeField(Symbol<?> symbol, SymbolTable table, FieldDeclaration fd) {

        int modifiers = fd.getModifiers();
        if (ModifierSet.isPrivate(modifiers)) {
            List<VariableDeclarator> vds = fd.getVariables();
            if (vds != null) {
                Iterator<VariableDeclarator> it = vds.iterator();
                while (it.hasNext()) {
                    VariableDeclarator vd = it.next();
                    if (vd.getId().getName().equals(symbol.getName())) {
                        Expression init = vd.getInit();
                        if (isReadOnlyExpression(init)) {
                            if (vds.size() == 1) {
                                remove(fd);
                            } else {
                                it.remove();
                            }
                        }
                    }
                }
            }
        }
    }
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:24,代码来源:RemoveUnusedSymbolsAction.java

示例4: split

import org.walkmod.javalang.ast.body.VariableDeclarator; //导入依赖的package包/类
private List<FieldDeclaration> split(FieldDeclaration fieldDeclaration) {
    List<FieldDeclaration> res = new LinkedList<FieldDeclaration>();
    if (fieldDeclaration.getVariables().size() > 1) {
        for (VariableDeclarator vd : fieldDeclaration.getVariables()) {
            FieldDeclaration fd = new FieldDeclaration();
            fd.setAnnotations(fieldDeclaration.getAnnotations());
            fd.setJavaDoc(fieldDeclaration.getJavaDoc());
            fd.setModifiers(fieldDeclaration.getModifiers());
            fd.setType(fieldDeclaration.getType());
            fd.setBeginLine(fieldDeclaration.getBeginLine());
            fd.setBeginColumn(fieldDeclaration.getBeginColumn());
            fd.setEndColumn(vd.getEndColumn());
            fd.setEndLine(vd.getEndLine());
            List<VariableDeclarator> vdList = new LinkedList<VariableDeclarator>();
            vdList.add(vd);
            fd.setVariables(vdList);
            res.add(fd);
        }
    } else {
        res.add(fieldDeclaration);
    }
    return res;
}
 
开发者ID:rpau,项目名称:javalang,代码行数:24,代码来源:FieldDeclarationPolicy.java

示例5: getVariableDefinitions

import org.walkmod.javalang.ast.body.VariableDeclarator; //导入依赖的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

示例6: replaceChildNode

import org.walkmod.javalang.ast.body.VariableDeclarator; //导入依赖的package包/类
@Override
public boolean replaceChildNode(Node oldChild, Node newChild) {
    boolean updated = false;
    if (oldChild == type) {
        type = (Type) newChild;
        updated = true;
    }
    if (!updated && annotations != null) {
        List<AnnotationExpr> auxAnnotations = new LinkedList<AnnotationExpr>(annotations);
        updated = replaceChildNodeInList(oldChild, newChild, auxAnnotations);
        if (updated) {
            annotations = auxAnnotations;
        }

    }
    if (!updated && vars != null) {
        List<VariableDeclarator> auxVars = new LinkedList<VariableDeclarator>(vars);

        updated = replaceChildNodeInList(oldChild, newChild, auxVars);

        if (updated) {
            vars = auxVars;
        }
    }
    return updated;
}
 
开发者ID:rpau,项目名称:javalang,代码行数:27,代码来源:VariableDeclarationExpr.java

示例7: visit

import org.walkmod.javalang.ast.body.VariableDeclarator; //导入依赖的package包/类
public void visit(FieldDeclaration n, Object arg) {
    prepareComments(n);
    printPreviousComments(n, arg);
    JavadocComment comment = n.getJavaDoc();
    printJavadoc(comment, arg);

    printPreviousComments(n, arg);
    printMemberAnnotations(n.getAnnotations(), arg);
    Type type = n.getType();
    printPreviousComments(type, arg);

    printModifiers(n.getModifiers());
    type.accept(this, arg);
    printer.print(" ");
    for (Iterator<VariableDeclarator> i = n.getVariables().iterator(); i.hasNext();) {
        VariableDeclarator var = i.next();
        var.accept(this, arg);
        if (i.hasNext()) {
            printer.print(", ");
        }
    }
    printer.print(";");
}
 
开发者ID:rpau,项目名称:javalang,代码行数:24,代码来源:DumpVisitor.java

示例8: visit

import org.walkmod.javalang.ast.body.VariableDeclarator; //导入依赖的package包/类
public Node visit(FieldDeclaration n, A arg) {
    if (n.getJavaDoc() != null) {
        n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, 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> variables = n.getVariables();
    for (int i = 0; i < variables.size(); i++) {
        variables.set(i, (VariableDeclarator) variables.get(i).accept(this, arg));
    }
    removeNulls(variables);
    return n;
}
 
开发者ID:rpau,项目名称:javalang,代码行数:20,代码来源:ModifierVisitorAdapter.java

示例9: compare

import org.walkmod.javalang.ast.body.VariableDeclarator; //导入依赖的package包/类
@Override
public int compare(FieldDeclaration fd1, FieldDeclaration fd2) {
    if (fd1.getType().equals(fd2.getType())) {
        List<VariableDeclarator> vds = fd1.getVariables();
        List<VariableDeclarator> vds2 = fd2.getVariables();
        if (vds == null || vds.size() == 0 || vds2 == null || vds2.size() == 0) {
            return -1;
        }
        if (vds.size() == vds2.size()) {
            if (vds.containsAll(vds2)) {
                return 0;
            }
        }
    }
    return -1;
}
 
开发者ID:rpau,项目名称:javalang,代码行数:17,代码来源:FieldDeclarationComparator.java

示例10: VariableDeclarator

import org.walkmod.javalang.ast.body.VariableDeclarator; //导入依赖的package包/类
final public VariableDeclarator VariableDeclarator() throws ParseException {
    VariableDeclaratorId id;
    Expression init = null;
    id = VariableDeclaratorId();
    switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
        case ASSIGN:
            jj_consume_token(ASSIGN);
            init = VariableInitializer();
            break;
        default:
            jj_la1[38] = jj_gen;;
    }
    {
        if (true)
            return new VariableDeclarator(id.getBeginLine(), id.getBeginColumn(), token.endLine, token.endColumn,
                    id, init);
    }
    throw new Error("Missing return statement in function");
}
 
开发者ID:rpau,项目名称:javalang,代码行数:20,代码来源:ASTParser.java

示例11: visit

import org.walkmod.javalang.ast.body.VariableDeclarator; //导入依赖的package包/类
public void visit(VariableDeclarator n, VisitorContext ctx) {
    Object o = ctx.get(NODE_TO_COMPARE_KEY);
    if (o != null && o instanceof VariableDeclarator) {
        boolean backup = isUpdated();
        setIsUpdated(false);
        VariableDeclarator aux = (VariableDeclarator) o;
        inferASTChanges(n.getId(), aux.getId());
        inferASTChanges(n.getInit(), aux.getInit());
        if (!isUpdated()) {
            increaseUnmodifiedNodes(VariableDeclarator.class);
        } else {
            increaseUpdatedNodes(VariableDeclarator.class);
        }
        setIsUpdated(backup || isUpdated());
    } else if (o != null) {
        setIsUpdated(true);
        applyUpdate(n, (Node) o);
    }
}
 
开发者ID:walkmod,项目名称:walkmod-javalang-plugin,代码行数:20,代码来源:ChangeLogVisitor.java

示例12: testInnerComments

import org.walkmod.javalang.ast.body.VariableDeclarator; //导入依赖的package包/类
@Test
public void testInnerComments() throws ParseException {
   String code = "public class B { private /*final*/ int name;}";
   DefaultJavaParser parser = new DefaultJavaParser();
   CompilationUnit cu = parser.parse(code, false);
   CompilationUnit cu2 = parser.parse(code, false);

   FieldDeclaration fd = (FieldDeclaration) cu.getTypes().get(0).getMembers().get(0);
   List<VariableDeclarator> vds = fd.getVariables();
   vds.add(new VariableDeclarator(new VariableDeclaratorId("surname")));
   Comment c = cu.getComments().get(0);
   c.setContent("static");

   List<Action> actions = getActions(cu2, cu);
   Assert.assertEquals(1, actions.size());

   assertCode(actions, code, "public class B { /*static*/private int name, surname;}");

}
 
开发者ID:walkmod,项目名称:walkmod-javalang-plugin,代码行数:20,代码来源:ChangeLogVisitorTest.java

示例13: visit

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

        if (n.getInit() != null) {
            Symbol<?> aux = symbolTable.findSymbol(n.getId().getName(), ReferenceType.VARIABLE);
            Scope scope = new Scope(aux);
            aux.setInnerScope(scope);
            symbolTable.pushScope(scope);
            n.getInit().accept(expressionTypeAnalyzer, arg);
            symbolTable.popScope();
        }
    }
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:12,代码来源:SymbolVisitorAdapter.java

示例14: doPop

import org.walkmod.javalang.ast.body.VariableDeclarator; //导入依赖的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

示例15: VariableDeclarationExpr

import org.walkmod.javalang.ast.body.VariableDeclarator; //导入依赖的package包/类
public VariableDeclarationExpr(int beginLine, int beginColumn, int endLine, int endColumn, int modifiers,
        List<AnnotationExpr> annotations, Type type, List<VariableDeclarator> vars) {
    super(beginLine, beginColumn, endLine, endColumn);
    this.modifiers = modifiers;
    setAnnotations(annotations);
    setType(type);
    setVars(vars);
}
 
开发者ID:rpau,项目名称:javalang,代码行数:9,代码来源:VariableDeclarationExpr.java


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