Home » Modeling » TMF (Xtext) » Detecting duplicate inferred types
Detecting duplicate inferred types [message #1065167] |
Mon, 24 June 2013 14:50 |
Zoltan Ujhelyi Messages: 392 Registered: July 2015 |
Senior Member |
|
|
Hi,
we are using JvmModelInferrer to generate a Java implementation from our Xbase-based language.
However, one of our users managed to create a set of input models that resulted in inferring two different classes with the same name. In this case, the model inference and code generation process executed without a warning (or error), only there were some hard to decipher errors in the generated code.
We want to detect this issue earlier, as it makes using our environment very hard, but I couldn't find the correct place to add this check. The simple declarative Java validator does not work, as I don't know the set of types already generated (e.g. by another model file), and in the JvmModelInferrer I only get back a new model element with the qualified name specified, so I also do not know whether the element exists.
Can you give me some hint where to add this validation logic?
Thanks in advance,
Zoltán
|
|
| |
Re: Detecting duplicate inferred types [message #1065284 is a reply to message #1065230] |
Tue, 25 June 2013 08:49 |
Zoltan Ujhelyi Messages: 392 Registered: July 2015 |
Senior Member |
|
|
Hi,
thanks for the answer. Sadly, it does not help too much for me - I do understand, that the Java validator is not the best place for describing this validation, however, I did not found any other place that could be used to detect this issue.
We have met several different manifestations of the same issue, as from a single model element ('pattern') we generate several different classes differentiated by a prefix, and it is possible to name the model elements in a way that these prefixes clash.
The best solution would be to detect when a name clash happens and report it (but only then). In worst case, I could write a validator that disallows such prefixing issues, but it would be a really artificial constraint, so I am looking for better solutions.
But thanks again,
Zoltán
|
|
| |
Re: Detecting duplicate inferred types [message #1065313 is a reply to message #1065310] |
Tue, 25 June 2013 10:05 |
Zoltan Ujhelyi Messages: 392 Registered: July 2015 |
Senior Member |
|
|
Hi,
sorry for being unclear - I left out another kind of inferred element.
The issue is, that the two kind of elements can result in a name clash, and either I have to limit file names or pattern names seriously, or introduce another set of name generation (seems really hard), or detect clashes at some point.
But a very similar issue can come forth with the single patterns as well: a fully qualified name of a pattern is calculated similarly to Java classes: a package declaration and the pattern name. However, these qualified names could clash between patterns, if they are put into multiple files. Such issues could be detected the same way, so I guess, it would be reasonable to find them the same way.
Thanks for your help again,
Zoltán
|
|
|
Re: Detecting duplicate inferred types [message #1065323 is a reply to message #1065167] |
Tue, 25 June 2013 10:27 |
Jan Koehnlein Messages: 760 Registered: July 2009 Location: Hamburg |
Senior Member |
|
|
Not sure it it works, but this is what I'd try:
If an element with the same name has already been created, it should be
indexed. So validate for each inferred JVM type, if an indexed element
exists and if so if its associated element (IJvmModelAssociations) is
the same. If not, it's a duplicate.
This could be a useful code pointer
org.eclipse.xtext.common.types.ui.refactoring.participant.JvmElementFinder.findJvmElementDeclarationInIndex(EObject,
IProject, ResourceSet)
Am 24.06.13 16:50, schrieb Zoltan Ujhelyi:
> Hi,
>
> we are using JvmModelInferrer to generate a Java implementation from our
> Xbase-based language.
>
> However, one of our users managed to create a set of input models that
> resulted in inferring two different classes with the same name. In this
> case, the model inference and code generation process executed without a
> warning (or error), only there were some hard to decipher errors in the
> generated code.
>
> We want to detect this issue earlier, as it makes using our environment
> very hard, but I couldn't find the correct place to add this check. The
> simple declarative Java validator does not work, as I don't know the set
> of types already generated (e.g. by another model file), and in the
> JvmModelInferrer I only get back a new model element with the qualified
> name specified, so I also do not know whether the element exists.
>
> Can you give me some hint where to add this validation logic?
>
> Thanks in advance,
> Zoltán
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
---
Get professional support from the Xtext committers at www.typefox.io
|
|
| | | | |
Goto Forum:
Current Time: Fri Apr 19 23:53:59 GMT 2024
Powered by FUDForum. Page generated in 0.03713 seconds
|