ASTNodes And Views - eclipse

I would like to know if there is a function that when i give it an ASTNode object (the ASTNode can be a class, method or a field in a CompilationUnit) as an argument it can show this object in a view (Tree view or Table view). If there isn't any such function, is there another way or workaround of doing it?
Thanks for your help.

You may be able to use the ASTView plugin

It's not clear if you are referring to Java or just something else. I'm assuming you need a Java tool. I'm not sure what exactly you expect to see in the "view".
Do check out nWire. It may be what you are looking for. Given any component in your code (like Class, field, etc.) it can show all possible associations to other components.

Related

obtain the layers control from the map object

Say I add a Control.Layers object on a map like this:
L.control.layers(baseLayers, overlays).addTo(someMap)
When I am later given the someMap object what is the proper way to obtain the layer control from it? E.g. I was hoping something like:
let controls = someMap.getControls();
... where I would then presumably be able to iterate and use the typeof operator to find the control I am interested in.
The closest I have found in answering the question is this SO answer which suggests extending the L.Control class and overriding onAdd in order to store a custom property on the map object. I find it hard to be believe it needs to be so convoluted as that. Plus, even if that approach was taken, how I am supposed to know that my overridden onAdd method does everything that the implementation in the original Layers Control.Layers does?
The way it is implemented, adding a control to a map just leaves the control object with reference to the map object.
This means that the map object is unaware of the controls it has created (EDIT I should say: controls that were added to the map)
I guess there was no need for that. If you have a use case that shows this is a problem, you should open an issue.
So, I'm afraid the answer you already have is the right one.

what makes a variable be visible (intellij idea)

With intellij idea, how do I find out what makes a variable be visible?
An example of when it is hard:
Suppose you look at class A, and you see a variable something. If you jump to source you see that it's defined in trait X. But you don't extend trait X directly. What do you extend, then, that makes this variable visible? If you have a deeply nested hierarchy, tracking can be hard.
Any recommendations or solutions?
EDIT: Please vote for the feature if you're interested: http://youtrack.jetbrains.com/issue/IDEA-124369
I don't think that IntelliJ IDEA has any shortcut for "finding what makes a variable visible".
However you can determine it using the "Find Usages" option (Alt + F7). For example:
import java.nio._
object TempObj extends App {
def func = 2
val p = file.Paths.get("some-path")
func
}
So Find Usages on "file", tells you that its from the Package "file" (in heading of the new Tab it also shows the complete package name, ex: Find Usages of java.nio.file in Project Files).
Whereas Find Usages on func will tell you that its a Method (And the Tab heading now says: Find Usages of func() in Project and Libraries)
So now in way you can determine, what exactly makes the variable visible. This also works for imports since it shows the package from which it is imported and you can then look for import of that packages.
I know of two almost-solutions to this problem.
Go-to-declaration, as you mentioned, solves this problem in the case of local variables.
More generally, the "find usages" feature gives you a neat little breakdown by type and file of different uses of the variable. From this you can see if it's involved in a static import.
It's not perfect, but with a moment's thought these two are generally sufficient to figure out what you want.
Use ctrl+b or F4 to jump to source code. Alternatively you can use ctrl+shift+a to get option/action. You can find shortcuts at http://gaerfield.github.io/ide-shortcuts/ as well. Hope it will help.
From what I understood you want to see the code that creates an Object you use, for instance Mystery someMystery;.
That gives you two options to populate someMystery:
someMystery = ... where ... is your code to populate
someMystery and if that is the case you should follow
that code (with ctrl+B as far as you need to) to the point where it
actually creates the Mystery object.
Use CDI to populate that object instance for you, in which case you should look into the CDI mechanism in order to see in what way the object instance is populated.
In either way IMO there is no way to know for sure if the someMystery instance is of some more concrete class than Mystery, because it is decided in runtime, not in compile time, so your next bet would be to run the program in debug and see what object goes into someMystery, although you are not guaranteed to get the same type of object every time.
PS. My answer is based entirely on my java understanding of the topic, can't say if it is valid for scala also.
This might not be exactly the answer you were hoping to get.
However, quoting yourself,
If you have a deeply nested hierarchy, tracking can be hard.
Have you considered using composition over inheritance? Perhaps this would remove the need for the feature you are looking for.
Deeply nested hierarchy doesn't sound good. I understand your pain about that.
When you override vals or defs there is a little circle next to the line number that shows where it is from even when it is from nested hierarchy. Hovering over vals with the command key down also shows you a little tooltip where it is from.
Does this help?
https://youtu.be/r3D9axSlBo8
if you want class, field or method to be visible, you need to implement them as public. If it was your question.

