[Xtext2] Extending XbaseCompiler [message #685769] |
Sun, 19 June 2011 14:40  |
Eclipse User |
|
|
|
Hi,
I've added an own literal in the domain model example grammer like this:
XLiteral returns XExpression
: XClosure
| XBooleanLiteral
| XIntLiteral
| XNullLiteral
| XStringLiteral
| XTypeLiteral
// own literals
| XDateLiteral
;
XDateLiteral : value = STRING;
Now I want to create some code in the generated entity class and therefore I need to implement the _toJavaExpression method in the DomainmodelComplier, right?
Something similar to this:
public void _toJavaExpression(XDateLiteral lit, IAppendable b) {
b.append("new ");
b.append("java.text.SimpleDateFormat");
b.append("( \"").append(F_DATE).append("\" ).parse( \"").append(lit.getValue()).append("\" )");
}
(It is not really correct code as I took out some code to simplify the example)
The question is, how can I add the java.text.SimpleDateFormat to the ImportManager?
The API of IAppendable offers no access to it!
Thank,
Ingo Meyer
|
|
|
|
|
|
|
|
Re: [Xtext2] Extending XbaseCompiler [message #699889 is a reply to message #699860] |
Fri, 22 July 2011 10:30   |
Eclipse User |
|
|
|
Originally posted by:
On 22.07.11 15.53, Ingo Meyer wrote:
>
> Also one want to generate more then one java class from one model entity
> (e.g. interface and impl class). How can that be handled in the inferrer?
> With a lot of entities in the model we may have dependencies from entity
> A and B in both directions. As far as I found out the JdtTypeProvider
> can just reference already existing java classes in scr-gen folder,
> cause it wants to load them with the JDT AST parser in the
> JdtBasedTypeFactory.createType. This is totally strange for me as I just
> want to generate text files and the generator should not depend on a
> specific ordering of the generated artifacts!
My impression, from writing my own inferrer, is that the types will
either come from the classpath, i.e. existing classes indexed by Jdt, or
the set of classes inferred by you. In the latter case, you
create/instantiate the type/class descriptions yourself during the
inference, using an injected typesFactory, and when needed create
TypeReferences to them.
Hallvard
|
|
|
|
Re: [Xtext2] Extending XbaseCompiler [message #700667 is a reply to message #700638] |
Sat, 23 July 2011 17:10  |
Eclipse User |
|
|
|
Originally posted by:
On 23.07.11 22.25, Sven Efftinge wrote:
>
> So if you want to reference something which is not on the classpath
> you'll have to create the EMF objects somehow and make sure it is in the
> index.
I still wonder how to ensure that the manually created JvmTypes are in
the index. You wrote in a previous post that if you put them in the
resource's, at the top level, they would be indexed. What kind of
container should they (the JvmTypes) be collected in? An arbitrary
EObject? Would it also work if I put them in a separate resource in the
resourceSet (a bit cleaner)?
Hallvard
|
|
|
Powered by
FUDForum. Page generated in 0.04013 seconds