简体   繁体   English

Eclipse 查找方法的引用

[英]Eclipse find references for method

I wanted to find all the callers of the the method "get" for the following class:我想找到以下类的“get”方法的所有调用者:

package com.zzz.zzz.zzz.services;

public final class EMF {
  private static final EntityManagerFactory emfInstance =
    Persistence.createEntityManagerFactory("obamaCareIsGood4U");

  private EMF() {}

  public static EntityManagerFactory get() {
    return emfInstance;
  }
}

So I highlited the text "get" and right-clicked References - project.所以我突出显示了文本“get”并右键单击 References - project。 But it returned references to every method called "get", rather than just references to com.zzz.zzz.zzz.services.EMF.get().但它返回对每个名为“get”的方法的引用,而不仅仅是对 com.zzz.zzz.zzz.services.EMF.get() 的引用。

Is this an eclipse bug?这是日食错误吗? How do I get Eclipse to show references only to com.zzz.zzz.zzz.services.EMF.get()?如何让 Eclipse 仅显示对 com.zzz.zzz.zzz.services.EMF.get() 的引用?

Eclipse Platform  Version:
4.2.0.v20120608-135145-9JF7BHV8FyMteji0Oi_ePMz0xuZ8TVo7lV0z0ecb
Build id:
I20120608-1400,

Spring Tool Suite Version: 3.0.0.M3 Build Id: 201207050802 

Output of reference search:参考搜索的输出:

com.google.common.base - guava-12.0.jar - C:\Users\SofiaVergara\.m2\repository\com\google\guava\guava\12.0 - PatientCare
com.google.common.base - guava-gwt-12.0.jar - C:\Users\SofiaVergara\.m2\repository\com\google\guava\guava-gwt\12.0 - PatientCare
com.google.gwt.junit.server - gwt-user-2.4.0.jar - C:\Users\SofiaVergara\.m2\repository\com\google\gwt\gwt-user\2.4.0 - PatientCare
com.google.gwt.requestfactory.server - gwt-servlet-2.2.0.jar - C:\Users\SofiaVergara\.m2\repository\com\google\gwt\gwt-servlet\2.2.0 - PatientCare
com.google.gwt.resources.rg - gwt-user-2.4.0.jar - C:\Users\SofiaVergara\.m2\repository\com\google\gwt\gwt-user\2.4.0 - PatientCare
com.google.gwt.user.cellview.client - gwt-servlet-2.2.0.jar - C:\Users\SofiaVergara\.m2\repository\com\google\gwt\gwt-servlet\2.2.0 - PatientCare
com.google.gwt.validation.rebind - gwt-user-2.4.0.jar - C:\Users\SofiaVergara\.m2\repository\com\google\gwt\gwt-user\2.4.0 - PatientCare
com.google.web.bindery.requestfactory.apt - gwt-user-2.4.0.jar - C:\Users\SofiaVergara\.m2\repository\com\google\gwt\gwt-user\2.4.0 - PatientCare
com.google.web.bindery.requestfactory.gwt.rebind.model - gwt-user-2.4.0.jar - C:\Users\SofiaVergara\.m2\repository\com\google\gwt\gwt-user\2.4.0 - PatientCare
com.google.web.bindery.requestfactory.vm - gwt-user-2.4.0.jar - C:\Users\SofiaVergara\.m2\repository\com\google\gwt\gwt-user\2.4.0 - PatientCare
com.zzz.zzz.zzz.PatientCare.services.impl - src/main/java/server - PatientCare
com.sun.istack - jaxb-impl-2.2.4.jar - C:\Users\SofiaVergara\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.4 - PatientCare
com.sun.xml.bind.v2 - jaxb-impl-2.2.4.jar - C:\Users\SofiaVergara\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.4 - PatientCare
com.sun.xml.bind.v2.runtime - jaxb-impl-2.2.4.jar - C:\Users\SofiaVergara\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.4 - PatientCare
com.sun.xml.bind.v2.runtime.output - jaxb-impl-2.2.4.jar - C:\Users\SofiaVergara\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.4 - PatientCare
com.sun.xml.bind.v2.runtime.property - jaxb-impl-2.2.4.jar - C:\Users\SofiaVergara\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.4 - PatientCare
com.sun.xml.bind.v2.runtime.reflect - jaxb-impl-2.2.4.jar - C:\Users\SofiaVergara\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.4 - PatientCare
com.sun.xml.bind.v2.runtime.reflect.opt - jaxb-impl-2.2.4.jar - C:\Users\SofiaVergara\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.4 - PatientCare
com.sun.xml.bind.v2.runtime.unmarshaller - jaxb-impl-2.2.4.jar - C:\Users\SofiaVergara\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.4 - PatientCare
javax.persistence.spi - hibernate-jpa-2.0-api-1.0.1.Final.jar - C:\Users\SofiaVergara\.m2\repository\org\hibernate\javax\persistence\hibernate-jpa-2.0-api\1.0.1.Final - PatientCare
javax.xml.bind - jaxb-api-2.2.3.jar - C:\Users\SofiaVergara\.m2\repository\javax\xml\bind\jaxb-api\2.2.3 - PatientCare
org.codehaus.jackson - jackson-core-asl-1.8.5.jar - C:\Users\SofiaVergara\.m2\repository\org\codehaus\jackson\jackson-core-asl\1.8.5 - PatientCare
org.codehaus.jackson.impl - jackson-core-asl-1.8.5.jar - C:\Users\SofiaVergara\.m2\repository\org\codehaus\jackson\jackson-core-asl\1.8.5 - PatientCare
org.codehaus.jackson.io - jackson-core-asl-1.8.5.jar - C:\Users\SofiaVergara\.m2\repository\org\codehaus\jackson\jackson-core-asl\1.8.5 - PatientCare
org.codehaus.jackson.map.ext - jackson-mapper-asl-1.8.5.jar - C:\Users\SofiaVergara\.m2\repository\org\codehaus\jackson\jackson-mapper-asl\1.8.5 - PatientCare
org.codehaus.jackson.map.ser - jackson-mapper-asl-1.8.5.jar - C:\Users\SofiaVergara\.m2\repository\org\codehaus\jackson\jackson-mapper-asl\1.8.5 - PatientCare
org.fusesource.restygwt.client.dispatcher - restygwt-1.3-SNAPSHOT.jar - C:\Users\SofiaVergara\.m2\repository\org\fusesource\restygwt\restygwt\1.3-SNAPSHOT - PatientCare
org.hibernate.context - hibernate-core-3.6.10.Final.jar - C:\Users\SofiaVergara\.m2\repository\org\hibernate\hibernate-core\3.6.10.Final - PatientCare
org.hibernate.stat - hibernate-core-3.6.10.Final.jar - C:\Users\SofiaVergara\.m2\repository\org\hibernate\hibernate-core\3.6.10.Final - PatientCare
org.hibernate.util - hibernate-core-3.6.10.Final.jar - C:\Users\SofiaVergara\.m2\repository\org\hibernate\hibernate-core\3.6.10.Final - PatientCare
org.hibernate.validator.internal.util - hibernate-validator-4.3.0.Final.jar - C:\Users\SofiaVergara\.m2\repository\org\hibernate\hibernate-validator\4.3.0.Final - PatientCare
org.hibernate.validator.internal.util.scriptengine - hibernate-validator-4.3.0.Final.jar - C:\Users\SofiaVergara\.m2\repository\org\hibernate\hibernate-validator\4.3.0.Final - PatientCare
org.jboss.resteasy.client - resteasy-jaxrs-2.3.4.Final.jar - C:\Users\SofiaVergara\.m2\repository\org\jboss\resteasy\resteasy-jaxrs\2.3.4.Final - PatientCare
org.jboss.resteasy.client.cache - resteasy-jaxrs-2.3.4.Final.jar - C:\Users\SofiaVergara\.m2\repository\org\jboss\resteasy\resteasy-jaxrs\2.3.4.Final - PatientCare
org.jboss.resteasy.core - resteasy-jaxrs-2.3.4.Final.jar - C:\Users\SofiaVergara\.m2\repository\org\jboss\resteasy\resteasy-jaxrs\2.3.4.Final - PatientCare
org.jboss.resteasy.spi - resteasy-jaxrs-2.3.4.Final.jar - C:\Users\SofiaVergara\.m2\repository\org\jboss\resteasy\resteasy-jaxrs\2.3.4.Final - PatientCare
org.jboss.resteasy.util - resteasy-jaxrs-2.3.4.Final.jar - C:\Users\SofiaVergara\.m2\repository\org\jboss\resteasy\resteasy-jaxrs\2.3.4.Final - PatientCare

