Skip to content

Commit

Permalink
use classToExtend in Domainmodel example
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Dec 23, 2023
1 parent f620b2a commit bad8527
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,29 @@ class CompilerTest {
]
}

@Test def void testGeneratedJavaInheritedMethod() throws Exception {
#[
'''
entity Foo extends Bar {
// getName and setName inherited from Bar
op doStuff(String x) : String {
return x + ' ' + getName()
}
}
''',
'''
entity Bar {
name : String
}
'''
].compile [
val fooObj = it.getCompiledClass("Foo").getDeclaredConstructor().newInstance
fooObj.invoke('setName', 'World')
assertEquals("Hello World", fooObj.invoke('doStuff','Hello'))
]
}


@Test def void compareGeneratedJava() throws Exception {
'''
entity Foo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,45 @@ public void testGeneratedJavaFromSeveralInputs() throws Exception {
this._compilationTestHelper.compile(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(_builder.toString(), _builder_1.toString())), _function);
}

@Test
public void testGeneratedJavaInheritedMethod() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("entity Foo extends Bar {");
_builder.newLine();
_builder.append("\t");
_builder.append("// getName and setName inherited from Bar");
_builder.newLine();
_builder.append("\t");
_builder.append("op doStuff(String x) : String {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return x + \' \' + getName()");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("entity Bar {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("name : String");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
try {
final Object fooObj = it.getCompiledClass("Foo").getDeclaredConstructor().newInstance();
this._reflectExtensions.invoke(fooObj, "setName", "World");
Assert.assertEquals("Hello World", this._reflectExtensions.invoke(fooObj, "doStuff", "Hello"));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
this._compilationTestHelper.compile(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(_builder.toString(), _builder_1.toString())), _function);
}

@Test
public void compareGeneratedJava() throws Exception {
StringConcatenation _builder = new StringConcatenation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class DomainmodelJvmModelInferrer extends AbstractModelInferrer {
def dispatch infer(Entity entity, extension IJvmDeclaredTypeAcceptor acceptor, boolean prelinkingPhase) {
accept(entity.toClass( entity.fullyQualifiedName )) [
documentation = entity.documentation
if (entity.superType !== null)
superTypes += entity.superType.cloneWithProxies
classToExtend = entity.superType.cloneWithProxies

// let's add a default constructor
members += entity.toConstructor []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.eclipse.xtext.common.types.JvmGenericType;
import org.eclipse.xtext.common.types.JvmMember;
import org.eclipse.xtext.common.types.JvmOperation;
import org.eclipse.xtext.common.types.JvmParameterizedTypeReference;
import org.eclipse.xtext.common.types.JvmTypeReference;
import org.eclipse.xtext.example.domainmodel.domainmodel.Entity;
import org.eclipse.xtext.example.domainmodel.domainmodel.Feature;
Expand Down Expand Up @@ -64,13 +63,7 @@ public class DomainmodelJvmModelInferrer extends AbstractModelInferrer {
protected void _infer(final Entity entity, @Extension final IJvmDeclaredTypeAcceptor acceptor, final boolean prelinkingPhase) {
final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
this._jvmTypesBuilder.setDocumentation(it, this._jvmTypesBuilder.getDocumentation(entity));
JvmParameterizedTypeReference _superType = entity.getSuperType();
boolean _tripleNotEquals = (_superType != null);
if (_tripleNotEquals) {
EList<JvmTypeReference> _superTypes = it.getSuperTypes();
JvmTypeReference _cloneWithProxies = this._jvmTypesBuilder.cloneWithProxies(entity.getSuperType());
this._jvmTypesBuilder.<JvmTypeReference>operator_add(_superTypes, _cloneWithProxies);
}
it.setClassToExtend(this._jvmTypesBuilder.cloneWithProxies(entity.getSuperType()));
EList<JvmMember> _members = it.getMembers();
final Procedure1<JvmConstructor> _function_1 = (JvmConstructor it_1) -> {
};
Expand Down

0 comments on commit bad8527

Please sign in to comment.