Manipulating location is failing because of < and > in location - rascal

I have a location
|java+class:///smallsql/database/CommandDrop|(114,115,<3,68>,<8,5>)
which I would like to convert to
|project://SmallSQL/src/smallsql/database/CommandDrop.java|(114,115,<3,68>,<8,5>).
I want to do this by using toString, then manipulate the resulting String and then apply a toLocation. However, this is failing because toString will turn < into \< and similar for >. Now toLocation will see it as a malformed URI. Anyone any idea?

If you want to manipulate a path of a location, keeping the rest the same, just do it like this:
myLoc.path = myManipulation(myLoc.path);
where myManipulation is a function.
But to me it seems you just want to resolve the logical location to a physical one:
import IO;
myLoc = resolveLocation(myLoc);
Mind you, the project's M3 model must have been registered before using analysis::m3::Registry::registerProject otherwise the resolution won't work.
You can also directly look up the path you need by looking it up in the M3 model's declarations table.

Related

How to use the instance name as a string in Modelica code?

I have a Modelica simulation model composed by some models connected to each other.
I would like to save some data of some of the model instances in my simulation model at a given time using the built-in function
Modelica.Utilities.Streams.writeRealMatrix();
To be sure which instance writes which file, I would like to include the instance name in the writeRealMatrix() output file name, e.g., in case I have an instance called myModel, using the name:
myModelOut.mat.
To do this, I need a way to get the instance name and put it into a string.
I know that Modelica allows using instance names in model icons, through a Text record, using the keyword "%name", but I don't know how to do the same in a regular string (I mean outside any record or icon annotation).
Does anyone know if there is a way to do this?
Thank you in advance.
In your case I think the function getInstanceName() should be a good approach. Using it will need you to edit the model, but given you are writing information from with the class using writeRealMatrix() this shouldn't be an issue.
I have created a small example package with a constant block, that stores its name into final parameter of type String. The example then writes the string to the console at the termination of the simulation:
package GetName
block ConstantNamed "Generate constant signal of type Real"
extends Modelica.Blocks.Sources.Constant;
final parameter String name = getInstanceName();
end ConstantNamed;
model Example
extends Modelica.Icons.Example;
ConstantNamed myConst(k=23) annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
equation
when terminal() then
Modelica.Utilities.Streams.print("### Here is the models full path: '" + myConst.name + "'");
end when;
end Example;
annotation (uses(Modelica(version="4.0.0")));
end GetName;
This should result in a simulation log containing the path of the instance of ConstantNamed, which is Example.myConst:
Note: The print function is added to Example in the above code. It could be added to the ConstantNamed as well. For the case from the question, the print shouldn't be necessary anyways...
Besides that, in case you are using Dymola, there is the ModelManagement library, which contains some functions like ModelManagement.Structure.AST.Classes.ComponentsInClass. But these are more intended to be applied from "outside" to a given model.

Return Filtered Module in DXL

I need to make a filter in certain Module and get the filtered items and loop over them and do some kind of operation.
problem is filtering isn't done , something is wrong as follows :
Filter SwTest = includes(attribute "aVerificationStrategy" ,"SwTest")
Filter Implemented = (attribute "aObjectStatus" < "inReview")
Filter SwTestReqsCASTLE = SwTest && Implemented
Module m = srs_doc
set(m, SwTestReqsCASTLE, accepted , rejected)
filtering on OR ApplyFiltering(m) , i tried each as don't know difference !
so what is wrong ?
Before I answer your main question, first allow me to answer your implied question about the difference between "filtering on" and "ApplyFiltering(m)". The difference is that "filtering on" displays the current filter in the module window, meaning that objects are either shown or hidden depending on the filter. "ApplyFiltering(m)" applies the current filter settings to the module explorer (the area to the left of your objects that shows the hierarchy). "filtering on" shows and hides objects and "ApplyFiltering(m)" reflects the status of those objects in the module explorer.
As for why your filters are not being applied, there could be several reasons:
It is good practice to turn filtering off before you start setting filters. Add the line "filtering off" before the rest of your code.
Your "Implemented" filter is not defined properly. DOORS will see "inReview" as a string, and it will perform a direct comparison with the string value of your "aObjectStatus" attribute in order to determine if an object is accepted or rejected. Is this what you intended?
What type of variable is srs_doc? If it's a string then you need to
call read(), share(), or edit() in order to actually open the
module. If it is a module variable then that line is correct.
I am assuming that "accepted" and "rejected" are integers, but if they are not previously declared then they need to be.
Based on the first paragraph in my comment, your last line should read "filtering on"
Is the module you want to filter being displayed? I realize this is probably obvious, but I have made this mistake before so I thought I should mention it. A filter cannot be applied on a module that is not currently being displayed.
As a side note, you can compound your SwTest and Implemented filters without creating extra Filter variables as follows:
Filter SwTestReqsCASTLE = includes(attribute "aVerificationStrategy", "SwTest") && (attribute "aObjectStatus" < "inReview")
I hope some of that helps! Good luck, and let me know if none of the above solves your problem.