With get highlighted, hit Ctrl+Shift+G.使用突出显示,按 Ctrl+Shift+G。 It'll come up with a list of results in the search tab/window.它会在搜索选项卡/窗口中显示结果列表。 It'll find all references within your workspace.它会在您的工作区中找到所有引用。 It does it via proper references, and not a plain text search.它通过适当的引用而不是纯文本搜索来实现。

Find references in Project relies on method name, that's why it's not accurate.在 Project 中查找引用依赖于方法名称,这就是它不准确的原因。 Try using Call Hierarchy.尝试使用调用层次结构。

In Eclipse Kepler you can configure the search to filter out all Potential Matches (when using References - Workspace / Project or Hierarchy . To activate the filter, click the small down-arrow at the right top of the Search view and activate the Potential Matches check-box.在 Eclipse Kepler 中,您可以配置搜索以过滤掉所有潜在匹配(当使用References - Workspace / ProjectHierarchy时)。要激活过滤器,请单击搜索视图右上方的小向下箭头并激活潜在匹配检查-盒子。在此处输入图像描述

Sometimes, if you have multiple methods of the same name, eg, constructors of a class, all with the same name but different signature, for example, it can be a pain to find all callers of one of those constructors.有时,如果您有多个同名的方法,例如,一个类的构造函数,它们都具有相同的名称但签名不同,那么找到其中一个构造函数的所有调用者可能会很痛苦。 A trick you can use is to comment out the one you are investigating, and build.您可以使用的一个技巧是注释掉您正在调查的内容,然后构建。 The compiler will then tell you all the places it is unable to find that signature, and hence these are exactly all the places that are trying to call that method with that name and that particular signature.编译器然后会告诉您它无法找到该签名的所有地方,因此这些正是所有试图使用该名称和该特定签名调用该方法的地方。

Eclipse continues to have a bug, where Search->References->Workspace does not find method references. Eclipse 仍然存在一个错误,其中 Search->References->Workspace 找不到方法引用。

I'm using this Eclipse: Version: 2022-06 (4.24.0) Build id: 20220609-1112我正在使用这个 Eclipse:版本:2022-06 (4.24.0) 构建 ID:20220609-1112

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

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