本文整理汇总了Java中japa.parser.ast.body.MethodDeclaration.setBody方法的典型用法代码示例。如果您正苦于以下问题:Java MethodDeclaration.setBody方法的具体用法?Java MethodDeclaration.setBody怎么用?Java MethodDeclaration.setBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类japa.parser.ast.body.MethodDeclaration
的用法示例。
在下文中一共展示了MethodDeclaration.setBody方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addAttachSkeleton
import japa.parser.ast.body.MethodDeclaration; //导入方法依赖的package包/类
private void addAttachSkeleton() {
List<Parameter> params = Collections.emptyList();
MethodDeclaration method = new MethodDeclaration(
ModifierSet.PUBLIC, new VoidType(), "attach", params);
AnnotationExpr override = new MarkerAnnotationExpr(new NameExpr("Override"));
method.setAnnotations(Collections.singletonList(override));
BlockStmt block = new BlockStmt();
Expression e = new MethodCallExpr(new SuperExpr(), "attach");
List<Statement> sts = Collections.singletonList((Statement)new ExpressionStmt(e));
block.setStmts(sts);
method.setBody(block);
if (getType().getMembers()==null) {
getType().setMembers(new LinkedList<BodyDeclaration>());
}
getType().getMembers().add(method);
}
示例2: addOnBecomingVisibleMethod
import japa.parser.ast.body.MethodDeclaration; //导入方法依赖的package包/类
@SuppressWarnings("unused")
private void addOnBecomingVisibleMethod() {
List<Parameter> params = Collections.emptyList();
MethodDeclaration method = new MethodDeclaration(
ModifierSet.PUBLIC, new VoidType(), "onBecomingVisible", params);
AnnotationExpr override = new MarkerAnnotationExpr(new NameExpr("Override"));
method.setAnnotations(Collections.singletonList(override));
BlockStmt block = new BlockStmt();
Expression e = new MethodCallExpr(new SuperExpr(), "onBecomingVisible");
List<Statement> sts = Collections.singletonList((Statement)new ExpressionStmt(e));
block.setStmts(sts);
method.setBody(block);
if (getType().getMembers()==null) {
getType().setMembers(new LinkedList<BodyDeclaration>());
}
getType().getMembers().add(method);
}
示例3: addClaraHandler
import japa.parser.ast.body.MethodDeclaration; //导入方法依赖的package包/类
private MethodDeclaration addClaraHandler(String id, String className) {
ensureImport(className);
String shortName = className.substring(className.lastIndexOf(".")+1);
String handlerName = generateHandlerNameFor(id, shortName);
Parameter p = new Parameter(new ClassOrInterfaceType(shortName), new VariableDeclaratorId("event"));
MethodDeclaration handler = new MethodDeclaration(
ModifierSet.PUBLIC, new VoidType(), handlerName, Collections.singletonList(p));
handler.setBody(new BlockStmt());
handler.setAnnotations(createClaraHandlerAnnotations(id));
addNotification(handler, shortName+" on "+id);
addMember(handler);
return handler;
}
示例4: buildUnit
import japa.parser.ast.body.MethodDeclaration; //导入方法依赖的package包/类
public static void buildUnit() {
CompilationUnit compUnit = new CompilationUnit();
compUnit.setPackage(new PackageDeclaration(ASTHelper
.createNameExpr("compiladores.aula")));
// create the type declaration
ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration(
ModifierSet.PUBLIC, false, "AulaJavaParser");
ASTHelper.addTypeDeclaration(compUnit, type);
// create a method
MethodDeclaration method = new MethodDeclaration(ModifierSet.PUBLIC,
ASTHelper.VOID_TYPE, "main");
method.setModifiers(ModifierSet.addModifier(method.getModifiers(),
ModifierSet.STATIC));
ASTHelper.addMember(type, method);
// add a parameter to the method
Parameter param = ASTHelper.createParameter(
ASTHelper.createReferenceType("String", 0), "args");
param.setVarArgs(true); //makes the parameter a ",,," array
ASTHelper.addParameter(method, param);
// add a body to the method
BlockStmt block = new BlockStmt();
method.setBody(block);
// add a statement do the method body
NameExpr clazz = new NameExpr("System");
FieldAccessExpr field = new FieldAccessExpr(clazz, "out");
MethodCallExpr call = new MethodCallExpr(field, "println");
ASTHelper.addArgument(call, new StringLiteralExpr("Hello World!"));
ASTHelper.addStmt(block, call);
System.out.println(compUnit.toString());
}
示例5: visit
import japa.parser.ast.body.MethodDeclaration; //导入方法依赖的package包/类
public Node visit(MethodDeclaration 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<TypeParameter> typeParameters = n.getTypeParameters();
if (typeParameters != null) {
for (int i = 0; i < typeParameters.size(); i++) {
typeParameters.set(i, (TypeParameter) typeParameters.get(i).accept(this, arg));
}
removeNulls(typeParameters);
}
n.setType((Type) n.getType().accept(this, arg));
List<Parameter> parameters = n.getParameters();
if (parameters != null) {
for (int i = 0; i < parameters.size(); i++) {
parameters.set(i, (Parameter) parameters.get(i).accept(this, arg));
}
removeNulls(parameters);
}
List<NameExpr> throwz = n.getThrows();
if (throwz != null) {
for (int i = 0; i < throwz.size(); i++) {
throwz.set(i, (NameExpr) throwz.get(i).accept(this, arg));
}
removeNulls(throwz);
}
if (n.getBody() != null) {
n.setBody((BlockStmt) n.getBody().accept(this, arg));
}
return n;
}
示例6: addClaraDataSourceMethod
import japa.parser.ast.body.MethodDeclaration; //导入方法依赖的package包/类
private MethodDeclaration addClaraDataSourceMethod(String id, String returnType) {
String handlerName = generateDataSourceNameFor(id);
Type type = createDataSourceReturnType(returnType);
List<Parameter> params = Collections.emptyList();
MethodDeclaration source = new MethodDeclaration(
ModifierSet.PUBLIC, type, handlerName, params);
source.setBody(new BlockStmt());
source.setAnnotations(createClaraDataSourceAnnotations(id));
setTestMethodBodyFor(source, returnType);
addMember(source);
return source;
}