本文整理汇总了Java中org.jboss.forge.roaster.model.source.MethodSource类的典型用法代码示例。如果您正苦于以下问题:Java MethodSource类的具体用法?Java MethodSource怎么用?Java MethodSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MethodSource类属于org.jboss.forge.roaster.model.source包,在下文中一共展示了MethodSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findConfigureMethod
import org.jboss.forge.roaster.model.source.MethodSource; //导入依赖的package包/类
public static MethodSource<JavaClassSource> findConfigureMethod(JavaClassSource clazz) {
MethodSource<JavaClassSource> method = clazz.getMethod("configure");
// must be public void configure()
if (method != null && method.isPublic() && method.getParameters().isEmpty() && method.getReturnType().isType("void")) {
return method;
}
// maybe the route builder is from unit testing with camel-test as an anonymous inner class
// there is a bit of code to dig out this using the eclipse jdt api
method = findCreateRouteBuilderMethod(clazz);
if (method != null) {
return findConfigureMethodInCreateRouteBuilder(clazz, method);
}
return null;
}
示例2: findInlinedConfigureMethods
import org.jboss.forge.roaster.model.source.MethodSource; //导入依赖的package包/类
public static List<MethodSource<JavaClassSource>> findInlinedConfigureMethods(JavaClassSource clazz) {
List<MethodSource<JavaClassSource>> answer = new ArrayList<>();
List<MethodSource<JavaClassSource>> methods = clazz.getMethods();
if (methods != null) {
for (MethodSource<JavaClassSource> method : methods) {
if (method.isPublic()
&& (method.getParameters() == null || method.getParameters().isEmpty())
&& (method.getReturnType() == null || method.getReturnType().isType("void"))) {
// maybe the method contains an inlined createRouteBuilder usually from an unit test method
MethodSource<JavaClassSource> builder = findConfigureMethodInCreateRouteBuilder(clazz, method);
if (builder != null) {
answer.add(builder);
}
}
}
}
return answer;
}
示例3: parseCamelSimpleExpressions
import org.jboss.forge.roaster.model.source.MethodSource; //导入依赖的package包/类
public static List<ParserResult> parseCamelSimpleExpressions(MethodSource<JavaClassSource> method) {
List<ParserResult> answer = new ArrayList<ParserResult>();
MethodDeclaration md = (MethodDeclaration) method.getInternal();
Block block = md.getBody();
if (block != null) {
for (Object statement : block.statements()) {
// must be a method call expression
if (statement instanceof ExpressionStatement) {
ExpressionStatement es = (ExpressionStatement) statement;
Expression exp = es.getExpression();
List<ParserResult> expressions = new ArrayList<ParserResult>();
parseExpression(null, method.getOrigin(), block, exp, expressions);
if (!expressions.isEmpty()) {
// reverse the order as we will grab them from last->first
Collections.reverse(expressions);
answer.addAll(expressions);
}
}
}
}
return answer;
}
示例4: getEventHandler
import org.jboss.forge.roaster.model.source.MethodSource; //导入依赖的package包/类
private void getEventHandler(final MethodSource<JavaClassSource> method, final String listenerName) {
final String eventTypeName = method.getParameters()
.get(0)
.getType()
.getName();
String eventHandlerType = null;
for (AnnotationSource<JavaClassSource> annotation : method.getAnnotations()) {
eventHandlerType = axonUtil.getEventHandlerType(annotation.getName());
}
if (eventHandlerType == null) {
throw new VisualAxonException(method.getName() + " is not a valid Axon EventHandler");
}
eventBus.post(EventHandlerSpotted.builder()
.eventName(eventTypeName)
.type(eventHandlerType)
.listener(listenerName)
.build());
}
示例5: applyAccessTransformation
import org.jboss.forge.roaster.model.source.MethodSource; //导入依赖的package包/类
/**
* Applies access transformations to a parsed type and all of its nested members.
*
* TODO: Add support for inheritance to reduce the size of AT configs.
*/
@SuppressWarnings("unchecked")
private void applyAccessTransformation(@Nonnull AccessTransformationMap transformationMap, @Nonnull JavaType classSource) {
this.getLog().info("Applying access transformations to " + classSource.getQualifiedName());
transformationMap.getTypeMappings(classSource.getQualifiedName()).ifPresent((t) -> {
if (classSource instanceof VisibilityScopedSource) {
t.getVisibility().ifPresent(((VisibilityScopedSource) classSource)::setVisibility);
}
if (classSource instanceof FieldHolderSource) {
((List<FieldSource>) ((FieldHolderSource) classSource).getFields()).forEach((f) -> t.getFieldVisibility(f.getName()).ifPresent(f::setVisibility));
}
if (classSource instanceof MethodHolderSource) {
((List<MethodSource>) ((MethodHolderSource) classSource).getMethods()).forEach((m) -> t.getMethodVisibility(m.getName()).ifPresent(m::setVisibility));
}
((List<JavaType>) classSource.getNestedClasses()).forEach((c) -> this.applyAccessTransformation(transformationMap, c));
});
}
示例6: addPropertyChangeSupport
import org.jboss.forge.roaster.model.source.MethodSource; //导入依赖的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);");
}
示例7: addContextReplaceMethods
import org.jboss.forge.roaster.model.source.MethodSource; //导入依赖的package包/类
private void addContextReplaceMethods(String contextName, ComponentData data, JavaClassSource source) {
if (!isUnique(data)) {
List<MethodSource<JavaClassSource>> constructors = getConstructorData(data);
source.addMethod()
.setName(String.format("replace%1$s", getTypeName(data)))
.setReturnType(contextName + "Entity")
.setPublic()
.setParameters(constructors != null && constructors.size() > 0
? memberNamesWithTypeFromConstructor(constructors.get(0))
: memberNamesWithType(getMemberData(data)))
.setBody(String.format("%3$sEntity entity = get%1$sEntity();" +
" if(entity == null) {" +
" entity = set%1$s(%2$s);" +
" } else { " +
" entity.replace%1$s(%2$s);" +
" }" +
" return entity;"
, getTypeName(data), constructors != null && constructors.size() > 0
? memberNamesFromConstructor(constructors.get(0))
: memberNames(getMemberData(data))
, contextName));
}
}
示例8: decorateSource
import org.jboss.forge.roaster.model.source.MethodSource; //导入依赖的package包/类
@Override
public JavaClassSource decorateSource(UIExecutionContext context, Project project, JavaClassSource source)
throws Exception
{
source.addImport("org.wildfly.swarm.Swarm");
MethodSource<JavaClassSource> method = source.addMethod()
.setPublic()
.setStatic(true)
.setReturnTypeVoid()
.setName("main")
.addThrows(Exception.class);
method.addParameter("String[]", "args");
StringBuilder body = new StringBuilder();
body.append("Swarm swarm = new Swarm();").append(System.lineSeparator());
body.append("swarm.start();").append(System.lineSeparator());
body.append("swarm.deploy();");
method.setBody(body.toString());
WildFlySwarmFacet facet = project.getFacet(WildFlySwarmFacet.class);
WildFlySwarmConfigurationBuilder newConfig = WildFlySwarmConfigurationBuilder.create(facet.getConfiguration());
newConfig.mainClass(source.getQualifiedName());
facet.setConfiguration(newConfig);
return source;
}
示例9: updateMethods
import org.jboss.forge.roaster.model.source.MethodSource; //导入依赖的package包/类
public void updateMethods(JavaClassSource javaClassSource,
List<org.kie.workbench.common.services.datamodeller.core.Method> methods,
ClassTypeResolver classTypeResolver) throws Exception {
List<MethodSource<JavaClassSource>> currentMethods = javaClassSource.getMethods();
if (currentMethods != null) {
for (MethodSource<JavaClassSource> currentMethod : currentMethods) {
if (isAccepted(currentMethod)) {
javaClassSource.removeMethod(currentMethod);
}
}
}
if (methods != null) {
for (org.kie.workbench.common.services.datamodeller.core.Method method : methods) {
addMethod(javaClassSource,
method,
classTypeResolver);
}
}
}
示例10: addMethod
import org.jboss.forge.roaster.model.source.MethodSource; //导入依赖的package包/类
private void addMethod(JavaClassSource javaClassSource,
org.kie.workbench.common.services.datamodeller.core.Method method,
ClassTypeResolver classTypeResolver) throws ClassNotFoundException {
MethodSource<JavaClassSource> methodSource = javaClassSource.addMethod();
methodSource.setName(method.getName());
methodSource.setReturnType(buildMethodReturnTypeString(method.getReturnType(),
classTypeResolver));
methodSource.setParameters(buildMethodParameterString(method.getParameters(),
classTypeResolver));
methodSource.setBody(method.getBody());
methodSource.setVisibility(buildVisibility(method.getVisibilty()));
for (Annotation annotation : method.getAnnotations()) {
addAnnotation(methodSource,
annotation);
}
}
示例11: execute
import org.jboss.forge.roaster.model.source.MethodSource; //导入依赖的package包/类
@Override
public Result execute(UIExecutionContext context) throws Exception
{
final Result result = original.execute(context);
final Project project = helper.getProject(context.getUIContext());
final DependencyFacet facet = project.getFacet(DependencyFacet.class);
// add dependencies
facet.addDirectDependency(SpringBootFacet.SPRING_BOOT_STARTER_WEB);
facet.addDirectDependency(SpringBootFacet.CXF_SPRING_BOOT);
facet.addDirectDependency(SpringBootFacet.JACKSON_JAXRS_PROVIDER);
// remove EE dependencies
facet.removeDependency(SpringBootFacet.JBOSS_EJB_SPEC);
facet.removeDependency(SpringBootFacet.JBOSS_JAXRS_SPEC);
facet.removeDependency(SpringBootFacet.JBOSS_SERVLET_SPEC);
facet.removeManagedDependency(SpringBootFacet.JBOSS_EE_SPEC);
// add CXF properties to application.properties
final Properties cxfProps = new Properties();
cxfProps.put("cxf.jaxrs.component-scan", "true");
cxfProps.put("cxf.path", "/rest");
SpringBootHelper.writeToApplicationProperties(project, cxfProps);
SpringBootHelper.modifySpringBootApplication(project, sbApp -> {
sbApp.addImport("com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider");
final MethodSource<JavaClassSource> method = sbApp.addMethod("public JacksonJsonProvider config() {\n" +
"\t\treturn new JacksonJsonProvider();\n" +
"\t}");
method.addAnnotation("org.springframework.context.annotation.Bean");
return sbApp;
});
return result;
}
示例12: createMethods
import org.jboss.forge.roaster.model.source.MethodSource; //导入依赖的package包/类
private List<ServiceMethod> createMethods(MethodHolderSource<?> source) {
List<ServiceMethod> results = Lists.newArrayList();
for (MethodSource<?> method : source.getMethods()) {
results.add(new ServiceMethod((JavaType<?>) source, method));
}
return results;
}
示例13: ServiceMethod
import org.jboss.forge.roaster.model.source.MethodSource; //导入依赖的package包/类
public ServiceMethod(JavaType<?> type, MethodSource<?> method) {
this.type = type;
this.method = method;
ServiceRequestProps globalProps = createProps(type);
ServiceRequestProps methodProps = createProps(method);
this.props = methodProps.merged(globalProps);
this.params = createParams(method);
}
示例14: findCreateRouteBuilderMethod
import org.jboss.forge.roaster.model.source.MethodSource; //导入依赖的package包/类
private static MethodSource<JavaClassSource> findCreateRouteBuilderMethod(JavaClassSource clazz) {
MethodSource method = clazz.getMethod("createRouteBuilder");
if (method != null && (method.isPublic() || method.isProtected()) && method.getParameters().isEmpty()) {
return method;
}
return null;
}
示例15: doParseCamelUris
import org.jboss.forge.roaster.model.source.MethodSource; //导入依赖的package包/类
private static List<ParserResult> doParseCamelUris(MethodSource<JavaClassSource> method, boolean consumers, boolean producers,
boolean strings, boolean fields) {
List<ParserResult> answer = new ArrayList<ParserResult>();
if (method != null) {
MethodDeclaration md = (MethodDeclaration) method.getInternal();
Block block = md.getBody();
if (block != null) {
for (Object statement : md.getBody().statements()) {
// must be a method call expression
if (statement instanceof ExpressionStatement) {
ExpressionStatement es = (ExpressionStatement) statement;
Expression exp = es.getExpression();
List<ParserResult> uris = new ArrayList<ParserResult>();
parseExpression(method.getOrigin(), block, exp, uris, consumers, producers, strings, fields);
if (!uris.isEmpty()) {
// reverse the order as we will grab them from last->first
Collections.reverse(uris);
answer.addAll(uris);
}
}
}
}
}
return answer;
}