Lines 10-15
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.internal.compiler.lookup; |
11 |
package org.eclipse.jdt.internal.compiler.lookup; |
12 |
|
12 |
|
|
|
13 |
import org.eclipse.jdt.core.compiler.CharOperation; |
13 |
import org.eclipse.jdt.internal.compiler.ast.ASTNode; |
14 |
import org.eclipse.jdt.internal.compiler.ast.ASTNode; |
14 |
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; |
15 |
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; |
15 |
import org.eclipse.jdt.internal.compiler.ast.Annotation; |
16 |
import org.eclipse.jdt.internal.compiler.ast.Annotation; |
Lines 57-70
Link Here
|
57 |
} |
58 |
} |
58 |
|
59 |
|
59 |
/* |
60 |
/* |
60 |
* declaringUniqueKey # scopeIndex / varName |
61 |
* declaringUniqueKey # scopeIndex(0-based) # varName [# occurrenceCount(0-based)] |
61 |
* p.X { void foo() { int local; } } --> Lp/X;.foo()V#1/local |
62 |
* p.X { void foo() { int local; int local;} } --> Lp/X;.foo()V#1#local#1 |
62 |
*/ |
63 |
*/ |
63 |
public char[] computeUniqueKey(boolean isLeaf) { |
64 |
public char[] computeUniqueKey(boolean isLeaf) { |
64 |
StringBuffer buffer = new StringBuffer(); |
65 |
StringBuffer buffer = new StringBuffer(); |
65 |
|
66 |
|
66 |
// declaring method or type |
67 |
// declaring method or type |
67 |
BlockScope scope = this.declaringScope; |
68 |
BlockScope scope = this.declaringScope; |
|
|
69 |
int occurenceCount = 0; |
68 |
if (scope != null) { |
70 |
if (scope != null) { |
69 |
// the scope can be null. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=185129 |
71 |
// the scope can be null. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=185129 |
70 |
MethodScope methodScope = scope instanceof MethodScope ? (MethodScope) scope : scope.enclosingMethodScope(); |
72 |
MethodScope methodScope = scope instanceof MethodScope ? (MethodScope) scope : scope.enclosingMethodScope(); |
Lines 83-93
Link Here
|
83 |
|
85 |
|
84 |
// scope index |
86 |
// scope index |
85 |
getScopeKey(scope, buffer); |
87 |
getScopeKey(scope, buffer); |
|
|
88 |
|
89 |
// find number of occurences of a variable with the same name in the scope |
90 |
LocalVariableBinding[] locals = scope.locals; |
91 |
for (int i = 0; i < scope.localIndex; i++) { // use linear search assuming the number of local per scope is low |
92 |
LocalVariableBinding local = locals[i]; |
93 |
if (CharOperation.equals(this.name, local.name)) { |
94 |
if (this == local) |
95 |
break; |
96 |
occurenceCount++; |
97 |
} |
98 |
} |
86 |
} |
99 |
} |
87 |
// variable name |
100 |
// variable name |
88 |
buffer.append('#'); |
101 |
buffer.append('#'); |
89 |
buffer.append(this.name); |
102 |
buffer.append(this.name); |
90 |
|
103 |
|
|
|
104 |
// add occurence count to avoid same key for duplicate variables |
105 |
// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=149590) |
106 |
if (occurenceCount > 0) { |
107 |
buffer.append('#'); |
108 |
buffer.append(occurenceCount); |
109 |
} |
110 |
|
91 |
int length = buffer.length(); |
111 |
int length = buffer.length(); |
92 |
char[] uniqueKey = new char[length]; |
112 |
char[] uniqueKey = new char[length]; |
93 |
buffer.getChars(0, length, uniqueKey, 0); |
113 |
buffer.getChars(0, length, uniqueKey, 0); |