How to view Java's byte code in eclipse IDE? - eclipse

Sometimes, in Eclipse , i press a combination of keys which take me to the editor page that shows contents of my .class file (bytecode). I never seem to be able to remember what that key combination is.
Can someone please let me know?
Or in other words, how can one see own bytecode?

Eclipse's default class file viewer shows the source (see VonC's answer) if it has been associated with the binaries, otherwise it gives a javap-like view of the class (with an option to attach source). I'm guessing it's the latter that you are looking for.
I've never found a way to cleanly force Eclipse to show that output rather than the linked source. What you probably want is an Eclipse plug-in that provides Javap like functionality (or an interface to javap). Look for plugins stating they "disassemble" (as opposed to "decompile," like jad).
Barring a plug-in, you could probably configure an external tool to perform javap but it might not play nicely with other eclipse features.
Edit: Let me be clear about the above: If you hit F3, Eclipse does the following (generally, the actual procedure might be slightly different):
Resolves the target (if you are selecting a Java file, it will be the Java file itself; if you are selecting or your cursor is over a class name it will be the class declaration, similar for a method declaration, etc).
Searches the build path (same project first) for a Java file containing the target. If found, opens up an writable editor displaying that Java source file.
For class/method declarations, it continues searching references on your build path for a class file that contains the declaration. If it is found, then
a) If the class file has had source attached to it, open up a read-only editor of the linked Java file.
b) If the class file does not have source attached to it, then open up a read-only panel showing the disassembled (javap-like) bytecode of the compiled class file.
My guess would be that you're thinking there's a dedicated key sequence to 3.b), but I don't think there is. But again, I would love to be proven wrong here.

Using the following external tool configuration we can view java byte code in eclipse with the help of javap:
To get the above pop-up select Run option and select External Tools and select External Tools configuration...
${system_path:javap} is used to locate javap in the JDK used by the Eclipse. You can use an absolute path to javap instead.
${project_loc} returns the absolute path to the project. This is used, since I could not find a pre-define variable to use, to locate the .class file of a resource, and that's why javap runs in the project's directory instead of the directory containing the .class file.
Among the arguments passed to javap:
bin is the default output folder for Eclipse projects. Change this to build/classes or whatever is used by the project. Note, the value is relative to ${project_loc}; you can specify absolute paths instead.
${java_type_name} is used to obtain the selected class name.
You can select a Java file in the Project explorer view or Project navigator view, or even a Java type in any of the views, and then run the external tool. Note - this approach doesn't work quite well when you select a method, an inner class etc. and then run the tool, as they are not resources on their own, leading to the scenario where ${project_loc} will be empty.
Source
Dr. Garbage Tools is a suite of Eclipse Plugins released under Apache Open Source license.
Install Bytecode Visualizer using Eclipse Marketplace.
To view a bytecode:
Right click on .java file, select open with and select other you will get the following popup:
Search "Bytecode Visualizer" and select the option it opens the file as follows there you can find Bytecode option as shown:
Enhanced Class Decompiler
"Window > Preferences > General > Editors > File Associations"
Change default to your for both .class association.
"*.class" : "Class Decompiler Viewer" is selected by default.
"*.class without source" : "Class Decompiler Viewer" is selected by default.

You can use ASM 4.0 Plugin.
Installation
The Bytecode Outline plugin can be installed from the Eclipse Update Manager with the ObjectWeb Eclipse Update Site http://download.forge.objectweb.org/eclipse-update/
Alternatively, the plugin can be downloaded from the ObjectWeb Forge site, and manually installed in the Eclipse plugins directory.
Usage
To see the bytecode of the current .java or .class file:
Window -> Show View -> Other -> Java -> Bytecode
To compare the bytecode of two .java or .class files:
select two *.class or *.java files -> right click -> Compare with -> Each Other Bytecode
or
select one *.class or *.java file -> right click -> Compare with -> Another Class Bytecode
http://asm.ow2.org/eclipse/index.html

Well... if the .class is selected in the Navigator View or Package Explorer view, a simple F3 is enough to open a decompiled version of it in the editor.

As hinted at by user833970: The Bytecode Outline plugin: http://andrei.gmxhome.de/bytecode/index.html
At its base, it provides a "bytecode" view for the currently opened Java file which is what you were looking for.
However, you can also assign it to load any random .class file instead of the default .class viewer, and it surpasses it in many ways. For example, this viewer actually jumps to the right spot in the bytecode if you click on a member in the Outline view.
Download links (for dropin use) can be found at the afore-mentioned link, the update-site is http://andrei.gmxhome.de/eclipse/.

If you are really interested in the bytecode there is a eclipse plugin that lets you open and edit the bytecode of a .class file using a text editor.
https://github.com/itemis/jbc

