ObeoNetwork / M2Doc

The M2Doc technology enables the generation of Office Open XML documents from models.
http://obeonetwork.github.io/M2Doc/
Eclipse Public License 2.0
39 stars 22 forks source link

Template construct does not support Custom Service #467

Closed mypsycho closed 2 years ago

mypsycho commented 2 years ago

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please have a look to the support pages of our website : http://m2doc.org/support/

Current behavior

Template Construct does not support the use of service provided by IServicesConfigurator. Validation fails when invocation is template construct. On the other side, validation does not fail when used in the body of the document.

Error is due to org.eclipse.acceleo.query.runtime.impl.JavaMethodService#matches(IReadOnlyQueryEnvironment, IType[]) When iType instanceof EClassifierLiteralType, 'cls' has a wrong value.

Expected behavior

In such case, validation should not fail and generation should be allowed.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

When a metamodel has inheritance, template construct is needed.

Environment


M2Doc version: 3.2.1
Eclipse version: 4.21.0
Platform version:   Windows 11 

Others:

Acceleo version: 3.7.11
mypsycho commented 2 years ago

Following patch in ssh://user@git.eclipse.org:29418/acceleo/org.eclipse.acceleo.git seems to be enough.

diff --git a/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/runtime/impl/JavaMethodService.java b/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/runtime/impl/JavaMethodService.java
index 460ecdd..72f5d2b 100644
--- a/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/runtime/impl/JavaMethodService.java
+++ b/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/runtime/impl/JavaMethodService.java
@@ -262,7 +262,7 @@
            Class<?> cls;
            final IType iType = argumentTypes[i];
            if (iType instanceof EClassifierLiteralType) {
-               cls = EClass.class;
+               cls = ((EClassifierLiteralType)iType).getType().getInstanceClass();
            } else if (iType instanceof EClassifierType) {
                cls = queryEnvironment.getEPackageProvider().getClass(((EClassifierType)iType).getType());
                if (cls == null) {
ylussaud commented 2 years ago

Thank you for reporting this issue. The fix seems a bit odd... This part of the code is used when providing an EClass to a service via pkg::EClass so the type of the element passed here is an EClass. Maybe something is missing in the initialization of the AQL interperter when evaluating a template construct...