Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getter dispatch in case of default value in K3 #55

Open
fcoulon opened this issue Oct 3, 2017 · 5 comments
Open

Getter dispatch in case of default value in K3 #55

fcoulon opened this issue Oct 3, 2017 · 5 comments

Comments

@fcoulon
Copy link
Contributor

fcoulon commented Oct 3, 2017

For the case:

  • An EClass containing an attribute foo
  • An Aspect over this class declaring foo with a default value
    Can we consider the aspect has the priority?

It is breaking a test case in Melange. We load a model of merged Ecore + Aspect and try to access the attribute declared in the Aspect but we access the null value of the model.

val gemocHackGetter = '''
try {
for (java.lang.reflect.Method m : _self.getClass().getMethods()) {
if (m.getName().equals("«IF f.type.simpleName == "boolean" || f.type.simpleName == "Boolean"»is«ELSE»get«ENDIF»«f.simpleName.substring(0,1).toUpperCase() + f.simpleName.substring(1)»") &&
m.getParameterTypes().length == 0) {
Object ret = m.invoke(_self);
if (ret != null) {
return («f.type.type.qualifiedName») ret;
}«IF !f.type.primitive» else {
return null;
}
«ENDIF»
}
}
} catch (Exception e) {
// Chut !
}
return «PROP_VAR_NAME».«f.simpleName»;

@ebousse
Copy link
Contributor

ebousse commented Oct 3, 2017

Are we talking about an EClass generated by Melange, where the foo attribute is automatically added with the aspect EAnnotation? Or are we talking about a user-made EClass which happens to have an aspect defining the attribute foo a second time?

  • In the first case, I would suggest to set the default value in the generated Ecore file, if possible.
  • In the second case, we would need to check if this is the first time that the attribute is being accessed, and if it is, we can indeed probably pick the aspect default value if the EMF value

@fcoulon
Copy link
Contributor Author

fcoulon commented Oct 3, 2017

I was talking of the first case but the second one is relevant too.

@ebousse
Copy link
Contributor

ebousse commented Oct 3, 2017

So for the first case, the best would be to patch Melange to generate a more complete EClass, where the EStructuralFeature foo has its defaultValue set to the one that was written in the aspect.

But can this default value be accessed when the aspect is parsed?

@fcoulon
Copy link
Contributor Author

fcoulon commented Oct 3, 2017

I guess we have to deal with Expression for default value at the Xtend side
Maybe the Java compiler is smart enough to evaluate it

@ebousse
Copy link
Contributor

ebousse commented Oct 3, 2017

Ah you are right, the expression might not be a primitive/serializable value...

In that case, yes you are right something smarter can be done in K3, such as checking only on the first access whether there is a default expression specified in the aspect.

@dvojtise dvojtise changed the title Getter dispatch Getter dispatch in case of default value in K3 Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants