Sven, here is some more information, and a simplification of what I was trying to do:
My Annotation
@Retention(RetentionPolicy::SOURCE)
@Target(ElementType::TYPE)
@Active(ProjectStructureProcessor)
annotation ProjectStructure
{
}
My Annotated Interface
@ProjectStructure()
interface ResourceDefinition
{
def String aaa()
}
My Annotation Processor
class ProjectStructureProcessor extends AbstractInterfaceProcessor
{
def private List<Path> getPaths(Path folder, extension TransformationContext context)
{
log("folder: " + folder)
val list = <Path>newArrayList()
val q = new LinkedList<Path>
q.offer(folder)
while (!q.empty)
{
val p = q.poll
log("poll q: " + p)
list.add(p)
context.getChildren(p).forEach[q.add(it)]
}
list
}
override doRegisterGlobals(InterfaceDeclaration annotatedInterface, RegisterGlobalsContext context)
{
super.doRegisterGlobals(annotatedInterface, context)
}
override doTransform(MutableInterfaceDeclaration annotatedInterface, extension TransformationContext context)
{
super.doTransform(annotatedInterface, context)
log(annotatedInterface.toString)
val projectFolder = annotatedInterface.compilationUnit.filePath.projectFolder
log("project\n" + getPaths(projectFolder, context).toString)
val sourceFolder = annotatedInterface.compilationUnit.filePath.sourceFolder
log("source\n" + getPaths(sourceFolder, context).toString)
val targetFolder = annotatedInterface.compilationUnit.filePath.targetFolder
log("target\n" + getPaths(targetFolder, context).toString)
}
override doGenerateCode(InterfaceDeclaration annotatedInterface, extension CodeGenerationContext context)
{
super.doGenerateCode(annotatedInterface, context)
}
}
And here is an exception I get on the annotated interface:
Error during annotation processing:
java.lang.IllegalArgumentException:
Path must include project and resource name: /MiscTools
at
org.eclipse.core.runtime.Assert.isLegal(Assert.java:63)
at
org.eclipse.core.internal.resources.Workspace.newResource(Workspace.java:2163)
at
org.eclipse.core.internal.resources.Container.getFolder(Container.java:222)
at
org.eclipse.xtext.xbase.ui.file.EclipseFileSystemSupportImpl.getEclipseFolder(EclipseFileSystemSupportImpl.java:56)
at
org.eclipse.xtext.xbase.ui.file.EclipseFileSystemSupportImpl.getChildren(EclipseFileSystemSupportImpl.java:76)
at
org.eclipse.xtend.core.macro.TransformationContextImpl.getChildren(TransformationContextImpl.java:338)
at
resources.ProjectStructureProcessor.getPaths(ProjectStructureProcessor.java:42)
at
resources.ProjectStructureProcessor.doTransform(ProjectStructureProcessor.java:70)
at
annotation.processing.AbstractInterfaceProcessor.doTransform(AbstractInterfaceProcessor.java:18)
If I try and process the source directory first (rather than the project folder) I get a different exception on the annotated interface:Error during annotation processing:
org.eclipse.core.internal.resources.ResourceException:
Resource '/MiscTools/source/tools/SomeTool.xtend'
does not exist.
at org.eclipse.core.internal.resources.Resource.checkExists(Resource.java:341)
at
org.eclipse.core.internal.resources.Resource.checkAccessible(Resource.java:215)
at
org.eclipse.core.internal.resources.Container.members(Container.java:266)
at
org.eclipse.core.internal.resources.Container.members(Container.java:249)
at
org.eclipse.xtext.xbase.ui.file.EclipseFileSystemSupportImpl.getChildren(EclipseFileSystemSupportImpl.java:77)
at
org.eclipse.xtend.core.macro.TransformationContextImpl.getChildren(TransformationContextImpl.java:338)
...
I hope this sheds some light on the problem.
Thanks,
Chris.