I'm using eclipse Juno with PDT. Autocomplete works fine except in a specific situation.
If I do this it works fine
class Example {
public function doit() {
$v = new Example();
}
}
I can control-click the Example() object fine and also I see the doit() method when autocompleting $v->.
Now see this example
class Example2 {
public function doit() {
$v = (new Example2());
}
}
Now the autocompleter is broken, I cannot control-click anything but also the outline view is now empty. Eclipse cannot see any methods or anything. There is nothing in the eclipse logs.
Of course this is a stupid example but I've seen this construction happening in statements with the ternary operator in external frameworks. This is pretty annoying because the objects from such classes cannot be used anymore with the autocompleter.
This call relates to Eclipse PHP autocomplete acting funny, some files complete some don't btw where I also replied with the actual issue. Please don't shoot me for re-posting.
Related
I think 5 years has passed since Lambda has been released for Java.
public static void main(String[] args) {
go();
}
private static void go() {
Set<String> set = new HashSet<>();
set.stream().forEach((s) -> {
inner(s);
});
}
private static void inner(String s) {
inner1(s);
}
private static void inner1(String s) {
}
When I press CTRL-ALT-H - (open call hierarchy) on inner1 method, I expect to see a whole stack trace from in inner1 to main method. Instead, my staktrace is trimmed on inner method. I've just downloaded the newest Eclipse, I think it 2018-12, previously I was using Mars.
Intellij can show me the expected call-hierarchy, and I don't really understand why Eclipse still can't do it. Not sure if anyone else is using Eclipse in 2019, but maybe you can advise a plugin or something.
Switching to Intellij is not an option, I tried couple of times, but the habit is hard to overcome.
UPDATE
There is similar - SO question
At run time, evaluation of a lambda expression is similar to
evaluation of a class instance creation expression, insofar as normal
completion produces a reference to an object. Evaluation of a lambda
expression is distinct from execution of the lambda body.
and
Just note, that for lambdas implementing library types like
Consumer, the number of callers into accept(T) in a workspace may
easily become unmanageable, similar to any call hierarchy through,
e.g, Runnable.run() - but that doesn't question the general usefulness
of call hierarchies through lambdas.
I don't really care about lambda internals, somehow other IDE is able to show expected stacktrace
There's an existing old bug for eclipse, reported in 2016, still in NEW status
Bug 498498 - [1.8][search][call hierarchy] No usage for lambdas
Call hierarchy on bar method correctly shows usage in accept, and for accept there is no usage shown.
This issue was already present in mars.
There are 3 votes to fix it, you can vote too
From your edit's links there's another relevant old bug in NEW status
Bug 468561 - [search]Call Hierarchy stops searching in doubly-nested lambda chain
with 3 votes too...
Eclipse 4.22 (Q4 2021) should help:
Improved lambda support in the Call Hierarchy view
The Call Hierarchy view is enhanced with showing not only the callers of the lambda function, but the callers of the declaring function too.
For the following code:
Checking the callers of the function() will show this:
The [declaration] node in the tree is the new addition, which shows the callers of the definer() function, in this case, only the main() function.
We found a bug in old code which could be easily found if there would be a warning,
The issue was that inner class member was used but not assigned or initialized. Sample code minimized. Problem is that url is always null.
public class Main {
public class Sender {
private String url;
public Sender() {
}
public void send() {
OtherClass.send(url);
}
}
}
In intellij it warns about variable never assigned. In eclipse I didn't find such warning.
The code is more complex and adding a warning at any level will reduce time to find similar bugs.
Is it possible in eclipse to warn in some way if variable is used before assigned/initialized ?
You can use SpotBugs(successor of findbugs) eclipse plugin. Right click on project Spotbugs->find bugs this will find these types of bugs.
I suggest also installing sonarlint plugin which has good static analysis capabilities.
https://marketplace.eclipse.org/content/spotbugs-eclipse-plugin
https://marketplace.eclipse.org/content/sonarlint
I am having an issue in Eclipse (with Dagger 1 still).
In dagger, for dependency injection (javax.inject), you create a Module class, with provides methods, like this:
#dagger.Module
class FooModule {
#dagger.Provides
Something provideSomething() {
return new Something();
}
}
And this will generate a class (using annotation processing) called FooModule$$ModuleAdapter$ProvideSomethingProvidesAdapter.
If I set a breakpoint in a provideSomething method in FooModule class (my code), Eclipse almost always actually stops on that same line number in the FooModule$$ModuleAdapter$ProvideSomethingProvidesAdapter class instead.
Does anyone know how to avoid this problem? I suspect this is likely an Eclipse issue where it is somehow is mapping the generated file to what it thinks is the "source" file, but that's of course not what I want.
Is there perhaps some setting in eclipse to avoid this problem?
I needed to 'wrap' (for academic purposes) the GL2 interface in a class of mine that uses delegation to the current GLContext, something like:
public abstract class GL2Wrapper implements GL2 {
private GL2 current() {
return GLContext.getCurrentGL().getGL2();
}
// delegated methods here
public void glEnableClientState(int arrayName) {
current().glEnableClientState(arrayName);
}
// ... (2000+ methods to go)
}
// Somewhere else
public class GlWindow extends GLWrapper {
public GlWindow() {
glBegin(GL_TRIANGLES);
glVertex3f( 1, 0, 0);
glVertex3f( 0, 1, 0);
glVertex3f(-1, 0, 0);
glEnd();
}
}
It all works fine in runtime, but the class ends up with 2000+ methods.
I don't have a doubt that the code design is 'arguable', my question is more Eclipse Luna related.
Eclipse Luna hangs every time I use any type of auto-completion in the GlWindow class. It gets worst if I need to add something in GL2Wrapper.
I didn't have this problem (at least not this bad) in Eclipse Kepler and before.
Is there any eclipse configuration (maybe compiler related) that can help me leverage the problem?
Thanks in advance,
Regards,
LL
It looks like an Eclipse bug 433515 - Eclipse freezes every few minutes.
Same kind of issue for me when calling autocompletion in Javascript code into a JSP page or Javascript file, or even just hovering with the mouse a JavaScript code. The memory usage is playing the yoyo and Eclipse freezes.
I'm in a generic method, debugging, but i get no information about variables, can't execute statements using ctrl-shift-i, eclipse tells the that the method ... isn't available on the type T.
I can't believe it's meant to (not) work like this ...
[edit]
I'm using the eclipse that's part of RAD 7.5.4
[another edit]
Here's some code but I doubt you'll get any info from this
public abstract class GenericGroupController<T extends Group> {
...
public String addUser(final Model model, final Long id, final WebRequest request) {
T group = groupManager.loadGroup(id);
...
// this method will fail if i highlight and click ctr-shift-i
// but it will work otherwise (actually so will the method above
// because that's generic as well)
Long groupId = group.getId();
...
return getAddUserView();
}
}
If you are able to debug, as in see a stack trace, you can always see the variables in the variables window if not in the code. A lot of places where the code isn't available you can do the same. It isn't nice, but, it gets the job done.