Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Detecting duplicate inferred types
Detecting duplicate inferred types [message #1065167] Mon, 24 June 2013 14:50 Go to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
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 #1065230 is a reply to message #1065167] Mon, 24 June 2013 22:46 Go to previous messageGo to next message
Ian McDevitt is currently offline Ian McDevittFriend
Messages: 70
Registered: December 2012
Location: Belfast
Member
This sounds like a package question. Or was this two separate models creating the same fully qualified names?

The validator checks the input model before inferring, it doesn't check the generated output so you would need to decide how the model/DSL specifies the output package as well as class name. If two models both specify the same package and the same class, and you want to prevent this, then you might need to enforce that something from the model name goes into the package or classname?
Re: Detecting duplicate inferred types [message #1065284 is a reply to message #1065230] Tue, 25 June 2013 08:49 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
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 #1065310 is a reply to message #1065284] Tue, 25 June 2013 09:56 Go to previous messageGo to next message
Ian McDevitt is currently offline Ian McDevittFriend
Messages: 70
Registered: December 2012
Location: Belfast
Member
If you have a single model element from which you are generating several different classes with different prefixes then I don't understand where there is a clash.
If your model element is called X and your different prefixes are A_ and B_ then you would generate classes called A_X and B_X, no?
Re: Detecting duplicate inferred types [message #1065313 is a reply to message #1065310] Tue, 25 June 2013 10:05 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
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 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
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
Re: Detecting duplicate inferred types [message #1065365 is a reply to message #1065323] Tue, 25 June 2013 12:56 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Thanks Jan,

that seems an idea that might be worth checking. I will look at it and report back with the results.

Cheers,
Zoltán
Re: Detecting duplicate inferred types [message #1713077 is a reply to message #1065365] Fri, 30 October 2015 16:01 Go to previous messageGo to next message
Denes Harmath is currently offline Denes HarmathFriend
Messages: 9
Registered: August 2014
Junior Member
Thanks for the pointer, we managed to detect fully qualified name clashes by using LiveShadowedResourceDescriptions#getExportedObjects(EClass, QualifiedName, boolean): if there is another exported object with the same FQN but a different URI than the validated model element, then we have a duplicate.
However, only those elements have to be checked that share classpath with the validated element, since if the generated classes are not in the same classpath, they will not cause any problems. Does Xtext offer a mechanism to get only the exported objects that are on the classpath of the given element? (We want to avoid any dependency to JDT and the Platform Resources API.)
Re: Detecting duplicate inferred types [message #1713084 is a reply to message #1713077] Fri, 30 October 2015 16:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you may have a look at org.eclipse.xtext.resource.containers.StateBasedContainerManager.getContainer(IResourceDescription, IResourceDescriptions) and its visible containers

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 30 October 2015 16:55]

Report message to a moderator

Re: Detecting duplicate inferred types [message #1713221 is a reply to message #1713084] Mon, 02 November 2015 13:49 Go to previous message
Denes Harmath is currently offline Denes HarmathFriend
Messages: 9
Registered: August 2014
Junior Member
Thank you very much, this solved our problem. For the record, the concepts are documented in https://eclipse.org/Xtext/documentation/303_runtime_concepts.html, chapter Global Scopes and Resource Descriptions.
Previous Topic:Null-Pointer Exception when using AssertError
Next Topic:Adding own extension class to domainmodel example
Goto Forum:
  


Current Time: Fri Apr 19 23:53:59 GMT 2024

Powered by FUDForum. Page generated in 0.03713 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top