11package com .sourcegraph .semanticdb_javac ;
22
3- import com .sun .tools .javac .code .Kinds ;
4- import com .sun .tools .javac .code .Scope ;
53import com .sun .tools .javac .code .Symbol ;
64
7- import java . util . ArrayList ;
8- import java . util . Collections ;
9- import java .util .IdentityHashMap ;
5+ import javax . lang . model . element . Element ;
6+ import javax . lang . model . element . ExecutableElement ;
7+ import java .util .* ;
108
119import static com .sourcegraph .semanticdb_javac .Debugging .pprint ;
1210
@@ -33,7 +31,7 @@ public String semanticdbSymbol(Symbol sym, LocalSymbolsCache locals) {
3331 }
3432
3533 public boolean isNone (Symbol sym ) {
36- return sym == null || sym . kind == Kinds . NIL || ( sym . kind & Kinds . ERRONEOUS ) != 0 ;
34+ return sym == null ;
3735 }
3836
3937 private String uncachedSemanticdbSymbol (Symbol sym , LocalSymbolsCache locals ) {
@@ -97,18 +95,13 @@ private SemanticdbSymbols.Descriptor semanticdbDescriptor(Symbol sym) {
9795 * SemanticDB spec</a>.
9896 */
9997 private String methodDisambiguator (Symbol .MethodSymbol sym ) {
100- Scope .Entry lookup =
101- sym .owner .members ().lookup (sym .name , s -> s instanceof Symbol .MethodSymbol );
102- ArrayList <Symbol > peers = new ArrayList <>();
103- while (lookup != null ) {
104- if (lookup .sym != null ) {
105- peers .add (lookup .sym );
98+ Iterable <? extends Element > elements = sym .owner .getEnclosedElements ();
99+ ArrayList <ExecutableElement > methods = new ArrayList <>();
100+ for (Element e : elements ) {
101+ if (e instanceof ExecutableElement && e .getSimpleName () == sym .name ) {
102+ methods .add ((ExecutableElement ) e );
106103 }
107- lookup = lookup .next ();
108104 }
109- // NOTE(olafur): reverse the iteration from `Scope.Entry` to get order in which the symbols are
110- // defined in source.
111- Collections .reverse (peers );
112105 // NOTE(olafur): sort static methods last, according to the spec. Historical note: this
113106 // requirement is
114107 // part of the SemanticDB spec because static methods and non-static methods have a different
@@ -117,8 +110,9 @@ private String methodDisambiguator(Symbol.MethodSymbol sym) {
117110 // definitions.
118111 // In practice, it's unusual to mix static and non-static methods so this shouldn't be a big
119112 // issue.
120- peers .sort ((a , b ) -> Boolean .compare (a .isStatic (), b .isStatic ()));
121- int index = peers .indexOf (sym );
113+ methods .sort (
114+ (a , b ) -> Boolean .compare (a .getReceiverType () == null , b .getReceiverType () == null ));
115+ int index = methods .indexOf (sym );
122116 if (index == 0 ) return "()" ;
123117 return String .format ("(+%d)" , index );
124118 }
0 commit comments