1616import org .apache .maven .scm .provider .ScmUrlUtils ;
1717import org .apache .maven .shared .utils .StringUtils ;
1818import org .eclipse .core .runtime .IPath ;
19+ import org .eclipse .core .runtime .NullProgressMonitor ;
1920import org .eclipse .jdt .core .IClassFile ;
2021import org .eclipse .jdt .core .IClasspathEntry ;
2122import org .eclipse .jdt .core .IField ;
3233import org .eclipse .jdt .internal .core .PackageFragmentRoot ;
3334import org .eclipse .jdt .launching .JavaRuntime ;
3435import org .eclipse .jdt .ls .core .internal .JavaLanguageServerPlugin ;
36+ import org .eclipse .jdt .ls .core .internal .handlers .FindLinksHandler ;
3537import org .eclipse .lsp4j .Hover ;
3638import org .eclipse .lsp4j .Location ;
3739
40+ import com .microsoft .java .lsif .core .internal .JdtlsUtils ;
3841import com .microsoft .java .lsif .core .internal .emitter .LsifEmitter ;
3942import com .microsoft .java .lsif .core .internal .indexer .LsifService ;
4043import com .microsoft .java .lsif .core .internal .indexer .Repository ;
@@ -72,6 +75,18 @@ public SymbolData(Project project, Document document) {
7275 this .document = document ;
7376 }
7477
78+ public Document getDocument () {
79+ return this .document ;
80+ }
81+
82+ public ReferenceResult getReferenceResult () {
83+ return this .referenceResult ;
84+ }
85+
86+ public Moniker getGroupMoniker () {
87+ return this .groupMoniker ;
88+ }
89+
7590 synchronized public void ensureResultSet (LsifService lsif , Range sourceRange ) {
7691 if (this .resultSet == null ) {
7792 ResultSet resultSet = lsif .getVertexBuilder ().resultSet ();
@@ -137,7 +152,7 @@ synchronized public void generateExportMoniker(LsifService lsif, String identifi
137152 LsifEmitter .getInstance ().emit (lsif .getEdgeBuilder ().attach (this .schemeMoniker , this .groupMoniker ));
138153 }
139154
140- synchronized public void resolveDefinition (LsifService lsif , Location definitionLocation ) {
155+ synchronized public void resolveDefinition (LsifService lsif , IJavaElement element , Location definitionLocation ) {
141156 if (this .definitionResolved ) {
142157 return ;
143158 }
@@ -148,9 +163,37 @@ synchronized public void resolveDefinition(LsifService lsif, Location definition
148163 DefinitionResult defResult = VisitorUtils .ensureDefinitionResult (lsif , this .resultSet );
149164 LsifEmitter .getInstance ().emit (lsif .getEdgeBuilder ().item (defResult , definitionRange , document ,
150165 ItemEdge .ItemEdgeProperties .DEFINITIONS ));
166+ if (element instanceof IMethod ) {
167+ IMethod mostAbstractMethod = getMostAbstractDeclaration ((IMethod ) element );
168+ if (mostAbstractMethod != null ) {
169+ Location abstractDefinitionLocation = JdtlsUtils .getElementLocation (mostAbstractMethod );
170+ String id = VisitorUtils .createSymbolKey (abstractDefinitionLocation );
171+ Document abstractDefinitionDocument = Repository .getInstance ().enlistDocument (lsif ,
172+ abstractDefinitionLocation .getUri (), this .project );
173+ SymbolData abstractSymbolData = Repository .getInstance ().enlistSymbolData (id ,
174+ abstractDefinitionDocument , this .project );
175+ Repository .getInstance ().addReferenceResults (this , abstractSymbolData );
176+ }
177+ }
151178 this .definitionResolved = true ;
152179 }
153180
181+ private IMethod getMostAbstractDeclaration (IMethod method ) {
182+ IMethod current = null ;
183+ try {
184+ while (method != null ) {
185+ method = FindLinksHandler .findOverriddenMethod (method , new NullProgressMonitor ());
186+ if (method == null ) {
187+ return current ;
188+ }
189+ current = method ;
190+ }
191+ } catch (JavaModelException e ) {
192+ return null ;
193+ }
194+ return null ;
195+ }
196+
154197 synchronized public void resolveTypeDefinition (LsifService lsif , Document docVertex ,
155198 org .eclipse .lsp4j .Range sourceLspRange ) {
156199 if (this .typeDefinitionResolved ) {
@@ -190,8 +233,7 @@ synchronized public void resolveImplementation(LsifService lsif, Document docVer
190233 this .implementationResolved = true ;
191234 }
192235
193- synchronized public void resolveReference (LsifService lsif , Document sourceDocument , Location definitionLocation ,
194- Range sourceRange ) {
236+ synchronized public void resolveReference (LsifService lsif , Document sourceDocument , Location definitionLocation , Range sourceRange ) {
195237 if (this .referenceResult == null ) {
196238 ReferenceResult referenceResult = VisitorUtils .ensureReferenceResult (lsif , this .resultSet );
197239 this .referenceResult = referenceResult ;
0 commit comments