Custom Rascal location protocols for M3

The Java specific M3 has these pretty location protocols like java+method, java+enum, java+variable and many more. As far as I understand these pretty locations function as aliases for "real" locations like |project://example-project/src/HelloWorld.java|(0,1,<2,3>,<4,5>), referring to a specific piece of code within that file.
I would like to create those pretty locations for my own CSS specific M3. So they should look something like css+declaration or css+ruleset. I already have the actual "real" locations which I now directly pass on to the M3 Core. But this looks really messy and you cannot tell the locations apart.
So how do link my "real" locations to these pretty locations so that they actually function within the Rascal terminal? Can someone tell me the steps required to achieve this? Or maybe show me an example? I have already looked at the implementation for the Java specific M3 but I cannot seem to get my head around it.
Great question. To register the locations such that they are resolved on the REPL and in the IDE for opening files and such you have to register them with the "name server"
import analysis::m3::Registry;
registerProject(|project://myProject|, myM3Model); // side-effect alert!
This code will use the #declarations table from your M3 model which should map your logical locs to your physical locs.
It does that like so:
void registerProject(loc project, M3 model) {
rel[str scheme, loc name, loc src] perScheme
= {<name.scheme, name, src> | <name, src> <- model#declarations};
for (str scheme <- perScheme<scheme>)
registerLocations(scheme, project.authority, (name : src | <name, src> <- perScheme[scheme]));
}
From this code you can also learn that calling registerLocations directly is also possible. This basically adds a lookup map to the lookup registry, first indexed by scheme, then by authority and finally by path name.

Grails: query or criteria against a string/value pairs map property

Grails gives the possibility of creating simple string/value map properties section "Maps of Objects", first paragraph.
I was wondering, is there a way to later query the domain class (using Gorm dynamic finders, criterias or HQL) using the map property as part of the query (i.e adding a condition for the key X to have the value Y)?
After playing with it a bit and almost give up, I discovered the map syntax to (surprisingly) work in HQL. Assuming the class looks like:
class SomeClass {
Map pairKeyProperty
}
You can build queries that look like the following:
select * from SomeClass sc where sc.pairKeyProperty['someKey'] = 'someValue' and sc.pairKeyProperty['someOtherKey'] = 'someOtherValue'
Pretty neat! I still would prefer to use criterias as they are much cleaner to compose, but they seem to not support the same syntax (or I couldn't find it).
I created a sample app in GitHub:
https://github.com/deigote/grails-simple-map-of-string-value-pairs
It can be visisted at:
http://grails-map-of-string-pairs.herokuapp.com/
The form above uses a cross join. To enforce an inner join use
join sc.pairKeyProperty pk1 on index(pk1) = 'someKey'
where 'someValue' in elements(pk1)

JsonSerializer field order (don't want alphabetical) - Java

I'm using JsonSerializer to convert an Object to a JSON String but the order is wrong. The attributes are automatically sorted alphabetically but I want them in the order they have been listed in the class (e.g. "endPoint" should not appear before "startPoint").
When I call JsonSerializer. I only see 4 methods (toJava or toJson). I tried doing includes with the order but it doesn't work/I'm not doing it right. The way I'm doing it is like this:
return new String[]{"errorDescription", "searchResultRecord.billOfLadingNumber",
"searchResultRecord.bookingNumber", "searchResultRecord.advancedManifest",
"searchResultRecord.inboundCustomsClearanceStatus", "searchResultRecord.cargoReleaseStatus", "searchResultRecord.freightChargeReleaseStatus",
"searchResultRecord.container.containerNumber", "searchResultRecord.container.latestEvent.event",
"searchResultRecord.container.latestEvent.location", "searchResultRecord.container.latestEvent.time"};
As you can see there is obj.obj.attr parts being included. But when I try to run this code I only see "errorDescription" in the output string. I then tried "searchResultRecord" without attributes but it only showed 2 of the attributes in the output :x
Any idea how to fix the order so its not alphabetical? All examples online seem to be from an older version of the class with more accessible methods~ Thanks for any info.
You can try using
#XmlType(propOrder={"startPoint", "endPoint"})
on the class you defined as #XmlRootElement. Those attributes and any other you want will sorted as you defined on propOrder.

Resources