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


Java BodyDeclaration类代码示例

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


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

示例1: loadThisSymbol

import org.walkmod.javalang.ast.body.BodyDeclaration; //导入依赖的package包/类
private void loadThisSymbol(ObjectCreationExpr n, A arg) {
    if (AnonymousClassUtil.isAnonymousClass(n) && AnonymousClassUtil.needsSymbolData(n)) {
        ScopeLoader scopeLoader = new ScopeLoader(typeTable, expressionTypeAnalyzer, actionProvider);
        Scope scope = n.accept(scopeLoader, symbolTable);
        if (scope != null) {
            symbolTable.pushScope(scope);
        }
        if (n.getAnonymousClassBody() != null) {
            for (BodyDeclaration member : n.getAnonymousClassBody()) {
                member.accept(this, arg);
            }
        }
        if (scope != null) {
            symbolTable.popScope();
        }
    }

}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:19,代码来源:SymbolVisitorAdapter.java

示例2: visit

import org.walkmod.javalang.ast.body.BodyDeclaration; //导入依赖的package包/类
public void visit(ClassOrInterfaceDeclaration type, T context) {
    boolean restore = false;
    if (startingNode == null) {
        startingNode = type;
        restore = true;
    }
    String name = getContext(type, context);
    String oldCtx = contextName;
    contextName = name;
    List<BodyDeclaration> members = type.getMembers();
    processMembers(members, context);
    contextName = oldCtx;
    if (restore) {
        startingNode = null;
    }
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:17,代码来源:TypesLoaderVisitor.java

示例3: loadMethods

import org.walkmod.javalang.ast.body.BodyDeclaration; //导入依赖的package包/类
private void loadMethods(List<BodyDeclaration> members, Scope scope) {
    if (!scope.hasMethodsLoaded() && members != null) {
        try {
            for (BodyDeclaration member : members) {
                if (member instanceof ConstructorDeclaration) {
                    ConstructorDeclaration cd = (ConstructorDeclaration) member;
                    pushConstructor((SymbolType) ((SymbolDataAware<?>) member.getParentNode()).getSymbolData(),
                            table, cd);
                }
                if (member instanceof MethodDeclaration) {
                    MethodDeclaration md = (MethodDeclaration) member;
                    pushMethod((SymbolType) ((SymbolDataAware<?>) member.getParentNode()).getSymbolData(),
                            table, md);

                }
            }
        } catch (Exception e) {
            throw new RuntimeException("Error loading methods in a given scope", e);
        }
        scope.setHasMethodsLoaded(true);
    }
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:23,代码来源:LoadMethodDeclarationsAction.java

示例4: visit

import org.walkmod.javalang.ast.body.BodyDeclaration; //导入依赖的package包/类
public R visit(AnnotationDeclaration 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);
        }
    }
    if (n.getMembers() != null) {
        for (BodyDeclaration member : n.getMembers()) {
            member.accept(this, arg);
        }
    }
    return null;
}
 
开发者ID:rpau,项目名称:javalang,代码行数:17,代码来源:GenericVisitorAdapter.java

示例5: addEntersBetween

import org.walkmod.javalang.ast.body.BodyDeclaration; //导入依赖的package包/类
private void addEntersBetween(Node n1, Node n2) {
    int end = n2.getBeginLine();
    if (n2 instanceof BodyDeclaration) {
        JavadocComment jc = ((BodyDeclaration) n2).getJavaDoc();
        if (jc != null && !jc.isNewNode()) {
            end = jc.getBeginLine();
        }
    }
    if (n1.getEndLine() < n2.getBeginLine()) {
        int start = n1.getEndLine();
        if (n1 instanceof LineComment || n1 instanceof JavadocComment || n1 instanceof SwitchEntryStmt) {
            start = start + 1;
        }
        if (start > end) {
            end = n2.getBeginLine();
        }
        for (int i = start; i < end; i++) {
            printer.printLn();
        }

    }
}
 
开发者ID:rpau,项目名称:javalang,代码行数:23,代码来源:DumpVisitor.java

示例6: getFirstWritenLine

import org.walkmod.javalang.ast.body.BodyDeclaration; //导入依赖的package包/类
private int getFirstWritenLine(int startLine, Node n2) {
    int line = n2.getBeginLine();
    if (n2 instanceof BodyDeclaration) {
        JavadocComment jc = ((BodyDeclaration) n2).getJavaDoc();
        if (jc != null && !jc.isNewNode()) {
            line = jc.getBeginLine();
        }
    }
    if (comments != null) {
        Iterator<Comment> it = comments.iterator();
        boolean found = false;
        while (it.hasNext() && !found) {
            Comment c = it.next();
            if (!c.isNewNode() && startLine <= c.getBeginLine()) {
                found = c.isPreviousThan(n2) && c.getBeginLine() < line;
                if (found) {
                    line = c.getBeginLine();
                }
            }
        }
    }

    return line;
}
 
开发者ID:rpau,项目名称:javalang,代码行数:25,代码来源:DumpVisitor.java

示例7: visit

import org.walkmod.javalang.ast.body.BodyDeclaration; //导入依赖的package包/类
public void visit(EnumConstantDeclaration 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);
        }
    }
    if (n.getArgs() != null) {
        for (Expression e : n.getArgs()) {
            e.accept(this, arg);
        }
    }
    if (n.getClassBody() != null) {
        for (BodyDeclaration member : n.getClassBody()) {
            member.accept(this, arg);
        }
    }
}
 
开发者ID:rpau,项目名称:javalang,代码行数:21,代码来源:VoidVisitorAdapter.java

示例8: visit

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

示例9: compare

