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


Java JavaClassSource.getMethod方法代码示例

本文整理汇总了Java中org.jboss.forge.roaster.model.source.JavaClassSource.getMethod方法的典型用法代码示例。如果您正苦于以下问题:Java JavaClassSource.getMethod方法的具体用法?Java JavaClassSource.getMethod怎么用?Java JavaClassSource.getMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jboss.forge.roaster.model.source.JavaClassSource的用法示例。


在下文中一共展示了JavaClassSource.getMethod方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findConfigureMethod

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的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;
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:17,代码来源:CamelJavaParserHelper.java

示例2: findCreateRouteBuilderMethod

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的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;
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:8,代码来源:CamelJavaParserHelper.java

示例3: parse

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
@Test
public void parse() throws Exception {
    JavaClassSource clazz = (JavaClassSource) Roaster.parse(new File("src/test/java/io/fabric8/forge/camel/java/MySimpleRouteBuilder.java"));
    MethodSource<JavaClassSource> method = clazz.getMethod("configure");

    List<ParserResult> list = CamelJavaParserHelper.parseCamelSimpleExpressions(method);
    for (ParserResult simple : list) {
        System.out.println("Simple: " + simple.getElement());
        System.out.println("  Line: " + findLineNumber(simple.getPosition()));
    }
    Assert.assertEquals("${body} > 100", list.get(0).getElement());
    Assert.assertEquals(26, findLineNumber(list.get(0).getPosition()));
    Assert.assertEquals("${body} > 200", list.get(1).getElement());
    Assert.assertEquals(29, findLineNumber(list.get(1).getPosition()));
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:16,代码来源:RoasterSimpleRouteBuilderConfigureTest.java

示例4: processRestControllerClass

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
/**
 * Processes a Spring MVC REST controller class that is annotated with RestController. Also collects any required model objects based on parameters and
 * return types of each endpoint into the specified model classes set.
 *
 * @param clazz the class to process
 *
 * @throws MojoExecutionException if any errors were encountered.
 */
private void processRestControllerClass(Class<?> clazz) throws MojoExecutionException
{
    // Get the Java class source information.
    JavaClassSource javaClassSource = sourceMap.get(clazz.getSimpleName());
    if (javaClassSource == null)
    {
        throw new MojoExecutionException("No source resource found for class \"" + clazz.getName() + "\".");
    }

    Api api = clazz.getAnnotation(Api.class);
    boolean hidden = api != null && api.hidden();

    if ((clazz.getAnnotation(RestController.class) != null) && (!hidden))
    {
        log.debug("Processing RestController class \"" + clazz.getName() + "\".");

        // Default the tag name to the simple class name.
        String tagName = clazz.getSimpleName();

        // See if the "Api" annotation exists.
        if (api != null && api.tags().length > 0)
        {
            // The "Api" annotation was found so use it's configured tag.
            tagName = api.tags()[0];
        }
        else
        {
            // No "Api" annotation so try to get the tag name from the class name. If not, we will stick with the default simple class name.
            Matcher matcher = tagPattern.matcher(clazz.getSimpleName());
            if (matcher.find())
            {
                // If our class has the form
                tagName = matcher.group("tag");
            }
        }
        log.debug("Using tag name \"" + tagName + "\".");

        // Add the tag and process each method.
        swagger.addTag(new Tag().name(tagName));
        for (Method method : clazz.getDeclaredMethods())
        {
            // Get the method source information.
            List<Class<?>> methodParamClasses = new ArrayList<>();
            for (Parameter parameter : method.getParameters())
            {
                methodParamClasses.add(parameter.getType());
            }
            MethodSource<JavaClassSource> methodSource =
                javaClassSource.getMethod(method.getName(), methodParamClasses.toArray(new Class<?>[methodParamClasses.size()]));
            if (methodSource == null)
            {
                throw new MojoExecutionException(
                    "No method source found for class \"" + clazz.getName() + "\" and method name \"" + method.getName() + "\".");
            }

            // Process the REST controller method along with its source information.
            processRestControllerMethod(method, clazz.getAnnotation(RequestMapping.class), tagName, methodSource);
        }
    }
    else
    {
        log.debug("Skipping class \"" + clazz.getName() + "\" because it is either not a RestController or it is hidden.");
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:73,代码来源:RestControllerProcessor.java

示例5: should_create_incontainer_test

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
@Test
public void should_create_incontainer_test() throws Exception
{
   assertThat(project.hasFacet(WildFlySwarmFacet.class), is(true));
   try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class,
            project.getRoot()))
   {
      controller.initialize();
      controller.setValueFor("targetPackage", "org.example");
      controller.setValueFor("named", "HelloWorldTest");

      assertThat(controller.isValid(), is(true));
      final AtomicBoolean flag = new AtomicBoolean();
      controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
      {
         @Override
         public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
         {
            if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created"))
            {
               flag.set(true);
            }
         }
      });
      controller.execute();
      assertThat(flag.get(), is(true));
   }
   JavaResource javaResource = project.getFacet(JavaSourceFacet.class)
            .getTestJavaResource("org.example.HelloWorldTest");
   assertThat(javaResource.exists(), is(true));
   JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents());
   assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue())));
   final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment");
   assertThat(defaultDeployment, is((notNullValue())));
   assertThat(defaultDeployment.getValues().size(), is(0));

   final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service");
   assertThat(testMethod, is(notNullValue()));
   assertThat(testMethod.getAnnotation(Test.class), is(notNullValue()));

}
 