I've tried several different solutions for this.
Bytecode Visualizer (available here: https://sourceforge.net/projects/drgarbagetools/ ) is, in my opinion, the best solution. It neatly displays the output and makes clear how it links to the source code. I've noticed a few minor misinterpretations on some of the bytecodes, but you can get the gist of it.
Unfortunately, it doesn't seem to support Neon at time of writing. It does support Mars, though.

Related

unsolved inclusion #include <bb/cascades/Application>

The momentics IDe for BB10 has encountered a problem or at least I believe that al my inclusions appears as unsolved. when I compile the app it compile correctly and everything works pretty well. But the problem is that I need to import some libraryes like #include and as long as this libreries are shown as insolved inclusion I cannot declare any object of those types.
Does any one know what can be this and how to solve it.
Things done berofe:
I've tried cleaning the workspace and creating a new project and also the new project works perfectly, also I've tried going to configure add and and some libraries. this works but only works for specific libraries, not at all for libraries.
Edit 1: As I saw on other posts, I've reinstalled the 10.1 sdk that is the one I need, but no luck
In the Workspace's Project Explorer pane, right click the project, and then select Build Configurations -> Set Active -> Simulator-Debug (Just to be sure.)
From menus, Window -> Preferences. In the Preferences dialog's left pane choose C/C++ -> Indexer.
To get intellisense to work when authoring well before making builds, under Indexer options, check boxes Index source files not included in the build, index unused headers, index source and header files opened in editor. And under indexing strategy check both boxes, automatic update and update after every file save.
Finally, under Build configuration for the indexer select the Use active build configuration option (Just to be sure.).
For class declaration in header file, the erratic feedback from IDE will disappear (as of Momentics 2.1.2) only after cpp file for implementation, that includes the header is saved.
If modifying header, after setting up as above, right-clicking on the project in Workspace pane -> Index -> Rebuild should work.

How to debug Eclipse source code

I am having tough time to figure out debugging UI parts of Eclipse. I couldn't find any information on google (or) Eclipse web site.
All I wanted to do is to find out the code that gets executed when we double-click a file in project explorer to open the file in Editor.
I tried to bring up Eclipse source code from Plug-ins view -> right click on the plugins -> import as Source Project. But, I am unsure what are all the components that constitutes to the UI part. I get some weird errors when I try to import everything that's found in plug-ins view.
Where can I find the information related to debugging Eclipse source code?
Instead of using Plug-ins->Import as Source Project, I would recommend opening the Plug-ins view, selecting all plug-ins, right click, and Add to Java Search.
Then you can use Open Type Ctrl-Shift-t to search for class names and the source will be attached so you can read it, set breakpoints, and debug.
In your case, I think you want to investigate IWorkbench, IWorkbenchWindow, and IWorkbenchPage. The openEditor(*) methods on IWorkbenchPage will be of particular interest.
You may also want to take a look at the org.eclipse.ui.editors and org.eclipse.core.contenttype.contentTypes extension points.

Eclipse: quick search on filename

Very often while working in Eclipse I realize that I remember class name, but forgot in which package this class is. Using Search is not very convenient. Too many clicks and key presses. I wonder, is there a plugin to simplify this process? For example, would be great if there was text-edit box in the top of package explorer which could filter showing packages and .java files depending of entered text. Anyone knows something like that?
Eclipse does provide similar functions:
Open Resource Shift+Ctrl+R for all resource files (including Java files)
Open Type Shift+Ctrl+T for all Java classes in classpath.
They also filter the list as you type.
Note that they search all files of all opened projects in current workspace.

Eclipse CDT indexing not working to find declarations within the project

I have installed Eclipse & CDT plugin on newly installed Ubuntu. The indexing is set to "Fast indexing" which is recommended ("Full Indexing" seems to have marginal difference).
At so many places, if I press 'F3' ('show declaration') on any class name or include file name, the cursor remains stand still and it doesn't lead to the declaration. However, it works for standard files and symbols like, stdio.h, std::vector and so on.
For example, I have 2 files,
/home/myself/Workspace/Project/X/Y/include/file.h
/home/myself/Workspace/Project/X/src/file.cpp
I am not able to see any declaration of any class or variables displayed in file.cpp which are residing inside file.h. Even pressing 'F3' on #include"file.h", I am not able to go to file.h.
Eclipse Workspace is created at Workspace folder the C++ project is created at Project folder. To store the include path, I have followed this procedure in Eclipse:
Project -> Properties -> C/C++ General -> Paths and Symbols -> Library and Paths -> Add "/Project/X/Y/include/file.h" (used 'Workspace' and 'FileSystem' tabs both)
But still no luck. I have done enough searching on internet and SO, but couldn't find anything useful. Note that, I am using eclipse only for code browsing and not for building the code as of now.
Ok, got it working. Actually whatever include paths I have included in Paths and Symbols are redundant and they make no difference as everything under Workspace/Project will be indexed.
The solution is very weird and it's related to scalability, which I came to know from this link. In Eclipse go to,
Window -> Preferences -> C/C++ -> Editor -> Scalability -> "Enable scalability mode when ..."
Set a huge number such as 500000 and press "OK". The problem was solved! For my case the actual set value was 5000 and the source file I was seeing was of 16k+ lines.

eclipse find resource not compiled

When I click Ctrl+Shift+R in eclipse I get a dialog that allows me to find a resource. However it shows all resources regardless if they are not compiled or compiled. Is there any way to filter so it shows just not compiled resource? Or can I hide compiled resources in some way?
To hide compiled resources when you:
open (Ctrl+Shift+R) the "Open resource dialog",
click on the black triangle on the top right,
then on "Show derived resources": it must be un-selected.
You will not see any .class file.
From: What is new in eclipse3.3
If you want to only search for Java classes, then I suggest to use Ctrl-Shift-T.
For others kinds of resources, I am not sure if you can filter the result of this popup...
See answer from VonC
As an additional note on VonC's solution, this works as long as the classes are contained within a different directory-tree to the source files - for example many projects build the classes files into a target directory which mirrors the directory structure of the src tree.
In most situations, Eclipse will have set the derived flag on this target directory (right click on target and view properties) - although some Eclipse plugins (Maven/SVN) seem to sometimes get this derived flag wrong (not sure which is the culprit).