|
|
|
|
|
|
|
|
|
|
Re: (no subject) [message #691035 is a reply to message #691029] |
Thu, 30 June 2011 15:20 |
Missing name Mising name Messages: 15 Registered: June 2010 |
Junior Member |
|
|
I didn't know that was possible with Xtext 2.0.0, I thought you have to migrate to Xtend2...
Anyway, I'd still like to know how to get the path to the previously generated file (or its contents) in Xtend2 (when using the JavaProjectBasedBuilderParticipant). Is there any way to achieve this (other than hardcoding the path inside the Xtend2 template)?
Thank you
[Updated on: Fri, 01 July 2011 14:13] Report message to a moderator
|
|
|
Re: (no subject) [message #692051 is a reply to message #690633] |
Sun, 03 July 2011 10:32 |
|
Sven Efftinge wrote on Thu, 30 June 2011 04:14Am 6/29/11 9:40 PM, schrieb forums-noreply@eclipse.org:
> Hm, ok... But, how do I get to the contents of already generated files
> from the Xtend2 template then? Aren't there any plans to support
> something like protected regions in next releases of Xtext 2 directly
> inside the framework?
> Thanks for the replies
> Mio
In Xtend 2 a fucntion using a template expression really jsut returns a
CharSequence so you can easily postprocess it (i.e. replace a certain
marker with your protected regions contents).
We don't have plans to add support for it.
Sven
Aw..
Do you have plans to support IFileSystemAccess::getFileContents() ?
|
|
|
|
|
|
Re: (no subject) [message #696647 is a reply to message #693402] |
Thu, 14 July 2011 13:39 |
David Uebelacker Messages: 2 Registered: July 2011 |
Junior Member |
|
|
Hi
i run into the same problem. My generator should only generate a file if the file does not exists. After reading this post i was a little bit disappointed, but solved/hacked it as follows:
public class FileSystemUtils {
public void generateFileIfNotExists(IFileSystemAccess fsa, String fileName,
CharSequence contents) {
File tFile = new File(getBasePath(fsa).getAbsolutePath()
+ File.separator + fileName.substring(3));
if (!tFile.exists()) {
fsa.generateFile(fileName, contents);
}
}
public File getBasePath(IFileSystemAccess fsa) {
try {
Field rootField = fsa.getClass().getDeclaredField("root");
rootField.setAccessible(true);
Object rootObject = rootField.get(fsa);
Method folderMethod = rootObject.getClass().getMethod("getFolder",
String.class);
Object folder = folderMethod.invoke(rootObject, getProjectName(fsa)
+ File.separator + "tmp");
URI locationURI = (URI) folder.getClass()
.getMethod("getLocationURI").invoke(folder);
String tPath = locationURI.getPath();
File basePath = new File(tPath);
return basePath.getParentFile();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public String getProjectName(IFileSystemAccess fsa) {
try {
Field pathesField = AbstractFileSystemAccess.class
.getDeclaredField("pathes");
pathesField.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, String> pathes = (Map<String, String>) pathesField
.get(fsa);
return pathes.get(IFileSystemAccess.DEFAULT_OUTPUT).split(
File.separator)[1];
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
@Inject extension FileSystemUtils fsu
def doGenerate(Entity entity, IFileSystemAccess fsa){
var basePath = fsa.basePath;
fsa.generateFileIfNotExists("myProject/" + entity.name + ".h", entity.compileHeader)
It's not nice and works only with the EclipseResourceFileSystemAccess implementation, so i also would really be happy about an getBasePath method in IFileSystemAccess.
David
|
|
|
(no subject) [message #696651 is a reply to message #693402] |
Thu, 14 July 2011 13:39 |
David Uebelacker Messages: 2 Registered: July 2011 |
Junior Member |
|
|
Hi
i run into the same problem. My generator should only generate a file if the file does not exists. After reading this post i was a little bit disappointed, but solved/hacked it as follows:
public class FileSystemUtils {
public void generateFileIfNotExists(IFileSystemAccess fsa, String fileName,
CharSequence contents) {
File tFile = new File(getBasePath(fsa).getAbsolutePath()
+ File.separator + fileName.substring(3));
if (!tFile.exists()) {
fsa.generateFile(fileName, contents);
}
}
public File getBasePath(IFileSystemAccess fsa) {
try {
Field rootField = fsa.getClass().getDeclaredField("root");
rootField.setAccessible(true);
Object rootObject = rootField.get(fsa);
Method folderMethod = rootObject.getClass().getMethod("getFolder",
String.class);
Object folder = folderMethod.invoke(rootObject, getProjectName(fsa)
+ File.separator + "tmp");
URI locationURI = (URI) folder.getClass()
.getMethod("getLocationURI").invoke(folder);
String tPath = locationURI.getPath();
File basePath = new File(tPath);
return basePath.getParentFile();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public String getProjectName(IFileSystemAccess fsa) {
try {
Field pathesField = AbstractFileSystemAccess.class
.getDeclaredField("pathes");
pathesField.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, String> pathes = (Map<String, String>) pathesField
.get(fsa);
return pathes.get(IFileSystemAccess.DEFAULT_OUTPUT).split(
File.separator)[1];
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
@Inject extension FileSystemUtils fsu
def doGenerate(Entity entity, IFileSystemAccess fsa){
var basePath = fsa.basePath;
fsa.generateFileIfNotExists("myProject/" + entity.name + ".h", entity.compileHeader)
It's not nice and works only with the EclipseResourceFileSystemAccess implementation, so i also would really be happy about an getBasePath method in IFileSystemAccess.
David
|
|
|
|
[xtext 2.0] protected region support? [message #697026 is a reply to message #696748] |
Fri, 15 July 2011 10:46 |
|
+1 on enhancement request.
I disagree on getBasePath() though, it limits the functionality to the local filesystem.
A getBaseURI() would be more like it. A filesystem resource would return a "file:" URI while others, maybe virtual filesystems or inside Eclipse workspace will return a different scheme (a WebDAV resource could return "http:".. .
|
|
|
|
|
Re: [xtext 2.0] protected region support? [message #728707 is a reply to message #728464] |
Fri, 23 September 2011 17:40 |
|
I just realized that the built-in IFileSystemAccess implementations are (most common):
* JavaIoFileSystemAccess
* EclipseResourceFileSystemAccess
both contain a way to provide protected region support, albeit protected visibility (e.g. JavaIoFileSystemAccess.getPathes()) and needs to be subclassed.
Making getFileContents() and/or getFileUri() part of IFileSystemAccess would be great. Implementations that can't support it can just return UnsupportedOperationException (inherited from AbstractFilesystemAccess).
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05306 seconds