Home » Archived » EMF-IncQuery » UML Incquery pattern : constrain to particular model name(UML Incquery pattern : constrain to particular model name)
|
Re: UML Incquery pattern : constrain to particular model name [message #1681814 is a reply to message #1681688] |
Tue, 17 March 2015 13:21 |
Eric Lépicier Messages: 25 Registered: October 2013 |
Junior Member |
|
|
Hi,
(1) The use you make of find getPackage+ is not correct.
The getPackage pattern must be written as a transitive pattern to be used in the find...+ transitive closure expression.
Your approach mimics imperative recursivity, and it isn't the right way to express your need.
You may try something like :
pattern filterToModel(m1: Class) {
Package.name(myProject, "MyProjectName");
find getPackage+(myProject, pack); // pack is a subpackage of myProject, at any level of subpackages
Class.^package(m1, pack);
}
pattern getPackage(pack:Package, subpack : Package) { // transitive pattern with two parameters of the same type, allowing recursive calls with find +
Package.nestingPackage(subpack, pack);
}
(2) I didn't find a way to do it, except adding a parameters model as a complementary resource, and then writing cross-resource patterns, thus querying both your UML model and your parameter model.
Cheers
--Eric
|
|
|
Re: UML Incquery pattern : constrain to particular model name [message #1681932 is a reply to message #1681814] |
Tue, 17 March 2015 14:21 |
Salwa Alzahmi Messages: 37 Registered: June 2013 |
Member |
|
|
Hi Eric , thanks for the reply,.
I tried your solution but dont seem to work .
the only concern that i have, is that the recursive call has to stop if it finds a package in the high hierarchy with a specific name . That is , if I have the Class c1, its parent package should be inherited from a package with the name "MyProjectName" . Otherwise that class should not be consider as a match .
I am asking for this , because when i display the classes in my UML model , it shows all class that is belong to my project and the external classes related to other java project such as (Thread , HttpRequest, ArrayList) .
I attached the code of the patterns .
Thank you
|
|
|
Re: UML Incquery pattern : constrain to particular model name [message #1682053 is a reply to message #1681932] |
Tue, 17 March 2015 15:24 |
Zoltan Ujhelyi Messages: 392 Registered: July 2015 |
Senior Member |
|
|
Hi Salwa,
(1) The problem with your getPackage pattern is that you are limiting it to packages named "MyProjectName" (as visible in your eiq file). You should do something similar as Eric proposed:
pattern filterToModel(m1: Class) {
//There is a package with the name "MyProjectName"
Package.name(myProject, "MyProjectName");
// pack is a subpackage (either direct or indirect) of myProject
find getPackage+(myProject, pack);
//m1 is a class in the Package pack
Class.^package(m1, pack);
}
/** This pattern enumerates all package-subpackage pairs. */
pattern childPackage(pack:Package, subpack : Package) {
Package.nestingPackage(subpack, pack);
}
(2) Loading the possible values from a file is possible, but not recommended. The main issue is that EMF-IncQuery addresses incremental queries; and unless the list of elements is fixed during the entire lifecycle it will not be safe to use. If it is fixed, you can use check expressions with corresponding Java functions that determines whether a package name is in your file.
However, I am not recommending to use this approach, as it is very easy to provide something that will not work correctly or performantly (basically, the check expressions are often not called, and there is no guaranteed execution path; and the calculated results are then cached).
On the other hand, if you want to use some packages, you could model them directly: either via corresponding profiles/stereotypes; or by creating an EMF model that refers to the enabled package instances, and use these references for matching.
I hope, this was clear. If not, please try to provide some details, what is not clear, what does it mean "I tried your solution but dont seem to work ." (e.g. what are the expected results, what results do you get, how does the instance model look like).
Cheers,
Zoltán
|
|
| |
Re: UML Incquery pattern : constrain to particular model name [message #1684170 is a reply to message #1683696] |
Wed, 18 March 2015 10:09 |
Zoltan Ujhelyi Messages: 392 Registered: July 2015 |
Senior Member |
|
|
Hi Salwa,
thanks for the attachments, I have now found different causes while your queries were not working as expected:
1. Your pattern definitions were using derived features (all such usage were reported by warnings in the code), and by default EMF-IncQuery does not allow the usage of derived features, as more often than not they do not provide correct change notifications, making incremental evaluation impossible. We are in the process of making such features available for querying (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=414824), and that feature should work shortly (I hope, they will be available next week). In the meanwhile, I have replaced the usage of these features with different model traversals to make the feature work.
2. "MyProjectName" was not a Package but a Model in UML terminology. This was problematic, because the getPackage pattern expected to have a Package as its first parameter, and would not match when called with a model. I have updated with an extra feature traversal that goes down one level from the Model to its member Packages, and then used these to call the getPackage pattern.
3. In the nonEmptyClass pattern in the filterModel call the name 'cl' was misspelled as 'c1'. The system issued a warning, as this is most likely not what you have wanted to provide, and it did not do correct filtering.
I have attached an updated version of your queries that worked in my incquery instance.
Cheers,
Zoltán
|
|
|
Re: UML Incquery pattern : constrain to particular model name [message #1684841 is a reply to message #1683696] |
Wed, 18 March 2015 15:51 |
Eric Lépicier Messages: 25 Registered: October 2013 |
Junior Member |
|
|
Salwa Alzahmi wrote on Wed, 18 March 2015 07:00Hi Zoltan,
(1) I tried Eric solution but the graph is not coming . Both of you suggested to get first the package ("MyProjectName"), and then go down in the sub-packages to get all classes. However, what confusing is hat you are using Package.nestingPackage (Go Up) instead of Package.nestedPackage (Go Down).
Hi,
Sorry if my answer was only based on my comprehension of your code snippet ...
I just want to mention that again, in your formulation, you consider incquery as an imperative language whereas it's a declarative one. There is no signification in the constraints order, none is "executed" first, and nobody "goes down" ...
So, one can read the filterToModel pattern either as "give me all classes in subpackages of MyProjectName", or as "is this particular class a member of a subpackage of MyProjectName". The constraint is the same : the existence of a matching path between MyProjectname and a class.
In the same way, there shall be no difference in matching a couple with a feature or its opposite.
pattern childPackage(pack:Package, subpack : Package) {
Package.nestingPackage(subpack, pack);
}
and
pattern childPackage(pack:Package, subpack : Package) {
Package.nestedPackages(pack, subpack);
}
are equivalent, as long as nestingPackage and nestedPackages are fully opposites.
Cheers,
--Eric
[Updated on: Fri, 20 March 2015 08:24] Report message to a moderator
|
|
| | | | | | | | |
Re: UML Incquery pattern : constrain to particular model name [message #1714310 is a reply to message #1710399] |
Wed, 11 November 2015 16:37 |
Abel Hegedus Messages: 197 Registered: September 2015 |
Senior Member |
|
|
First of all, sorry for the late answer, my subscription to this thread was lost when my e-mail changed.
I have tried your queries with the example model and found the issue. Your model looks like this:
- root : Model
--- my project : Model
--- externals : Model
However, that way, "externals" is a packaged element of "root". Furthermore, all Classes will match filterToModel, because they are contained by "root" (transitively).
Instead, you should check that a given class is not contained by the externals model, like this:
package uml.queries
import "http://www.eclipse.org/uml2/5.0.0/UML"
pattern getPackage(pack:Package, subpack : Package) {
Package.nestedPackage(pack, subpack);
}
pattern filterToModel(m1: Class) {
neg find containedByExternalModel(m1);
Package.packagedElement(_, m1);
}
pattern containedByExternalModel(m1: Class) {
find externalModel(myProject);
Model.packagedElement(myProject, topPackage);
find getPackage+(topPackage, pack);
Package.packagedElement(pack, m1);
}
pattern existModel(m:Model){
neg find externalModel(m);
}
pattern externalModel(m:Model){
Model.name(m, "externals");
}
|
|
|
Goto Forum:
Current Time: Thu Sep 26 21:06:59 GMT 2024
Powered by FUDForum. Page generated in 0.06097 seconds
|