当前位置: 首页>>代码示例>>Java>>正文


Java JavaClassSource.addMethod方法代码示例

本文整理汇总了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);");
    }
 
开发者ID:wildfly-swarm,项目名称:wildfly-config-api,代码行数:24,代码来源:ResourceFactory.java

示例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;
}
 
开发者ID:unicesi,项目名称:pascani,代码行数:39,代码来源:InterceptorBasedProbeGenerator.java

示例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;
}
 
开发者ID:unicesi,项目名称:pascani,代码行数:54,代码来源:ScaProbeGenerator.java


注:本文中的org.jboss.forge.roaster.model.source.JavaClassSource.addMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。