本文整理汇总了Java中org.jboss.forge.roaster.model.source.JavaClassSource.addField方法的典型用法代码示例。如果您正苦于以下问题:Java JavaClassSource.addField方法的具体用法?Java JavaClassSource.addField怎么用?Java JavaClassSource.addField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.forge.roaster.model.source.JavaClassSource
的用法示例。
在下文中一共展示了JavaClassSource.addField方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addArquillianResourceEnricher
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
private void addArquillianResourceEnricher(JavaClassSource test) {
if (asClient.hasValue())
{
test.addImport("org.jboss.arquillian.test.api.ArquillianResource");
final FieldSource<JavaClassSource> urlField = test.addField();
urlField
.setName("url")
.setType(URL.class)
.setPrivate();
urlField.addAnnotation("ArquillianResource");
}
}
示例2: interceptor
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
@Override public JavaClassSource interceptor(final String packageName,
final List<Class<? extends Event<?>>> events) {
File directory = new File(path);
String className = new NameProposal(
this.probeName + "Interceptor.java", directory).getNewName();
JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
// Add imports
javaClass.addImport(PascaniRuntime.class);
javaClass.addImport(LocalEventProducer.class);
javaClass.addImport(Event.class);
javaClass.addImport(UUID.class);
for (Class<? extends Event<?>> clazz : events)
javaClass.addImport(clazz);
// Set general properties
javaClass.setPackage(packageName);
javaClass.addAnnotation(Scope.class).setStringValue("value",
"COMPOSITE");
javaClass.setName(className);
javaClass.addInterface(IntentHandler.class);
// Add an event producer
String producerVar = "producer";
FieldSource<?> field = javaClass.addField();
field.setType(LocalEventProducer.class.getSimpleName() + "<"
+ Event.class.getSimpleName() + "<?>" + ">");
field.setName(producerVar).setPrivate().setFinal(true);
String constructor = ProbeTemplates
.getProducerInitialization(producerVar);
javaClass.addMethod().setConstructor(true).setBody(constructor);
// Override the invoke method
String paramName = "ijp";
String invokeBody = ProbeTemplates.getInterceptorMethodBody(
producerVar, paramName, events);
MethodSource<?> invoke = javaClass.addMethod();
invoke.setReturnType(Object.class);
invoke.setName("invoke");
invoke.addThrows("Throwable");
invoke.addParameter(IntentJoinPoint.class, paramName);
invoke.setBody(invokeBody);
invoke.setPublic();
return javaClass;
}