Bug 513294 - Type parameters are resolved in wrong context
Summary: Type parameters are resolved in wrong context
Status: NEW
Alias: None
Product: Eclemma
Classification: Technology
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 minor
Target Milestone: ---   Edit
Assignee: Project inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 502563
Blocks:
  Show dependency tree
 
Reported: 2017-03-08 04:23 EST by Marc R. Hoffmann CLA
Modified: 2017-07-03 16:20 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc R. Hoffmann CLA 2017-03-08 04:23:13 EST
EclEmma maps coverage data to JDT Java model elements down to IMethod level. Collected coverage data comes with fully resolved binary method signatures. To map those to source methods unresolved IMethod signatures must be resolved (only if  methods are overloaded and the plain name is ambigous).

For this EclEmma implements utility to resolve method signatures:

https://github.com/eclipse/eclemma/blob/master/org.eclipse.eclemma.core/src/org/eclipse/eclemma/internal/core/analysis/SignatureResolver.java

While fixing bug 512756 we came up with a new corner case which does not resolve properly:

  // S resolves to java.lang.Comparable
  public class ScopeSample<S extends Comparable> {

    // This has no influence on the type of S
    class Comparable {
    }

    class Inner {

      // So S still resolves to java.lang.Comparable
      void Foo(S param) {
      }

    }

  }

When resolving the type parameter S for the signature of method ScopeSample.Inner.Foo() the following happens:

EXPECTED

The type parameter S must resolve to java.lang.Comparable

ACTUAL 

The type parameter S resolves to ScopeSample.Comparable
Comment 1 Marc R. Hoffmann CLA 2017-03-08 05:02:30 EST
Posted a question about this in the JDT mailing list. Maybe there is a better way to resolve method signatures:

http://dev.eclipse.org/mhonarc/lists/jdt-dev/msg00887.html
Comment 2 Marc R. Hoffmann CLA 2017-03-08 08:59:39 EST
According to JLS 6.3 (https://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.3): "The scope of a top level type (ยง7.6) is all type declarations in the package in which the top level type is declared."

Current implementation uses the type's method body as scope, which is wrong.
Comment 3 Stephan Herrmann CLA 2017-03-08 18:07:12 EST
Seeing Signature.getTypeErasure(identifier) in your code (and without understanding the details of it), I hazard the guess that you are erasing too early. Perhaps your strategy should be modified to first resolve S to the ITypeParameter of the IType for ScopeScample, and then compute the erasure of it (perhaps directly using its first bound or such).

For demonstration: if you first erase S to Comparable and then resolve Comparable in the scope of Inner the actual behaviour should be expected.
Comment 4 Marc R. Hoffmann CLA 2017-03-09 01:19:31 EST
As Stephan noted on the JDT mailing list there is open request for a new API to resolve type parameters: Bug 502563
Comment 5 Marc R. Hoffmann CLA 2017-03-09 01:30:09 EST
Stephan, I the problem here is that the type parameters of types are resolved in the wrong context: They must not be resolved within the type, but within the parent context of the type. So

* For inner classes within the parent type (IType.resolveType)
* For top level classes within the package scope

Is there an API to resolve types within package scope?