|
Re: [JET] How to load a java file with a fully qualified name? [message #664215 is a reply to message #664185] |
Thu, 07 April 2011 20:56   |
Eclipse User |
|
|
|
William:
JET has not tags to do this out of the box, but it would not be too difficult to create a custom JET tag that did what you want.
It might look something like:
<myjava:loadClass project="project name" fqn="..." var="varToSet"/>
The tag implementation would have to do a number of things:
1) resolve the project name into first an IProject and then a IJavaProject:
IProject proj = ResourcesPlugin.getWorkspace.getProject(prjName);
IJavaProject jProj = JavaCore.create(proj);
2) find the Java type (IType) corresponding to the fully qualified class name:
IType type = jProj.findType(fqClassName);
3) Use the ASTParser to get a DOM:
ASTParser parser = new ASTParser(AST.JLS3);
if(type.isBinary) {
parser.setSource( type.getClassFile() );
} else {
parser.setSource( type.getCompilationUnit() );
}
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
4) Set the JET variable:
context.setVariable( variableName, cu );
You could get fancier, but see if you can make that work first.
Paul
|
|
|
|
|
Re: [JET] How to load a java file with a fully qualified name? [message #664949 is a reply to message #664240] |
Tue, 12 April 2011 15:02  |
Eclipse User |
|
|
|
William:
Several things might be going wrong.
1) The tag isn't imported into the template. Two ways to do this:
i) an <%@taglib %> directive, with the fully qualified id of the tag library (plugin-id + '.' + id-used-in-the-declaring-plug.xml)
ii) import the tag library (with the same id as above) via the hosting JET project's plugin.xml. Need an 'importLibrary' tag with the autoImport attribute set to 'true'.
2) You developed your tag in a separate plug-in project (from the JET project), and you are trying to run the JET project from the workspace. This won't work. JET does some magic to load the JET project out of the workspace - it does not extend this ability to referenced plug-ins. The solution? Launch a runtime workbench that includes both the JET project and the plug-in project defining the tag, and test from there. OR, declare the tag in the sample plug-in as the JET templates
Paul
|
|
|
Powered by
FUDForum. Page generated in 0.26851 seconds