|
Re: DSL Type Parameter is not used in extends [message #1857611 is a reply to message #1857599] |
Thu, 16 February 2023 20:14 |
|
hi, i tried this with domain model example in xtext/master and am getting
public class Test<T extends Number> extends ArrayList<T> {
=> can you provide reproducing example and unit test?
@Test def void compareGeneratedJava() throws Exception {
'''
import java.util.ArrayList
entity Test<T extends Number> extends ArrayList<T> {}
'''.compile[assertEquals('''
import java.util.ArrayList;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
@SuppressWarnings("all")
public class Test<T extends Number> extends ArrayList<T> {
@Override
public String toString() {
String result = new ToStringBuilder(this).addAllFields().toString();
return result;
}
}
'''.toString, getSingleGeneratedCode)
]
}
class DomainmodelJvmModelInferrer extends AbstractModelInferrer {
@Inject extension JvmTypesBuilder
@Inject extension IQualifiedNameProvider
@Inject extension DomainmodelJvmModelHelper
@Inject extension IJvmModelAssociations
@Inject extension IJvmModelAssociator
def dispatch infer(Entity entity, extension IJvmDeclaredTypeAcceptor acceptor, boolean prelinkingPhase) {
accept(entity.toClass( entity.fullyQualifiedName )) [
documentation = entity.documentation
for ( typeParameter : entity.typeParameters) {
it.typeParameters += typeParameter.cloneWithProxies
}
if (entity.superType !== null) {
it.superTypes += entity.superType.cloneWithProxies
}
else {
it.superTypes += Object.typeRef
}
// let's add a default constructor
members += entity.toConstructor []
// now let's go over the features
for ( f : entity.features ) {
.....
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
Re: DSL Type Parameter is not used in extends [message #1857628 is a reply to message #1857613] |
Fri, 17 February 2023 09:11 |
|
still cannot reproduce
MULTIPLE FILES WERE GENERATED
File 1 : /myProject/./src-gen/tommy/o/mvvm/dsl/test/TstEntityChildWithTypeParameter.java
package tommy.o.mvvm.dsl.test;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
@SuppressWarnings("all")
public class TstEntityChildWithTypeParameter<T extends Number> {
private T type;
public T getType() {
return this.type;
}
public void setType(final T type) {
this.type = type;
}
@Override
public String toString() {
String result = new ToStringBuilder(this).addAllFields().toString();
return result;
}
}
File 2 : /myProject/./src-gen/tommy/o/mvvm/dsl/test/TstEntityChildWithTypeParameterSub.java
package tommy.o.mvvm.dsl.test;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
@SuppressWarnings("all")
public class TstEntityChildWithTypeParameterSub<T extends Number> extends TstEntityChildWithTypeParameter<T> {
@Override
public String toString() {
String result = new ToStringBuilder(this).addAllFields().toString();
return result;
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
Re: DSL Type Parameter is not used in extends [message #1857631 is a reply to message #1857613] |
Fri, 17 February 2023 09:34 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
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 09:34] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04183 seconds