Compare sources in eclipse - java

Very often I encounter situation where I need to see or manually compare two eclipse sources. It can be a situation when I extending some class and looking at current implementation of superclass and writing similar implementation in subclass. Here are solutions come in mind with time:
Just copy prototype class in another file and edit it in place with commenting/uncommenting. This solution seems a bit dirty to me and causes hidden "copy-paste" bugs.
Open prototype class in another editor and make it "always visible". It's a tricky.
Have state where prototype and actual classes accesed sequentially, so we can using Back-Forward hotkeys ALT+LEFT and ALT+RIGHT to switch between them, but the problem left - we have only one active screen at time.
Is there a more clever way to get functionality that I need?

I think that #Nos explains the more accurate solution, but if you need to have two active editors at the same time... You only need to open the both files, and then "detach" one of the tabs, or move it to another editor.
To move a tab to other editor window, you only need to click on the tab title and drag it to another position. It will automatically created another editor window.

you can click on source file tab and right click-> then select new editor. you will get duplicate tab there. after that click on that and drag to any direction and you will get two different frames for file

I am not sure what version of Eclipse you are using but in general you just select the two files (using the ctrl-key + mouse) you wish to compare, then right click on one of the selected files, go to "Compare with" sub-menu and select 'Each Other'?

Related

Is there a way to open two tabs for the same file in IDEA?

