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


Java FieldDeclaration.getVariables方法代码示例

本文整理汇总了Java中org.walkmod.javalang.ast.body.FieldDeclaration.getVariables方法的典型用法代码示例。如果您正苦于以下问题:Java FieldDeclaration.getVariables方法的具体用法?Java FieldDeclaration.getVariables怎么用?Java FieldDeclaration.getVariables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.walkmod.javalang.ast.body.FieldDeclaration的用法示例。


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

示例1: visit

import org.walkmod.javalang.ast.body.FieldDeclaration; //导入方法依赖的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: removeField

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

示例3: apply

import org.walkmod.javalang.ast.body.FieldDeclaration; //导入方法依赖的package包/类
@Override
public void apply(FieldDeclaration remoteObject, List<FieldDeclaration> localList,
        List<FieldDeclaration> resultList) {
    List<FieldDeclaration> localFields = new LinkedList<FieldDeclaration>();
    if (localList != null) {
        for (FieldDeclaration localField : localList) {
            localFields.addAll(split(localField));
        }
    }
    if (remoteObject.getVariables() != null && remoteObject.getVariables().size() > 1) {
        List<FieldDeclaration> remoteFields = split(remoteObject);
        for (FieldDeclaration remoteField : remoteFields) {
            super.apply(remoteField, localFields, resultList);
        }
    } else {
        super.apply(remoteObject, localFields, resultList);
    }
}
 
开发者ID:rpau,项目名称:javalang,代码行数:19,代码来源:FieldDeclarationPolicy.java

示例4: split

import org.walkmod.javalang.ast.body.FieldDeclaration; //导入方法依赖的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: visit

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

示例6: compare

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

示例7: testInnerComments

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

示例8: visit

import org.walkmod.javalang.ast.body.FieldDeclaration; //导入方法依赖的package包/类
public R visit(FieldDeclaration n, A arg) {
    if (n.getJavaDoc() != null) {
        n.getJavaDoc().accept(this, arg);
    }
    if (n.getAnnotations() != null) {
        for (AnnotationExpr a : n.getAnnotations()) {
            a.accept(this, arg);
        }
    }
    n.getType().accept(this, arg);
    for (VariableDeclarator var : n.getVariables()) {
        var.accept(this, arg);
    }
    return null;
}
 
开发者ID:rpau,项目名称:javalang,代码行数:16,代码来源:GenericVisitorAdapter.java

示例9: visit

import org.walkmod.javalang.ast.body.FieldDeclaration; //导入方法依赖的package包/类
public void visit(FieldDeclaration n, A arg) {
    if (n.getJavaDoc() != null) {
        n.getJavaDoc().accept(this, arg);
    }
    if (n.getAnnotations() != null) {
        for (AnnotationExpr a : n.getAnnotations()) {
            a.accept(this, arg);
        }
    }
    n.getType().accept(this, arg);
    for (VariableDeclarator var : n.getVariables()) {
        var.accept(this, arg);
    }
}
 
开发者ID:rpau,项目名称:javalang,代码行数:15,代码来源:VoidVisitorAdapter.java

示例10: loadFields

import org.walkmod.javalang.ast.body.FieldDeclaration; //导入方法依赖的package包/类
private void loadFields(List<BodyDeclaration> members, Scope scope) {
    if (!scope.hasFieldsLoaded()) {
        if (members != null) {

            for (BodyDeclaration member : members) {
                if (member instanceof FieldDeclaration) {

                    FieldDeclaration fd = (FieldDeclaration) member;
                    Type type = fd.getType();
                    List<SymbolAction> actions = null;

                    Symbol<?> root = table.getScopes().peek().getRootSymbol();
                    if (root != null) {
                        Node location = root.getLocation();
                        if (location != null) {
                            if (location == member.getParentNode()) {
                                if (actionProvider != null) {
                                    actions = actionProvider.getActions(fd);
                                }
                            }
                        }
                    }

                    SymbolType resolvedType = ASTSymbolTypeResolver.getInstance().valueOf(type);

                    if (resolvedType == null) {
                        resolvedType = new SymbolType(Object.class);
                    }
                    type.setSymbolData(resolvedType);

                    for (VariableDeclarator var : fd.getVariables()) {
                        SymbolType symType = resolvedType.clone();
                        if (symType.getArrayCount() == 0) {
                            symType.setArrayCount(var.getId().getArrayCount());
                        }

                        table.pushSymbol(var.getId().getName(), ReferenceType.VARIABLE, symType, var, actions,
                                true);

                    }

                }
            }

        }
        scope.setHasFieldsLoaded(true);
    }
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:49,代码来源:LoadFieldDeclarationsAction.java


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