本文整理汇总了Java中com.github.javaparser.ASTHelper.addMember方法的典型用法代码示例。如果您正苦于以下问题:Java ASTHelper.addMember方法的具体用法?Java ASTHelper.addMember怎么用?Java ASTHelper.addMember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.javaparser.ASTHelper
的用法示例。
在下文中一共展示了ASTHelper.addMember方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClassDeclaration
import com.github.javaparser.ASTHelper; //导入方法依赖的package包/类
/**
* Generates the class definition for the Operation
*/
private ClassOrInterfaceDeclaration getClassDeclaration() {
ClassOrInterfaceDeclaration operation = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC,
false, getOperationClassName());
operation.setImplements(Collections.singletonList(iOperation));
operation.setJavaDoc(javadocComment);
operation.setComment(new BlockComment(
" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n"
+ " * ===== THIS CODE HAS BEEN DYNAMICALLY GENERATED! DO NOT MODIFY! ==== *\n"
+ " * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "));
operation.setMembers(socketHintDeclarationCollection
.getAllSocketHints()
.stream()
.map(SocketHintDeclaration::getDeclaration)
.filter(declaration -> declaration != null)
.collect(Collectors.toList()));
ASTHelper.addMember(operation, getNameMethod());
ASTHelper.addMember(operation, getDescriptionMethod());
ASTHelper.addMember(operation, getCategoryMethod());
ASTHelper.addMember(operation, getCreateInputSocketsMethod());
ASTHelper.addMember(operation, getCreateOutputSocketsMethod());
ASTHelper.addMember(operation, getPerformMethod());
return operation;
}
示例2: execute
import com.github.javaparser.ASTHelper; //导入方法依赖的package包/类
public void execute(PathResolver pathResolver) throws Exception {
CompilationUnit cu = new CompilationUnit();
cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr(pkgName)));
cu.setImports(Arrays.asList(
new ImportDeclaration(ASTHelper.createNameExpr("org.seasar.doma.jdbc.Config"), false, false),
new ImportDeclaration(ASTHelper.createNameExpr("org.seasar.doma.jdbc.dialect.Dialect"), false, false),
new ImportDeclaration(ASTHelper.createNameExpr("org.seasar.doma.jdbc.dialect.H2Dialect"), false, false),
new ImportDeclaration(ASTHelper.createNameExpr("javax.sql.DataSource"), false, false)
));
ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, "DomaConfig");
type.setImplements(Collections.singletonList(new ClassOrInterfaceType("Config")));
ASTHelper.addTypeDeclaration(cu, type);
MethodDeclaration getDataSourceMethod = new MethodDeclaration(ModifierSet.PUBLIC, ASTHelper.createReferenceType("DataSource", 0), "getDataSource");
getDataSourceMethod.setAnnotations(Collections.singletonList(OVERRIDE_ANNOTATION));
BlockStmt getDataSourceBody = new BlockStmt();
ASTHelper.addStmt(getDataSourceBody, new ReturnStmt(new NullLiteralExpr()));
getDataSourceMethod.setBody(getDataSourceBody);
ASTHelper.addMember(type, getDataSourceMethod);
MethodDeclaration getDialectMethod = new MethodDeclaration(ModifierSet.PUBLIC, ASTHelper.createReferenceType("Dialect", 0), "getDialect");
getDialectMethod.setAnnotations(Collections.singletonList(OVERRIDE_ANNOTATION));
BlockStmt getDialectBody = new BlockStmt();
ObjectCreationExpr newDialect = new ObjectCreationExpr(null, new ClassOrInterfaceType("H2Dialect"), null);
ASTHelper.addStmt(getDialectBody, new ReturnStmt(newDialect));
getDialectMethod.setBody(getDialectBody);
ASTHelper.addMember(type, getDialectMethod);
try (OutputStreamWriter writer = new OutputStreamWriter(
pathResolver.destinationAsStream(destination))) {
writer.write(cu.toString());
}
}
示例3: createCU
import com.github.javaparser.ASTHelper; //导入方法依赖的package包/类
/**
* creates the compilation unit
*/
private static CompilationUnit createCU() {
CompilationUnit cu = new CompilationUnit();
// set the package
cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr("java.parser.test")));
// create the type declaration
ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, "GeneratedClass");
ASTHelper.addTypeDeclaration(cu, 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);
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);
return cu;
}
示例4: setup
import com.github.javaparser.ASTHelper; //导入方法依赖的package包/类
@Before
public void setup(){
CompilationUnit cu = new CompilationUnit();
// set the package
cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr("java.parser.test")));
// create the type declaration
ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, "GeneratedClass");
ASTHelper.addTypeDeclaration(cu, 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);
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);
unit = cu;
}
示例5: whenAStaticMethodCalledReturningIsAddedToClassInTheCompilationUnit
import com.github.javaparser.ASTHelper; //导入方法依赖的package包/类
@When("a public static method called \"$methodName\" returning void is added to class $position in the compilation unit")
public void whenAStaticMethodCalledReturningIsAddedToClassInTheCompilationUnit(String methodName, int position) {
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
TypeDeclaration type = compilationUnit.getTypes().get(position -1);
MethodDeclaration method = new MethodDeclaration(ModifierSet.PUBLIC, new VoidType(), methodName);
method.setModifiers(ModifierSet.addModifier(method.getModifiers(), ModifierSet.STATIC));
ASTHelper.addMember(type, method);
state.put("cu1", compilationUnit);
}
示例6: generateEnum
import com.github.javaparser.ASTHelper; //导入方法依赖的package包/类
/**
* Generates the enumeration class body.
*
* @return The generated Enumeration
*/
private EnumDeclaration generateEnum() {
final String valueString = "value";
// Create new Enum
EnumDeclaration newEnum = new EnumDeclaration(
ModifierSet.PUBLIC,
null,
getEnumerationClassName(),
null,
generateEnumConstantDeclarations(),
null
);
// Add a field value for the public final value variable
FieldDeclaration valueField = new FieldDeclaration(
ModifierSet.addModifier(ModifierSet.FINAL, ModifierSet.PUBLIC),
ASTHelper.INT_TYPE,
Collections.singletonList(
new VariableDeclarator(new VariableDeclaratorId(valueString))
));
ASTHelper.addMember(newEnum, valueField);
// Add the constructor to take the opencv value
ConstructorDeclaration enumConstructor = new ConstructorDeclaration(
0,
null,
null,
name,
Collections.singletonList(
ASTHelper.createParameter(ASTHelper.INT_TYPE, valueString)
),
null,
getDefaultConstructorBlockStatement(valueString)
);
ASTHelper.addMember(newEnum, enumConstructor);
return newEnum;
}
示例7: visit
import com.github.javaparser.ASTHelper; //导入方法依赖的package包/类
@Override
public void visit(MethodDeclaration n, Object arg) {
if (!methodFilter.test(n)) {
return;
}
MethodDeclaration method = new MethodDeclaration(n.getModifiers(), methodReturnTypeFunction.apply(n), n.getName());
if (methodCommentMutator != null) {
method.setComment(methodCommentMutator.apply(n.getComment()));
} else {
method.setComment(n.getComment());
}
for (Parameter parameter : n.getParameters()) {
Parameter param = ASTHelper.createParameter(parameter.getType(), parameter.getId().getName());
param.setVarArgs(parameter.isVarArgs());
ASTHelper.addParameter(method, param);
}
if (n.getTypeParameters() != null) {
method.setTypeParameters(new ArrayList<>());
method.getTypeParameters().addAll(n.getTypeParameters());
}
if (n.getAnnotations() != null) {
method.setAnnotations(n.getAnnotations());
}
ASTHelper.addMember(resultType, method);
}
示例8: execute
import com.github.javaparser.ASTHelper; //导入方法依赖的package包/类
@Override
public void execute(PathResolver pathResolver) throws Exception {
CompilationUnit cu = new CompilationUnit();
cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr("db.migration")));
List<ImportDeclaration> imports = new ArrayList<>();
imports.add(new ImportDeclaration(ASTHelper.createNameExpr("org.flywaydb.core.api.migration.jdbc.JdbcMigration"), false, false));
imports.add(new ImportDeclaration(ASTHelper.createNameExpr("java.sql.Connection"), false, false));
imports.add(new ImportDeclaration(ASTHelper.createNameExpr("java.sql.Statement"), false, false));
cu.setImports(imports);
String version = LocalDateTime.now().format(VERSION_FMT);
ClassOrInterfaceDeclaration migrationClass = new ClassOrInterfaceDeclaration(
ModifierSet.PUBLIC, false, "V" + version + "__Create"
+ CaseConverter.pascalCase(tableName));
ASTHelper.addTypeDeclaration(cu, migrationClass);
List<ClassOrInterfaceType> implementList = new ArrayList<>();
implementList.add(new ClassOrInterfaceType("JdbcMigration"));
migrationClass.setImplements(implementList);
MethodDeclaration migrateMethod = new MethodDeclaration(ModifierSet.PUBLIC, ASTHelper.VOID_TYPE, "migrate");
ASTHelper.addMember(migrationClass, migrateMethod);
ASTHelper.addParameter(migrateMethod, ASTHelper.createParameter(
ASTHelper.createReferenceType("Connection", 0), "connection"
));
migrateMethod.setThrows(Collections.singletonList(ASTHelper.createNameExpr("Exception")));
List<AnnotationExpr> annotations = new ArrayList<>();
annotations.add(new MarkerAnnotationExpr(ASTHelper.createNameExpr("Override")));
migrateMethod.setAnnotations(annotations);
BlockStmt block = new BlockStmt();
migrateMethod.setBody(block);
TryStmt tryStmt = new TryStmt(createStatementExecuteBlock(), null, null);
tryStmt.setResources(Collections.singletonList(createAssignStatement()));
ASTHelper.addStmt(block, tryStmt);
try (Writer writer = new OutputStreamWriter(
pathResolver.destinationAsStream(
"src/main/java/db/migration/" + migrationClass.getName() + ".java"))) {
writer.write(cu.toString());
}
}