Sometimes I need to look at one piece of code already written and write another piece in the same file. When the code is too long, for beauty or other reasons, I have to write for a while and then slide to the piece of code I want to see, and then slide it back to write again. Is there any good way to avoid this trouble?
thanks a lot
You don't have to use a mouse to do it! Remember everything in IDEA is configurable so my keyboard shortcuts may not work for you though you can configure them in the keymap.
There are two ways which you can open multiple files in IDEA:
The first method would be to split the editor:
search by action cmd shift A on mac
type split and choose how you'd like to split
The second method would be to open the file in a new flowable window:
Select on a file in the project window
Use shortcut shift f4 or search by action cmd shift A on mac
Type open source in new window and hit enter
right click into tab name, and select split vertically or horizontally
if you are using git. then find "local changes". it will compare your current changes with the origin
https://www.jetbrains.com/help/idea/viewing-changes-information.html#comparing_local_changes
In Android Studio I see "Split Vertically/Horizontally" options when I right-click on the tab name which do exactly what you want. Since AS is derived from IDEA the functionality might be there too.
If you use JetBrains IDEA, the form can be split vertically by right-clicking
If you use Eclipse, you can ctrl + shift + [

How to retrieve the actual value of the "link with editor" button in eclipse

I'm developing a eclipse plugin and i'm implementing the link with editor functionality.
My question is:
How do we know (on the EditorPart when this is activated) the actual value of the state of the link with editor command button (IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR) if is active or not? in order to do something or not.
By the way is there any example source of how to do this?
There isn't one setting for this, rather it is specific to individual views. You can have Package Explorer with linking set and Project Explorer with linking off at the same time.
The views with linking set just use IPartListener2 to listen to part changes. So there is no easy way to determine if this is set.
You need to register a link helper extension, which in turn uses an implementation of ILinkHelper to map forth and back between navigator selection and editor.
However, as long as IFiles are shown in the navigator and as long as your custom editor uses a IFileEditorInput, you don't need to do anything, as this is covered by the standard ResourceLinkHelper. Setting a breakpoint into that class is the best way to debug the flow in a standard Eclipse application.
That said, you should not watch the toggle button state as such at all.

In Eclipse, how do I limit the Open Type shortcut to only show source files in my current project

I have multiple games and when I am working on these games I often use the Open Type shortcut to find my classes, however every time I use it, all classes in the workspace of the name show up. Since I have multiple games, when I want to search for the Player class, for example, multiple Player classes show up and often times the one I am looking for is not the top.
Is there anyway to change this so that it only shows the files from the selected project or even to just show the ones from the current or most recent project first?
All help is appreciated, thanks.
Create a Working Set from which to search:
Open the Open Type dialog.
Click on the arrow in the upper right.
Choose 'Select Working Set' -> New.
From there you can choose what you wish to add to the working set...a Project, a package, certain classes, etc...
Of course, you will have to change this working set depending upon where you wish to search. Further information

Questions about IntelliJ to Eclipse transition

I just started using eclipse for some personal projects and am finding the transition from IntelliJ (what I use at work) kind of annoying. I hope it's kosher to ask a few different questions in the same thread. Here goes:
1) How do I get "views" (I'm not sure if this is the term. I mean windows such as Project Explorer, Servers, Console, etc) to stay expanded and on top even after I've clicked back on the editor or another view. I'm pretty sure that right now all of these tabs are "quick views" that I have minimized and then docked, so I may not be doing this right to begin with. In IntelliJ, I would simply just pin the tab.
2) How can I open a file (for instance, an ant build.xml) without having to make it part of an eclipse project? I want the syntax highlighting and Ctrl-click ability that the IDE will give me (not to mention being able to use eclipse's built-in ant), but I don't need to associate the file with any others and so don't see the point of having to make it a part of a project.
3) Is it just me (wouldn't be surprised) or does eclipse have a bug with parsing empty html tags within the body of html tags of the same type. I've only tested this in a JSP, and it doesn't happen with JSF tags. For example: <div id="foo"><div id="bar"/></div>. Eclipse will give a warning saying the first div tag has no end tag. This is with the most recent version of eclipse for Java EE, no plugins have been installed.
4) Finally, a general question: Any best practices or resources to look at for organizing the eclipse interface and perspectives/views? What about workspaces/projects? Is there some tutorial out there that would be really informative that I could read through in less than an hour?
I appreciate any answers and tips/tricks.
First of all, please acknowledge that there are different people in the world and there are people who don't work the "Eclipse way". Even if I was paid for it (and I am), I couldn't work with IDEA. So if Eclipse rubs you the wrong way, it may not be for you. That out of the way, your answers:
In Eclipse, you open a view and let it stay where it is. In IDEA, the view changes all the time, things pop up and go away. Eclipse is static unless you specifically move things around. There are two ways to move things: You can minimize a part (a part is something which contains tabbed views). This moves the part into the closest border. Or you can maximize the current part (Ctrl-M). This pushes all other parts out of the way. Another Ctrl-M will restore the view.
This is a good place to show the difference between IDEA and Eclipse. IDEA tries to anticipate what you're doing and to be helpful. For me, this means it always gets in my way. It will start to format source as I type, things move, etc. That freaks me out. Eclipse is like a toolbox. Everything is there but you have to pick it up. A toolbox doesn't move on its own accord and it doesn't try to be smart.
Eclipse is based on the idea of a workspace. The workspace is the universe and nothing outside exists. If you need to go outside, you must first create a file or folder. In the "New File/Folder" wizard, you can open the advanced options (at the bottom) and link this resource to a real file/folder in the file system. May sound like a lot of effort but it allows Eclipse to display virtually anything in the explorer since it just shows "resources" in there, not actually files.
Smells like a bug. Please report it at https://bugs.eclipse.org/bugs/
I'm not aware of anything.
[EDIT] 3. As cletus pointed out, is not valid HTML. So that might cause the warning.
An Eclipse Perspective is a collection Views and their position. You can customize or create new perspectives, but the existing ones are good enough for a start (Java, J2EE, Java Browsing etc.). I recommend to stick with the default layout for a while until you've managed to use the quick view feature (which, personally, i find quite annoying). On small screens, i simply like to use Ctrl-M to switch the Editor to fullscreen mode and back, without the need of minimizing single views or move them around.
Yes, you can run external build scripts as well and it's called External Tool in Eclipse. Go to Run > External Tools > External Tools Configurations. Create either a new Ant-based config or a native executable (Program). The location of the build script or executable can either be workspace-relative (Browse Workspace) or absolute on the file system (Browse File System)

Can you save groups of tabs in Eclipse so you can open them later?

