I'm new to eclipse's TPTP profiling tool . I have received a TPTP trace and I need help to understand the content provided.
The trace that contains function call entry and exists alongside with parameter of the function call on entry. It is from JHotDraw, a Java program . Here is a sample of the trace:
Entered: CH/ifa/draw/standard/ToolButton.paint---[sun.java2d.SunGraphics2D[font=javax.swing.plaf.FontUIResource[family=Dialog,name=Dialog,style=bold,size=12],color=sun.swing.PrintColorUIResource[r=51,g=51,b=51]]]
Exited: CH/ifa/draw/standard/ToolButton.paint---[sun.java2d.SunGraphics2D[font=javax.swing.plaf.FontUIResource[family=Dialog,name=Dialog,style=bold,size=12],color=sun.swing.PrintColorUIResource[r=51,g=51,b=51]]]
Entered: CH/ifa/draw/application/DrawApplication.paletteUserOver---[CH.ifa.draw.standard.ToolButton[,304,1,24x24,disabled,alignmentX=0.0,alignmentY=0.5,border=javax.swing.border.CompoundBorder#1308786,flags=296,maximumSize=,minimumSize=,preferredSize=,defaultIcon=javax.swing.ImageIcon#1f647e2,disabledIcon=sun.swing.ImageIconUIResource#d253d9,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=14,bottom=2,right=14],paintBorder=true,paintFocus=true,pressedIcon=javax.swing.ImageIcon#924039,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=javax.swing.ImageIcon#5c7d2e,text=,defaultCapable=false], false]
My questions are:
1)I would like to know why the parameters are sometimes detailed in variable\value pairs (like the PrintColorUIResource object in the first line) and sometimes given as a reference like ImageIcon#924039?
According tot he doc args should output all method arguments.
2) When the parameter is a complex type, how does TPTP describe its content? For example, in the first line, the parameter of the function is an object of type sun.java2d.SunGraphics2D. This object is described by two values, font and color, each of which is recessively defined. From the documentation (link below), I can see the object SunGraphics2D has dozens of local variables, one of which is called font, but none called color. The constructor does have two parameters color and font, but also two other parameters.
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b27/sun/java2d/SunGraphics2D.java
Likewise object sun.swing.PrintColorUIResource at the end of the same function call is described w.r.t. 3 valuse, r,g,b. I can't find these variable in the documentation.
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/sun/swing/PrintColorUIResource.java#PrintColorUIResource
3) Why is the value or the variable name sometimes ommited? eg: maximumSize=,minimumSize=, ... or at the end of the 3rd fct call : =false], false]
4) Is there any documentation I can refer myself to to better understand the trace content?
Thank you for your help and your kind consideration.
Related
I'm writing MATLAB functions for use by others. I know how to use nargin, varargin, etc. to create a function with variable number of inputs.
The function I'm currently writing is recursive and I need to pass an argument to handle the recursion, but the user should never pass anything in for that argument (or they should pass in the non-intuitive starting value, but they don't need to be distracted by that). I want to 'hide' this argument from the user, so that when they're writing code to use this function and MATLAB pops up that little yellow window that tells them what arguments the function takes, it just prompts them for the arguments they care about.
To be more explicit, when you type rand(, MATLAB pops up a little help window with
rand()
rand(n)
rand(sz1,...,szN)
...
My function recursively builds a matrix and I've currently defined it this way:
function ret = M(arg1, arg2, HideThisRecursiveArgument)
% code that sets the starting value for HideThisRecursiveArgument when it's not passed
% code that calls M(...) again with a different recursion value
end
When the user types M(, I want MATLAB's little help popup to display the usage as:
M(arg1, arg2)
(arg1 and arg2 are named in a self descriptive manner, so this would be a sufficient 'help page' for my function.)
How can I document this usage so MATLAB's function usage help popup will display this to the user?
If I use varargin, the user might get distracted/confused by trying to figure out what else could be passed in, so that's unsatisfactory. I've tried defining my function with 2 arguments and then looking for a 3rd when it's called, but MATLAB doesn't like that.
Edit
I've found the Add Help for Your Program page, and if the user uses the help command or clicks the More Help... link in that yellow usage popup, I can control what they see there, but this doesn't tell me how to control what appears on the usage popup.
I would opt for two separate interfaces, the function to be called externally and your internal recursive function with the hidden argument:
function z=foo(x,y)
z=internalfoo(x,y,pi);
end
function z=internalfoo(x,y,secret)
if x>y
z=internalfoo(y,x,secret);
else
z=secret*x;
end
end
You can place both in the same file foo.m, only the foo() can be called externally (unless you do nasty stuff). Above example contains a local function. Depending on your task a nested function with shared variables is sometimes practical for recursion.
Regarding the second part of your question, look into functionSignatures.json. This allows you to customize the code suggestions and completions, unfortunately only within the Live Editor.
Examples incl. multiple signatures for the same function can be found in the doc.
Note: I had to restart MATLAB prior to experimenting in the Live Editor
Additionally, if you use R2021a checkout the new arguments syntax for declaring function argument validation, see doc.
First of all, matlab version is 2011b, so I cannot use Simulink.MaskParameters class.
I have one simulink mask and some parameters inside. I need to determine in my function for each parameter if it is "evaluable" or "tunable".
Those two things are two checkboxes in the mask parameters dialog which you can select for any parameter.
For "tunable", there's the MaskTunableValues property. For "enable", there's the "MaskEnables" property.
Do you know if there's a way to programmatically access the same property but for "evaluate" ?
Thanks
#Phil Goddard's answer shows you how to find the parameter. To complete the answer, the actual parameter is MaskVariables. Evaluate flag is embedded into the MaskVariables string. It is not straightforward to modify this. For example for two parameters MaskVariables string contains something like this:
"a=#1;b=&2;"
In this string the # sign indicates evaluation. Based on that, parameter a is evaluated and parameter b is not. If you want to change the evaluate flag, you need to set this string for MaskVariables parameter exactly how it was except for # or & signs.
For more information see R2011b documentation for mask parameters at https://www.mathworks.com/help/releases/R2011b/toolbox/simulink/slref/f23-18517.html. Towards the bottom of the page there is more detail about MaskVariables parameter.
You're using too old a release for most people to be able to give you an exact solution, however, I'm sure (from memory) that this parameter is available.
If you click on the mask to select the block, then go to the MATLAB command line and type
get_param(gcb,'ObjectParameters')
you'll get a list of all the block properties. (You may already know that since you're aware of MaskTunableValues and MaskEnables.) Near the bottom of that list are all of the properties related to the mask.
Now manually look at each/all of those properties, e.g.
get_param(gcb,'MaskTunableValues')
and you'll find that one of them is a structure that contains the information that you're looking for. (You may need to dig down into the structure to find the specific info.)
Answer for versions > 2011b (tested on 2014b):
Ok found it, actually the matlab documentation is REALLY unclear regarding the Simulink.MaskParameter class and here is how it works:
First, get the Mask class from your block:
mask = Simulink.Mask.get(gcb)
The Mask class is a structure containing all mask parameters:
parameters = mask.Parameters(:)
parameters is a (array of) Simulink.MaskParameter object which will contains all the necessary properties, including Evaluate.
If for example you have acquired a object of type handleplot with expression like below:
handle = plot(t,functoin1 , t , function2 ) ;
Now handle will be an array that contains two elements, handle(1) and handle(2). Now suppose you want to change some properties of one of these objects, like set a LineWidth, change the Color, or the like.
Is there any way in which you can activate auto-completion or suggestions when you type handle(1). (note the memebership operator .)? I am looking for the automatic suggestions that MATLAB provides for member functions in a combobox near the blinking cursor, similar to the way other IDEs provide this feature:
MATLAB's objects support tab completion. After typing handle(1). simply hit tab and you will receive a list of available methods and properties of the graphics object.
If you want more help on a method, you will also get a popup dialog of the method and the accepted input arguments.
If you want to programmatically get a list of properties of an object, you can use properties
properties(t)
If you want a listing of all properties and their values, just use get
get(t)
i use this method ...
for example i'm writing a program in matlab editor and when im want to know the properties of an object just stop coding and run the program , know it's have my object (for example handle) and know i can write the properties(handle) in command window to know the exact properties of handle . as Suever says .
I'm using Intellij IDEA 13 for android development.
Some methods has long list of parameters. For example, db.query(...) and I can't remember the order of them.
Is there any plugin or can i change some settings to make IDEA insert variables from function template?
Thanks
You have a couple of options. Ctrl+P will show a lit of the parameters, with the current one bolded. As long as you have either the source or javadoc for the library (or JDK/SDK) attached to the corresponding definition, you will see the parameters' names.
If you invoke code completion while entering parameters, IDEA will show at the top only ones that are of the correct type. Furthermore, if one of you local variables is the same name (or similar to) the required parameter's name, it will be at the top of the list. So if there is a method that takes an int named 'width', and I have several int variables, but one is named 'theWidth', it would be at the top. (Again, this assumes you have javadoc or source attached so IDEA can determine parameter names.) If IDEA can find local variables that satisfy all parameters (or all the first x parameters) of the method, there will be an option in the code completion list to complete all of them, The icon will be a double circle. The below screen shot shows how the HttpServletReqest is at the top of the list. So I do not have to remember if the parameter order is "request, response" or "response, "request". Notice the fourth option is to complete both the request and the response.
Let us say that I have a Matlab function and I change its signature (i.e. add parameter). As Matlab does not 'compile' is there an easy way to determine which other functions do not use the right signature (i.e. submits the additional parameter). I do not want to determine this at runtime (i.e. get an error message) or have to do text searches. Hope this makes sense. Any feedback would be very much appreciated. Many thanks.
If I understand you correctly, you want to change a function's signature and find all functions/scripts/classes that call it in the "old" way, and change it to the "new" way.
You also indicated you don't want to do it at runtime, or do text searches, but there is no way to detect "incorrect" calls at "parse-time", so I'm afraid these demands leave no option at all to detect old function calls...
What I would do in that case is temporarily add a few lines to the new function:
function myFunc(param1, param2, newParam) % <-- the NEW signature
if nargin == 2
clc, error('old call detected.'); end
and then run the main script/function/whatever in which this function resides. You'll get one error for each time something calls the function incorrectly, along with the error stack in the Matlab command window.
It is then a matter of clicking on the link in the bottom of the error stack, correct the function call, and repeat from the top until no more errors occur.
Don't forget to remove these lines when you're done, or better, replace the word error with warning just to capture anything that was missed.
Better yet: if you're on linux, a text search would be a matter of
$ grep -l 'myFunc(.*,.*); *.m'
which will list all the files having the "incorrect" call. That's not too difficult I'd say...You can probably do a similar thing with the standard windows search, but I can't test that right now.
This is more or less what the dependency report was invented for. Using that tool, you can find what functions/scripts call your altered function. Then it is just a question of manually inspecting every occurrence.
However, I'd advise to make your changes to the function signature such that backwards compatibility is maintained. You can do so by specifying default values for new parameters and/or issuing a warning in those scenarios. That way, your code will run, and you will get run-time hints of deprecated code (which is more or less a necessary evil in interpreted/dynamic languages).
For many dynamic languages (and MATLAB specifically) it is generally impossible to fully inspect the code without the interpreter executing the code. Just imagine the following piece of code:
x = magic(10);
In general, you'd say that the magic function is called. However, magic could map to a totally different function. This could be done in ways that are invisible to a static analysis tool (such as the dependency report): e.g. eval('magic = 1:100;');.
The only way is to go through your whole code base, either inspecting every occurrence manually (which can be found easily with a text search) or by running a test that fully covers your code base.
edit:
There is however a way to access intermediate outputs of the MATLAB parser. This can be accessed using the undocumented and unsupported mtree function (which can be called like this: t = mtree(file, '-file'); for every file in your code base). Using the resulting structure you might be able to find calls with a certain amount of parameters.