Bug 132677 - IProblem ranges for method invocations should be minimal
Summary: IProblem ranges for method invocations should be minimal
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.3   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 133046
Blocks:
  Show dependency tree
 
Reported: 2006-03-21 09:25 EST by Tobias Widmer CLA
Modified: 2009-08-30 02:34 EDT (History)
4 users (show)

See Also:


Attachments
Different patches for jdt/core projects (30.35 KB, application/octet-stream)
2006-03-23 12:49 EST, Olivier Thomann CLA
no flags Details
Simplified patch to apply on the org.eclipse.jdt.core project (22.89 KB, patch)
2006-03-23 15:24 EST, Olivier Thomann CLA
no flags Details | Diff
screenshot (2.79 KB, image/png)
2006-03-26 13:40 EST, Martin Aeschlimann CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Widmer CLA 2006-03-21 09:25:23 EST
A method invocation to a deprecated method currently causes a problem with a range corresponding to the MethodInvocation AST node. This is in contrast to field accesses where the problem only covers the range of the field name.

This causes problems if the method invocation has several problems, such as in the following case:

/** @deprecated Use Bar1 instead */
public class Bar {
  /** @deprecated Use bar1 instead */
  public void bar() {}
  /** @deprecated Use field1 instead */
  public int field;
}

class Foo {
  private final Bar b;
  Foo(Bar bar) {
    b = bar;
  }
  public void foo() {
    new Bar().bar(); // Hover over this line
    b.field(); // Hover over this line
  }
}

The method invocation line marked above hides three warnings, which are not easily accessible ie.  during quick fix or hovering.

