简体   繁体   English

Eclipse - `open call hierarchy`得到了错误的结果

[英]Eclipse - `open call hierarchy` got wrong result

Here is my sample java code: 这是我的示例java代码:

public class Test {
    public static void foo() {
        Foo.InnerKey key = new Foo.InnerKey();
        getInstance().query(key);
    }

    public static void bar() {
        Bar.InnerKey key = new Bar.InnerKey();
        getInstance().query(key);
    }

    public static MyIF getInstance(){
        // TODO code to get instance
        return null;
    }

}


interface MyIF {
    public void query(Foo.InnerKey key); // Method to open call hierarchy
    public void query(Bar.InnerKey key);
}


class Foo {
    static class InnerKey  {}
}

class Bar {
    static class InnerKey {}
}

When I open call hierarchy of method query(Foo.InnerKey key) from Eclipse(kepler), I got both foo & bar methods, which bar is not expected. 当我打开方法的调用层次query(Foo.InnerKey key)在Eclipse(开普勒),我有两个foobar的方法,这bar预计不会。

在此输入图像描述

But in netbeans(7.3.1), the result of call hierarchy is OK: 但是在netbeans(7.3.1)中,调用层次结果是可以的:

在此输入图像描述

Is it a bug of Eclipse? 这是Eclipse的错误吗? Thanks. 谢谢。

This is definitely a JDT bug that should be reported. 这绝对是一个应该报告的JDT错误。 And the bug is not directly related to the call hierarchy, but instead to the org.eclipse.jdt.core search API, when searching for method references, where the parameter is a member type of another type (as eg Foo.InnerKey ). 并且bug与调用层次结构没有直接关系,而是与org.eclipse.jdt.core搜索API直接相关,在搜索方法引用时,参数是另一种类型的成员类型(例如Foo.InnerKey )。 Therefore this bug manifests itself for every JDT functionality, that relies on finding method references by using the JDT search engine. 因此,这个错误表现为每个JDT功能,它依赖于使用JDT搜索引擎查找方法引用。 For example you will also get wrong results when showing the references to MyIF#query(Foo.InnerKey) or when using the Java search, to search for the method MyIF#query(Foo.InnerKey) . 例如,在显示对MyIF#query(Foo.InnerKey)的引用或使用Java搜索时,您也会得到错误的结果,以搜索MyIF#query(Foo.InnerKey) In these cases the search engine will not only return references to MyIF#query(Foo.InnerKey) , as would be expected, but also to MyIF#query(Bar.InnerKey) . 在这种情况下,搜索引擎不仅会返回引用MyIF#query(Foo.InnerKey)正如所预料的,而且要MyIF#query(Bar.InnerKey)

The relevant code, where this bug occurs, is in org.eclipse.jdt.internal.core.search.matching.MethodLocator#matchMethod(MethodBinding, boolean) . 发生此错误的相关代码位于org.eclipse.jdt.internal.core.search.matching.MethodLocator#matchMethod(MethodBinding, boolean) And it seems, that the bug was introduced by fixing JDT Bug 41018 . 看起来,这个bug是通过修复JDT Bug 41018引入的。

Here is a snippet of the relevant code in the class MethodLocator: 以下是MethodLocator类中相关代码的片段:

protected int matchMethod(MethodBinding method, boolean skipImpossibleArg) {
    [...]
    // verify each parameter
    for (int i = 0; i < parameterCount; i++) {
        TypeBinding argType = method.parameters[i];
        int newLevel = IMPOSSIBLE_MATCH;
        if (argType.isMemberType()) {
            // only compare source name for member type (bug 41018)
            newLevel = CharOperation.match(this.pattern.parameterSimpleNames[i], argType.sourceName(), this.isCaseSensitive)
                ? ACCURATE_MATCH
                : IMPOSSIBLE_MATCH;
        } else {
            // TODO (frederic) use this call to refine accuracy on parameter types
            // newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], this.pattern.parametersTypeArguments[i], 0, argType);
            newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], argType);
            [...]
        }
    }
    [...]
}

The problem here is the if (argType.isMemberType()) statement, that was introduced to fix Bug 41018 . 这里的问题是if (argType.isMemberType())语句,它是为修复Bug 41018而引入的。 The comment also states that for member types only the source name gets compared . 该评论还指出,对于成员类型, 仅比较源名称 If this if-statement is removed, the bug goes away and the call hierarchy shows the correct references (but I guess this would of course re-introduce bug 41018 - I didn't test this). 如果删除了这个if语句,那么bug就会消失,调用层次结构会显示正确的引用(但我想这当然会重新引入bug 41018 - 我没有测试过这个)。

Edit 编辑

On a side note, there also seems to be a bug when displaying the source codes Javadoc for MyIF#query(Bar.InnerKey) - both when using the Javadoc-Hover over the method or when showing the method in the Javadoc view. 另外,在显示源代码Javadoc for MyIF#query(Bar.InnerKey)时似乎也存在一个错误 - 当在方法上使用Javadoc-Hover或在Javadoc视图中显示方法时。

public interface MyIF {
    /**
     * Javadoc for: query(Foo.InnerKey key)
     */
    public void query(Foo.InnerKey key); // Method to open call hierarchy
    /**
     * Javadoc for: query(Bar.InnerKey key)
     */
    public void query(Bar.InnerKey key);
}

When hovering over a query method reference in the Test class (eg getInstance().query(key) ), both methods are found and one is able to select one (without the ability to differentiate between the two). 将鼠标悬停在Test类中的查询方法引用(例如getInstance().query(key) )时,会找到两种方法,并且可以选择一种方法(无法区分这两种方法)。

When opening the Javadoc view and selecting any of the query method references in the Test class, the Javadoc view always displays only the Javadoc of the first found method in the source class (ie MyIF#query(Foo.InnerKey) ). 打开Javadoc视图并选择Test类中的任何查询方法引用时,Javadoc视图始终只显示源类中第一个找到的方法的Javadoc(即MyIF#query(Foo.InnerKey) )。

This doesn't seem to be directly related to the bug described above, and it will also not be resolved, when removing the if-statement mentioned above... 这似乎与上述错误没有直接关系,并且在删除上面提到的if语句时也无法解决...

I think it may be the same issue as this existing bug (although your example is simpler, IMO). 我认为它可能与现有错误相同(尽管您的示例更简单,IMO)。 I suggest you add a comment and your example to that bug report. 我建议您在该错误报告中添加评论和示例。

Also, could be related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=123836 which is suspected as a culprit for another, https://bugs.eclipse.org/bugs/show_bug.cgi?id=394475 此外,可能与https://bugs.eclipse.org/bugs/show_bug.cgi?id=123836有关,这被怀疑是另一个人的罪魁祸首, https://bugs.eclipse.org/bugs/show_bug.cgi? ID = 394475

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM