breakpoints location change by modifying code - eclipse

in eclipse and Visual studio, I find that placing a break point in certain line
1- public class HelloWorld {
* 2- public static void main(String[] args) {
3- System.out.println("Hello, World");
4- }
5- }
if i placed breakpoint in line 3 and edited the code in notepad editor to add anything before that line then open back eclipse it'll point automatically to line 4 with the breakpoint as it adapted the line I chose before.
1- public class HelloWorld {
2- public static void main(String[] args) {
3- int i=0;
* 4- System.out.println("Hello, World");
5- }
6- }
I need to know the location of the code in eclipse source code that handle this case? or is there any known algorithm that is used to adapt the breakpoint location after modifying the code ?
I don't think it searches for the line by text as when I change the content of the line it does go to it w'ever the change

To control syntax, types etc., modern IDE creates tree-model of your source code (similar what compiler does before compiling).
The changes in code - inside or outside IDE - does not require rebuilding the entire tree, therefore it is able to remember at which node of "source tree" the breakpoint is, rather than remembering only line.
It is quite handy, if you are actively debugging and changing the code, you do not have to move all your breakpoint up or down, if the code few lines up or down.
It looks like this , the breakpoint is (probably) attached not to line, but to one of those nodes.

Related

How can I Jump/Go Back to the Breakpoint When I Debug? (in STS)

I want skip/jump some part of code block and go back to the breakpoint when I debug the code. In Visual Studio Code, it was possible. Is there a way to do it in STS?
Code Example;
public static void main(String[] args) {
String temp = "Initialized"; //1
temp = "Changed"; //2
System.out.println(temp); //3
temp = "Stackoverflow"; //4
System.out.println(temp); //5
}
For example, after I initialize temp variable, I may not want to change it and jump to breakpoint-3 (with skipping breakpoint-2). Then I expect to see temp variable as "Initialized" in debug console. After that, I may want to turn back to the breakpoint-2 and change my data to "Changed" and then print it. My point is, Instead of comment out lines, run program, then uncomment and re-run program; I want to do this operation in single time. Thank You!

Eclipse CDT override popup tooltip message won't go away even across other windows on Ubuntu

Ubuntu 18.04, Eclipse 2019.09, files:
cat.hpp
#include <string>
class Cat : public Animal {
public:
std::string noise();
};
animal.hpp
#include <string>
class Animal {
public:
virtual std::string noise() = 0;
std::string poo();
};
Example on a Git repo.
Now from the cat.hpp file, I want to go to the parent method declaration on Animal. So I click the triangle to the left of the line as shown at: How to find the overridden method in Eclipse?
However, if I move the mouse over the triangle quickly and click it, I do go to Animal, but the tooltip saying:
Implements Animal::noise via Animal
stays visible.
The hover has to be relatively quick, around less than 1 second, or else you can't reproduce. But this just happens to be the natural speed at which I would click it most of the time.
Even worse, it remains visible on top of other non Eclipse windows, e.g. the browser as I am writing this answer.
Is there any workaround for this, or an existing bug report that I can upvote?
There is this closed old bug report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=20987 but it was marked as resolved.
As a workaround, I just go to any one of those triangle symbols, and hover it without clicking for a second. The message then finally goes away.

E4 close a part from an innactive Perspective

I have an e4 application that has two perspective:
Operations
Configuration -> Contains (among other things) a part stack where the configurations are open. Each configuration in a part.
When a new model is loaded all configuration parts are to be closed. This works fine if a load the new model when the configuration perspective is active.
However, if I open some configurations in the Configuration perspective. Switch to the Operations perspective and load a new model.
I can see in the logs that the code to close the parts is called and everything seems to be alright. However, when i switch back to the configuration perspective the parts are still visible an open.
Could somebody tell me how to make sure that the parts are close, regardless of the which is the active perspective?
I found a "workaround" to solve my issue.
I had an event thrown to detect the model load as follows and use it to "close"/hide the parts:
#Inject #Optional
void modelLoadedHandler(#UIEventTopic(STUConstants.UI_TOPIC_CONFIG_LOADED) Object nothing) {
viewer.setInput(sleConfigService);
//Close open config parts
MPartStack stack = (MPartStack) modelService
.find(STUConstants.PART_STACK_ID_CONFIG_VIEW,
application);
List<MStackElement> parts = new ArrayList<>(stack.getChildren());
MPart mpart;
for (MStackElement element : parts) {
mpart = (MPart) element;
log.error("Removing part {} visible {}", mpart.getElementId(), mpart.isVisible());
partService.hidePart(mpart, true);
}
// Adding this make it work regardless of which perspective is
// active.
stack.getChildren().clear();
}
Adding the stack.getChildren().clear(); did the trick. I am not hundred percent whether that would be the right way to deal with this, as i would have though that the PartStack should be emptied automatically when i remove a part.

