本文整理汇总了Java中org.walkmod.javalang.ast.expr.ObjectCreationExpr.getAnonymousClassBody方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectCreationExpr.getAnonymousClassBody方法的具体用法?Java ObjectCreationExpr.getAnonymousClassBody怎么用?Java ObjectCreationExpr.getAnonymousClassBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.walkmod.javalang.ast.expr.ObjectCreationExpr
的用法示例。
在下文中一共展示了ObjectCreationExpr.getAnonymousClassBody方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadThisSymbol
import org.walkmod.javalang.ast.expr.ObjectCreationExpr; //导入方法依赖的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();
}
}
}
示例2: visit
import org.walkmod.javalang.ast.expr.ObjectCreationExpr; //导入方法依赖的package包/类
public void visit(ObjectCreationExpr n, T context) {
boolean restore = false;
if (startingNode == null) {
startingNode = n;
restore = true;
}
List<BodyDeclaration> members = n.getAnonymousClassBody();
if (members != null) {
SymbolType st = symbolTable.getType("this", ReferenceType.VARIABLE);
n.setSymbolData(st);
String name = st.getName();
String oldCtx = contextName;
contextName = name;
processMembers(members, context);
contextName = oldCtx;
}
if (restore) {
startingNode = null;
}
}
示例3: visit
import org.walkmod.javalang.ast.expr.ObjectCreationExpr; //导入方法依赖的package包/类
public R visit(ObjectCreationExpr n, A arg) {
if (n.getScope() != null) {
n.getScope().accept(this, arg);
}
if (n.getTypeArgs() != null) {
for (Type t : n.getTypeArgs()) {
t.accept(this, arg);
}
}
n.getType().accept(this, arg);
if (n.getArgs() != null) {
for (Expression e : n.getArgs()) {
e.accept(this, arg);
}
}
if (n.getAnonymousClassBody() != null) {
for (BodyDeclaration member : n.getAnonymousClassBody()) {
member.accept(this, arg);
}
}
return null;
}
示例4: visit
import org.walkmod.javalang.ast.expr.ObjectCreationExpr; //导入方法依赖的package包/类
public void visit(ObjectCreationExpr n, A arg) {
if (n.getScope() != null) {
n.getScope().accept(this, arg);
}
if (n.getTypeArgs() != null) {
for (Type t : n.getTypeArgs()) {
t.accept(this, arg);
}
}
n.getType().accept(this, arg);
if (n.getArgs() != null) {
for (Expression e : n.getArgs()) {
e.accept(this, arg);
}
}
if (n.getAnonymousClassBody() != null) {
for (BodyDeclaration member : n.getAnonymousClassBody()) {
member.accept(this, arg);
}
}
}
示例5: testAddAnnotationInInnerClass
import org.walkmod.javalang.ast.expr.ObjectCreationExpr; //导入方法依赖的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}");
}
示例6: visit
import org.walkmod.javalang.ast.expr.ObjectCreationExpr; //导入方法依赖的package包/类
public Node visit(ObjectCreationExpr n, A arg) {
if (n.getScope() != null) {
n.setScope((Expression) n.getScope().accept(this, arg));
}
List<Type> typeArgs = n.getTypeArgs();
if (typeArgs != null) {
for (int i = 0; i < typeArgs.size(); i++) {
typeArgs.set(i, (Type) typeArgs.get(i).accept(this, arg));
}
removeNulls(typeArgs);
}
n.setType((ClassOrInterfaceType) n.getType().accept(this, arg));
List<Expression> args = n.getArgs();
if (args != null) {
for (int i = 0; i < args.size(); i++) {
args.set(i, (Expression) args.get(i).accept(this, arg));
}
removeNulls(args);
}
List<BodyDeclaration> anonymousClassBody = n.getAnonymousClassBody();
if (anonymousClassBody != null) {
for (int i = 0; i < anonymousClassBody.size(); i++) {
anonymousClassBody.set(i, (BodyDeclaration) anonymousClassBody.get(i).accept(this, arg));
}
removeNulls(anonymousClassBody);
}
return n;
}
示例7: isAnonymousClass
import org.walkmod.javalang.ast.expr.ObjectCreationExpr; //导入方法依赖的package包/类
public static boolean isAnonymousClass(ObjectCreationExpr n) {
return n.getAnonymousClassBody() != null;
}
示例8: visit
import org.walkmod.javalang.ast.expr.ObjectCreationExpr; //导入方法依赖的package包/类
@Override
public Scope visit(ObjectCreationExpr n, SymbolTable symbolTable) {
List<BodyDeclaration> body = n.getAnonymousClassBody();
if (body != null) {
SymbolType st = ASTSymbolTypeResolver.getInstance().valueOf(n.getType());
Scope scope = new Scope();
symbolTable.pushScope(scope);
List<BodyDeclaration> members = n.getAnonymousClassBody();
boolean anonymousClass = members != null;
if (anonymousClass) {
List<SymbolAction> actions = new LinkedList<SymbolAction>();
actions.add(new LoadTypeParamsAction());
actions.add(new LoadTypeDeclarationsAction(typeTable));
actions.add(new LoadFieldDeclarationsAction(actionProvider));
actions.add(new LoadMethodDeclarationsAction(actionProvider, expressionTypeAnalyzer));
actions.add(new LoadEnumConstantLiteralsAction());
if (actionProvider != null) {
actions.addAll(actionProvider.getActions(n));
}
Symbol<?> superSymbol =
symbolTable.pushSymbol("super", ReferenceType.VARIABLE, st, n, (List<SymbolAction>) null);
if (st == null) {
throw new RuntimeException("Error resolving " + n.getType().toString() + " in " + n.toString()
+ ", line: " + n.getBeginLine());
}
Class<?> superTypeClass = st.getClazz();
Symbol<?> superType = symbolTable.findSymbol(superTypeClass.getCanonicalName(), ReferenceType.TYPE);
if (superType != null) {
superSymbol.setInnerScope(superType.getInnerScope());
}
String name = symbolTable.generateAnonymousClass();
SymbolType type = SymbolType.anonymousClassOf(name);
try {
type.getClazz();
} catch (TypeNotFoundException e) {
// The java compiler does not generate classes for code disabled via conditional compilation.
// For definition of conditional compilation see
// JLS 14.21. Unreachable Statements,
// http://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.21
if (ConditionalCompilationUtil.isDisabledCode(n)) {
// if we have symbol data of base type we keep that.
final SymbolType base = (SymbolType) n.getSymbolData();
type = base != null ? base.markDisabledCode() : new SymbolType(Object.class).markDisabledCode();
} else {
throw e;
}
}
Symbol<?> anonymousType = symbolTable.pushSymbol(name, ReferenceType.TYPE, type, n);
anonymousType.setInnerScope(scope);
Symbol<ObjectCreationExpr> thisSymbol =
new Symbol<ObjectCreationExpr>("this", type, n, ReferenceType.VARIABLE, false, actions);
scope.setRootSymbol(thisSymbol);
thisSymbol.setInnerScope(scope);
symbolTable.pushSymbol(thisSymbol);
for (BodyDeclaration member : members) {
if (member instanceof TypeDeclaration) {
process((TypeDeclaration) member, symbolTable);
}
}
}
symbolTable.popScope(true);
return scope;
}
return null;
}
示例9: visit
import org.walkmod.javalang.ast.expr.ObjectCreationExpr; //导入方法依赖的package包/类
public void visit(ObjectCreationExpr n, Object arg) {
prepareComments(n);
printPreviousComments(n, arg);
if (n.getScope() != null) {
n.getScope().accept(this, arg);
printer.print(".");
}
ClassOrInterfaceType type = n.getType();
printPreviousComments(type, arg);
int beginLine = n.getType().getEndLine();
printer.print("new ");
List<Type> typeArgs = n.getTypeArgs();
if (typeArgs != null) {
printTypeArgs(n.getTypeArgs(), arg);
printer.print(" ");
}
n.getType().accept(this, arg);
List<Expression> args = n.getArgs();
printArguments(args, arg);
if (args != null && !args.isEmpty()) {
Expression lastType = args.get(args.size() - 1);
int begin = lastType.getEndLine();
if (begin > beginLine) {
beginLine = begin;
}
}
if (n.getAnonymousClassBody() != null) {
printer.print(" {");
printer.indent();
List<BodyDeclaration> members = n.getAnonymousClassBody();
if (members != null) {
if (!members.isEmpty()) {
printFirstBlankLines(n, members, beginLine);
printChildrenNodes(n, members, null, arg);
printEntersAfterMembersAndBeforeComments(n, members);
}
}
printContainingCommentsAndEnters(n, members, arg, beginLine);
printer.unindent();
printer.print("}");
}
}