I have several different processes within a single project that I work on. I am constantly opening and closing tabs(java files) in the code editor for that particular process. Each process almost always uses the same java files.
I was wondering if it is possible to save what files are opened as part of the working set so I can select what working set I want and have all the java files open that I will need to work with. Currently the working set just sets the tree to these files, but I am looking to also have it open the files I need.
I hope this makes sense...
Mylyn should be your answer here.
Mylyn is a task-focused interface for Eclipse that makes working with very large workspaces as easy as working with small ones.
Mylyn extends Eclipse with mechanisms for keeping track of the tasks that you work on.
Mylyn monitors your work activity on those tasks to identify information relevant to the task-at-hand. Mylyn monitors Eclipse and captures your interaction in a task context.
System artifacts such as files, types, methods, and fields get assigned a degree-of-interest based on how recently and frequently you interact with them.
This results in uninteresting elements being filtered from view within Eclipse, allowing you to focus in on what is important.
Following Saheed's answer, don't miss CodeKiller's comment:
You can
Activate the task to reopen all files and
Deactivate the task to close all the files.
Bookmarks (mentioned here by user1039663) is a valable alternative.
Eclipse provides multiple ways of structuring the IDE desktop:
Perspectives: Customization of the positions of open and closed views and editors. You can copy and rename existing perspectives like the Java perspective and suit them to your needs by customizing them. See the Window menu or right-click on the perspective icon in the upper right corner
Task Management Tools like Mylyn: see answer by VonC
Multiple Windows: You can open new windows and move them to your second monitor. Select Window > New Window to open a new window. Each window keeps track of its own open editors.
Multiple Instances of Eclipse: You can always use multiple workspaces and multiple instances of Eclipse. However, this is only recommended when working on different projects, as both instances would overwrite each others files when rebuilding.
Hotkeys: By using shortcuts like Ctrl-T and Alt-Left/Alt-Right and Ctrl-Q you can quickly jump to previous locations where you have edited source files. This is a great help in navigating the open workspace.
Extended VS Presentation provides capabilities to save sessions.
Unluckily, it only works with Eclipse 3.1 to 3.8:
Project page at Eclipse Marketplace
The accepted answer tells us which tool could be used but does not provide a quick and dirty explanation on how to use it.
In my case, I hadn't finished researching a large code base but I needed to save my progress so I could return to it later hence the need to save all open tabs using Mylyn.
If you already have Mylyn installed, navigate to Window -> Show View -> Task List to view the list of tasks. If you've never used it before, the list will be empty.
Right-click inside the Task List view then New -> Category to create a new category. Right-click again New -> Task to create a new task.
Double-click on the task you just created then click on the Context tab at the bottom left of the view.
Now navigate to each tab which you would like Mylyn to save by clicking on the tab name. Notice how an entry for the source file for that tab is added in Context tab of the Task List view.
Once you've cycled through all the tabs you'd like to save, you can confirm they were saved by closing each one and double-clicking the source file in the Task List to restore the tab.
I've edited this answer as per below comment (include essential parts of answer in this post).
Yes, you can save off groups of tabs in Eclipse by installing this Session Manager plug-in.
I've wanted this functionality in Eclipse as well. I recently wrote a feature and have been successfully using it for a few months now. It is a new OSGi type extension and works with Eclipse Neon and above.
Here's how to install it.
In Eclipse, go to Help → Install New Software
Click “Add”, enter a name like “Editor Sessions” and the following URL.
http://spillikinaerospace.com/eclipseInstall/
Unckeck “Group items by category” to see the feature.
Check the box that says “Editor Sessions Manager” and click Next.
Read and agree to the short license agreement.
Click the remaining install buttons.
Allow Eclipse to restart.
Full set of instructions are here: http://chrishull.com/projects/eclipse/
Please give it a try and send comments. I've found it a very useful tool as I work with several Eclipse projects at once and need to recall file groups.
Hope you enjoy it;
-Chris
In addition to all mentioned... Did you try Bookmarks? You can save multiple bookmarks into one set, there are bookmark sets management option and you can add descriptions with prefixes to group bookmarks on the same set. Finally and more important: you can select multiple bookmarks, select goto and multiple editors will be opened at once.
You need a Macro. Searching using this term at Eclipse plugin sites like eclipseplugincentral.com and so on must yield enough suggestions, for example Practically Macro. Good luck.

Categories