How to resolve a referenced type in a compilation unit [message #632056] |
Mon, 11 October 2010 07:47  |
Eclipse User |
|
|
|
Hello,
I'm trying to find a clean way to resolve a referenced type in a compilation unit.
For example, given the following code :
package com.example.rs;
import javax.persistence.EntityManager;
@Path(CustomerResource.URI_BASE)
public class CustomerResource {
private final org.slf4j.Logger logger = LoggerFactory.getLogger(CustomerResource.class);
@PersistenceContext
private EntityManager entityManager = null;
public static final String URI_BASE = "/customers";
...
}
I would expect the following results :
- resolveType(entityManager) -> IType(javax.persistence.EntityManager)
- resolveType(org.slf4j.Logger logger) -> IType(org.slf4j.Logger logger)
- resolveType(CustomerResource) -> IType(com.example.rs.CustomerResource)
For now, I managed to write a utility method that basically :
- creates an AST Parser and parses the given IType (here, CustomerResouce)
- retrieve the imports
- iterates on the ImportDeclarations to match the Type without the package name (EntityManager, Logger, CustomerResource)
- Returns the IType based on the fully qualified name
Is there somthing equivalent or better in the Eclipse AST/JDT APIs for such a need ?
Thank you in advance
Regards,
Xavier
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03223 seconds