import org.walkmod.javalang.ast.body.BodyDeclaration; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public int compare(BodyDeclaration o1, BodyDeclaration o2) {
    Integer o1_position = Arrays.binarySearch(order, o1.getClass().getSimpleName());
    Integer o2_position = Arrays.binarySearch(order, o2.getClass().getSimpleName());
    if (o1_position < 0) {
        return 0;
    } else if (o1_position == o2_position) {
        if (comparator.containsKey(order[o1_position])) {
            return comparator.get(order[o1_position]).compare(o1, o2);
        } else {
            return 0;
        }
    } else {
        return o1_position.compareTo(o2_position);
    }
}
 
开发者ID:rpau,项目名称:javalang,代码行数:18,代码来源:BodyDeclaratorComparator.java

示例10: applyAppend

import org.walkmod.javalang.ast.body.BodyDeclaration; //导入依赖的package包/类
private void applyAppend(Node id) {

        AppendAction action = null;
        if (generateActions) {
            Position pos = position.peek();
            int extraLines = 0;
            if (((id instanceof AnnotationExpr) || !(id instanceof Expression)) && pos.getLine() > 1) {
                extraLines++;
            }
            if (id instanceof BodyDeclaration) {
                extraLines++;
            }
            action = new AppendAction(pos.getLine(), pos.getColumn(), id, indentationLevel, indentationSize,
                    extraLines);

            actionsToApply.add(positionToApply(action), action);
        }
        increaseAddedNodes(id.getClass());
    }
 
开发者ID:walkmod,项目名称:walkmod-javalang-plugin,代码行数:20,代码来源:ChangeLogVisitor.java

示例11: testAddAnnotationInInnerClass

import org.walkmod.javalang.ast.body.BodyDeclaration; //导入依赖的package包/类
@Test
public void testAddAnnotationInInnerClass() throws ParseException {
   String code = "public class Foo {\n\tpublic void aux(){\n\t\t new X(){\n\t\t\tvoid hello(){\n\t\t\t\ty();\n\t\t\t}\n\t\t};\n\t}\n}";
   DefaultJavaParser parser = new DefaultJavaParser();
   CompilationUnit cu = parser.parse(code, false);
   CompilationUnit cu2 = parser.parse(code, false);
   MethodDeclaration md = (MethodDeclaration) cu.getTypes().get(0).getMembers().get(0);
   List<Statement> stmts = md.getBody().getStmts();
   ExpressionStmt stmt = (ExpressionStmt) stmts.get(0);
   ObjectCreationExpr oce = (ObjectCreationExpr) stmt.getExpression();

   List<BodyDeclaration> body = oce.getAnonymousClassBody();

   MethodDeclaration md2 = (MethodDeclaration) body.get(0);
   List<AnnotationExpr> annotations = new LinkedList<AnnotationExpr>();
   annotations.add(new MarkerAnnotationExpr(new NameExpr("Override")));
   md2.setAnnotations(annotations);

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

   assertCode(actions, code,
         "public class Foo {\n\tpublic void aux(){\n\t\t new X(){\n\t\t\[email protected]\n\t\t\tvoid hello(){\n\t\t\t\ty();\n\t\t\t}\n\t\t};\n\t}\n}");

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

示例12: processMembers

import org.walkmod.javalang.ast.body.BodyDeclaration; //导入依赖的package包/类
public void processMembers(List<BodyDeclaration> members, T context) {
    if (members != null) {
        for (BodyDeclaration bd : members) {
            if (bd instanceof TypeDeclaration) {
                bd.accept(this, context);
            }
        }
    }
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:10,代码来源:TypesLoaderVisitor.java

示例13: testMethodsOverwritingInAnnonymousClasses

import org.walkmod.javalang.ast.body.BodyDeclaration; //导入依赖的package包/类
@Test
public void testMethodsOverwritingInAnnonymousClasses() throws Exception {
    String code =
            "public class A{ public Object get() { return null; } public A foo = new A() { public String get(){ return name();} private String name(){ return \"hello\"; }};}";
    CompilationUnit cu = run(code);
    BodyDeclaration bd = cu.getTypes().get(0).getMembers().get(1);
    FieldDeclaration aux = (FieldDeclaration) bd;
    ObjectCreationExpr expr = (ObjectCreationExpr) aux.getVariables().get(0).getInit();
    MethodDeclaration md = (MethodDeclaration) expr.getAnonymousClassBody().get(1);
    Assert.assertNotNull(md.getUsages());
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:12,代码来源:SymbolVisitorAdapterTest.java

示例14: testOverrideOnSimpleInnerClass

import org.walkmod.javalang.ast.body.BodyDeclaration; //导入依赖的package包/类
@Test
public void testOverrideOnSimpleInnerClass() throws Exception {
    CompilationUnit cu =
            compile("public class Foo{ class Bar {" + "public String toString(){ return \"\"; }" + " }}");

    BodyDeclaration innerClass = cu.getTypes().get(0).getMembers().get(0);
    MethodDeclaration method = (MethodDeclaration) ((ClassOrInterfaceDeclaration) innerClass).getMembers().get(0);

    assertMethods(method, methods(Object.class.getMethod("toString")));
}
 
开发者ID:rpau,项目名称:javalang-compiler,代码行数:11,代码来源:OverrideAnalyzerTest.java

示例15: ObjectCreationExpr

import org.walkmod.javalang.ast.body.BodyDeclaration; //导入依赖的package包/类
public ObjectCreationExpr(Expression scope, ClassOrInterfaceType type, List<Expression> args,
        List<BodyDeclaration> anonymousBody) {
    setScope(scope);
    setType(type);
    setArgs(args);
    setAnonymousClassBody(anonymousBody);
}
 
开发者ID:rpau,项目名称:javalang,代码行数:8,代码来源:ObjectCreationExpr.java


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