在Window > Preferences > General > Search下,有选项Ignore potential matches
它有什么作用?无论我是否激活它,我都看不出有什么不同。
它是只对 Java 开发有意义的选项吗(我从不这样做,但我确实使用 Eclipse 在 C、Python 和 PHP 中开发)?
在Window > Preferences > General > Search下,有选项Ignore potential matches
它有什么作用?无论我是否激活它,我都看不出有什么不同。
它是只对 Java 开发有意义的选项吗(我从不这样做,但我确实使用 Eclipse 在 C、Python 和 PHP 中开发)?
有关示例,请参见错误 127442:根据您搜索的内容(类、方法……),搜索引擎可以找到可以匹配的实例(但不能确定)。
这些实例被标记为“ POTENTIAL_MATCH
”:
具有不同数量参数的方法不是潜在的匹配项。
(见错误 97322)
潜在匹配是解析失败的匹配(例如,方法绑定为空)。
如果用户搜索“foo(String)
”(没有限定String
),那么“foo(java.lang.String)
”和“foo(p.String)
”都是完全匹配的。对于
.class
文件案例,我认为我们只能在缺少类型案例的情况下进行潜在匹配(请参阅错误 196200),即如果 .class 文件已编译并且它引用的某些类型丢失了。
在错误 382778中发现了一个当前的潜在匹配不当行为示例:
我有一个公共静态无效方法
printIt(String name)
。
当我打开它的调用层次结构时,一些调用者丢失了。我猜调用者丢失了,因为 java 搜索将它们标记为潜在而不是完全匹配的
printIt(String)
参考。
以下代码有时被标记为潜在的,有时被标记为准确的:
// Listing 1
PublicInterface2 impl2 = new Impl2("Name Broken");
Static.printIt(impl2.getName());
当搜索结果被标记为潜在时,调用者会从
printIt()
调用层次结构中丢失。
PublicInterface2 is an empty public interface which extends PackageInterface2Getters.
PackageInterface2Getters is an empty default-scoped interface which extends PackageInterface1Getters.
PackageInterface1Getters is a default-scoped interface which declares String getName().
所以
impl2.getName()
上面返回一个String
.报告了一些问题,我猜这些问题会使匹配被标记为潜在:
...
Filename : \D:\workspace\eclipse\_runtimes\jdt\call-hierarchy-bug\src\main\PublicInterface2.java
COMPILED type(s)
2 PROBLEM(s) detected
- Pb(2) PackageInterface1Getters cannot be resolved to a type
- Pb(327) The hierarchy of the type PublicInterface2 is inconsistent
结果是:
The compiler asks the "
NameEnvironment
" to get the type information of any dependent type.
Search has it's ownNameEnvironment
implementation inJavaSearchNameEnvironment
and it is not looking for secondary types.
This is bad and it is surprising that we haven't run into this problem until now.
In Eclipse Luna (Service Release 1 (4.4.1)) I searched just for references to this Java method:
merge(DashboardConfigurationModel template, DashboardModel custom)
It returns two references. One of these calls to the merge()
method passes in a DashboardConfigurationModel
and a DashboardModel
, as befits the method signature. This is a match all right!
The other reference to a merge()
method passes in a String
and a Map
. It is marked in Eclipse as a "potential match" but in my mind, since the argument types don't match, this has zero potential to be a match.
I then checked Ignore potential matches, did the search again, and this noise went away.