本文整理汇总了Java中org.jboss.forge.roaster.model.source.JavaClassSource.addMethod方法的典型用法代码示例。如果您正苦于以下问题:Java JavaClassSource.addMethod方法的具体用法?Java JavaClassSource.addMethod怎么用?Java JavaClassSource.addMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.forge.roaster.model.source.JavaClassSource
的用法示例。
在下文中一共展示了JavaClassSource.addMethod方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addPropertyChangeSupport
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
protected void addPropertyChangeSupport(JavaClassSource type, ClassPlan plan) {
// property change listeners
type.addField()
.setName("pcs")
.setType(PropertyChangeSupport.class)
.setPrivate();
final MethodSource<JavaClassSource> listenerAdd = type.addMethod();
listenerAdd.getJavaDoc().setText("Adds a property change listener");
listenerAdd.setPublic()
.setName("addPropertyChangeListener")
.addParameter(PropertyChangeListener.class, "listener");
listenerAdd.setBody("if(null==this.pcs) this.pcs = new PropertyChangeSupport(this);\n" +
"this.pcs.addPropertyChangeListener(listener);");
final MethodSource<JavaClassSource> listenerRemove = type.addMethod();
listenerRemove.getJavaDoc().setText("Removes a property change listener");
listenerRemove.setPublic()
.setName("removePropertyChangeListener")
.addParameter(PropertyChangeListener.class, "listener");
listenerRemove.setBody("if(this.pcs!=null) this.pcs.removePropertyChangeListener(listener);");
}
示例2: probe
import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
/**
* Generates a class extending {@link LocalProbe} with the corresponding
* connection information.
*
* @param packageName
* The package of the generated java class
* @param routingKey
* The routing key designated to the probe
* @return an object encapsulating the java source code
*/
public JavaClassSource probe(final String packageName,
final String routingKey) {
File directory = new File(this.path);
String className = new NameProposal(getProbeClassName(), directory)
.getNewName();
JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
// Add imports
javaClass.addImport(LocalProbe.class);
javaClass.addImport(Context.class);
// Set general properties
javaClass.setPackage(packageName);
javaClass.setName(className);
javaClass.setSuperType(LocalProbe.class);
String constructorBody = InterceptorBasedProbeTemplates
.getProbeConstructor(routingKey, Context.PROBE);
MethodSource<?> constructor = javaClass.addMethod();
constructor.setConstructor(true);
constructor.setBody(constructorBody);
constructor.addThrows(Exception.class);
return javaClass;
}
示例3: 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;
}