Generate all setXXX calls of a POJO in Eclipse?

Im currently doing a lot of testing with JPA entities, where i have to keep calling the setter methods on the entity that looks something like this :
myEntity.setXXX(value);
myEntity.setYYY(value);
myEntity.setZZZ(value);
Is there any magic shortcut or menu in eclipse IDE to generate all the setter-method-calls that starts with "set", like those displayed in the ctrl-space (auto completion) popup (i think the inherited methods from Object are not being shown at popup) ?
So im imagining something like :
i type myEntity.set
and myEntity.set* are generated right away
Im a lazy programmer and currently using Eclipse Helios IDE.
Thank you !
Edit
Im not looking for source -> generate getter and setter, because that would helps me in generating the methods itself. Generating the method calls is what i want to achieve.
I have found the answer (I was always searching for this thing)...
The easiest way is to expand the class members in the "Package Explorer", sort them by name, multi-select all the setters, and then you have in the clipboard all the method names...
;-)
I like #Oscar's answer. It does lead to some cleanup though.
When I paste from the clipboard, I get something that looks like this:
setOne(int)
setTwo(String)
In order to clean this up, I first add semicolons with this search/replace regexp:
search = (.)$
replace = \1;
Then I add the getter calls (assuming incoming data object is named "data"):
search = s(et.*)\(.*
replace = s\1(data.g\1());
This doesn't handle multiple arguments in a method call...
you can use the outline at right side. There you can sort alphabetically or by declaration order using the toolbar button of the view.
and then you can filter out non required this.
From here also you can copy..all setter functions or getters functions names...
There is eclipse plugin to do that. The name of the plugin is **
FastCode
**. There are so many templates. Among those there is template to generate code for create object of the class and all setters method.
Source --> Generate Getters and Setters...
You can also get at it via the Quick Fix command (Ctrl+1) when the cursor is on a property.
EDIT
If you are simply looking for a faster way to copy properties from one object to another I suggest that you look at using reflection. I think this path would be much easier long term then generating the same-looking code over-and-over.
Commons BeanUtils can take away some of the pain in writing pure reflection code. For example, copyProperties takes a destination bean and either another bean or a Map as the source.

Drupal - dynamic options for text_list field

I have a custom node type for which I want to have a field that uses a special combobox based on list_text. When one chooses the type list_text it is normally possible to enter a static list of selectable texts, however, I want this list to be dynamic, i.e. based on the results of a db_query. What is the best way to do this using Drupal 7?
A simple example for clarification: A node of this custom type X contains a field that points to another node, so whenever a node of type X is created I want a combobox that contains all other nodes.
(Best solution would be to only display the combobox during node creation, and no longer during edit. But I could also live with it if the combobox was shown during the edit as well.)
I have tried to customize options_select by defining my own data type and implementing hook_options_list accordingly. The combobox was displayed during creation with the correct values, however, I could not save it.. I have no idea what went wrong there, but on the first submit it would change to a different theme, and when I tried again I got an internal server error. Am I on the right track at all with defining a completely new data type for the field? there surely must be a simpler way?
You're right in that you don't need a new datatype. Here's a good tutorial on how to do this. It's not specifically for D7 but I didn't see much that wasn't still applicable. There may be a better way to do it in D7 specifically but I would love to know it too if so :)
The tutorial linked by allegroconmolto sent me on the right way. Thanks for that.
Here's the simpler way of doing it: tutorial
Basically, it is, as I assumed, a common problem and hence a simple solution for it was included in the webform module by now. It provides a hook_webform_select_options_info which can be used to register a callback method. The callback method is then called each time a corresponding option select of a webform is shown, so that you can easily fill it with the results of a dbquery or anything else. Works like a charm and takes next to no time to implement.

Filter/Sort the classes in problems view based on author in eclipse

I need to filter or sort the warnings in problems,Tasks view based on the author names given in the class.[#author userName]. Is there any way i could configure it. If not can some one give direction to extend the view and add my own either filter or sorting.
Thanks in advance
There doesnt seem to be a way to do this by default, but extending the problems view to add this information seems feasible. See this for example: http://www.pushing-pixels.org/?p=881