Does Eclipse have a variable visualizer? - java

In Visual Studio, there is a feature to add a custom visualizer to the IDE. This allows you to write your own dialog showing the contents of complex objects at run-time (i.e. it might take a Person record and show the forename, surname and date of birth).
I can't find this feature in Eclipse/Java, but was wondering if it might be called something different?
Thanks,
Rich

The Feature is called Detail Formatter in Eclipse: Details

I don't know about a special dialog, but in general a custom implementation of .toString() do the trick.

The closest thing that you can get in Eclipse is Variables View and Expressions. view. You can also Add a Watch Expression in variables view to track any particular object.

Related

JFace - How to remove preference property?

I'm wokring with a little JFace preference store where I can add preferences straight forward enough, but have trouble when I want to remove one of the preferences I've put in.
I can't see anything in the APIs that allows for removal. What is the correct way for doing this?
Assuming you are using IPreferenceStore you call setToDefault("pref id") to reset a preference to its default value.
This is weird !!
I asked this same question 3 days ago in the eclipse JFace forum: https://www.eclipse.org/forums/index.php/t/1088245
I only got answers not related to my need.
The answer is that it is not possible. Also you can not set the value or the default of a preference to "null"
In my app (JMSToolBox), the need is to "cleanup" the file that is backing the PersistenceStore as the user may store a lot of "keys/preferences" that may become obsolete at some point in time. I wanted a way to "remove/delete" them from the file to keep the PreferenceStore file as compact as possible.
I ended up writing my own version of PreferenceStore that exposes the "remove" method from the internal "Properties" object used by PreferenceStore. This class is not designed to fullfill my need.
Code is here

Autocomplete in eclipse like in visual studio

I know there is a Ctrl+Space dialog box that show the methods options that I have.
But if i have a method that I not fully remember the name of it and I remember only a part of the name.
For example: There is a big static class which contains tons of methods starting with "add"
add1_Buffer, add2_Render, add7_Function and so on..
now I don't remember the fully name but i remember only "Buffer".
so I want to type "buffer" press Ctrl+Space and get the "add1_Buffer" method and all the names
that contain the name "buffer" in it.
Edit:
By the way, i need it on the OpenGL api where there are tons of functions and i am not familiar with all of them i know only keywords, I was searching for something like in visual studio that is really fast and easy.
If you start typing the a in add1_Buffer and then an upper B and then press Ctrl + Space you will find the correct method.
You can then continue writing the word Buffer if there are more methods starting with add and then having an upper B.
This means that you'll have to remember at least the first part of your method but hopefully you do.
Add the CodeRecommenders plugin to your installation. That has a subwords completion, which the normal JDT code completion does not have.
Use search. From the Search menu at the top of the window, select "Java Search". You can limit your search to methods and use wildcards to search for *Buffer* if you know that Buffer is in the method name.
The shortcut Ctrl + O gives an outline of the current source. So you can view and search all your methods in your current class. Use wildcards when needed.
This merely meets you req: alt+/, just a replacement for ctrl+space
Currently there is no direct way to do that in eclipse. But i found these are helpful. here
This post resembles your's look at it. Similar one here

Accessing Netbeans Code Completion Variable List Programmatically

I have a working educational Java-palette Module for Netbeans that helps first-year students learn the basics of programming without needing to worry so much about syntax.
When a student drags an item from the palette, they get a popup that allows them to fill-in the details of the code to be dropped, such as variable names or values. I have ComboBoxes that list all the variables in the document. For the Java version of the palette, I simply used JavaParser to get a list of the variables, method names, classes, etc.
Now, I'm doing a version of this palette for C++ students. This time around, I'd rather not use JavaParser, javacc, ANTLR, etc as it seems like overkill. NetBeans already has the list I need when you hit Ctrl+space, but I can't find a way to access the list from a form. Geertjan has a great tutorial on using code completion in a JEditorPane
which addresses implementing your own code completion provider which brings me back to square one.
And this page suggests that NetBeans is simply grabbing a list of variables from the debugger stack. The debugger API doesn't suggest any straight forward methods for asking for a variable list that I could discern.
Any suggestion on using Netbeans APIs to grab a list of variables from a C++ source file, rather than resorting to a parser?

Eclipse - how can I determine the number of methods in a Java application

