View | Details | Raw Unified | Return to bug 149590 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/LocalVariableBinding.java (-2 / +22 lines)
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);
(-)model/org/eclipse/jdt/internal/core/util/BindingKeyParser.java (-2 / +11 lines)
Lines 430-436 Link Here
430
		// default is to do nothing
430
		// default is to do nothing
431
	}
431
	}
432
	
432
	
433
	public void consumeLocalVar(char[] varName) {
433
	public void consumeLocalVar(char[] varName, int occurrenceCount) {
434
		// default is to do nothing
434
		// default is to do nothing
435
	}
435
	}
436
	
436
	
Lines 695-701 Link Here
695
			}
695
			}
696
			parseLocalVariable();
696
			parseLocalVariable();
697
		} else {
697
		} else {
698
		 	consumeLocalVar(varName);
698
			int occurrenceCount = 0;
699
			if (this.scanner.isAtLocalVariableStart()) {
700
			 	if (this.scanner.nextToken() != Scanner.LOCAL_VAR) {
701
			 		malformedKey();
702
					return;
703
			 	}
704
				char[] occurrence = this.scanner.getTokenSource();
705
				occurrenceCount = Integer.parseInt(new String(occurrence));
706
			}
707
		 	consumeLocalVar(varName, occurrenceCount);
699
		}
708
		}
700
 	}
709
 	}
701
	
710
	
(-)model/org/eclipse/jdt/internal/core/util/BindingKeyResolver.java (-2 / +3 lines)
Lines 223-235 Link Here
223
 			}
223
 			}
224
	}
224
	}
225
225
226
	public void consumeLocalVar(char[] varName) {
226
	public void consumeLocalVar(char[] varName, int occurrenceCount) {
227
		if (this.scope == null) {
227
		if (this.scope == null) {
228
			this.scope = this.methodBinding.sourceMethod().scope;
228
			this.scope = this.methodBinding.sourceMethod().scope;
229
		}
229
		}
230
	 	for (int i = 0; i < this.scope.localIndex; i++) {
230
	 	for (int i = 0; i < this.scope.localIndex; i++) {
231
			LocalVariableBinding local = this.scope.locals[i];
231
			LocalVariableBinding local = this.scope.locals[i];
232
			if (CharOperation.equals(varName, local.name)) {
232
			if (CharOperation.equals(local.name, varName)
233
					&& occurrenceCount-- == 0) {
233
				this.methodBinding = null;
234
				this.methodBinding = null;
234
				this.compilerBinding = local;
235
				this.compilerBinding = local;
235
				return;
236
				return;
(-)model/org/eclipse/jdt/internal/core/util/KeyKind.java (-1 / +1 lines)
Lines 53-59 Link Here
53
		this.flags |= F_LOCAL;
53
		this.flags |= F_LOCAL;
54
	}
54
	}
55
55
56
	public void consumeLocalVar(char[] varName) {
56
	public void consumeLocalVar(char[] varName, int occurrenceCount) {
57
		this.flags |= F_LOCAL_VAR;
57
		this.flags |= F_LOCAL_VAR;
58
	}
58
	}
59
59

Return to bug 149590