Xbase: Fields in generated inner class not recognized, no problems as class in own file [message #1777774] |
Mon, 04 December 2017 15:04 |
René Bärnreuther Messages: 31 Registered: October 2017 |
Member |
|
|
Hi,
I'm struggeling with a strange problem currently.
In my Xbase based DSL I use Structures which are converted to Java Classes which contain attributes ( = fields).
So my DSL could look like this:
type Test : structure{
attribute b : integer;
}
main{
variable a : Test;
a.b <-- 4;
}
and the result should look something like this (you can ignore Serializable):
public class Model {
public static class Test implements Serializable {
public int b;
}
public static void main(final String[] Args) {
Test a= new Test();
a.b = 4;
}
If I build the class Test with the following as a class in a separate file it works perfectly fine.
The inferrer for this looks like this:
def inferStructs(List<Composition> types, IJvmDeclaredTypeAcceptor acceptor){
for(comp : types){
if (comp instanceof Composition) {
acceptor.accept(comp.toClass(comp.name)) [
superTypes += typeRef(Serializable)
for (attribute : comp.attributes) {
documentation = attribute.documentation
val field = attribute.toField(attribute.name, getTypeRefFor(attribute.typing))
field.visibility = JvmVisibility.PUBLIC
members += field
}
]
}
}
}
getTypeRef() returns the correct type and creates the correct field.
If I use my method to create it inside the class as a static inner class I get an error.
This is the inferrer to create it as inner class:
def inferStructsInClass(List<Composition> types, List<JvmMember> member){
for(comp : types){
if(comp instanceof Composition){
member += comp.toClass(comp.name)[
static = true
superTypes += typeRef(Serializable)
for(attribute : comp.attributes){
val field = attribute.toField(attribute.name, getTypeRefFor(attribute.typing))
field.visibility = JvmVisibility.PUBLIC
members+=field
}
]
}
}
}
The method where it gets called is the following:
def dispatch void infer(Program element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
val className = element.eResource.URI.trimFileExtension.lastSegment
//inferStructs(element.types.filter(Composition).toList,acceptor)
acceptor.accept(element.toClass(className)) [
inferEnums(element.types.filter(Enumeration).toList, members)
inferStructsInClass(element.types.filter(Composition).toList,members)
inferMethods((element.methods), members) /* Generate Mainblock */
if (element.mainBlock !== null) {
members += element.mainBlock.toMethod("main", typeRef(Void.TYPE)) [
parameters += element.toParameter("Args", typeRef("java.lang.String").addArrayTypeDimension)
static = true
documentation = element.mainBlock.documentation
body = element.mainBlock.body
]
}
]
}
The error I retrieve is the following:
java.lang.IllegalStateException: Cannot get name for JvmVoid: (eProxyURI: platform:/resource/StructureTest/src/model/Model.athena#|1)
at org.eclipse.xtext.xbase.compiler.output.SharedAppendableState.getName(SharedAppendableState.java:127)
at org.eclipse.xtext.xbase.compiler.output.TreeAppendable.getName(TreeAppendable.java:461)
at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.assignmentToJavaExpression(FeatureCallCompiler.java:889)
at de.ubt.ai1.athena.xbase.compiler.AthenaCompiler.assignmentToJavaExpression(AthenaCompiler.java:245)
at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.featureCalltoJavaExpression(FeatureCallCompiler.java:575)
at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler._toJavaStatement(FeatureCallCompiler.java:162)
at org.eclipse.xtext.xbase.compiler.FeatureCallCompiler.doInternalToJavaStatement(FeatureCallCompiler.java:111)
at org.eclipse.xtext.xbase.compiler.XbaseCompiler.doInternalToJavaStatement(XbaseCompiler.java:385)
at de.ubt.ai1.athena.xbase.compiler.AthenaCompiler.doInternalToJavaStatement(AthenaCompiler.java:263)
at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.internalToJavaStatement(AbstractXbaseCompiler.java:473)
at org.eclipse.xtext.xbase.compiler.XbaseCompiler._toJavaStatement(XbaseCompiler.java:410)
at org.eclipse.xtext.xbase.compiler.XbaseCompiler.doInternalToJavaStatement(XbaseCompiler.java:349)
at de.ubt.ai1.athena.xbase.compiler.AthenaCompiler.doInternalToJavaStatement(AthenaCompiler.java:263)
at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.internalToJavaStatement(AbstractXbaseCompiler.java:473)
at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.compile(AbstractXbaseCompiler.java:294)
at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.compile(AbstractXbaseCompiler.java:274)
at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.compile(JvmModelGenerator.java:1057)
at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateExecutableBody(JvmModelGenerator.java:1034)
at org.eclipse.xtext.xbase.compiler.JvmModelGenerator._generateMember(JvmModelGenerator.java:798)
at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateMember(JvmModelGenerator.java:1660)
at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.lambda$generateMembersInBody$2(JvmModelGenerator.java:292)
at org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow(ObjectExtensions.java:139)
at org.eclipse.xtext.xbase.compiler.LoopExtensions.lambda$forEach$0(LoopExtensions.java:38)
at java.lang.Iterable.forEach(Iterable.java:75)
at org.eclipse.xtext.xbase.compiler.LoopExtensions.forEach(LoopExtensions.java:40)
at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateMembersInBody(JvmModelGenerator.java:295)
at org.eclipse.xtext.xbase.compiler.JvmModelGenerator._generateBody(JvmModelGenerator.java:269)
at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateBody(JvmModelGenerator.java:1632)
at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateType(JvmModelGenerator.java:226)
at org.eclipse.xtext.xbase.compiler.JvmModelGenerator._internalDoGenerate(JvmModelGenerator.java:213)
at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.internalDoGenerate(JvmModelGenerator.java:1615)
at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.doGenerate(JvmModelGenerator.java:196)
at org.eclipse.xtext.generator.GeneratorDelegate.doGenerate(GeneratorDelegate.java:45)
at org.eclipse.xtext.generator.GeneratorDelegate.generate(GeneratorDelegate.java:34)
at org.eclipse.xtext.builder.BuilderParticipant.handleChangedContents(BuilderParticipant.java:588)
at org.eclipse.xtext.builder.BuilderParticipant.handleChangedContents(BuilderParticipant.java:573)
at org.eclipse.xtext.builder.BuilderParticipant.doGenerate(BuilderParticipant.java:558)
at org.eclipse.xtext.builder.BuilderParticipant.doBuild(BuilderParticipant.java:301)
at org.eclipse.xtext.builder.BuilderParticipant.build(BuilderParticipant.java:259)
at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant$DeferredBuilderParticipant.build(RegistryBuilderParticipant.java:161)
at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:69)
at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:291)
at org.eclipse.xtext.builder.impl.XtextBuilder.incrementalBuild(XtextBuilder.java:267)
at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:161)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:735)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:301)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:304)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:360)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:383)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:142)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:232)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
I already checked my method (AthenaCompiler, de.ubt.ai1.athena.xbase.compiler.AthenaCompiler.assignmentToJavaExpression(AthenaCompiler.java:245)) and found out, that the Feature of the expression (expr.getFeature() where expr is an Assignemtn) for the working case is "JvmFieldImplCustom" (which seems correct) whereas it is "JvmVoid" for the not working class when the class is generated as a inner class.
Has anyone an idea why this doesn't work?
Thanks in advance!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Xbase: Fields in generated inner class not recognized, no problems as class in own file [message #1777819 is a reply to message #1777818] |
Mon, 04 December 2017 20:09 |
|
i dont think content assit etc is all broken
should be a onliner in name provider eg.
class AthenaQualifiedNameProvider extends XbaseQualifiedNameProvider {
.....
public final static SimpleAttributeResolver<EObject, String> SIMPLENAME_RESOLVER = SimpleAttributeResolver.newResolver(String, "simpleName");
public override getFullyQualifiedName(EObject obj) {
if(obj instanceof Variable){
....
}
if (1==1) return super.getFullyQualifiedName(obj)
....
//return qualifiedNameConverter.toQualifiedName(name);
}
and similar in the computer
//TODO replace xxx with file name last segment
state.assignType(vr, getTypeForName("generated.xxx$"+comp.name, state))
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.04974 seconds