You can use the "resolveType" method to resolve the FQN:
JavaClassSource source = Roaster
.parse(JavaClassSource.class,
"import foo.bar.Talk;"
+ ""
+ "public class TalkService extends
CrudService<Talk, Long> {}");
String superType = source.getSuperType();
String firstType = Types.splitGenerics(superType)[0];
String resolvedType = source.resolveType(firstType);
System.out.println(resolvedType);// Returns "foo.bar.Talk"
Best Regards,
George Gastaldi
Principal Software Engineer
ggastald(a)redhat.com M: +55-47-99711-1000
<
https://red.ht/sig>
TRIED. TESTED. TRUSTED. <
https://redhat.com/trusted>
On Sat, Mar 9, 2019 at 5:01 PM Rafael Pestano <rmpestano(a)gmail.com> wrote:
Hi guys,
I have the following class:
public class TalkService extends CrudService<Talk, Long> ...
and I need to get the JavaClassSource of the first superClass type argment
(Talk).
The only way I've found was to get the type argument name and then find
the entity by looking at the imports but I wonder if there's a simpler way:
JavaClassSource service = Roaster.parse....
String entityName =
service.getSuperType().substring(service.getSuperType().indexOf("<")+1,service.getSuperType().indexOf(","));
Optional<Import> entityImport = service.getImports().stream().filter(i ->
i.getQualifiedName().endsWith(entityName))
.findFirst();
String entityQualifiedName = entityImport.get().getQualifiedName();
String sourceFolder =
sourceFacet.getSourceDirectory().getFullyQualifiedName();
JavaClassSource entity = Roaster.parse(JavaClassSource.class,
new File(sourceFolder + "/" + entityQualifiedName.replace(".",
"/") +
".java"));
--
Att,
Rafael M. Pestano
Desenvolvedor Java Cia. de Processamento de Dados do Rio Grande do Sul
http://rpestano.wordpress.com/
@realpestano
_______________________________________________
forge-users mailing list
forge-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/forge-users