Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » ensure import programatically
ensure import programatically [message #44962] Thu, 01 May 2008 20:26 Go to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 676
Registered: July 2009
Senior Member
Hey Paul,

is there a way to programatically (via scriptlet) add an import statement? My
use case:

I generate java classes from UML models. The structural part is done via JET,
method implementations are provided on the fly by a separate parser/generator
scheme.

For every field, I successfully make use of the <java:import> tag. For every UML
class I'd however also need to generate import statements from the "Element and
Package Import" elements in a model.

Now, if there's a field that has a type which is also imported via a
package/element import, I actually get the import twice. Once for the field, and
once for the element import model element.

I attached some piece of code, you'll see.

Thanks for suggestions.

Felix

<java:importsLocation package="{packageName($_class/@__qname)}"/>

<% ImportProvider provider = (ImportProvider)
context.getVariable("importProvider"); // this gives me package imports
Class thisClass = (Class) context.getVariable("_class");
List<String> importedPackages =
provider.getPackageImports(thisClass.getNearestPackage());
for (String _import : importedPackages) { %>
import <%=_import%>.*; // this is what I'd like JET to handle...
<% } %>
Re: ensure import programatically [message #45016 is a reply to message #44962] Sun, 04 May 2008 01:40 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Felix:

There's always a way :-)

This time, its pretty easy...

1) add dependencies (in plug-in manifest editor) to the following plug-in:
org.eclipse.emf.codegen

2) Add imports to the following two Java classes:
<%jet imports="org.eclipse.jet.taglib.java.JavaActionsUtil"%>
<%jet imports="org.eclipse.emf.codegen.util.ImportManager"%>

3) In your scriptlet:

<%
ImportManager im = JavaActionsUtil.getImportManager(out);
for(...) {
im.addImport(...);
}
%>

Paul
Re: ensure import programatically [message #45171 is a reply to message #45016] Wed, 07 May 2008 09:20 Go to previous message
Felix Dorner is currently offline Felix DornerFriend
Messages: 676
Registered: July 2009
Senior Member
Paul Elder wrote:
> Felix:
>
> There's always a way :-)
>
> This time, its pretty easy...

Yeah, it is! Thanks Paul. About the other issue with multivalued attributes,
I'll maby post a bug as you suggested later, right now I don't have time..
Previous Topic:Getting the name of an element which is itself an attribute value
Next Topic:Java class as source
Goto Forum:
  


Current Time: Tue Apr 23 14:23:45 GMT 2024

Powered by FUDForum. Page generated in 0.03498 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top