I'm trying to do something weird, I'm trying to determine how many methods has my Java application.
This weird thing has a purpose, it is because I have to improve the logging in the application, and it will require to make a revision of every method and add the logging if it is missing, update the logging if it already has.
I'm in the estimation process, so knowing how many methods has the application will help me to provide a high level estimation with a reasonable basis for this.
Then, here is the question, is there any way to know how many methods has my Java application?
Thanks in advance.
Fer
PS: I'm using Eclipse
Using Eclipse you can do this:
Press Ctrl-H (Search), then select the "Java Search" tab (if it doesn't appear click on the "Customize..." button at the lower left corner)
Put * in the search box
Select "Method" in the "Search For" fieldset
Select "Declarations" in the "Limit To" fieldset
Select "Sources" in the "Search In" fieldset
Select "Workspace" in the "Scope" fieldset
Click on "Search"
After the search is complete you should see a "XXXX declarations in..." message in the search view and that will be your result.
Hope it helps!
I would prefer using Reflection.
Retrieve all the class from expected packages, where logging is necessary
Summing up all the method available to all those class
Try to use a static code analyzer; Source Monitor, for example, is free SW and has the count you're searching for.
Use sonar - http://www.sonarsource.org/ - it's great tool for analyzing code.
Or look here: What are the good static code analysis plugins?
If you are going to add logging to so many methods you might want to consider implementing an AOP solution. It will allow you to write consistent loggers, makes it easier to maintain and doesn't clutter your code with boilerplate stuff. There are countless examples in Google.
Metrics is a nice plugin for Eclipse: http://metrics.sourceforge.net/
Number of Methods (NOM): Total number of methods defined in the selected scope
For a specific class, it's easy just from the class outline panel in eclipse select all methods then right click and copy the fully qualified name to the editor of your choice then it's a simple count lines.
Please press CTRL+O in your respective Java Class in the Eclipse IDE - You will get the number of methods in the respective Java class.
Now you should be able to see the number of methods available in that class.

I want to change the language of a SWT Application at Runtime. How to do that?

I'm developing an application to my software engineering class and one of the requisites is that it has 2 or more languages in the interface. I already implemented that. On the other hand, it is required that the user can change the language on its own will by choosing from a combobox or something like that.
As i'm using AWT and Netbeans, I can't edit the initComponents method of the form, as it is automatically generated. I have the option below in mind, but don't know if they would even work, so I'm asking for help.
-Edit the constructor of my class so that it looks like this:
public JFmyConstructor() {
initComponents(); //auto-generated
myInitMethod();
}
The problem I think i'm going to find is that I need to call the constructor one time after the interface is already running (and thus, all objects instantiated. Is there a workaround for this?
Probably my answer comes a little late (too bad you put wrong title)...
Obviously you do not have to call any constructor in order to switch language at runtime. In Java Desktop applications it is as ease as:
Locale brazilian = new Locale("pt", "BR");
Locale.setDefault(brazilian);
Of course if you want to switch it via JComboBox, you would probably do it a bit different. What I would do, I would actually create Model (Swing promotes MVC Design Pattern) that will hold data (different Locales) and I would set default Locale in correct ActionListener. It is not easy though.
Of course I would rather use native names for Locales. If you have them constructed, you can easily get native name Locale name by simply calling getDisplayName() passing itself as a parameter:
String brazilianNativeName = brazilian.getDisplayName(brazilian);
The result might be unsatisfactory for certain Locales (I believe Brazilian Portuguese is unfortunately one of them), but there is not much you can do about it (unless you use your own string).
To be honest, for just two languages, I would probably use some links instead. You can use simple JLabels to do that, just set correct font properties and color and assign common ActionListener. You can then query which one was actually clicked and create and set Locale appropriately. For homework that should be sufficient.
SWT and NetBeans is a weird combination. If you can do things the "normal" way with SWT and use Eclipse, then there's a powerful set of tools for managing localization, all built right in. See, for example, this introduction.
The best way is to use resource injection for all components (rather than getting i18n strings from a Bundle at panel construction time).
Resource Injection is available in a number of open source libraries or frameworks.
Since you use NetBeans, you should be able to generate an application based on Swing Application Framework (SAF), which already supports Resource Injection.
Otherwise, there are also libraries out there that do just that; simply google for "swing" "resource injection" and you'll find, e.g. Fuse library.
Edit:
You should also take a look at this SO question that deals exactly with the same problem, and which has more detailed answers (including my own).

Categories