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

Collapse All | Expand All

(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java (-2 / +4 lines)
Lines 132-139 Link Here
132
		/* Initializer bodies are parsed in the context of the type declaration, we must thus search it inside */
132
		/* Initializer bodies are parsed in the context of the type declaration, we must thus search it inside */
133
		if (this.referenceContext instanceof TypeDeclaration){
133
		if (this.referenceContext instanceof TypeDeclaration){
134
			TypeDeclaration type = (TypeDeclaration) this.referenceContext;
134
			TypeDeclaration type = (TypeDeclaration) this.referenceContext;
135
			for (int i = 0; i < type.fields.length; i++){
135
			FieldDeclaration[] fields = type.fields;
136
				FieldDeclaration field = type.fields[i];
136
			int length = fields == null ? 0 : fields.length;
137
			for (int i = 0; i < length; i++){
138
				FieldDeclaration field = fields[i];
137
				if (field != null
139
				if (field != null
138
						&& field.getKind() == AbstractVariableDeclaration.INITIALIZER
140
						&& field.getKind() == AbstractVariableDeclaration.INITIALIZER
139
						&& field.declarationSourceStart <= this.scanner.initialPosition
141
						&& field.declarationSourceStart <= this.scanner.initialPosition
(-)compiler/org/eclipse/jdt/internal/compiler/ClassFile.java (-1 / +1 lines)
Lines 1998-2004 Link Here
1998
						// report an error and abort: will lead to a problem type classfile creation
1998
						// report an error and abort: will lead to a problem type classfile creation
1999
						TypeDeclaration typeDeclaration = this.referenceBinding.scope.referenceContext;
1999
						TypeDeclaration typeDeclaration = this.referenceBinding.scope.referenceContext;
2000
						FieldDeclaration[] fieldDecls = typeDeclaration.fields;
2000
						FieldDeclaration[] fieldDecls = typeDeclaration.fields;
2001
						for (int i = 0, max = fieldDecls.length; i < max; i++) {
2001
						for (int i = 0, max = (fieldDecls == null) ? 0 : fieldDecls.length; i < max; i++) {
2002
							if (fieldDecls[i].binding == fieldBinding) {
2002
							if (fieldDecls[i].binding == fieldBinding) {
2003
								// problem should abort
2003
								// problem should abort
2004
								typeDeclaration.scope.problemReporter().stringConstantIsExceedingUtf8Limit(
2004
								typeDeclaration.scope.problemReporter().stringConstantIsExceedingUtf8Limit(
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java (-12 / +24 lines)
Lines 166-173 Link Here
166
		FieldBinding existingField;
166
		FieldBinding existingField;
167
		if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
167
		if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
168
			TypeDeclaration typeDecl = this.scope.referenceContext;
168
			TypeDeclaration typeDecl = this.scope.referenceContext;
169
			for (int i = 0, max = typeDecl.fields.length; i < max; i++) {
169
			FieldDeclaration[] fieldDeclarations = typeDecl.fields;
170
				FieldDeclaration fieldDecl = typeDecl.fields[i];
170
			int max = fieldDeclarations == null ? 0 : fieldDeclarations.length;
171
			for (int i = 0; i < max; i++) {
172
				FieldDeclaration fieldDecl = fieldDeclarations[i];
171
				if (fieldDecl.binding == existingField) {
173
				if (fieldDecl.binding == existingField) {
172
					synthField.name = CharOperation.concat(
174
					synthField.name = CharOperation.concat(
173
						TypeConstants.SYNTHETIC_OUTER_LOCAL_PREFIX,
175
						TypeConstants.SYNTHETIC_OUTER_LOCAL_PREFIX,
Lines 210-217 Link Here
210
		FieldBinding existingField;
212
		FieldBinding existingField;
211
		if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
213
		if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
212
			TypeDeclaration typeDecl = this.scope.referenceContext;
214
			TypeDeclaration typeDecl = this.scope.referenceContext;
213
			for (int i = 0, max = typeDecl.fields.length; i < max; i++) {
215
			FieldDeclaration[] fieldDeclarations = typeDecl.fields;
214
				FieldDeclaration fieldDecl = typeDecl.fields[i];
216
			int max = fieldDeclarations == null ? 0 : fieldDeclarations.length;
217
			for (int i = 0; i < max; i++) {
218
				FieldDeclaration fieldDecl = fieldDeclarations[i];
215
				if (fieldDecl.binding == existingField) {
219
				if (fieldDecl.binding == existingField) {
216
					if (this.scope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_5) {
220
					if (this.scope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_5) {
217
						synthField.name = CharOperation.concat(
221
						synthField.name = CharOperation.concat(
Lines 255-262 Link Here
255
	FieldBinding existingField;
259
	FieldBinding existingField;
256
	if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
260
	if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
257
		TypeDeclaration typeDecl = blockScope.referenceType();
261
		TypeDeclaration typeDecl = blockScope.referenceType();
258
		for (int i = 0, max = typeDecl.fields.length; i < max; i++) {
262
		FieldDeclaration[] typeDeclarationFields = typeDecl.fields;
259
			FieldDeclaration fieldDecl = typeDecl.fields[i];
263
		int max = typeDeclarationFields == null ? 0 : typeDeclarationFields.length;
264
		for (int i = 0; i < max; i++) {
265
			FieldDeclaration fieldDecl = typeDeclarationFields[i];
260
			if (fieldDecl.binding == existingField) {
266
			if (fieldDecl.binding == existingField) {
261
				blockScope.problemReporter().duplicateFieldInType(this, fieldDecl);
267
				blockScope.problemReporter().duplicateFieldInType(this, fieldDecl);
262
				break;
268
				break;
Lines 294-300 Link Here
294
		FieldBinding existingField;
300
		FieldBinding existingField;
295
		if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
301
		if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
296
			TypeDeclaration typeDecl = this.scope.referenceContext;
302
			TypeDeclaration typeDecl = this.scope.referenceContext;
297
			for (int i = 0, max = typeDecl.fields.length; i < max; i++) {
303
			int max = (typeDecl.fields == null) ? 0 : typeDecl.fields.length;
304
			for (int i = 0; i < max; i++) {
298
				FieldDeclaration fieldDecl = typeDecl.fields[i];
305
				FieldDeclaration fieldDecl = typeDecl.fields[i];
299
				if (fieldDecl.binding == existingField) {
306
				if (fieldDecl.binding == existingField) {
300
					synthField.name = CharOperation.concat(
307
					synthField.name = CharOperation.concat(
Lines 337-344 Link Here
337
		FieldBinding existingField;
344
		FieldBinding existingField;
338
		if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
345
		if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
339
			TypeDeclaration typeDecl = this.scope.referenceContext;
346
			TypeDeclaration typeDecl = this.scope.referenceContext;
340
			for (int i = 0, max = typeDecl.fields.length; i < max; i++) {
347
			FieldDeclaration[] fieldDeclarations = typeDecl.fields;
341
				FieldDeclaration fieldDecl = typeDecl.fields[i];
348
			int max = fieldDeclarations == null ? 0 : fieldDeclarations.length;
349
			for (int i = 0; i < max; i++) {
350
				FieldDeclaration fieldDecl = fieldDeclarations[i];
342
				if (fieldDecl.binding == existingField) {
351
				if (fieldDecl.binding == existingField) {
343
					synthField.name = CharOperation.concat(
352
					synthField.name = CharOperation.concat(
344
						TypeConstants.SYNTHETIC_ENUM_VALUES,
353
						TypeConstants.SYNTHETIC_ENUM_VALUES,
Lines 425-432 Link Here
425
		FieldBinding existingField;
434
		FieldBinding existingField;
426
		if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
435
		if ((existingField = getField(synthField.name, true /*resolve*/)) != null) {
427
			TypeDeclaration typeDecl = this.scope.referenceContext;
436
			TypeDeclaration typeDecl = this.scope.referenceContext;
428
			for (int i = 0, max = typeDecl.fields.length; i < max; i++) {
437
			FieldDeclaration[] fieldDeclarations = typeDecl.fields;
429
				FieldDeclaration fieldDecl = typeDecl.fields[i];
438
			int max = fieldDeclarations == null ? 0 : fieldDeclarations.length;
439
			for (int i = 0; i < max; i++) {
440
				FieldDeclaration fieldDecl = fieldDeclarations[i];
430
				if (fieldDecl.binding == existingField) {
441
				if (fieldDecl.binding == existingField) {
431
					synthField.name = CharOperation.concat(
442
					synthField.name = CharOperation.concat(
432
						fieldName,
443
						fieldName,
Lines 1256-1262 Link Here
1256
	if (hasRestrictedAccess())
1267
	if (hasRestrictedAccess())
1257
		field.modifiers |= ExtraCompilerModifiers.AccRestrictedAccess;
1268
		field.modifiers |= ExtraCompilerModifiers.AccRestrictedAccess;
1258
	FieldDeclaration[] fieldDecls = this.scope.referenceContext.fields;
1269
	FieldDeclaration[] fieldDecls = this.scope.referenceContext.fields;
1259
	for (int f = 0, length = fieldDecls.length; f < length; f++) {
1270
	int length = fieldDecls == null ? 0 : fieldDecls.length;
1271
	for (int f = 0; f < length; f++) {
1260
		if (fieldDecls[f].binding != field)
1272
		if (fieldDecls[f].binding != field)
1261
			continue;
1273
			continue;
1262
1274
(-)compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java (-2 / +4 lines)
Lines 952-959 Link Here
952
			/* Initializer bodies are parsed in the context of the type declaration, we must thus search it inside */
952
			/* Initializer bodies are parsed in the context of the type declaration, we must thus search it inside */
953
			if (this.referenceContext instanceof TypeDeclaration){
953
			if (this.referenceContext instanceof TypeDeclaration){
954
				TypeDeclaration type = (TypeDeclaration) this.referenceContext;
954
				TypeDeclaration type = (TypeDeclaration) this.referenceContext;
955
				for (int i = 0; i < type.fields.length; i++){
955
				FieldDeclaration[] fieldDeclarations = type.fields;
956
					FieldDeclaration field = type.fields[i];
956
				int length = fieldDeclarations == null ? 0 : fieldDeclarations.length;
957
				for (int i = 0; i < length; i++){
958
					FieldDeclaration field = fieldDeclarations[i];
957
					if (field != null
959
					if (field != null
958
						&& field.getKind() == AbstractVariableDeclaration.INITIALIZER
960
						&& field.getKind() == AbstractVariableDeclaration.INITIALIZER
959
						&& ((Initializer) field).block != null
961
						&& ((Initializer) field).block != null
(-)model/org/eclipse/jdt/internal/core/util/HandleFactory.java (-1 / +2 lines)
Lines 204-210 Link Here
204
					// inside field or initializer, must find proper one
204
					// inside field or initializer, must find proper one
205
					TypeDeclaration type = methodScope.referenceType();
205
					TypeDeclaration type = methodScope.referenceType();
206
					int occurenceCount = 1;
206
					int occurenceCount = 1;
207
					for (int i = 0, length = type.fields.length; i < length; i++) {
207
					int length = type.fields == null ? 0 : type.fields.length;
208
					for (int i = 0; i < length; i++) {
208
						FieldDeclaration field = type.fields[i];
209
						FieldDeclaration field = type.fields[i];
209
						if (field.declarationSourceStart <= elementPosition && elementPosition <= field.declarationSourceEnd) {
210
						if (field.declarationSourceStart <= elementPosition && elementPosition <= field.declarationSourceEnd) {
210
							switch (field.getKind()) {
211
							switch (field.getKind()) {
(-)search/org/eclipse/jdt/internal/core/search/matching/FieldLocator.java (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 278-284 Link Here
278
			TypeDeclaration typeDecl = scope.referenceContext;
278
			TypeDeclaration typeDecl = scope.referenceContext;
279
			FieldDeclaration fieldDecl = null;
279
			FieldDeclaration fieldDecl = null;
280
			FieldDeclaration[] fieldDecls = typeDecl.fields;
280
			FieldDeclaration[] fieldDecls = typeDecl.fields;
281
			for (int i = 0, length = fieldDecls.length; i < length; i++) {
281
			int length = fieldDecls == null ? 0 : fieldDecls.length;
282
			for (int i = 0; i < length; i++) {
282
				if (CharOperation.equals(bindingName, fieldDecls[i].name)) {
283
				if (CharOperation.equals(bindingName, fieldDecls[i].name)) {
283
					fieldDecl = fieldDecls[i];
284
					fieldDecl = fieldDecls[i];
284
					break;
285
					break;
(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (-2 / +3 lines)
Lines 557-566 Link Here
557
		// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=98378
557
		// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=98378
558
		return type;
558
		return type;
559
	}
559
	}
560
	// find occurence count of the given initializer in its type declaration
560
	// find occurrence count of the given initializer in its type declaration
561
	int occurrenceCount = 0;
561
	int occurrenceCount = 0;
562
	FieldDeclaration[] fields = typeDeclaration.fields;
562
	FieldDeclaration[] fields = typeDeclaration.fields;
563
	for (int i = 0, length = fields.length; i < length; i++) {
563
	int length = fields == null ? 0 : fields.length;
564
	for (int i = 0; i < length; i++) {
564
		if (fields[i].getKind() == AbstractVariableDeclaration.INITIALIZER) {
565
		if (fields[i].getKind() == AbstractVariableDeclaration.INITIALIZER) {
565
			occurrenceCount++;
566
			occurrenceCount++;
566
			if (fields[i].equals(fieldDeclaration)) break;
567
			if (fields[i].equals(fieldDeclaration)) break;
(-)src/org/eclipse/jdt/core/tests/compiler/parser/AbstractCompletionTest.java (-6 / +8 lines)
Lines 141-149 Link Here
141
			parser.parseBlockStatements((AbstractMethodDeclaration)foundMethod, unit);
141
			parser.parseBlockStatements((AbstractMethodDeclaration)foundMethod, unit);
142
		} else {
142
		} else {
143
			TypeDeclaration type = (TypeDeclaration)foundMethod;
143
			TypeDeclaration type = (TypeDeclaration)foundMethod;
144
			if (type.fields != null) {
144
			FieldDeclaration[] fields = type.fields;
145
				done : for (int i = 0; i < type.fields.length; i++) {
145
			if (fields != null) {
146
					FieldDeclaration field = type.fields[i];
146
				done : for (int i = 0; i < fields.length; i++) {
147
					FieldDeclaration field = fields[i];
147
					if (field.declarationSourceStart <= cursorLocation && (cursorLocation <= field.declarationSourceEnd || field.declarationSourceEnd == 0)) {
148
					if (field.declarationSourceStart <= cursorLocation && (cursorLocation <= field.declarationSourceEnd || field.declarationSourceEnd == 0)) {
148
						if (field instanceof Initializer) {
149
						if (field instanceof Initializer) {
149
							parser.parseBlockStatements((Initializer)field, type, unit);
150
							parser.parseBlockStatements((Initializer)field, type, unit);
Lines 359-367 Link Here
359
			}
360
			}
360
		}
361
		}
361
	}
362
	}
362
	if (type.fields != null) {
363
	FieldDeclaration[] fields = type.fields;
363
		for (int i = 0; i < type.fields.length; i++) {
364
	if (fields != null) {
364
			FieldDeclaration field = type.fields[i];
365
		for (int i = 0; i < fields.length; i++) {
366
			FieldDeclaration field = fields[i];
365
			if (field instanceof Initializer && field.declarationSourceStart <= cursorLocation && (cursorLocation <= field.declarationSourceEnd || field.declarationSourceEnd == 0)) {
367
			if (field instanceof Initializer && field.declarationSourceStart <= cursorLocation && (cursorLocation <= field.declarationSourceEnd || field.declarationSourceEnd == 0)) {
366
				return type;
368
				return type;
367
			}
369
			}
(-)src/org/eclipse/jdt/core/tests/compiler/parser/AbstractSelectionTest.java (-6 / +8 lines)
Lines 161-169 Link Here
161
		parser.parseBlockStatements((AbstractMethodDeclaration)foundMethod, unit);
161
		parser.parseBlockStatements((AbstractMethodDeclaration)foundMethod, unit);
162
	} else {
162
	} else {
163
		TypeDeclaration type = (TypeDeclaration)foundMethod;
163
		TypeDeclaration type = (TypeDeclaration)foundMethod;
164
		if (type.fields != null) {
164
		FieldDeclaration[] fields = type.fields;
165
			for (int i = 0; i < type.fields.length; i++) {
165
		if (fields != null) {
166
				FieldDeclaration field = type.fields[i];
166
			for (int i = 0; i < fields.length; i++) {
167
				FieldDeclaration field = fields[i];
167
				if (field instanceof Initializer && field.sourceStart <= selectionStart && selectionStart <= field.sourceEnd) {
168
				if (field instanceof Initializer && field.sourceStart <= selectionStart && selectionStart <= field.sourceEnd) {
168
					parser.parseBlockStatements((Initializer)field, type, unit);
169
					parser.parseBlockStatements((Initializer)field, type, unit);
169
					break;
170
					break;
Lines 283-291 Link Here
283
			}
284
			}
284
		}
285
		}
285
	}
286
	}
286
	if (type.fields != null) {
287
	FieldDeclaration[] fields = type.fields;
287
		for (int i = 0; i < type.fields.length; i++) {
288
	if (fields != null) {
288
			FieldDeclaration field = type.fields[i];
289
		for (int i = 0; i < fields.length; i++) {
290
			FieldDeclaration field = fields[i];
289
			if (field instanceof Initializer) {
291
			if (field instanceof Initializer) {
290
				Initializer initializer = (Initializer)field;
292
				Initializer initializer = (Initializer)field;
291
				Block block = initializer.block;
293
				Block block = initializer.block;
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java (+15 lines)
Lines 337-342 Link Here
337
		this.resultCollector);
337
		this.resultCollector);
338
}
338
}
339
/**
339
/**
340
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=328554
341
 */
342
public void testDeclarationOfAccessedFields4() throws CoreException {
343
	IMethod method =
344
		getCompilationUnit("JavaSearch", "src", "b10", "A.java").
345
			getType("A").getMethod("foo", new String[] {});
346
	searchDeclarationsOfAccessedFields(
347
		method,
348
		this.resultCollector
349
	);
350
	assertSearchResults(
351
		"",
352
		this.resultCollector);
353
}
354
/**
340
 * Declaration of referenced types test.
355
 * Declaration of referenced types test.
341
 */
356
 */
342
public void testDeclarationOfReferencedTypes01() throws CoreException {
357
public void testDeclarationOfReferencedTypes01() throws CoreException {
(-)workspace/JavaSearch/src/b10/A.java (+7 lines)
Added Link Here
1
package b10;
2
3
public class A {
4
	int foo() {
5
		return this.i;
6
	}
7
}

Return to bug 328786