Generating code via Xtend - how to check if target file already exists? Purpose: do not overwrite user created content

226 views
Skip to first unread message

gwie...@gmail.com

unread,
Mar 24, 2014, 10:41:02 AM3/24/14
to xtend...@googlegroups.com
Hi,

i've been using Xpand previously, and I'm somehow lost to achieve the following:

We are more or less generating a JPA repository with certain findByXXX methods, and we want to allow the programmer to provide his own finder methods. To achieve that, we generate an abstract java class as JPA repository, and if the target file does not exist, generate the class that derives from this class and where the user can add his own code. This is more or less the "old style" approach from Xpand and the old version of Xtend.

Maybe I'm missing alternatives with Xpand2, so I'm trying to do the same inside the generator (implement IGenerator), but of course I only have access to Ressource and IFileSystemAccess. I find no way how to find the absolute path of a file so that I can test for its existence. Every access to an URI instance (via Ressource, via IFileSystemAccessExtension2) leads to a path that is, even though requested to be absolute, relative to the working directory. And actually I would need access to the OutputConfiguration instance that is used when I create the content via IFileSystemAccess.generateFile().

Any ideas? As said, I'm probably doing something very wrong here trying to achieve things similar to the "old school" style.

Sven Efftinge

unread,
Mar 24, 2014, 10:55:57 AM3/24/14
to xtend...@googlegroups.com
This is not related to Xtend but about the code generation API provided by Xtext.
So please ask subsequent questions on the Xtext forum.

There are some extension interface to IFileSystemAccess. 
IFileSystemAccessExtension2 might be what you are looking for. You’ll have to downcast.

The reason why there is an abstraction over the filesystem is because within Eclipse a different file system API is used than in standalone vanilla Java mode.

Sven

--
You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

signature.asc
Reply all
Reply to author
Forward
0 new messages