Java Code Examples for org.jboss.forge.roaster.model.source.JavaClassSource#getMethod()
The following examples show how to use
org.jboss.forge.roaster.model.source.JavaClassSource#getMethod() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CamelJavaParserHelper.java From fabric8-forge with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: CamelJavaParserHelper.java From fabric8-forge with Apache License 2.0 | 5 votes |
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; }
Example 3
Source File: RoasterSimpleRouteBuilderConfigureTest.java From fabric8-forge with Apache License 2.0 | 5 votes |
@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())); }
Example 4
Source File: CreateTestClassCommandTest.java From thorntail-addon with Eclipse Public License 1.0 | 4 votes |
@Test public void should_create_incontainer_test() throws Exception { assertThat(project.hasFacet(ThorntailFacet.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())); }
Example 5
Source File: CreateTestClassCommandTest.java From thorntail-addon with Eclipse Public License 1.0 | 4 votes |
@Test public void should_create_asclient_test() throws Exception { assertThat(project.hasFacet(ThorntailFacet.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())); }
Example 6
Source File: CreateTestClassCommandTest.java From thorntail-addon with Eclipse Public License 1.0 | 4 votes |
@Test public void should_set_archivetype_test() throws Exception { assertThat(project.hasFacet(ThorntailFacet.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())); }