Inconsistent output to Eclipse Console View

I am invoking a compiler command but the compiler messages are not getting displayed in the Eclipse Console View consistently.
I have my launch() method implemented the same way as first code block of
this question; I have the command-line string setup which I use to call DebugPlugin.exec() method. However, unlike the the author of the question above, my output Eclipse console is very inconsistent. T
There is no activity in the console when I invoke the command and the console continues to display the "No console to display at this time." But after invoking the command numerous time and activating different consoles from the drop-down menu, the console occasionally does become active and message is displayed.
I am confused with how the eclipse is behaving and not sure how to resolve this issue. Any comment and/or recommendation would be appreciated.
Thanks!!
--
EDIT
To add some more info, running the external process using External Tools works fine. I add the compiler process c:\path\myprocess.exe in Locations field and the file to compile in the Arguments field within the External Tools Configuration window. When I run it, all the output is displayed fine. It just won't display when I run it programmatically through LaunchConfigurationDelegate class.
Maybe try bringing the console to front programmatically see if it helps:
* Bring the console to front.
*/
public static void showConsole() {
Display.getDefault().asyncExec(new Runnable() {
#Override
public void run() {
IWorkbenchWindow window = CUIPlugin.getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IViewPart consoleView =
page.findView(IConsoleConstants.ID_CONSOLE_VIEW);
if (consoleView == null) {
IWorkbenchPart activePart = page.getActivePart();
try {
consoleView =
page.showView(IConsoleConstants.ID_CONSOLE_VIEW);
} catch (PartInitException pie) {
CUIPlugin.log(pie);
}
// restore focus stolen by the creation of the
// console
page.activate(activePart);
} else {
boolean bringToTop = true;
if (bringToTop) {
page.bringToTop(consoleView);
}
}
}
}
}
});
}
Finally got it to work. The main change I've made is having my MyLaunchConfigurationDelegate extend LaunchConfigurationDelegate instead of just implementing ILaunchConfigurationDelegate. When observed through the debugger, the launch() method went through similar code path as external process that was launched via External Tools when MyLaunchConfigurationDelegate extended LaunchConfigurationDelegate.
I guess it was lack of information on my part but I wasn't sure which part of the code was more important to share.
Another piece of code that was removed was:
IProcess dbgProcess = DebugPlugin.newProcess(launch, compilerProcess, "XVR Compiler", processAttributes);
...
launch.removeProcess(dbgProcess);
I've added it while attempting different approach in debugging this issue and it actually caused more issues by removing the debugProcess before it has chance to display output to the console.

How do I know when user minimizes / maximizes Eclipse?

I need to respond to the events of minimizing / maximizing Eclipse window. How do I do that?
I can suggest a way: you can write a plugin for it.
For example see this improvized "tutorial", I made it, tried it works on Ganymede. A bit ugly at the final Shell variable, but working. If you know nicer solution just shoot :)
((actually there is a way: to extend your own ControlListener class, but that needs more coding :))
Create a new Plug-in Project, name it as you want, create it from a template named: Hello World Command
Open the SampleHandler class, and then replace the execute() function with this code.
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil
.getActiveWorkbenchWindowChecked(event);
final Shell s = window.getShell();
window.getShell().addControlListener(new ControlListener() {
#Override
public void controlMoved(ControlEvent e) {
// TODO Auto-generated method stub
}
#Override
public void controlResized(ControlEvent e) {
MessageDialog.openInformation(s,
"WindowEventHandler Plug-in", "RESIZED: "
+ e.toString() + "\nHello, Eclipse world");
}
});
MessageDialog.openInformation(window.getShell(),
"WindowEventHandler Plug-in",
"Hello, Eclipse world, resize will be taken care of.");
return null;
}
now. Start the project (Run As-> Eclipse application), and you'll se an Eclipse button on the toolbar. Click on it! It triggers the running of the above code where the essence is that the window.getShell() returns with the main window component so you can add listeners to it.
If you want it to run automatically, not just for a button, you have to find out a plugin where the entry point is connected to the starting of the application.
Hope this helps.
b
Found a way to do it easily: you have to create a ShellListener or ShellAdapter, which have methods that are called when the shell is iconified, deiconified, activated, deactivated and closed.
After creating it, add it as a listener with the following line:
int i;
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().addShellListener( yourListenerHere);
If you ever remove it from the shell's listeners list, be sure that Workbench, ActiveWorkbnchWindow and Shell are not null.