[
https://issues.jboss.org/browse/ROASTER-62?page=com.atlassian.jira.plugin...
]
Nicolas Challut commented on ROASTER-62:
----------------------------------------
Whao, dat tricky way to create a class oO
You could use this way (import are automatic) :
{code}
JavaClassSource source = Roaster.create(JavaClassSource.class);
source.setName("Bar");
source.setSuperType("org.apache.camel.builder.RouteBuilder");
{code}
but you're right, addThrows should not import java.lang.Exception
Roaster - adds java.lang.xxx imports which is automatic in Java
---------------------------------------------------------------
Key: ROASTER-62
URL:
https://issues.jboss.org/browse/ROASTER-62
Project: Roaster
Issue Type: Bug
Environment: Using Forge 2.14.0 so I use the Roaster that is shipped
Reporter: Claus Ibsen
Priority: Minor
I have this code that creates a Apache Camel class for building routes.
{code}
// need to parse to be able to extends another class
String top = String.format("public class %s extends RouteBuilder {}",
name.getValue());
final JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, top);
if (targetPackage.getValue() != null) {
javaClass.setPackage(targetPackage.getValue());
}
javaClass.addImport("org.apache.camel.builder.RouteBuilder");
javaClass.addMethod()
.setPublic()
.setReturnTypeVoid()
.setName("configure")
.setBody("from(\"timer:foo\").to(\"log:foo\");")
.addThrows(Exception.class);
facet.saveJavaSource(javaClass);
{code}
Notice that the configure method has a throws java.lang.Exception.
The generated source code has import java.lang.Exception which is automatic in java, and
all java.lang is auto imported and not to be defined.
The generated code
{code}
davsclaus:/opt/forge-distribution-2.14.0.Final/mydemo/$ cat
src/main/java/com/foo/Bar.java
package com.foo;
import org.apache.camel.builder.RouteBuilder;
import java.lang.Exception;
public class Bar extends RouteBuilder
{
public void configure() throws Exception
{
from("timer:foo").to("log:foo");
}
}davsclaus:/opt/forge-distribution-2.14.0.Final/mydemo/$ mvn clean install
{code}
--
This message was sent by Atlassian JIRA
(v6.3.11#6341)