In general, problem ranges should only cover the minimum if possible, such as Identifiers or Simple Names (and no "new" keyword as for deprecated constructors.

Use Java->Editor->Hovers->Expand vertical ruler icons to quickly see the problem ranges.
Comment 1 Olivier Thomann CLA 2006-03-21 09:41:28 EST
I'll look at this.
Comment 2 Olivier Thomann CLA 2006-03-21 11:27:24 EST
So you would expect the problem range to cover only:
new Bar().bar()
    ^^^
for the problem related to the deprecated constructor and:

new Bar().bar()
          ^^^
for the problem related to the deprecated method invocation.

Am I right?

This should then be generalized for all errors/warnings related to method invocation and constructor calls.
Comment 3 Tobias Widmer CLA 2006-03-21 11:38:35 EST
Yes, this is exactly what I meant.
Comment 4 Olivier Thomann CLA 2006-03-21 12:16:25 EST
Martin,

Could this have a side-effect on quick fix?
Comment 5 Martin Aeschlimann CLA 2006-03-21 12:27:53 EST
no, not yet. No tests yet for this feature (working on it). So it would be great if you can change this soon!
Comment 6 Olivier Thomann CLA 2006-03-21 15:45:14 EST
I plan to do it today or tomorrow.
I will change positions for all method invocations and constructor calls to be consistent.
Comment 7 Olivier Thomann CLA 2006-03-23 11:59:12 EST
My changes are ready to be released, but a lot of the quickfix tests are broken. I believe they make assumption on the problem's positions.
Martin,
How much time do you need to fix this?


Philippe, I cannot release this as long as quick fix is not fixed.
Comment 8 Olivier Thomann CLA 2006-03-23 12:12:56 EST
These tests seem to be impacted by the fix for this PR:
org.eclipse.jdt.ui.tests.quickfix.UnresolvedMethodsQuickFixTest
org.eclipse.jdt.ui.tests.quickfix.LocalCorrectionsQuickFixTest
org.eclipse.jdt.ui.tests.quickfix.TypeMismatchQuickFixTests
org.eclipse.jdt.ui.tests.quickfix.ModifierCorrectionsQuickFixTest
org.eclipse.jdt.ui.tests.quickfix.ChangeNonStaticToStaticTest
org.eclipse.jdt.ui.tests.quickfix.CleanUpTest

I'll run the refactoring tests to check if they are also broken.
Comment 9 Olivier Thomann CLA 2006-03-23 12:49:01 EST
Created attachment 36821 [details]
Different patches for jdt/core projects

Apply on HEAD and you should be able to reproduce the failures.
Quickfix should not rely on the problem's positions.
Comment 10 Olivier Thomann CLA 2006-03-23 13:57:56 EST
Refactoring tests are not affected by this fix.
Comment 11 Olivier Thomann CLA 2006-03-23 14:02:44 EST
Opened bug 133046 to track down the fix for quickfix feature.
Comment 12 Olivier Thomann CLA 2006-03-23 14:06:19 EST
Regression test will be org.eclipse.jdt.core.tests.compiler.regression.DeprecatedTest.test012
Comment 13 Olivier Thomann CLA 2006-03-23 15:24:53 EST
Created attachment 36841 [details]
Simplified patch to apply on the org.eclipse.jdt.core project

Use this patch if you apply on HEAD.
The previous patch contained other changes that have been released.
Comment 14 Martin Aeschlimann CLA 2006-03-26 13:39:33 EST
I think this patch is doing too much. There shouldn't be any failing tests in quick fixes e.g. on mismatching parameters, or static access warnings. This should all stay the same.

It also results in very strange behaviour in cases like
public class E {
    public void foo(Iterator iter) {
        String str, str2;
        str= iter.next();
    }
}
See screenshot.
Comment 15 Martin Aeschlimann CLA 2006-03-26 13:40:52 EST
Created attachment 36959 [details]
screenshot
Comment 16 Olivier Thomann CLA 2006-03-26 20:38:14 EST
I don't see what is strange.
import java.util.Iterator;

public class X {
    public void foo(Iterator iter) {
        String str, str2;
        str= iter.next();
    }
}

Before the patch, it would underline the whole expression ("iter.next()"). Now it simply underlines "next". This is right. What is weird in this error?

Quickfix needs to be changed. The patch is changing all method invocations to reduce the lenght of the underline red line. I won't change simply the deprecated case. I prefer to keep all problems consistent.

I put a patch in bug 133046 to fix the quickfix for the failing failures.

I don't like to make a change without changing other error report that are also using method invocations. This would make our compiler inconsistent when reporting errors.

I can update the title of the bug report if you prefer.
Comment 17 Martin Aeschlimann CLA 2006-03-27 07:25:29 EST
> What is weird in this error?
The error is that the _expression_ isn't assigment compatible. So highlighting the expression was exactly the right thing to do.

Other examples that I think got worse with the path:
- Indirect access warnings:  Only the method name is not enough, highlight the access.
- raw access: rawList.put(""). The problem is the raw type access, not just the method
Comment 18 Philipe Mulet CLA 2006-03-27 10:03:23 EST
I would tend to agree with Martin. 
My main problem is when method invocation span over multiple lines, like in anonymous type allocations etc...

Comment 19 Philipe Mulet CLA 2006-03-27 10:06:57 EST
Actually, any time the problem is truly related to the method invocation, I think highlighting the selector is an improvement.

The type mismatch is not specific to a method invocation, as pointed out by Martin; but in case the problem would be a visibility issue, a missing method (see  ProblemReporter#invalidMethod/invalidConstructor), then I would expect selector to be highlighted only to reduce clutter.

Similar for unchecked method invocation, issues with inference for generic methods.
Comment 20 Olivier Thomann CLA 2006-03-27 10:20:26 EST
OK, I'll try to get the changes in this direction.
Martin,

This might still involved changes in the quick fix.
Comment 21 Martin Aeschlimann CLA 2006-03-27 10:28:12 EST
To be honset, I'm a bit scared of such a change in the last minute. We obviously have good tests for these scenarios, but as there are so many, we also might have missed a case.
We really thought of just having the deprecation warning fixed, but do not really want to have such a massive change.
Comment 22 Olivier Thomann CLA 2006-03-27 10:33:23 EST
Here is a list of affected methods in ProblemReporter and the corresponding IProblem ids.
Let me know if you think about other cases.

cannotDireclyInvokeAbstractMethod: IProblem.DirectInvocationOfAbstractMethod
errorNoMethodFor: IProblem.NoMessageSendOnArrayType, IProblem.NoMessageSendOnBaseType
invalidMethod: IProblem.UndefinedMethod, IProblem.ParameterMismatch, IProblem.NotVisibleMethod, IProblem.AmbiguousMethod,
	IProblem.InheritedMethodHidesEnclosingName, IProblem.InstanceMethodDuringConstructorInvocation, IProblem.StaticMethodRequested,
	IProblem.GenericMethodTypeArgumentMismatch, IProblem.NonGenericMethod, IProblem.IncorrectArityForParameterizedMethod,
	IProblem.ParameterizedMethodArgumentTypeMismatch, IProblem.ParameterizedMethodArgumentTypeMismatch
invalidConstructor: IProblem.UndefinedConstructorInDefaultConstructor, IProblem.UndefinedConstructorInImplicitConstructorCall, IProblem.UndefinedConstructor
	IProblem.NotVisibleConstructorInDefaultConstructor, IProblem.NotVisibleConstructorInImplicitConstructorCall, IProblem.NotVisibleConstructor,
	IProblem.AmbiguousConstructorInDefaultConstructor, IProblem.AmbiguousConstructorInImplicitConstructorCall, IProblem.AmbiguousConstructor
	IProblem.GenericConstructorTypeArgumentMismatch, IProblem.NonGenericConstructor, IProblem.IncorrectArityForParameterizedConstructor,
	IProblem.ParameterizedConstructorArgumentTypeMismatch, IProblem.TypeArgumentsForRawGenericConstructor
javadocErrorNoMethodFor: IProblem.JavadocNoMessageSendOnArrayType, IProblem.JavadocNoMessageSendOnBaseType
javadocInvalidMethod: Same for invalid method, but for javadoc
mustUseAStaticMethod: IProblem.StaticMethodRequested
javadocInvalidConstructor: same for invalid constructor but for javadoc
noSuchEnclosingInstance: IProblem.EnclosingInstanceInConstructorCall, IProblem.MissingEnclosingInstanceForConstructorCall
	IProblem.MissingEnclosingInstance, IProblem.IncorrectEnclosingInstanceReference
deprecatedMethod: IProblem.UsingDeprecatedConstructor, IProblem.UsingDeprecatedMethod
Comment 23 Olivier Thomann CLA 2006-03-27 14:35:33 EST
Close as LATER.
Will investigate post 3.2.
Comment 24 Eclipse Webmaster CLA 2009-08-30 02:34:47 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.