开发者ID:forge,项目名称:wildfly-swarm-addon,代码行数:42,代码来源:CreateTestClassCommandTest.java

示例6: should_create_asclient_test

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
@Test
public void should_create_asclient_test() throws Exception
{
   assertThat(project.hasFacet(WildFlySwarmFacet.class), is(true));
   try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class,
            project.getRoot()))
   {
      controller.initialize();
      controller.setValueFor("targetPackage", "org.example");
      controller.setValueFor("named", "HelloWorldTest");
      controller.setValueFor("asClient", true);

      assertThat(controller.isValid(), is(true));
      final AtomicBoolean flag = new AtomicBoolean();
      controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
      {
         @Override
         public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
         {
            if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created"))
            {
               flag.set(true);
            }
         }
      });
      controller.execute();
      assertThat(flag.get(), is(true));
   }

   JavaResource javaResource = project.getFacet(JavaSourceFacet.class)
            .getTestJavaResource("org.example.HelloWorldTest");
   assertThat(javaResource.exists(), is(true));
   JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents());
   assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue())));

   final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment");
   assertThat(defaultDeployment, is((notNullValue())));
   final String testable = defaultDeployment.getLiteralValue("testable");
   assertThat(testable, is("false"));

   final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service");
   assertThat(testMethod, is(notNullValue()));
   assertThat(testMethod.getAnnotation(Test.class), is(notNullValue()));

}
 
开发者ID:forge,项目名称:wildfly-swarm-addon,代码行数:46,代码来源:CreateTestClassCommandTest.java

示例7: should_set_archivetype_test

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
@Test
public void should_set_archivetype_test() throws Exception
{
   assertThat(project.hasFacet(WildFlySwarmFacet.class), is(true));
   try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class,
            project.getRoot()))
   {
      controller.initialize();
      controller.setValueFor("targetPackage", "org.example");
      controller.setValueFor("named", "HelloWorldTest");
      controller.setValueFor("archiveType", "WAR");

      assertThat(controller.isValid(), is(true));
      final AtomicBoolean flag = new AtomicBoolean();
      controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
      {
         @Override
         public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
         {
            if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created"))
            {
               flag.set(true);
            }
         }
      });
      controller.execute();
      assertThat(flag.get(), is(true));
   }

   JavaResource javaResource = project.getFacet(JavaSourceFacet.class)
            .getTestJavaResource("org.example.HelloWorldTest");
   assertThat(javaResource.exists(), is(true));
   JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents());
   assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue())));

   final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment");
   assertThat(defaultDeployment, is((notNullValue())));
   final String testable = defaultDeployment.getLiteralValue("type");
   assertThat(testable, is("DefaultDeployment.Type.WAR"));

   final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service");
   assertThat(testMethod, is(notNullValue()));
   assertThat(testMethod.getAnnotation(Test.class), is(notNullValue()));

}
 
开发者ID:forge,项目名称:wildfly-swarm-addon,代码行数:46,代码来源:CreateTestClassCommandTest.java

示例8: should_set_mainclass_test

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
@Test
public void should_set_mainclass_test() throws Exception
{
   assertThat(project.hasFacet(WildFlySwarmFacet.class), is(true));
   try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class,
            project.getRoot()))
   {
      controller.initialize();
      controller.setValueFor("targetPackage", "org.example");
      controller.setValueFor("named", "HelloWorldTest");
      controller.setValueFor("archiveType", "WAR");
      controller.setValueFor("mainClass", "org.example.Main");

      assertThat(controller.isValid(), is(true));
      final AtomicBoolean flag = new AtomicBoolean();
      controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
      {
         @Override
         public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
         {
            if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created"))
            {
               flag.set(true);
            }
         }
      });
      controller.execute();
      assertThat(flag.get(), is(true));
   }

   JavaResource javaResource = project.getFacet(JavaSourceFacet.class)
            .getTestJavaResource("org.example.HelloWorldTest");
   assertThat(javaResource.exists(), is(true));
   JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents());
   assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue())));

   final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment");
   assertThat(defaultDeployment, is((notNullValue())));
   final String testable = defaultDeployment.getLiteralValue("type");
   assertThat(testable, is("DefaultDeployment.Type.WAR"));

   final String main = defaultDeployment.getLiteralValue("main");
   assertThat(main, is("org.example.Main"));

   final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service");
   assertThat(testMethod, is(notNullValue()));
   assertThat(testMethod.getAnnotation(Test.class), is(notNullValue()));

}
 
开发者ID:forge,项目名称:wildfly-swarm-addon,代码行数:50,代码来源:CreateTestClassCommandTest.java


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