DSL Type Parameter is not used in extends [message #1857599] |
Thu, 16 February 2023 08:50  |
Eclipse User |
|
|
|
In my DSL a Entity should be extended with a Java-class
***************************
Entity:
'entity' name=ValidID
('<' typeParameters+=JvmTypeParameter (',' typeParameters+=JvmTypeParameter)* '>')?
('extends' superType=JvmTypeReference)?
***************************
In the inferrer the entity-class is generated with following code:
***************************
def dispatch void infer(Entity entity, IJvmDeclaredTypeAcceptor acceptor, boolean isPrelinkingPhase) {
acceptor.accept(entity.toClass(entity.fullyQualifiedName)) [ entityType |
for ( typeParameter : entity.typeParameters) {
entityType.typeParameters += typeParameter.cloneWithProxies
}
if (entity.superType !== null) {
entityType.superTypes += entity.superType.cloneWithProxies
}
else {
entityType.superTypes += Object.typeRef
}
***************************
Wenn a entity with type-parameter is defined and the type-parameter is used as type-argument of the super-class, than as type-argument a questionmark ? is generated:
*** generated: ************************
public class Test<T extends Number> extends ArrayList<?> {
***************************
the dsl-code was
***************************
entity Test<T extends Number> extends ArrayList<T> {}
***************************
Question: how does the inferrer have to be adjusted so that the type argument of the super class is generated correctly with the type-argument T
*** should be generated: ************************
public class Test<T extends Number> extends ArrayList<T> {
***************************
|
|
|
|
|
|
|
Re: DSL Type Parameter is not used in extends [message #1857631 is a reply to message #1857613] |
Fri, 17 February 2023 04:34  |
Eclipse User |
|
|
|
Thomas,
I pasted the grammar snippet you provided into the DomainModel example:
Entity:
'entity' name=ValidID
('<' typeParameters+=JvmTypeParameter (',' typeParameters+=JvmTypeParameter)* '>')?
'extends' superType=JvmParameterizedTypeReference)? '{'
features+=Feature*
'}';
And added these lines to the inferred
for ( typeParameter : entity.typeParameters) {
it.typeParameters += typeParameter.cloneWithProxies
}
The compiled code for my sample model looks good.
package somePackage {
entity A<T extends Number> {
t: T
}
entity B<T extends Number> extends A<T> {}
}
package somePackage;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
@SuppressWarnings("all")
public class B<T extends Number> extends A<T> {
public B() {
}
public B(final Procedure1<B> initializer) {
initializer.apply(this);
}
@Override
public String toString() {
String result = new ToStringBuilder(this).addAllFields().toString();
return result;
}
}
I'm afraid you need to provide more information. Indeally a self-contained example with a unit test. If you have that available, please file a ticket on https://github.com/eclipse/xtext-extras.
[Updated on: Fri, 17 February 2023 04:34] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04025 seconds