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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/core/compiler/IProblem.java (+3 lines)
Lines 117-122 Link Here
117
 *									MissingSynchronizedModifierInInheritedMethod
117
 *									MissingSynchronizedModifierInInheritedMethod
118
 *		Stephan Herrmann  - added the following constants
118
 *		Stephan Herrmann  - added the following constants
119
 *									UnusedObjectAllocation									
119
 *									UnusedObjectAllocation									
120
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
120
 *******************************************************************************/
121
 *******************************************************************************/
121
package org.eclipse.jdt.core.compiler;
122
package org.eclipse.jdt.core.compiler;
122
123
Lines 359-364 Link Here
359
	int DuplicateBlankFinalFieldInitialization = FieldRelated + 82;
360
	int DuplicateBlankFinalFieldInitialization = FieldRelated + 82;
360
	/** @since 3.6 */
361
	/** @since 3.6 */
361
	int UnresolvedVariable = FieldRelated + 83;
362
	int UnresolvedVariable = FieldRelated + 83;
363
	/** @since 3.7 */
364
	int UnusedScopedField = Internal + FieldRelated + 84;
362
365
363
	// variable hiding
366
	// variable hiding
364
	/** @since 3.0 */
367
	/** @since 3.0 */
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java (-5 / +12 lines)
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Matt McCutchen - partial fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=122995
10
 *     Matt McCutchen - partial fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=122995
11
 *     Karen Moore - fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=207411
11
 *     Karen Moore - fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=207411
12
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.jdt.internal.compiler.ast;
14
package org.eclipse.jdt.internal.compiler.ast;
14
15
Lines 357-367 Link Here
357
		return this;
358
		return this;
358
	}
359
	}
359
360
360
	public final boolean isFieldUseDeprecated(FieldBinding field, Scope scope, boolean isStrictlyAssigned) {
361
	public final boolean isFieldUseDeprecated(FieldBinding field, Scope scope, int filteredBits) {
361
		// ignore references insing Javadoc comments
362
		if ((this.bits & ASTNode.InsideJavadoc) == 0			// ignore references inside Javadoc comments 
362
		if ((this.bits & ASTNode.InsideJavadoc) == 0 && !isStrictlyAssigned && field.isOrEnclosedByPrivateType() && !scope.isDefinedInField(field)) {
363
				&& (filteredBits & IsStrictlyAssigned) == 0 	// ignore write access
363
			// ignore cases where field is used from inside itself
364
				&& field.isOrEnclosedByPrivateType() 
364
			field.original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
365
				&& !scope.isDefinedInField(field)) 				// ignore cases where field is used from inside itself 
366
		{		
367
			if (((filteredBits & IsCompoundAssigned) != 0))
368
				// used, but usage may not be relevant
369
				field.original().compoundUseFlag++;
370
			else
371
				field.original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
365
		}
372
		}
366
373
367
		if ((field.modifiers & ExtraCompilerModifiers.AccRestrictedAccess) != 0) {
374
		if ((field.modifiers & ExtraCompilerModifiers.AccRestrictedAccess) != 0) {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java (-1 / +6 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.ast;
12
package org.eclipse.jdt.internal.compiler.ast;
12
13
Lines 290-295 Link Here
290
291
291
public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
292
public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
292
	boolean isStatic;
293
	boolean isStatic;
294
	// check if compound assignment is the only usage of a private field
295
	reportOnlyUselesslyReadPrivateField(currentScope, this.binding, valueRequired);
293
	FieldBinding codegenBinding = this.binding.original();
296
	FieldBinding codegenBinding = this.binding.original();
294
	this.receiver.generateCode(currentScope, codeStream, !(isStatic = codegenBinding.isStatic()));
297
	this.receiver.generateCode(currentScope, codeStream, !(isStatic = codegenBinding.isStatic()));
295
	if (isStatic) {
298
	if (isStatic) {
Lines 337-342 Link Here
337
340
338
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) {
341
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) {
339
	boolean isStatic;
342
	boolean isStatic;
343
	// check if postIncrement is the only usage of a private field
344
	reportOnlyUselesslyReadPrivateField(currentScope, this.binding, valueRequired);
340
	FieldBinding codegenBinding = this.binding.original();
345
	FieldBinding codegenBinding = this.binding.original();
341
	this.receiver.generateCode(currentScope, codeStream, !(isStatic = codegenBinding.isStatic()));
346
	this.receiver.generateCode(currentScope, codeStream, !(isStatic = codegenBinding.isStatic()));
342
	if (isStatic) {
347
	if (isStatic) {
Lines 577-583 Link Here
577
	if (this.actualReceiverType != oldReceiverType && this.receiver.postConversionType(scope) != this.actualReceiverType) { // record need for explicit cast at codegen since receiver could not handle it
582
	if (this.actualReceiverType != oldReceiverType && this.receiver.postConversionType(scope) != this.actualReceiverType) { // record need for explicit cast at codegen since receiver could not handle it
578
		this.bits |= NeedReceiverGenericCast;
583
		this.bits |= NeedReceiverGenericCast;
579
	}
584
	}
580
	if (isFieldUseDeprecated(fieldBinding, scope, (this.bits & ASTNode.IsStrictlyAssigned) !=0)) {
585
	if (isFieldUseDeprecated(fieldBinding, scope, this.bits)) {
581
		scope.problemReporter().deprecatedField(fieldBinding, this);
586
		scope.problemReporter().deprecatedField(fieldBinding, this);
582
	}
587
	}
583
	boolean isImplicitThisRcv = this.receiver.isImplicitThis();
588
	boolean isImplicitThisRcv = this.receiver.isImplicitThis();
(-)compiler/org/eclipse/jdt/internal/compiler/ast/JavadocFieldReference.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 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.ast;
12
package org.eclipse.jdt.internal.compiler.ast;
12
13
Lines 97-103 Link Here
97
		}
98
		}
98
		this.binding = (FieldBinding) fieldBinding;
99
		this.binding = (FieldBinding) fieldBinding;
99
100
100
		if (isFieldUseDeprecated(this.binding, scope, (this.bits & IsStrictlyAssigned) != 0)) {
101
		if (isFieldUseDeprecated(this.binding, scope, this.bits)) {
101
			scope.problemReporter().javadocDeprecatedField(this.binding, this, scope.getDeclarationModifiers());
102
			scope.problemReporter().javadocDeprecatedField(this.binding, this, scope.getDeclarationModifiers());
102
		}
103
		}
103
		return this.resolvedType = this.binding.type;
104
		return this.resolvedType = this.binding.type;
(-)compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java (-2 / +7 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.ast;
12
package org.eclipse.jdt.internal.compiler.ast;
12
13
Lines 380-385 Link Here
380
381
381
public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
382
public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
382
	FieldBinding lastFieldBinding = generateReadSequence(currentScope, codeStream);
383
	FieldBinding lastFieldBinding = generateReadSequence(currentScope, codeStream);
384
	// check if compound assignment is the only usage of a private field
385
	reportOnlyUselesslyReadPrivateField(currentScope, lastFieldBinding, valueRequired);
383
	boolean isFirst = lastFieldBinding == this.binding
386
	boolean isFirst = lastFieldBinding == this.binding
384
		&& (this.indexOfFirstFieldBinding == 1 || lastFieldBinding.declaringClass == currentScope.enclosingReceiverType())
387
		&& (this.indexOfFirstFieldBinding == 1 || lastFieldBinding.declaringClass == currentScope.enclosingReceiverType())
385
		&& this.otherBindings == null; // could be dup: next.next.next
388
		&& this.otherBindings == null; // could be dup: next.next.next
Lines 431-436 Link Here
431
434
432
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) {
435
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) {
433
	FieldBinding lastFieldBinding = generateReadSequence(currentScope, codeStream);
436
	FieldBinding lastFieldBinding = generateReadSequence(currentScope, codeStream);
437
	// check if this post increment is the only usage of a private field
438
	reportOnlyUselesslyReadPrivateField(currentScope, lastFieldBinding, valueRequired);
434
	boolean isFirst = lastFieldBinding == this.binding
439
	boolean isFirst = lastFieldBinding == this.binding
435
		&& (this.indexOfFirstFieldBinding == 1 || lastFieldBinding.declaringClass == currentScope.enclosingReceiverType())
440
		&& (this.indexOfFirstFieldBinding == 1 || lastFieldBinding.declaringClass == currentScope.enclosingReceiverType())
436
		&& this.otherBindings == null; // could be dup: next.next.next
441
		&& this.otherBindings == null; // could be dup: next.next.next
Lines 719-725 Link Here
719
				}				
724
				}				
720
		    }
725
		    }
721
			// only last field is actually a write access if any
726
			// only last field is actually a write access if any
722
			if (isFieldUseDeprecated(field, scope, (this.bits & ASTNode.IsStrictlyAssigned) !=0 && index+1 == length)) {
727
			if (isFieldUseDeprecated(field, scope, index+1 == length ? this.bits : 0)) {
723
				scope.problemReporter().deprecatedField(field, this);
728
				scope.problemReporter().deprecatedField(field, this);
724
			}
729
			}
725
			// constant propagation can only be performed as long as the previous one is a constant too.
730
			// constant propagation can only be performed as long as the previous one is a constant too.
Lines 954-960 Link Here
954
							&& (!fieldBinding.isStatic() || methodScope.isStatic)) {
959
							&& (!fieldBinding.isStatic() || methodScope.isStatic)) {
955
						scope.problemReporter().forwardReference(this, this.indexOfFirstFieldBinding-1, fieldBinding);
960
						scope.problemReporter().forwardReference(this, this.indexOfFirstFieldBinding-1, fieldBinding);
956
					}
961
					}
957
					if (isFieldUseDeprecated(fieldBinding, scope, (this.bits & ASTNode.IsStrictlyAssigned) != 0 && this.indexOfFirstFieldBinding == this.tokens.length)) {
962
					if (isFieldUseDeprecated(fieldBinding, scope, this.indexOfFirstFieldBinding == this.tokens.length ? this.bits : 0)) {
958
						scope.problemReporter().deprecatedField(fieldBinding, this);	
963
						scope.problemReporter().deprecatedField(fieldBinding, this);	
959
					}
964
					}
960
					if (fieldBinding.isStatic()) {
965
					if (fieldBinding.isStatic()) {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/Reference.java (-1 / +73 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 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 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.ast;
12
package org.eclipse.jdt.internal.compiler.ast;
12
13
Lines 15-22 Link Here
15
import org.eclipse.jdt.internal.compiler.flow.FlowContext;
16
import org.eclipse.jdt.internal.compiler.flow.FlowContext;
16
import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
17
import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
17
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
18
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
19
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
18
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
20
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
21
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
19
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
22
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
23
import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
20
import org.eclipse.jdt.internal.compiler.lookup.Scope;
24
import org.eclipse.jdt.internal.compiler.lookup.Scope;
21
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
25
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
22
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
26
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
Lines 87-90 Link Here
87
public abstract void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired);
91
public abstract void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired);
88
92
89
public abstract void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired);
93
public abstract void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired);
94
95
/* report if a private field is only read from a 'special operator',
96
 * i.e., in a postIncrement expression or a compound assignment,
97
 * where the information is never flowing out off the field. */
98
void reportOnlyUselesslyReadPrivateField(BlockScope currentScope, FieldBinding fieldBinding, boolean valueRequired) {
99
	if (valueRequired) {
100
		// access is relevant, turn compound use into real use:
101
		fieldBinding.compoundUseFlag = 0;
102
		fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
103
	} else {
104
		if (fieldBinding.isUsedOnlyInCompound()) {
105
			fieldBinding.compoundUseFlag--; // consume one
106
			if (fieldBinding.compoundUseFlag == 0					// report only the last usage
107
					&& fieldBinding.isOrEnclosedByPrivateType() 
108
					&& (this.implicitConversion & TypeIds.UNBOXING) == 0) // don't report if unboxing is involved (might cause NPE)
109
			{
110
				// compoundAssignment/postIncrement is the only usage of this field
111
				currentScope.problemReporter().unusedPrivateField(fieldBinding.sourceField());
112
				fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; // don't report again
113
			}
114
		}
115
	}
116
}
117
/* report a local/arg that is only read from a 'special operator',
118
 * i.e., in a postIncrement expression or a compound assignment,
119
 * where the information is never flowing out off the local/arg. */
120
static void reportOnlyUselesslyReadLocal(BlockScope currentScope, LocalVariableBinding localBinding, boolean valueRequired) {
121
	if (localBinding.declaration == null)
122
		return;  // secret local
123
	if ((localBinding.declaration.bits & ASTNode.IsLocalDeclarationReachable) == 0)
124
		return;  // declaration is unreachable
125
	if (localBinding.useFlag >= LocalVariableBinding.USED)
126
		return;  // we're only interested in cases with only compound access (negative count)
127
128
	if (valueRequired) {
129
		// access is relevant
130
		localBinding.useFlag = LocalVariableBinding.USED;
131
		return;
132
	} else {
133
		localBinding.useFlag++;
134
		if (localBinding.useFlag != 0)
135
			return; // still waiting to see more usages of this kind
136
	}
137
	// at this point we know we have something to report
138
	if (localBinding.declaration instanceof Argument) {
139
		// check compiler options to report against unused arguments
140
		MethodScope methodScope = currentScope.methodScope();
141
		if (methodScope != null) {
142
			MethodBinding method = ((AbstractMethodDeclaration)methodScope.referenceContext()).binding;
143
			
144
			boolean shouldReport = !method.isMain();
145
			if (method.isImplementing()) {
146
				shouldReport &= currentScope.compilerOptions().reportUnusedParameterWhenImplementingAbstract;
147
			} else if (method.isOverriding()) {
148
				shouldReport &= currentScope.compilerOptions().reportUnusedParameterWhenOverridingConcrete;
149
			}
150
			
151
			if (shouldReport) {
152
				// report the case of an argument that is unread except through a special operator
153
				currentScope.problemReporter().unusedArgument(localBinding.declaration);
154
			}
155
		}
156
	} else {
157
		// report the case of a local variable that is unread except for a special operator
158
		currentScope.problemReporter().unusedLocalVariable(localBinding.declaration);
159
	}
160
	localBinding.useFlag = LocalVariableBinding.USED; // don't report again
161
}
90
}
162
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java (-7 / +33 lines)
Lines 7-13 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 292478 - Report potentially null across variable assignment
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 292478 - Report potentially null across variable assignment,
11
 *     											    Contribution for bug 185682 - Increment/decrement operators mark local variables as read
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jdt.internal.compiler.ast;
13
package org.eclipse.jdt.internal.compiler.ast;
13
14
Lines 78-87 Link Here
78
					currentScope.problemReporter().uninitializedLocalVariable(localBinding, this);
79
					currentScope.problemReporter().uninitializedLocalVariable(localBinding, this);
79
					// we could improve error msg here telling "cannot use compound assignment on final local variable"
80
					// we could improve error msg here telling "cannot use compound assignment on final local variable"
80
				}
81
				}
81
				if (isReachable) {
82
				if (localBinding.useFlag != LocalVariableBinding.USED) {
82
					localBinding.useFlag = LocalVariableBinding.USED;
83
					// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
83
				} else if (localBinding.useFlag == LocalVariableBinding.UNUSED) {
84
					// access from compound assignment does not prevent "unused" warning, unless unboxing is involved:
84
					localBinding.useFlag = LocalVariableBinding.FAKE_USED;
85
					if (isReachable && (this.implicitConversion & TypeIds.UNBOXING) != 0) {
86
						localBinding.useFlag = LocalVariableBinding.USED;
87
					} else {
88
						// use values < 0 to count the number of compound uses:
89
						if (localBinding.useFlag <= LocalVariableBinding.UNUSED)
90
							localBinding.useFlag--;
91
					}
85
				}
92
				}
86
		}
93
		}
87
	}
94
	}
Lines 204-210 Link Here
204
		}
211
		}
205
	}
212
	}
206
213
207
	if (isFieldUseDeprecated(fieldBinding, scope, (this.bits & ASTNode.IsStrictlyAssigned) !=0))
214
	if (isFieldUseDeprecated(fieldBinding, scope, this.bits))
208
		scope.problemReporter().deprecatedField(fieldBinding, this);
215
		scope.problemReporter().deprecatedField(fieldBinding, this);
209
216
210
	if ((this.bits & ASTNode.IsStrictlyAssigned) == 0
217
	if ((this.bits & ASTNode.IsStrictlyAssigned) == 0
Lines 462-467 Link Here
462
 * are optimized in one access: e.g "a = a + 1" optimized into "a++".
469
 * are optimized in one access: e.g "a = a + 1" optimized into "a++".
463
 */
470
 */
464
public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
471
public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
472
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
473
	switch (this.bits & ASTNode.RestrictiveFlagMASK) {
474
		case Binding.LOCAL:
475
			LocalVariableBinding localBinding = (LocalVariableBinding) this.binding;
476
			// check if compound assignment is the only usage of this local
477
			Reference.reportOnlyUselesslyReadLocal(currentScope, localBinding, valueRequired);
478
			break;
479
		case Binding.FIELD:
480
			// check if compound assignment is the only usage of a private field
481
			reportOnlyUselesslyReadPrivateField(currentScope, (FieldBinding)this.binding, valueRequired);
482
	}
465
	this.generateCompoundAssignment(
483
	this.generateCompoundAssignment(
466
		currentScope,
484
		currentScope,
467
		codeStream,
485
		codeStream,
Lines 599-605 Link Here
599
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) {
617
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) {
600
	switch (this.bits & ASTNode.RestrictiveFlagMASK) {
618
	switch (this.bits & ASTNode.RestrictiveFlagMASK) {
601
		case Binding.FIELD : // assigning to a field
619
		case Binding.FIELD : // assigning to a field
602
			FieldBinding codegenField = (((FieldBinding)this.binding).original());
620
			FieldBinding fieldBinding = (FieldBinding)this.binding;
621
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
622
			// check if postIncrement is the only usage of a private field
623
			reportOnlyUselesslyReadPrivateField(currentScope, fieldBinding, valueRequired);
624
			FieldBinding codegenField = fieldBinding.original();
603
			if (codegenField.isStatic()) {
625
			if (codegenField.isStatic()) {
604
				if ((this.syntheticAccessors == null) || (this.syntheticAccessors[SingleNameReference.READ] == null)) {
626
				if ((this.syntheticAccessors == null) || (this.syntheticAccessors[SingleNameReference.READ] == null)) {
605
					TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenField, this.actualReceiverType, true /* implicit this */);
627
					TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenField, this.actualReceiverType, true /* implicit this */);
Lines 662-667 Link Here
662
			return;
684
			return;
663
		case Binding.LOCAL : // assigning to a local variable
685
		case Binding.LOCAL : // assigning to a local variable
664
			LocalVariableBinding localBinding = (LocalVariableBinding) this.binding;
686
			LocalVariableBinding localBinding = (LocalVariableBinding) this.binding;
687
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
688
			// check if postIncrement is the only usage of this local
689
			Reference.reportOnlyUselesslyReadLocal(currentScope, localBinding, valueRequired);
690
665
			// using incr bytecode if possible
691
			// using incr bytecode if possible
666
			if (localBinding.type == TypeBinding.INT) {
692
			if (localBinding.type == TypeBinding.INT) {
667
				if (valueRequired) {
693
				if (valueRequired) {
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java (-2 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 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 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
12
package org.eclipse.jdt.internal.compiler.lookup;
12
13
Lines 19-24 Link Here
19
20
20
public class FieldBinding extends VariableBinding {
21
public class FieldBinding extends VariableBinding {
21
	public ReferenceBinding declaringClass;
22
	public ReferenceBinding declaringClass;
23
	public int compoundUseFlag = 0; // number or accesses via postIncrement or compoundAssignment
24
	
22
protected FieldBinding() {
25
protected FieldBinding() {
23
	super(null, null, 0, null);
26
	super(null, null, 0, null);
24
	// for creating problem field
27
	// for creating problem field
Lines 332-338 Link Here
332
*/
335
*/
333
336
334
public final boolean isUsed() {
337
public final boolean isUsed() {
335
	return (this.modifiers & ExtraCompilerModifiers.AccLocallyUsed) != 0;
338
	return (this.modifiers & ExtraCompilerModifiers.AccLocallyUsed) != 0 || this.compoundUseFlag > 0;
339
}
340
/* Answer true if the only use of this field is in compound assignment or post increment
341
 */
342
343
public final boolean isUsedOnlyInCompound() {
344
	return (this.modifiers & ExtraCompilerModifiers.AccLocallyUsed) == 0 && this.compoundUseFlag > 0;
336
}
345
}
337
/* Answer true if the receiver has protected visibility
346
/* Answer true if the receiver has protected visibility
338
*/
347
*/
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/LocalVariableBinding.java (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 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 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
12
package org.eclipse.jdt.internal.compiler.lookup;
12
13
Lines 26-32 Link Here
26
	public static final int UNUSED = 0;
27
	public static final int UNUSED = 0;
27
	public static final int USED = 1;
28
	public static final int USED = 1;
28
	public static final int FAKE_USED = 2;
29
	public static final int FAKE_USED = 2;
29
	public int useFlag; // for flow analysis (default is UNUSED)
30
	public int useFlag; // for flow analysis (default is UNUSED), values < 0 indicate the number of compound uses (postIncrement or compoundAssignment)
30
31
31
	public BlockScope declaringScope; // back-pointer to its declaring scope
32
	public BlockScope declaringScope; // back-pointer to its declaring scope
32
	public LocalDeclaration declaration; // for source-positions
33
	public LocalDeclaration declaration; // for source-positions
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (-2 / +7 lines)
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Benjamin Muskalla - Contribution for bug 239066
10
 *     Benjamin Muskalla - Contribution for bug 239066
11
 *     Stephan Herrmann  - Contribution for bug 236385
11
 *     Stephan Herrmann  - Contribution for bug 236385
12
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.jdt.internal.compiler.problem;
14
package org.eclipse.jdt.internal.compiler.problem;
14
15
Lines 194-199 Link Here
194
		case IProblem.UnusedPrivateConstructor:
195
		case IProblem.UnusedPrivateConstructor:
195
		case IProblem.UnusedPrivateMethod:
196
		case IProblem.UnusedPrivateMethod:
196
		case IProblem.UnusedPrivateField:
197
		case IProblem.UnusedPrivateField:
198
		case IProblem.UnusedScopedField:
197
		case IProblem.UnusedPrivateType:
199
		case IProblem.UnusedPrivateType:
198
			return CompilerOptions.UnusedPrivateMember;
200
			return CompilerOptions.UnusedPrivateMember;
199
201
Lines 7250-7256 Link Here
7250
}
7252
}
7251
public void unusedPrivateField(FieldDeclaration fieldDecl) {
7253
public void unusedPrivateField(FieldDeclaration fieldDecl) {
7252
7254
7253
	int severity = computeSeverity(IProblem.UnusedPrivateField);
7255
	int problemId = (fieldDecl.modifiers & ClassFileConstants.AccPrivate) != 0 
7256
						? IProblem.UnusedPrivateField
7257
						: IProblem.UnusedScopedField;
7258
	int severity = computeSeverity(problemId);
7254
	if (severity == ProblemSeverities.Ignore) return;
7259
	if (severity == ProblemSeverities.Ignore) return;
7255
7260
7256
	FieldBinding field = fieldDecl.binding;
7261
	FieldBinding field = fieldDecl.binding;
Lines 7269-7275 Link Here
7269
				return; // do not report unused serialPersistentFields field
7274
				return; // do not report unused serialPersistentFields field
7270
	}
7275
	}
7271
	this.handle(
7276
	this.handle(
7272
			IProblem.UnusedPrivateField,
7277
			problemId,
7273
		new String[] {
7278
		new String[] {
7274
			new String(field.declaringClass.readableName()),
7279
			new String(field.declaringClass.readableName()),
7275
			new String(field.name),
7280
			new String(field.name),
(-)compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties (-3 / +5 lines)
Lines 8-13 Link Here
8
# Contributors:
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
9
#     IBM Corporation - initial API and implementation
10
#		Benjamin Muskalla - Contribution for bug 239066
10
#		Benjamin Muskalla - Contribution for bug 239066
11
#		Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
11
###############################################################################
12
###############################################################################
12
0 = {0}
13
0 = {0}
13
1 = super cannot be used in java.lang.Object
14
1 = super cannot be used in java.lang.Object
Lines 49-56 Link Here
49
58 = The final local variable {0} cannot be assigned. It must be blank and not using a compound assignment
50
58 = The final local variable {0} cannot be assigned. It must be blank and not using a compound assignment
50
59 = The parameter {0} should not be assigned
51
59 = The parameter {0} should not be assigned
51
60 = The final local variable {0} cannot be assigned, since it is defined in an enclosing type
52
60 = The final local variable {0} cannot be assigned, since it is defined in an enclosing type
52
61 = The local variable {0} is never read
53
61 = The local variable {0} is never used
53
62 = The parameter {0} is never read
54
62 = The parameter {0} is never used
54
63 = The code of method {0}({1}) is exceeding the 65535 bytes limit
55
63 = The code of method {0}({1}) is exceeding the 65535 bytes limit
55
64 = The code for the static initializer is exceeding the 65535 bytes limit
56
64 = The code for the static initializer is exceeding the 65535 bytes limit
56
65 = Too many parameters, parameter {0} is exceeding the limit of 255 words eligible for method parameters
57
65 = Too many parameters, parameter {0} is exceeding the limit of 255 words eligible for method parameters
Lines 65-77 Link Here
65
74 = Cannot make a static reference to the non-static field {0}
66
74 = Cannot make a static reference to the non-static field {0}
66
75 = Cannot reference a field before it is defined
67
75 = Cannot reference a field before it is defined
67
76 = The static field {0}.{1} should be accessed in a static way
68
76 = The static field {0}.{1} should be accessed in a static way
68
77 = The field {0}.{1} is never read locally
69
77 = The private field {0}.{1} is never used
69
78 = The static field {0}.{1} should be accessed directly
70
78 = The static field {0}.{1} should be accessed directly
70
79 = Unqualified access to the field {0}.{1} 
71
79 = Unqualified access to the field {0}.{1} 
71
80 = The final field {0}.{1} cannot be assigned
72
80 = The final field {0}.{1} cannot be assigned
72
81 = The blank final field {0} may not have been initialized
73
81 = The blank final field {0} may not have been initialized
73
82 = The final field {0} may already have been assigned
74
82 = The final field {0} may already have been assigned
74
83 = {0} cannot be resolved to a variable
75
83 = {0} cannot be resolved to a variable
76
84 = The field {0}.{1} is never used locally
75
77
76
90 = The local variable {0} is hiding another local variable defined in an enclosing type scope
78
90 = The local variable {0} is hiding another local variable defined in an enclosing type scope
77
91 = The local variable {0} is hiding a field from type {1}
79
91 = The local variable {0} is hiding a field from type {1}
(-)eval/org/eclipse/jdt/internal/eval/CodeSnippetFieldReference.java (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 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 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.eval;
12
package org.eclipse.jdt.internal.eval;
12
13
Lines 325-331 Link Here
325
		return null;
326
		return null;
326
	}
327
	}
327
328
328
	if (isFieldUseDeprecated(this.binding, scope, (this.bits & IsStrictlyAssigned) !=0)) {
329
	if (isFieldUseDeprecated(this.binding, scope, this.bits)) {
329
		scope.problemReporter().deprecatedField(this.binding, this);
330
		scope.problemReporter().deprecatedField(this.binding, this);
330
	}
331
	}
331
	// check for this.x in static is done in the resolution of the receiver
332
	// check for this.x in static is done in the resolution of the receiver
(-)eval/org/eclipse/jdt/internal/eval/CodeSnippetQualifiedNameReference.java (-3 / +4 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 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.eval;
12
package org.eclipse.jdt.internal.eval;
12
13
Lines 463-469 Link Here
463
			}
464
			}
464
		}
465
		}
465
		// only last field is actually a write access if any
466
		// only last field is actually a write access if any
466
		if (isFieldUseDeprecated((FieldBinding) this.binding, scope, (this.bits & IsStrictlyAssigned) !=0 && this.indexOfFirstFieldBinding == length)) {
467
		if (isFieldUseDeprecated((FieldBinding) this.binding, scope, this.indexOfFirstFieldBinding == length ? this.bits : 0)) {
467
			scope.problemReporter().deprecatedField((FieldBinding) this.binding, this);
468
			scope.problemReporter().deprecatedField((FieldBinding) this.binding, this);
468
		}
469
		}
469
	}
470
	}
Lines 510-516 Link Here
510
		}
511
		}
511
		if (field.isValidBinding()) {
512
		if (field.isValidBinding()) {
512
			// only last field is actually a write access if any
513
			// only last field is actually a write access if any
513
			if (isFieldUseDeprecated(field, scope, (this.bits & IsStrictlyAssigned) !=0 && index+1 == length)) {
514
			if (isFieldUseDeprecated(field, scope, index+1 == length ? this.bits : 0)) {
514
				scope.problemReporter().deprecatedField(field, this);
515
				scope.problemReporter().deprecatedField(field, this);
515
			}
516
			}
516
			// constant propagation can only be performed as long as the previous one is a constant too.
517
			// constant propagation can only be performed as long as the previous one is a constant too.
(-)eval/org/eclipse/jdt/internal/eval/CodeSnippetSingleNameReference.java (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 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 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.eval;
12
package org.eclipse.jdt.internal.eval;
12
13
Lines 101-107 Link Here
101
	}
102
	}
102
	this.constant = fieldBinding.constant();
103
	this.constant = fieldBinding.constant();
103
104
104
	if (isFieldUseDeprecated(fieldBinding, scope, (this.bits & IsStrictlyAssigned) !=0)) {
105
	if (isFieldUseDeprecated(fieldBinding, scope, this.bits)) {
105
		scope.problemReporter().deprecatedField(fieldBinding, this);
106
		scope.problemReporter().deprecatedField(fieldBinding, this);
106
	}
107
	}
107
	return fieldBinding.type;
108
	return fieldBinding.type;
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java (-1 / +2 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann  - Contribution for bug 295551
10
 *     Stephan Herrmann  - Contribution for bug 295551
11
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jdt.core.tests.compiler.regression;
13
package org.eclipse.jdt.core.tests.compiler.regression;
13
14
Lines 9355-9361 Link Here
9355
			"1. ERROR in A.java (at line 3)\n" + 
9356
			"1. ERROR in A.java (at line 3)\n" + 
9356
			"	private int i;\n" + 
9357
			"	private int i;\n" + 
9357
			"	            ^\n" + 
9358
			"	            ^\n" + 
9358
			"The field A.i is never read locally\n" + 
9359
			"The private field A.i is never used\n" + 
9359
			"----------\n";
9360
			"----------\n";
9360
	runNegativeTest(
9361
	runNegativeTest(
9361
			true,
9362
			true,
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java (-4 / +5 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
package org.eclipse.jdt.core.tests.compiler.regression;
12
13
Lines 223-234 Link Here
223
		"1. WARNING in X.java (at line 4)\n" +
224
		"1. WARNING in X.java (at line 4)\n" +
224
		"	private final Object o;\n" +
225
		"	private final Object o;\n" +
225
		"	                     ^\n" +
226
		"	                     ^\n" +
226
		"The field X.Test1.o is never read locally\n" +
227
		"The private field X.Test1.o is never used\n" +
227
		"----------\n" +
228
		"----------\n" +
228
		"2. WARNING in X.java (at line 13)\n" +
229
		"2. WARNING in X.java (at line 13)\n" +
229
		"	private final Object o;\n" +
230
		"	private final Object o;\n" +
230
		"	                     ^\n" +
231
		"	                     ^\n" +
231
		"The field X.Test2.o is never read locally\n" +
232
		"The private field X.Test2.o is never used\n" +
232
		"----------\n" +
233
		"----------\n" +
233
		"3. ERROR in X.java (at line 25)\n" +
234
		"3. ERROR in X.java (at line 25)\n" +
234
		"	System.out.println(o); // illegal; o is not definitely assigned\n" +
235
		"	System.out.println(o); // illegal; o is not definitely assigned\n" +
Lines 238-244 Link Here
238
		"4. WARNING in X.java (at line 42)\n" +
239
		"4. WARNING in X.java (at line 42)\n" +
239
		"	private final Object o;\n" +
240
		"	private final Object o;\n" +
240
		"	                     ^\n" +
241
		"	                     ^\n" +
241
		"The field X.Test5.o is never read locally\n" +
242
		"The private field X.Test5.o is never used\n" +
242
		"----------\n" +
243
		"----------\n" +
243
		"5. ERROR in X.java (at line 44)\n" +
244
		"5. ERROR in X.java (at line 44)\n" +
244
		"	Test5() {\n" +
245
		"	Test5() {\n" +
Lines 253-259 Link Here
253
		"7. WARNING in X.java (at line 52)\n" +
254
		"7. WARNING in X.java (at line 52)\n" +
254
		"	private final Object o;\n" +
255
		"	private final Object o;\n" +
255
		"	                     ^\n" +
256
		"	                     ^\n" +
256
		"The field X.Test6.o is never read locally\n" +
257
		"The private field X.Test6.o is never used\n" +
257
		"----------\n" +
258
		"----------\n" +
258
		"8. ERROR in X.java (at line 59)\n" +
259
		"8. ERROR in X.java (at line 59)\n" +
259
		"	other.o = new Object(); // illegal!  other.o is not assignable\n" +
260
		"	other.o = new Object(); // illegal!  other.o is not assignable\n" +
(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (-35 / +36 lines)
Lines 10-15 Link Here
10
 *     Benjamin Muskalla - Contribution for bug 239066
10
 *     Benjamin Muskalla - Contribution for bug 239066
11
 *     Stephan Herrmann  - Contribution for bug 236385
11
 *     Stephan Herrmann  - Contribution for bug 236385
12
 *     Stephan Herrmann  - Contribution for bug 295551
12
 *     Stephan Herrmann  - Contribution for bug 295551
13
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.jdt.core.tests.compiler.regression;
15
package org.eclipse.jdt.core.tests.compiler.regression;
15
16
Lines 2879-2885 Link Here
2879
	        "7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/Z.java (at line 58)\n" +
2880
	        "7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/Z.java (at line 58)\n" +
2880
	        "	final XX<?, XY> l1 = (XX<?, XY>) i.getKey();\n" +
2881
	        "	final XX<?, XY> l1 = (XX<?, XY>) i.getKey();\n" +
2881
	        "	                ^^\n" +
2882
	        "	                ^^\n" +
2882
	        "The local variable l1 is never read\n" +
2883
	        "The local variable l1 is never used\n" +
2883
	        "----------\n" +
2884
	        "----------\n" +
2884
	        "8. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/Z.java (at line 58)\n" +
2885
	        "8. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/Z.java (at line 58)\n" +
2885
	        "	final XX<?, XY> l1 = (XX<?, XY>) i.getKey();\n" +
2886
	        "	final XX<?, XY> l1 = (XX<?, XY>) i.getKey();\n" +
Lines 3059-3065 Link Here
3059
        "7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/Z.java (at line 58)\n" +
3060
        "7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/Z.java (at line 58)\n" +
3060
        "	final XX<?, XY> l1 = (XX<?, XY>) i.getKey();\n" +
3061
        "	final XX<?, XY> l1 = (XX<?, XY>) i.getKey();\n" +
3061
        "	                ^^\n" +
3062
        "	                ^^\n" +
3062
        "The local variable l1 is never read\n" +
3063
        "The local variable l1 is never used\n" +
3063
        "----------\n" +
3064
        "----------\n" +
3064
        "8. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/Z.java (at line 58)\n" +
3065
        "8. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/Z.java (at line 58)\n" +
3065
        "	final XX<?, XY> l1 = (XX<?, XY>) i.getKey();\n" +
3066
        "	final XX<?, XY> l1 = (XX<?, XY>) i.getKey();\n" +
Lines 6228-6234 Link Here
6228
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
6229
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
6229
		"	String u;\n" +
6230
		"	String u;\n" +
6230
		"	       ^\n" +
6231
		"	       ^\n" +
6231
		"The local variable u is never read\n" +
6232
		"The local variable u is never used\n" +
6232
		"----------\n" +
6233
		"----------\n" +
6233
		"2 problems (2 warnings)",
6234
		"2 problems (2 warnings)",
6234
		true);
6235
		true);
Lines 6315-6321 Link Here
6315
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
6316
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
6316
		"	String u;\n" +
6317
		"	String u;\n" +
6317
		"	       ^\n" +
6318
		"	       ^\n" +
6318
		"The local variable u is never read\n" +
6319
		"The local variable u is never used\n" +
6319
		"----------\n" +
6320
		"----------\n" +
6320
		"1 problem (1 warning)",
6321
		"1 problem (1 warning)",
6321
		true);
6322
		true);
Lines 6347-6353 Link Here
6347
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
6348
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
6348
		"	String u;\n" +
6349
		"	String u;\n" +
6349
		"	       ^\n" +
6350
		"	       ^\n" +
6350
		"The local variable u is never read\n" +
6351
		"The local variable u is never used\n" +
6351
		"----------\n" +
6352
		"----------\n" +
6352
		"2 problems (2 warnings)",
6353
		"2 problems (2 warnings)",
6353
		true);
6354
		true);
Lines 6374-6380 Link Here
6374
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
6375
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
6375
		"	String u;\n" +
6376
		"	String u;\n" +
6376
		"	       ^\n" +
6377
		"	       ^\n" +
6377
		"The local variable u is never read\n" +
6378
		"The local variable u is never used\n" +
6378
		"----------\n" +
6379
		"----------\n" +
6379
		"1 problem (1 warning)",
6380
		"1 problem (1 warning)",
6380
		true);
6381
		true);
Lines 6400-6406 Link Here
6400
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
6401
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
6401
		"	String u;\n" +
6402
		"	String u;\n" +
6402
		"	       ^\n" +
6403
		"	       ^\n" +
6403
		"The local variable u is never read\n" +
6404
		"The local variable u is never used\n" +
6404
		"----------\n" +
6405
		"----------\n" +
6405
		"1 problem (1 warning)",
6406
		"1 problem (1 warning)",
6406
		true);
6407
		true);
Lines 6431-6437 Link Here
6431
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
6432
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
6432
		"	String u;\n" +
6433
		"	String u;\n" +
6433
		"	       ^\n" +
6434
		"	       ^\n" +
6434
		"The local variable u is never read\n" +
6435
		"The local variable u is never used\n" +
6435
		"----------\n" +
6436
		"----------\n" +
6436
		"2 problems (2 warnings)",
6437
		"2 problems (2 warnings)",
6437
		true);
6438
		true);
Lines 6463-6469 Link Here
6463
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
6464
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
6464
		"	String u;\n" +
6465
		"	String u;\n" +
6465
		"	       ^\n" +
6466
		"	       ^\n" +
6466
		"The local variable u is never read\n" +
6467
		"The local variable u is never used\n" +
6467
		"----------\n" +
6468
		"----------\n" +
6468
		"2 problems (2 warnings)",
6469
		"2 problems (2 warnings)",
6469
		true);
6470
		true);
Lines 7564-7570 Link Here
7564
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
7565
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
7565
		"	int j;\n" +
7566
		"	int j;\n" +
7566
		"	    ^\n" +
7567
		"	    ^\n" +
7567
		"The local variable j is never read\n" +
7568
		"The local variable j is never used\n" +
7568
		"----------\n" +
7569
		"----------\n" +
7569
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
7570
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
7570
		"	this.<String>bar();\n" +
7571
		"	this.<String>bar();\n" +
Lines 7627-7633 Link Here
7627
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
7628
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
7628
		"	private void foo(int i) throws java.io.IOException {\n" +
7629
		"	private void foo(int i) throws java.io.IOException {\n" +
7629
		"	                     ^\n" +
7630
		"	                     ^\n" +
7630
		"The parameter i is never read\n" +
7631
		"The parameter i is never used\n" +
7631
		"----------\n" +
7632
		"----------\n" +
7632
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
7633
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
7633
		"	private void foo(int i) throws java.io.IOException {\n" +
7634
		"	private void foo(int i) throws java.io.IOException {\n" +
Lines 7637-7643 Link Here
7637
		"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
7638
		"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
7638
		"	int j;\n" +
7639
		"	int j;\n" +
7639
		"	    ^\n" +
7640
		"	    ^\n" +
7640
		"The local variable j is never read\n" +
7641
		"The local variable j is never used\n" +
7641
		"----------\n" +
7642
		"----------\n" +
7642
		"6. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
7643
		"6. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
7643
		"	this.<String>bar();\n" +
7644
		"	this.<String>bar();\n" +
Lines 7682-7688 Link Here
7682
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
7683
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
7683
		"	private void foo(int i) throws java.io.IOException {\n" +
7684
		"	private void foo(int i) throws java.io.IOException {\n" +
7684
		"	                     ^\n" +
7685
		"	                     ^\n" +
7685
		"The parameter i is never read\n" +
7686
		"The parameter i is never used\n" +
7686
		"----------\n" +
7687
		"----------\n" +
7687
		"1 problem (1 warning)",
7688
		"1 problem (1 warning)",
7688
		true);
7689
		true);
Lines 7787-7793 Link Here
7787
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
7788
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
7788
		"	int j;\n" +
7789
		"	int j;\n" +
7789
		"	    ^\n" +
7790
		"	    ^\n" +
7790
		"The local variable j is never read\n" +
7791
		"The local variable j is never used\n" +
7791
		"----------\n" +
7792
		"----------\n" +
7792
		"1 problem (1 warning)",
7793
		"1 problem (1 warning)",
7793
		true);
7794
		true);
Lines 7942-7948 Link Here
7942
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
7943
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
7943
		"	int j;\n" +
7944
		"	int j;\n" +
7944
		"	    ^\n" +
7945
		"	    ^\n" +
7945
		"The local variable j is never read\n" +
7946
		"The local variable j is never used\n" +
7946
		"----------\n" +
7947
		"----------\n" +
7947
		"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
7948
		"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
7948
		"	this.<String>bar();\n" +
7949
		"	this.<String>bar();\n" +
Lines 7992-7998 Link Here
7992
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
7993
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
7993
		"	private void foo(int i) throws java.io.IOException {\n" +
7994
		"	private void foo(int i) throws java.io.IOException {\n" +
7994
		"	                     ^\n" +
7995
		"	                     ^\n" +
7995
		"The parameter i is never read\n" +
7996
		"The parameter i is never used\n" +
7996
		"----------\n" +
7997
		"----------\n" +
7997
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
7998
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
7998
		"	private void foo(int i) throws java.io.IOException {\n" +
7999
		"	private void foo(int i) throws java.io.IOException {\n" +
Lines 8002-8008 Link Here
8002
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
8003
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
8003
		"	int j;\n" +
8004
		"	int j;\n" +
8004
		"	    ^\n" +
8005
		"	    ^\n" +
8005
		"The local variable j is never read\n" +
8006
		"The local variable j is never used\n" +
8006
		"----------\n" +
8007
		"----------\n" +
8007
		"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
8008
		"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
8008
		"	this.<String>bar();\n" +
8009
		"	this.<String>bar();\n" +
Lines 8057-8063 Link Here
8057
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8058
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8058
		"	private void foo(int i) throws java.io.IOException {\n" +
8059
		"	private void foo(int i) throws java.io.IOException {\n" +
8059
		"	                     ^\n" +
8060
		"	                     ^\n" +
8060
		"The parameter i is never read\n" +
8061
		"The parameter i is never used\n" +
8061
		"----------\n" +
8062
		"----------\n" +
8062
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8063
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8063
		"	private void foo(int i) throws java.io.IOException {\n" +
8064
		"	private void foo(int i) throws java.io.IOException {\n" +
Lines 8067-8073 Link Here
8067
		"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
8068
		"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
8068
		"	int j;\n" +
8069
		"	int j;\n" +
8069
		"	    ^\n" +
8070
		"	    ^\n" +
8070
		"The local variable j is never read\n" +
8071
		"The local variable j is never used\n" +
8071
		"----------\n" +
8072
		"----------\n" +
8072
		"6. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
8073
		"6. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
8073
		"	this.<String>bar();\n" +
8074
		"	this.<String>bar();\n" +
Lines 8117-8123 Link Here
8117
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8118
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8118
		"	private void foo(int i) throws java.io.IOException {\n" +
8119
		"	private void foo(int i) throws java.io.IOException {\n" +
8119
		"	                     ^\n" +
8120
		"	                     ^\n" +
8120
		"The parameter i is never read\n" +
8121
		"The parameter i is never used\n" +
8121
		"----------\n" +
8122
		"----------\n" +
8122
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8123
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8123
		"	private void foo(int i) throws java.io.IOException {\n" +
8124
		"	private void foo(int i) throws java.io.IOException {\n" +
Lines 8172-8178 Link Here
8172
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8173
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8173
		"	private void foo(int i) throws java.io.IOException {\n" +
8174
		"	private void foo(int i) throws java.io.IOException {\n" +
8174
		"	                     ^\n" +
8175
		"	                     ^\n" +
8175
		"The parameter i is never read\n" +
8176
		"The parameter i is never used\n" +
8176
		"----------\n" +
8177
		"----------\n" +
8177
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8178
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8178
		"	private void foo(int i) throws java.io.IOException {\n" +
8179
		"	private void foo(int i) throws java.io.IOException {\n" +
Lines 8182-8188 Link Here
8182
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
8183
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
8183
		"	int j;\n" +
8184
		"	int j;\n" +
8184
		"	    ^\n" +
8185
		"	    ^\n" +
8185
		"The local variable j is never read\n" +
8186
		"The local variable j is never used\n" +
8186
		"----------\n" +
8187
		"----------\n" +
8187
		"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
8188
		"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
8188
		"	this.<String>bar();\n" +
8189
		"	this.<String>bar();\n" +
Lines 8237-8248 Link Here
8237
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8238
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8238
		"	private void foo(int i) throws java.io.IOException {\n" +
8239
		"	private void foo(int i) throws java.io.IOException {\n" +
8239
		"	                     ^\n" +
8240
		"	                     ^\n" +
8240
		"The parameter i is never read\n" +
8241
		"The parameter i is never used\n" +
8241
		"----------\n" +
8242
		"----------\n" +
8242
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
8243
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
8243
		"	int j;\n" +
8244
		"	int j;\n" +
8244
		"	    ^\n" +
8245
		"	    ^\n" +
8245
		"The local variable j is never read\n" +
8246
		"The local variable j is never used\n" +
8246
		"----------\n" +
8247
		"----------\n" +
8247
		"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
8248
		"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
8248
		"	this.<String>bar();\n" +
8249
		"	this.<String>bar();\n" +
Lines 8297-8303 Link Here
8297
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8298
		"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8298
		"	private void foo(int i) throws java.io.IOException {\n" +
8299
		"	private void foo(int i) throws java.io.IOException {\n" +
8299
		"	                     ^\n" +
8300
		"	                     ^\n" +
8300
		"The parameter i is never read\n" +
8301
		"The parameter i is never used\n" +
8301
		"----------\n" +
8302
		"----------\n" +
8302
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8303
		"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
8303
		"	private void foo(int i) throws java.io.IOException {\n" +
8304
		"	private void foo(int i) throws java.io.IOException {\n" +
Lines 8307-8313 Link Here
8307
		"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
8308
		"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" +
8308
		"	int j;\n" +
8309
		"	int j;\n" +
8309
		"	    ^\n" +
8310
		"	    ^\n" +
8310
		"The local variable j is never read\n" +
8311
		"The local variable j is never used\n" +
8311
		"----------\n" +
8312
		"----------\n" +
8312
		"6. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 6)\n" +
8313
		"6. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 6)\n" +
8313
		"	next: for (;;) {\n" +
8314
		"	next: for (;;) {\n" +
Lines 8380-8386 Link Here
8380
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
8381
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
8381
		"	public void foo(int i) {\n" +
8382
		"	public void foo(int i) {\n" +
8382
		"	                    ^\n" +
8383
		"	                    ^\n" +
8383
		"The parameter i is never read\n" +
8384
		"The parameter i is never used\n" +
8384
		"----------\n" +
8385
		"----------\n" +
8385
		"1 problem (1 warning)",
8386
		"1 problem (1 warning)",
8386
		true);
8387
		true);
Lines 8471-8477 Link Here
8471
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
8472
		"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
8472
		"	public void foo(int i) {\n" +
8473
		"	public void foo(int i) {\n" +
8473
		"	                    ^\n" +
8474
		"	                    ^\n" +
8474
		"The parameter i is never read\n" +
8475
		"The parameter i is never used\n" +
8475
		"----------\n" +
8476
		"----------\n" +
8476
		"2 problems (2 warnings)",
8477
		"2 problems (2 warnings)",
8477
		true);
8478
		true);
Lines 8497-8503 Link Here
8497
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
8498
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
8498
		"	public void foo(int i) {\n" +
8499
		"	public void foo(int i) {\n" +
8499
		"	                    ^\n" +
8500
		"	                    ^\n" +
8500
		"The parameter i is never read\n" +
8501
		"The parameter i is never used\n" +
8501
		"----------\n" +
8502
		"----------\n" +
8502
		"1 problem (1 warning)",
8503
		"1 problem (1 warning)",
8503
		true);
8504
		true);
Lines 8979-8985 Link Here
8979
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
8980
		"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" +
8980
		"	public void foo(int i) {\n" +
8981
		"	public void foo(int i) {\n" +
8981
		"	                    ^\n" +
8982
		"	                    ^\n" +
8982
		"The parameter i is never read\n" +
8983
		"The parameter i is never used\n" +
8983
		"----------\n" +
8984
		"----------\n" +
8984
		"1 problem (1 warning)",
8985
		"1 problem (1 warning)",
8985
		true);
8986
		true);
Lines 11334-11340 Link Here
11334
		"2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + 
11335
		"2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + 
11335
		"	private int i;\n" + 
11336
		"	private int i;\n" + 
11336
		"	            ^\n" + 
11337
		"	            ^\n" + 
11337
		"The field X.i is never read locally\n" + 
11338
		"The private field X.i is never used\n" + 
11338
		"----------\n" + 
11339
		"----------\n" + 
11339
		"2 problems (1 error, 1 warning)",
11340
		"2 problems (1 error, 1 warning)",
11340
		true);
11341
		true);
Lines 11374-11380 Link Here
11374
		"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + 
11375
		"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + 
11375
		"	private int i;\n" + 
11376
		"	private int i;\n" + 
11376
		"	            ^\n" + 
11377
		"	            ^\n" + 
11377
		"The field X.i is never read locally\n" + 
11378
		"The private field X.i is never used\n" + 
11378
		"----------\n" + 
11379
		"----------\n" + 
11379
		"1 problem (1 error)",
11380
		"1 problem (1 error)",
11380
		true);
11381
		true);
Lines 11397-11403 Link Here
11397
		"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + 
11398
		"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + 
11398
		"	private int i;\n" + 
11399
		"	private int i;\n" + 
11399
		"	            ^\n" + 
11400
		"	            ^\n" + 
11400
		"The field X.i is never read locally\n" + 
11401
		"The private field X.i is never used\n" + 
11401
		"----------\n" + 
11402
		"----------\n" + 
11402
		"1 problem (1 error)",
11403
		"1 problem (1 error)",
11403
		true);
11404
		true);
Lines 11425-11431 Link Here
11425
		"2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + 
11426
		"2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + 
11426
		"	private int i;\n" + 
11427
		"	private int i;\n" + 
11427
		"	            ^\n" + 
11428
		"	            ^\n" + 
11428
		"The field X.i is never read locally\n" + 
11429
		"The private field X.i is never used\n" + 
11429
		"----------\n" + 
11430
		"----------\n" + 
11430
		"2 problems (1 error, 1 warning)",
11431
		"2 problems (1 error, 1 warning)",
11431
		true);
11432
		true);
Lines 11448-11454 Link Here
11448
		"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + 
11449
		"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + 
11449
		"	private int i;\n" + 
11450
		"	private int i;\n" + 
11450
		"	            ^\n" + 
11451
		"	            ^\n" + 
11451
		"The field X.i is never read locally\n" + 
11452
		"The private field X.i is never used\n" + 
11452
		"----------\n" + 
11453
		"----------\n" + 
11453
		"1 problem (1 error)",
11454
		"1 problem (1 error)",
11454
		true);
11455
		true);
(-)src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java (+3 lines)
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Benjamin Muskalla - Contribution for bug 239066
10
 *     Benjamin Muskalla - Contribution for bug 239066
11
 *     Stephan Herrmann  - Contribution for bug 236385
11
 *     Stephan Herrmann  - Contribution for bug 236385
12
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.jdt.core.tests.compiler.regression;
14
package org.eclipse.jdt.core.tests.compiler.regression;
14
15
Lines 848-853 Link Here
848
		expectedProblemAttributes.put("UnusedObjectAllocation", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
849
		expectedProblemAttributes.put("UnusedObjectAllocation", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
849
		expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
850
		expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
850
		expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
851
		expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
852
		expectedProblemAttributes.put("UnusedScopedField", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
851
		expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
853
		expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
852
		expectedProblemAttributes.put("UnusedPrivateType", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
854
		expectedProblemAttributes.put("UnusedPrivateType", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
853
		expectedProblemAttributes.put("UnusedTypeArgumentsForConstructorInvocation", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
855
		expectedProblemAttributes.put("UnusedTypeArgumentsForConstructorInvocation", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
Lines 1482-1487 Link Here
1482
		expectedProblemAttributes.put("UnusedObjectAllocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_OBJECT_ALLOCATION));
1484
		expectedProblemAttributes.put("UnusedObjectAllocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_OBJECT_ALLOCATION));
1483
		expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1485
		expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1484
		expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1486
		expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1487
		expectedProblemAttributes.put("UnusedScopedField", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1485
		expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1488
		expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1486
		expectedProblemAttributes.put("UnusedPrivateType", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1489
		expectedProblemAttributes.put("UnusedPrivateType", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER));
1487
		expectedProblemAttributes.put("UnusedTypeArgumentsForConstructorInvocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_TYPE_ARGUMENTS_FOR_METHOD_INVOCATION));
1490
		expectedProblemAttributes.put("UnusedTypeArgumentsForConstructorInvocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_TYPE_ARGUMENTS_FOR_METHOD_INVOCATION));
(-)src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java (-2 / +2 lines)
Lines 1713-1719 Link Here
1713
		"1. WARNING in p\\A.java (at line 6)\n" +
1713
		"1. WARNING in p\\A.java (at line 6)\n" +
1714
		"	private int i;\n" +
1714
		"	private int i;\n" +
1715
		"	            ^\n" +
1715
		"	            ^\n" +
1716
		"The field A.i is never read locally\n" +
1716
		"The private field A.i is never used\n" +
1717
		"----------\n" +
1717
		"----------\n" +
1718
		"2. ERROR in p\\A.java (at line 8)\n" +
1718
		"2. ERROR in p\\A.java (at line 8)\n" +
1719
		"	int x = i;\n" +
1719
		"	int x = i;\n" +
Lines 1946-1952 Link Here
1946
		"3. WARNING in p\\FieldQualification.java (at line 6)\n" +
1946
		"3. WARNING in p\\FieldQualification.java (at line 6)\n" +
1947
		"	String field = \"Enclosing field for anonymous type\";\n" +
1947
		"	String field = \"Enclosing field for anonymous type\";\n" +
1948
		"	       ^^^^^\n" +
1948
		"	       ^^^^^\n" +
1949
		"The field Local.field is never read locally\n" +
1949
		"The field Local.field is never used locally\n" +
1950
		"----------\n" +
1950
		"----------\n" +
1951
		"4. WARNING in p\\FieldQualification.java (at line 7)\n" +
1951
		"4. WARNING in p\\FieldQualification.java (at line 7)\n" +
1952
		"	void foo() {\n" +
1952
		"	void foo() {\n" +
(-)src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java (-2 / +3 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
package org.eclipse.jdt.core.tests.compiler.regression;
12
13
Lines 7190-7201 Link Here
7190
		"1. WARNING in X.java (at line 2)\n" +
7191
		"1. WARNING in X.java (at line 2)\n" +
7191
		"	private int unused1;\n" +
7192
		"	private int unused1;\n" +
7192
		"	            ^^^^^^^\n" +
7193
		"	            ^^^^^^^\n" +
7193
		"The field X.unused1 is never read locally\n" +
7194
		"The private field X.unused1 is never used\n" +
7194
		"----------\n" +
7195
		"----------\n" +
7195
		"2. WARNING in X.java (at line 7)\n" +
7196
		"2. WARNING in X.java (at line 7)\n" +
7196
		"	private int unused2;\n" +
7197
		"	private int unused2;\n" +
7197
		"	            ^^^^^^^\n" +
7198
		"	            ^^^^^^^\n" +
7198
		"The field X.unused2 is never read locally\n" +
7199
		"The private field X.unused2 is never used\n" +
7199
		"----------\n",
7200
		"----------\n",
7200
		null, null,
7201
		null, null,
7201
		JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings
7202
		JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings
(-)src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java (-4 / +5 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
package org.eclipse.jdt.core.tests.compiler.regression;
12
13
Lines 279-285 Link Here
279
		"1. WARNING in test\\AbstractVisibility.java (at line 5)\n" + 
280
		"1. WARNING in test\\AbstractVisibility.java (at line 5)\n" + 
280
		"	public int avf_public = avf_private;\n" + 
281
		"	public int avf_public = avf_private;\n" + 
281
		"	           ^^^^^^^^^^\n" + 
282
		"	           ^^^^^^^^^^\n" + 
282
		"The field AbstractVisibility.AvcPrivate.avf_public is never read locally\n" + 
283
		"The field AbstractVisibility.AvcPrivate.avf_public is never used locally\n" + 
283
		"----------\n" + 
284
		"----------\n" + 
284
		"2. WARNING in test\\AbstractVisibility.java (at line 10)\n" + 
285
		"2. WARNING in test\\AbstractVisibility.java (at line 10)\n" + 
285
		"	public int avm_public() {\n" + 
286
		"	public int avm_public() {\n" + 
Lines 290-296 Link Here
290
		"1. WARNING in test\\Visibility.java (at line 5)\n" + 
291
		"1. WARNING in test\\Visibility.java (at line 5)\n" + 
291
		"	public int vf_public = vf_private;\n" + 
292
		"	public int vf_public = vf_private;\n" + 
292
		"	           ^^^^^^^^^\n" + 
293
		"	           ^^^^^^^^^\n" + 
293
		"The field Visibility.VcPrivate.vf_public is never read locally\n" + 
294
		"The field Visibility.VcPrivate.vf_public is never used locally\n" + 
294
		"----------\n" + 
295
		"----------\n" + 
295
		"2. WARNING in test\\Visibility.java (at line 11)\n" + 
296
		"2. WARNING in test\\Visibility.java (at line 11)\n" + 
296
		"	public int vm_public() {\n" + 
297
		"	public int vm_public() {\n" + 
Lines 301-307 Link Here
301
		"1. WARNING in test\\copy\\VisibilityPackage.java (at line 5)\n" + 
302
		"1. WARNING in test\\copy\\VisibilityPackage.java (at line 5)\n" + 
302
		"	public int vf_public = vf_private;\n" + 
303
		"	public int vf_public = vf_private;\n" + 
303
		"	           ^^^^^^^^^\n" + 
304
		"	           ^^^^^^^^^\n" + 
304
		"The field VisibilityPackage.VpPrivate.vf_public is never read locally\n" + 
305
		"The field VisibilityPackage.VpPrivate.vf_public is never used locally\n" + 
305
		"----------\n" + 
306
		"----------\n" + 
306
		"2. WARNING in test\\copy\\VisibilityPackage.java (at line 10)\n" + 
307
		"2. WARNING in test\\copy\\VisibilityPackage.java (at line 10)\n" + 
307
		"	public int vm_public() {\n" + 
308
		"	public int vm_public() {\n" + 
Lines 312-318 Link Here
312
		"1. WARNING in test\\copy\\VisibilityPublic.java (at line 5)\n" + 
313
		"1. WARNING in test\\copy\\VisibilityPublic.java (at line 5)\n" + 
313
		"	public int vf_public = vf_private;\n" + 
314
		"	public int vf_public = vf_private;\n" + 
314
		"	           ^^^^^^^^^\n" + 
315
		"	           ^^^^^^^^^\n" + 
315
		"The field VisibilityPublic.VpPrivate.vf_public is never read locally\n" + 
316
		"The field VisibilityPublic.VpPrivate.vf_public is never used locally\n" + 
316
		"----------\n" + 
317
		"----------\n" + 
317
		"2. WARNING in test\\copy\\VisibilityPublic.java (at line 10)\n" + 
318
		"2. WARNING in test\\copy\\VisibilityPublic.java (at line 10)\n" + 
318
		"	public int vm_public() {\n" + 
319
		"	public int vm_public() {\n" + 
(-)src/org/eclipse/jdt/core/tests/compiler/regression/LocalVariableTest.java (-20 / +21 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
2
 * Copyright (c) 2005, 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 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
package org.eclipse.jdt.core.tests.compiler.regression;
12
13
Lines 411-417 Link Here
411
		"1. ERROR in X.java (at line 7)\n" +
412
		"1. ERROR in X.java (at line 7)\n" +
412
		"	void bar(int value) { // X#bar(...)\n" +
413
		"	void bar(int value) { // X#bar(...)\n" +
413
		"	             ^^^^^\n" +
414
		"	             ^^^^^\n" +
414
		"The parameter value is never read\n" +
415
		"The parameter value is never used\n" +
415
		"----------\n",
416
		"----------\n",
416
		// javac options
417
		// javac options
417
		JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */);
418
		JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */);
Lines 469-485 Link Here
469
		"1. ERROR in X.java (at line 5)\n" +
470
		"1. ERROR in X.java (at line 5)\n" +
470
		"	void foo(int value) { // X#foo(...)\n" +
471
		"	void foo(int value) { // X#foo(...)\n" +
471
		"	             ^^^^^\n" +
472
		"	             ^^^^^\n" +
472
		"The parameter value is never read\n" +
473
		"The parameter value is never used\n" +
473
		"----------\n" +
474
		"----------\n" +
474
		"2. ERROR in X.java (at line 7)\n" +
475
		"2. ERROR in X.java (at line 7)\n" +
475
		"	void bar(int value) { // X#bar(...)\n" +
476
		"	void bar(int value) { // X#bar(...)\n" +
476
		"	             ^^^^^\n" +
477
		"	             ^^^^^\n" +
477
		"The parameter value is never read\n" +
478
		"The parameter value is never used\n" +
478
		"----------\n" +
479
		"----------\n" +
479
		"3. ERROR in X.java (at line 24)\n" +
480
		"3. ERROR in X.java (at line 24)\n" +
480
		"	void parent(int value) { /* Parent#parent(...) */}\n" +
481
		"	void parent(int value) { /* Parent#parent(...) */}\n" +
481
		"	                ^^^^^\n" +
482
		"	                ^^^^^\n" +
482
		"The parameter value is never read\n" +
483
		"The parameter value is never used\n" +
483
		"----------\n",
484
		"----------\n",
484
		// javac options
485
		// javac options
485
		JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */);
486
		JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */);
Lines 537-553 Link Here
537
		"1. ERROR in X.java (at line 5)\n" +
538
		"1. ERROR in X.java (at line 5)\n" +
538
		"	void foo(int value) { // X#foo(...)\n" +
539
		"	void foo(int value) { // X#foo(...)\n" +
539
		"	             ^^^^^\n" +
540
		"	             ^^^^^\n" +
540
		"The parameter value is never read\n" +
541
		"The parameter value is never used\n" +
541
		"----------\n" +
542
		"----------\n" +
542
		"2. ERROR in X.java (at line 7)\n" +
543
		"2. ERROR in X.java (at line 7)\n" +
543
		"	void bar(int value) { // X#bar(...)\n" +
544
		"	void bar(int value) { // X#bar(...)\n" +
544
		"	             ^^^^^\n" +
545
		"	             ^^^^^\n" +
545
		"The parameter value is never read\n" +
546
		"The parameter value is never used\n" +
546
		"----------\n" +
547
		"----------\n" +
547
		"3. ERROR in X.java (at line 24)\n" +
548
		"3. ERROR in X.java (at line 24)\n" +
548
		"	void parent(int value) { /* Parent#parent(...) */}\n" +
549
		"	void parent(int value) { /* Parent#parent(...) */}\n" +
549
		"	                ^^^^^\n" +
550
		"	                ^^^^^\n" +
550
		"The parameter value is never read\n" +
551
		"The parameter value is never used\n" +
551
		"----------\n",
552
		"----------\n",
552
		// javac options
553
		// javac options
553
		JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */);
554
		JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */);
Lines 605-636 Link Here
605
		"1. ERROR in X.java (at line 5)\n" +
606
		"1. ERROR in X.java (at line 5)\n" +
606
		"	void foo(int value) { // X#foo(...)\n" +
607
		"	void foo(int value) { // X#foo(...)\n" +
607
		"	             ^^^^^\n" +
608
		"	             ^^^^^\n" +
608
		"The parameter value is never read\n" +
609
		"The parameter value is never used\n" +
609
		"----------\n" +
610
		"----------\n" +
610
		"2. ERROR in X.java (at line 7)\n" +
611
		"2. ERROR in X.java (at line 7)\n" +
611
		"	void bar(int value) { // X#bar(...)\n" +
612
		"	void bar(int value) { // X#bar(...)\n" +
612
		"	             ^^^^^\n" +
613
		"	             ^^^^^\n" +
613
		"The parameter value is never read\n" +
614
		"The parameter value is never used\n" +
614
		"----------\n" +
615
		"----------\n" +
615
		"3. ERROR in X.java (at line 10)\n" +
616
		"3. ERROR in X.java (at line 10)\n" +
616
		"	void top(int value) { /* X#top(...)*/}\n" +
617
		"	void top(int value) { /* X#top(...)*/}\n" +
617
		"	             ^^^^^\n" +
618
		"	             ^^^^^\n" +
618
		"The parameter value is never read\n" +
619
		"The parameter value is never used\n" +
619
		"----------\n" +
620
		"----------\n" +
620
		"4. ERROR in X.java (at line 11)\n" +
621
		"4. ERROR in X.java (at line 11)\n" +
621
		"	void parent(int value) { /* X#parent(...) */}\n" +
622
		"	void parent(int value) { /* X#parent(...) */}\n" +
622
		"	                ^^^^^\n" +
623
		"	                ^^^^^\n" +
623
		"The parameter value is never read\n" +
624
		"The parameter value is never used\n" +
624
		"----------\n" +
625
		"----------\n" +
625
		"5. ERROR in X.java (at line 12)\n" +
626
		"5. ERROR in X.java (at line 12)\n" +
626
		"	public void doit(int value) { /* X#doit(...) */}\n" +
627
		"	public void doit(int value) { /* X#doit(...) */}\n" +
627
		"	                     ^^^^^\n" +
628
		"	                     ^^^^^\n" +
628
		"The parameter value is never read\n" +
629
		"The parameter value is never used\n" +
629
		"----------\n" +
630
		"----------\n" +
630
		"6. ERROR in X.java (at line 24)\n" +
631
		"6. ERROR in X.java (at line 24)\n" +
631
		"	void parent(int value) { /* Parent#parent(...) */}\n" +
632
		"	void parent(int value) { /* Parent#parent(...) */}\n" +
632
		"	                ^^^^^\n" +
633
		"	                ^^^^^\n" +
633
		"The parameter value is never read\n" +
634
		"The parameter value is never used\n" +
634
		"----------\n",
635
		"----------\n",
635
		// javac options
636
		// javac options
636
		JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */);
637
		JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */);
Lines 683-714 Link Here
683
		"1. ERROR in X.java (at line 3)\n" +
684
		"1. ERROR in X.java (at line 3)\n" +
684
		"	void foo(int value) { // X#foo(...)\n" +
685
		"	void foo(int value) { // X#foo(...)\n" +
685
		"	             ^^^^^\n" +
686
		"	             ^^^^^\n" +
686
		"The parameter value is never read\n" +
687
		"The parameter value is never used\n" +
687
		"----------\n" +
688
		"----------\n" +
688
		"2. ERROR in X.java (at line 5)\n" +
689
		"2. ERROR in X.java (at line 5)\n" +
689
		"	void bar(int value) { // X#bar(...)\n" +
690
		"	void bar(int value) { // X#bar(...)\n" +
690
		"	             ^^^^^\n" +
691
		"	             ^^^^^\n" +
691
		"The parameter value is never read\n" +
692
		"The parameter value is never used\n" +
692
		"----------\n" +
693
		"----------\n" +
693
		"3. ERROR in X.java (at line 9)\n" +
694
		"3. ERROR in X.java (at line 9)\n" +
694
		"	void top(int value) { /* X#top(...)*/}\n" +
695
		"	void top(int value) { /* X#top(...)*/}\n" +
695
		"	             ^^^^^\n" +
696
		"	             ^^^^^\n" +
696
		"The parameter value is never read\n" +
697
		"The parameter value is never used\n" +
697
		"----------\n" +
698
		"----------\n" +
698
		"4. ERROR in X.java (at line 11)\n" +
699
		"4. ERROR in X.java (at line 11)\n" +
699
		"	void parent(int value) { /* X#parent(...) */}\n" +
700
		"	void parent(int value) { /* X#parent(...) */}\n" +
700
		"	                ^^^^^\n" +
701
		"	                ^^^^^\n" +
701
		"The parameter value is never read\n" +
702
		"The parameter value is never used\n" +
702
		"----------\n" +
703
		"----------\n" +
703
		"5. ERROR in X.java (at line 13)\n" +
704
		"5. ERROR in X.java (at line 13)\n" +
704
		"	public void doit(int value) { /* X#doit(...) */}\n" +
705
		"	public void doit(int value) { /* X#doit(...) */}\n" +
705
		"	                     ^^^^^\n" +
706
		"	                     ^^^^^\n" +
706
		"The parameter value is never read\n" +
707
		"The parameter value is never used\n" +
707
		"----------\n" +
708
		"----------\n" +
708
		"6. ERROR in X.java (at line 21)\n" +
709
		"6. ERROR in X.java (at line 21)\n" +
709
		"	void parent(int value) { /* Parent#parent(...) */}\n" +
710
		"	void parent(int value) { /* Parent#parent(...) */}\n" +
710
		"	                ^^^^^\n" +
711
		"	                ^^^^^\n" +
711
		"The parameter value is never read\n" +
712
		"The parameter value is never used\n" +
712
		"----------\n",
713
		"----------\n",
713
		// javac options
714
		// javac options
714
		JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */);
715
		JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */);
(-)src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java (-18 / +19 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
package org.eclipse.jdt.core.tests.compiler.regression;
12
13
Lines 94-100 Link Here
94
		"1. WARNING in p1\\A.java (at line 3)\n" +
95
		"1. WARNING in p1\\A.java (at line 3)\n" +
95
		"	private int value;								\n" +
96
		"	private int value;								\n" +
96
		"	            ^^^^^\n" +
97
		"	            ^^^^^\n" +
97
		"The field A.value is never read locally\n" +
98
		"The private field A.value is never used\n" +
98
		"----------\n" +
99
		"----------\n" +
99
		"2. ERROR in p1\\A.java (at line 6)\n" +
100
		"2. ERROR in p1\\A.java (at line 6)\n" +
100
		"	value = 2;								\n" +
101
		"	value = 2;								\n" +
Lines 344-350 Link Here
344
		"1. WARNING in p1\\A.java (at line 3)\n" +
345
		"1. WARNING in p1\\A.java (at line 3)\n" +
345
		"	private String success = \"SUCCESS\";			\n" +
346
		"	private String success = \"SUCCESS\";			\n" +
346
		"	               ^^^^^^^\n" +
347
		"	               ^^^^^^^\n" +
347
		"The field A.success is never read locally\n" +
348
		"The private field A.success is never used\n" +
348
		"----------\n" +
349
		"----------\n" +
349
		"2. ERROR in p1\\A.java (at line 7)\n" +
350
		"2. ERROR in p1\\A.java (at line 7)\n" +
350
		"	public void aTask() {System.out.println(A.success);}\n" +
351
		"	public void aTask() {System.out.println(A.success);}\n" +
Lines 2263-2269 Link Here
2263
				"1. WARNING in com\\internap\\other\\ScopeExample.java (at line 4)\r\n" +
2264
				"1. WARNING in com\\internap\\other\\ScopeExample.java (at line 4)\r\n" +
2264
				"	private static final String LOGGER = \"FAILED\";\r\n" +
2265
				"	private static final String LOGGER = \"FAILED\";\r\n" +
2265
				"	                            ^^^^^^\n" +
2266
				"	                            ^^^^^^\n" +
2266
				"The field ScopeExample.LOGGER is never read locally\n" +
2267
				"The private field ScopeExample.LOGGER is never used\n" +
2267
				"----------\n" +
2268
				"----------\n" +
2268
				"2. ERROR in com\\internap\\other\\ScopeExample.java (at line 8)\r\n" +
2269
				"2. ERROR in com\\internap\\other\\ScopeExample.java (at line 8)\r\n" +
2269
				"	System.out.println(LOGGER);\r\n" +
2270
				"	System.out.println(LOGGER);\r\n" +
Lines 2654-2660 Link Here
2654
		"1. WARNING in X.java (at line 2)\n" +
2655
		"1. WARNING in X.java (at line 2)\n" +
2655
		"	private String value;\n" +
2656
		"	private String value;\n" +
2656
		"	               ^^^^^\n" +
2657
		"	               ^^^^^\n" +
2657
		"The field D.value is never read locally\n" +
2658
		"The private field D.value is never used\n" +
2658
		"----------\n" +
2659
		"----------\n" +
2659
		"2. ERROR in X.java (at line 13)\n" +
2660
		"2. ERROR in X.java (at line 13)\n" +
2660
		"	super(getValue());\n" +
2661
		"	super(getValue());\n" +
Lines 3264-3275 Link Here
3264
		"2. WARNING in B.java (at line 3)\n" + 
3265
		"2. WARNING in B.java (at line 3)\n" + 
3265
		"	public final String length = \"very long\";\n" + 
3266
		"	public final String length = \"very long\";\n" + 
3266
		"	                    ^^^^^^\n" + 
3267
		"	                    ^^^^^^\n" + 
3267
		"The field A.B.length is never read locally\n" + 
3268
		"The field A.B.length is never used locally\n" + 
3268
		"----------\n" + 
3269
		"----------\n" + 
3269
		"3. WARNING in B.java (at line 5)\n" + 
3270
		"3. WARNING in B.java (at line 5)\n" + 
3270
		"	private int [] B = new int[5];\n" + 
3271
		"	private int [] B = new int[5];\n" + 
3271
		"	               ^\n" + 
3272
		"	               ^\n" + 
3272
		"The field A.B is never read locally\n" + 
3273
		"The private field A.B is never used\n" + 
3273
		"----------\n" + 
3274
		"----------\n" + 
3274
		"4. ERROR in B.java (at line 9)\n" + 
3275
		"4. ERROR in B.java (at line 9)\n" + 
3275
		"	System.out.println(A.B.length);\n" + 
3276
		"	System.out.println(A.B.length);\n" + 
Lines 3298-3309 Link Here
3298
		"1. WARNING in B.java (at line 3)\n" + 
3299
		"1. WARNING in B.java (at line 3)\n" + 
3299
		"	private final String length = \"very long\";\n" + 
3300
		"	private final String length = \"very long\";\n" + 
3300
		"	                     ^^^^^^\n" + 
3301
		"	                     ^^^^^^\n" + 
3301
		"The field A.B.length is never read locally\n" + 
3302
		"The private field A.B.length is never used\n" + 
3302
		"----------\n" + 
3303
		"----------\n" + 
3303
		"2. WARNING in B.java (at line 5)\n" + 
3304
		"2. WARNING in B.java (at line 5)\n" + 
3304
		"	private int [] B = new int[5];\n" + 
3305
		"	private int [] B = new int[5];\n" + 
3305
		"	               ^\n" + 
3306
		"	               ^\n" + 
3306
		"The field A.B is never read locally\n" + 
3307
		"The private field A.B is never used\n" + 
3307
		"----------\n" + 
3308
		"----------\n" + 
3308
		"3. ERROR in B.java (at line 9)\n" + 
3309
		"3. ERROR in B.java (at line 9)\n" + 
3309
		"	System.out.println(A.B.length);\n" + 
3310
		"	System.out.println(A.B.length);\n" + 
Lines 3338-3354 Link Here
3338
		"1. WARNING in A.java (at line 2)\n" + 
3339
		"1. WARNING in A.java (at line 2)\n" + 
3339
		"	private int x;\n" + 
3340
		"	private int x;\n" + 
3340
		"	            ^\n" + 
3341
		"	            ^\n" + 
3341
		"The field A.x is never read locally\n" + 
3342
		"The private field A.x is never used\n" + 
3342
		"----------\n" + 
3343
		"----------\n" + 
3343
		"2. WARNING in A.java (at line 4)\n" + 
3344
		"2. WARNING in A.java (at line 4)\n" + 
3344
		"	private int x;\n" + 
3345
		"	private int x;\n" + 
3345
		"	            ^\n" + 
3346
		"	            ^\n" + 
3346
		"The field A.B.x is never read locally\n" + 
3347
		"The private field A.B.x is never used\n" + 
3347
		"----------\n" + 
3348
		"----------\n" + 
3348
		"3. WARNING in A.java (at line 5)\n" + 
3349
		"3. WARNING in A.java (at line 5)\n" + 
3349
		"	private C c = new C() {\n" + 
3350
		"	private C c = new C() {\n" + 
3350
		"	          ^\n" + 
3351
		"	          ^\n" + 
3351
		"The field A.B.c is never read locally\n" + 
3352
		"The private field A.B.c is never used\n" + 
3352
		"----------\n" + 
3353
		"----------\n" + 
3353
		"4. WARNING in A.java (at line 6)\n" + 
3354
		"4. WARNING in A.java (at line 6)\n" + 
3354
		"	void foo() {\n" + 
3355
		"	void foo() {\n" + 
Lines 3363-3369 Link Here
3363
		"6. WARNING in A.java (at line 12)\n" + 
3364
		"6. WARNING in A.java (at line 12)\n" + 
3364
		"	private int x;\n" + 
3365
		"	private int x;\n" + 
3365
		"	            ^\n" + 
3366
		"	            ^\n" + 
3366
		"The field A.C.x is never read locally\n" + 
3367
		"The private field A.C.x is never used\n" + 
3367
		"----------\n");
3368
		"----------\n");
3368
}
3369
}
3369
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=316956
3370
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=316956
Lines 3393-3409 Link Here
3393
		"1. WARNING in A.java (at line 2)\n" + 
3394
		"1. WARNING in A.java (at line 2)\n" + 
3394
		"	private int x;\n" + 
3395
		"	private int x;\n" + 
3395
		"	            ^\n" + 
3396
		"	            ^\n" + 
3396
		"The field A.x is never read locally\n" + 
3397
		"The private field A.x is never used\n" + 
3397
		"----------\n" + 
3398
		"----------\n" + 
3398
		"2. WARNING in A.java (at line 4)\n" + 
3399
		"2. WARNING in A.java (at line 4)\n" + 
3399
		"	private int x;\n" + 
3400
		"	private int x;\n" + 
3400
		"	            ^\n" + 
3401
		"	            ^\n" + 
3401
		"The field A.B.x is never read locally\n" + 
3402
		"The private field A.B.x is never used\n" + 
3402
		"----------\n" + 
3403
		"----------\n" + 
3403
		"3. WARNING in A.java (at line 5)\n" + 
3404
		"3. WARNING in A.java (at line 5)\n" + 
3404
		"	private C c = new C() {\n" + 
3405
		"	private C c = new C() {\n" + 
3405
		"	          ^\n" + 
3406
		"	          ^\n" + 
3406
		"The field A.B.c is never read locally\n" + 
3407
		"The private field A.B.c is never used\n" + 
3407
		"----------\n" + 
3408
		"----------\n" + 
3408
		"4. WARNING in A.java (at line 6)\n" + 
3409
		"4. WARNING in A.java (at line 6)\n" + 
3409
		"	void foo() {\n" + 
3410
		"	void foo() {\n" + 
Lines 3435-3446 Link Here
3435
		"1. WARNING in A.java (at line 2)\n" + 
3436
		"1. WARNING in A.java (at line 2)\n" + 
3436
		"	private int x;\n" + 
3437
		"	private int x;\n" + 
3437
		"	            ^\n" + 
3438
		"	            ^\n" + 
3438
		"The field A.x is never read locally\n" + 
3439
		"The private field A.x is never used\n" + 
3439
		"----------\n" + 
3440
		"----------\n" + 
3440
		"2. WARNING in A.java (at line 3)\n" + 
3441
		"2. WARNING in A.java (at line 3)\n" + 
3441
		"	private C c = new C() {\n" + 
3442
		"	private C c = new C() {\n" + 
3442
		"	          ^\n" + 
3443
		"	          ^\n" + 
3443
		"The field A.c is never read locally\n" + 
3444
		"The private field A.c is never used\n" + 
3444
		"----------\n" + 
3445
		"----------\n" + 
3445
		"3. WARNING in A.java (at line 4)\n" + 
3446
		"3. WARNING in A.java (at line 4)\n" + 
3446
		"	void foo() {\n" + 
3447
		"	void foo() {\n" + 
Lines 3455-3461 Link Here
3455
		"5. WARNING in A.java (at line 9)\n" + 
3456
		"5. WARNING in A.java (at line 9)\n" + 
3456
		"	private int x;\n" + 
3457
		"	private int x;\n" + 
3457
		"	            ^\n" + 
3458
		"	            ^\n" + 
3458
		"The field A.C.x is never read locally\n" + 
3459
		"The private field A.C.x is never used\n" + 
3459
		"----------\n");
3460
		"----------\n");
3460
}
3461
}
3461
public static Class testClass() {	return LookupTest.class;
3462
public static Class testClass() {	return LookupTest.class;
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ProblemConstructorTest.java (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 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 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
package org.eclipse.jdt.core.tests.compiler.regression;
12
13
Lines 185-191 Link Here
185
		"3. WARNING in X.java (at line 6)\n" + 
186
		"3. WARNING in X.java (at line 6)\n" + 
186
		"	public int unusedField = 0;\n" + 
187
		"	public int unusedField = 0;\n" + 
187
		"	           ^^^^^^^^^^^\n" + 
188
		"	           ^^^^^^^^^^^\n" + 
188
		"The field X.M.unusedField is never read locally\n" + 
189
		"The field X.M.unusedField is never used locally\n" + 
189
		"----------\n" + 
190
		"----------\n" + 
190
		"4. WARNING in X.java (at line 7)\n" + 
191
		"4. WARNING in X.java (at line 7)\n" + 
191
		"	public class N {}\n" + 
192
		"	public class N {}\n" + 
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java (-6 / +443 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
package org.eclipse.jdt.core.tests.compiler.regression;
12
13
Lines 143-149 Link Here
143
		"1. WARNING in X.java (at line 2)\r\n" +
144
		"1. WARNING in X.java (at line 2)\r\n" +
144
		"	public void foo(boolean b) {\r\n" +
145
		"	public void foo(boolean b) {\r\n" +
145
		"	                        ^\n" +
146
		"	                        ^\n" +
146
		"The parameter b is never read\n" +
147
		"The parameter b is never used\n" +
147
		"----------\n" /* expectedCompilerLog */,
148
		"----------\n" /* expectedCompilerLog */,
148
		"" /* expectedOutputString */,
149
		"" /* expectedOutputString */,
149
		false /* forceExecution */,
150
		false /* forceExecution */,
Lines 214-220 Link Here
214
		"1. WARNING in X.java (at line 3)\n" +
215
		"1. WARNING in X.java (at line 3)\n" +
215
		"	public void foo(boolean b) {\n" +
216
		"	public void foo(boolean b) {\n" +
216
		"	                        ^\n" +
217
		"	                        ^\n" +
217
		"The parameter b is never read\n" +
218
		"The parameter b is never used\n" +
218
		"----------\n" /* expectedCompilerLog */,
219
		"----------\n" /* expectedCompilerLog */,
219
		"" /* expectedOutputString */,
220
		"" /* expectedOutputString */,
220
		false /* forceExecution */,
221
		false /* forceExecution */,
Lines 279-285 Link Here
279
		"1. ERROR in X.java (at line 2)\r\n" +
280
		"1. ERROR in X.java (at line 2)\r\n" +
280
		"	public void foo(boolean b) {\r\n" +
281
		"	public void foo(boolean b) {\r\n" +
281
		"	                        ^\n" +
282
		"	                        ^\n" +
282
		"The parameter b is never read\n" +
283
		"The parameter b is never used\n" +
283
		"----------\n" /* expectedCompilerLog */,
284
		"----------\n" /* expectedCompilerLog */,
284
		"" /* expectedOutputString */,
285
		"" /* expectedOutputString */,
285
		false /* forceExecution */,
286
		false /* forceExecution */,
Lines 555-561 Link Here
555
		"1. WARNING in X.java (at line 3)\n" +
556
		"1. WARNING in X.java (at line 3)\n" +
556
		"	void foo(int unused) throws IOException {}\n" +
557
		"	void foo(int unused) throws IOException {}\n" +
557
		"	             ^^^^^^\n" +
558
		"	             ^^^^^^\n" +
558
		"The parameter unused is never read\n" +
559
		"The parameter unused is never used\n" +
559
		"----------\n" +
560
		"----------\n" +
560
		"2. ERROR in X.java (at line 3)\n" +
561
		"2. ERROR in X.java (at line 3)\n" +
561
		"	void foo(int unused) throws IOException {}\n" +
562
		"	void foo(int unused) throws IOException {}\n" +
Lines 594-600 Link Here
594
		"1. WARNING in X.java (at line 3)\n" +
595
		"1. WARNING in X.java (at line 3)\n" +
595
		"	void foo(int unused) throws IOException {}\n" +
596
		"	void foo(int unused) throws IOException {}\n" +
596
		"	             ^^^^^^\n" +
597
		"	             ^^^^^^\n" +
597
		"The parameter unused is never read\n" +
598
		"The parameter unused is never used\n" +
598
		"----------\n" +
599
		"----------\n" +
599
		"2. WARNING in X.java (at line 3)\n" +
600
		"2. WARNING in X.java (at line 3)\n" +
600
		"	void foo(int unused) throws IOException {}\n" +
601
		"	void foo(int unused) throws IOException {}\n" +
Lines 631-637 Link Here
631
		"1. ERROR in X.java (at line 2)\n" +
632
		"1. ERROR in X.java (at line 2)\n" +
632
		"	public X(boolean b) {\n" +
633
		"	public X(boolean b) {\n" +
633
		"	                 ^\n" +
634
		"	                 ^\n" +
634
		"The parameter b is never read\n" +
635
		"The parameter b is never used\n" +
635
		"----------\n" /* expectedCompilerLog */,
636
		"----------\n" /* expectedCompilerLog */,
636
		"" /* expectedOutputString */,
637
		"" /* expectedOutputString */,
637
		false /* forceExecution */,
638
		false /* forceExecution */,
Lines 1683-1686 Link Here
1683
		"The assignment to variable nvx has no effect\n" + 
1684
		"The assignment to variable nvx has no effect\n" + 
1684
		"----------\n");
1685
		"----------\n");
1685
}
1686
}
1687
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
1688
public void test0046() {
1689
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
1690
		return;
1691
	Map customOptions = getCompilerOptions();
1692
	customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
1693
	this.runNegativeTest(
1694
			new String[] {
1695
				"X.java",
1696
				"class X {\n" + 
1697
				"    int foo() {\n" + 
1698
				"        int i=1;\n" + 
1699
				"        boolean b=false;\n" + 
1700
				"        b|=true;\n" + 			// not a relevant usage
1701
				"        int k = 2;\n" + 
1702
				"        --k;\n" + 				// not a relevant usage
1703
				"        k+=3;\n" + 			// not a relevant usage
1704
				"        Integer j = 3;\n" + 
1705
				"        j++;\n" + 				// relevant because unboxing is involved
1706
				"        i++;\n" +				// not relevant but should still not report because next is relevant
1707
				"        return i++;\n" + 		// value after increment is used
1708
				"    }\n" + 
1709
				"}"
1710
			},
1711
			"----------\n" + 
1712
			"1. WARNING in X.java (at line 4)\n" + 
1713
			"	boolean b=false;\n" + 
1714
			"	        ^\n" + 
1715
			"The local variable b is never used\n" + 
1716
			"----------\n" + 
1717
			"2. WARNING in X.java (at line 6)\n" + 
1718
			"	int k = 2;\n" + 
1719
			"	    ^\n" + 
1720
			"The local variable k is never used\n" + 
1721
			"----------\n",
1722
			null/*classLibraries*/,
1723
			true/*shouldFlushOutputDirectory*/,
1724
			customOptions);
1725
}
1726
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
1727
// variant with private fields instead of locals
1728
public void test0046_field() {
1729
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
1730
		return;
1731
	Map customOptions = getCompilerOptions();
1732
	customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
1733
	this.runNegativeTest(
1734
			new String[] {
1735
				"X.java",
1736
				"class X {\n" + 
1737
				"    private int i=1;\n" + 
1738
				"    private boolean b=false;\n" + 
1739
				"    private int k = 2;\n" + 
1740
				"    private Integer j = 3;\n" + 
1741
				"    int foo() {\n" + 
1742
				"        b|=true;\n" + 			// not a relevant usage
1743
				"        --k;\n" + 				// not a relevant usage
1744
				"        k+=3;\n" + 			// not a relevant usage
1745
				"        j++;\n" + 				// relevant because unboxing is involved
1746
				"        return i++;\n" + 		// value after increment is used
1747
				"    }\n" + 
1748
				"}"
1749
			},
1750
			"----------\n" + 
1751
			"1. WARNING in X.java (at line 3)\n" + 
1752
			"	private boolean b=false;\n" + 
1753
			"	                ^\n" + 
1754
			"The private field X.b is never used\n" + 
1755
			"----------\n" + 
1756
			"2. WARNING in X.java (at line 4)\n" + 
1757
			"	private int k = 2;\n" + 
1758
			"	            ^\n" + 
1759
			"The private field X.k is never used\n" + 
1760
			"----------\n",
1761
			null/*classLibraries*/,
1762
			true/*shouldFlushOutputDirectory*/,
1763
			customOptions);
1764
}
1765
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
1766
// variant with private fields instead of locals - this-qualified access
1767
public void test0046_field_this_qualified() {
1768
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
1769
		return;
1770
	Map customOptions = getCompilerOptions();
1771
	customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
1772
	this.runNegativeTest(
1773
			new String[] {
1774
				"X.java",
1775
				"class X {\n" + 
1776
				"    private int i=1;\n" + 
1777
				"    private boolean b=false;\n" + 
1778
				"    private int k = 2;\n" + 
1779
				"    private Integer j = 3;\n" + 
1780
				"    int foo() {\n" + 
1781
				"        this.b|=true;\n" + 		// not a relevant usage
1782
				"        --this.k;\n" + 			// not a relevant usage
1783
				"        getThis().k+=3;\n" + 		// not a relevant usage
1784
				"        this.j++;\n" + 			// relevant because unboxing is involved
1785
				"        return this.i++;\n" + 		// value after increment is used
1786
				"    }\n" +
1787
				"    X getThis() { return this; }\n" + 
1788
				"}"
1789
			},
1790
			"----------\n" + 
1791
			"1. WARNING in X.java (at line 3)\n" + 
1792
			"	private boolean b=false;\n" + 
1793
			"	                ^\n" + 
1794
			"The private field X.b is never used\n" + 
1795
			"----------\n" + 
1796
			"2. WARNING in X.java (at line 4)\n" + 
1797
			"	private int k = 2;\n" + 
1798
			"	            ^\n" + 
1799
			"The private field X.k is never used\n" + 
1800
			"----------\n",
1801
			null/*classLibraries*/,
1802
			true/*shouldFlushOutputDirectory*/,
1803
			customOptions);
1804
}
1805
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
1806
// variant with private fields instead of locals - regular qualified access
1807
public void test0046_field_qualified() {
1808
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
1809
		return;
1810
	Map customOptions = getCompilerOptions();
1811
	customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
1812
	this.runNegativeTest(
1813
			new String[] {
1814
				"X.java",
1815
				"class X {\n" + 
1816
				"    private int i=1;\n" + 
1817
				"    private boolean b=false;\n" + 
1818
				"    private int k = 2;\n" + 
1819
				"    private Integer j = 3;\n" + 
1820
				"    int foo(X that) {\n" + 
1821
				"        that.b|=true;\n" + 		// not a relevant usage
1822
				"        --that.k;\n" + 			// not a relevant usage
1823
				"        that.k+=3;\n" + 			// not a relevant usage
1824
				"        that.j++;\n" + 			// relevant because unboxing is involved
1825
				"        that.i++;\n"+				// not relevant but should still not report because next is relevant
1826
				"        return that.i++;\n" + 		// value after increment is used
1827
				"    }\n" + 
1828
				"}"
1829
			},
1830
			"----------\n" + 
1831
			"1. WARNING in X.java (at line 3)\n" + 
1832
			"	private boolean b=false;\n" + 
1833
			"	                ^\n" + 
1834
			"The private field X.b is never used\n" + 
1835
			"----------\n" + 
1836
			"2. WARNING in X.java (at line 4)\n" + 
1837
			"	private int k = 2;\n" + 
1838
			"	            ^\n" + 
1839
			"The private field X.k is never used\n" + 
1840
			"----------\n",
1841
			null/*classLibraries*/,
1842
			true/*shouldFlushOutputDirectory*/,
1843
			customOptions);
1844
}
1845
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
1846
// variant with fields inside a private type
1847
public void test0046_field_in_private_type() {
1848
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
1849
		return;
1850
	Map customOptions = getCompilerOptions();
1851
	customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
1852
	this.runNegativeTest(
1853
			new String[] {
1854
				"X.java",
1855
				"class X {\n" +
1856
				"    private class Y {\n" + 
1857
				"        int i=1;\n" + 
1858
				"        public boolean b=false;\n" + 
1859
				"        protected int k = 2;\n" + 
1860
				"        Integer j = 3;\n" +
1861
				"    }\n" + 
1862
				"    int foo(Y y) {\n" + 
1863
				"        y.b|=true;\n" + 				// not a relevant usage
1864
				"        --y.k;\n" + 					// not a relevant usage
1865
				"        y.k+=3;\n" + 					// not a relevant usage
1866
				"        y.j++;\n" + 					// relevant because unboxing is involved
1867
				"        int result = y.i++;\n" + 	// value after increment is used
1868
				"        y.i++;\n" +					// not relevant, but previous is
1869
				"        return result;\n" +
1870
				"    }\n" + 
1871
				"}"
1872
			},
1873
			"----------\n" + 
1874
			"1. WARNING in X.java (at line 4)\n" + 
1875
			"	public boolean b=false;\n" + 
1876
			"	               ^\n" + 
1877
			"The field X.Y.b is never used locally\n" + 
1878
			"----------\n" + 
1879
			"2. WARNING in X.java (at line 5)\n" + 
1880
			"	protected int k = 2;\n" + 
1881
			"	              ^\n" + 
1882
			"The field X.Y.k is never used locally\n" + 
1883
			"----------\n",
1884
			null/*classLibraries*/,
1885
			true/*shouldFlushOutputDirectory*/,
1886
			customOptions);
1887
}
1888
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
1889
public void test0047() {
1890
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
1891
		return;
1892
	Map customOptions = getCompilerOptions();
1893
	customOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING);
1894
	customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
1895
	this.runNegativeTest(
1896
			new String[] {
1897
				"X.java",
1898
				"class X {\n" + 
1899
				"    void foo(int param1, int param2, Integer param3) {\n" + 
1900
				"        boolean b=false;\n" + 
1901
				"        b|=true;\n" + 			// not a relevant usage
1902
				"        param1++;\n" + 		// not a relevant usage
1903
				"        {\n" +
1904
				"            int val=23;\n" +
1905
				"            param2 += val;\n" +// not a relevant usage of param2
1906
				"        }\n" +
1907
				"        param3++;\n" + 		// relevant because unboxing is involved
1908
				"    }\n" + 
1909
				"}"
1910
			},
1911
			"----------\n" + 
1912
			"1. WARNING in X.java (at line 2)\n" + 
1913
			"	void foo(int param1, int param2, Integer param3) {\n" + 
1914
			"	             ^^^^^^\n" + 
1915
			"The parameter param1 is never used\n" + 
1916
			"----------\n" + 
1917
			"2. WARNING in X.java (at line 2)\n" + 
1918
			"	void foo(int param1, int param2, Integer param3) {\n" + 
1919
			"	                         ^^^^^^\n" + 
1920
			"The parameter param2 is never used\n" + 
1921
			"----------\n" + 
1922
			"3. WARNING in X.java (at line 3)\n" + 
1923
			"	boolean b=false;\n" + 
1924
			"	        ^\n" + 
1925
			"The local variable b is never used\n" + 
1926
			"----------\n",
1927
			null/*classLibraries*/,
1928
			true/*shouldFlushOutputDirectory*/,
1929
			customOptions);
1930
}
1931
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
1932
// To verify that unused parameter warning is not shown for an implementing method's parameter when
1933
// CompilerOptions.OPTION_ReportUnusedParameterWhenImplementingAbstract is disabled
1934
public void test0048() {
1935
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
1936
		return;
1937
	Map customOptions = getCompilerOptions();
1938
	customOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING);
1939
	customOptions.put(CompilerOptions.OPTION_ReportUnusedParameterWhenImplementingAbstract, CompilerOptions.DISABLED);
1940
	customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
1941
	this.runNegativeTest(
1942
			new String[] {
1943
				"X.java",
1944
				"public class X extends A implements Y{\n" + 
1945
				"   public void foo(int param1, int param2, Integer param3) {\n" + // implementing method, so dont warn
1946
				"        boolean b=false;\n" + 
1947
				"        b|=true;\n" + 			// not a relevant usage
1948
				"        param1++;\n" + 		// not a relevant usage
1949
				"        param2 += 1;\n" + 		// not a relevant usage
1950
				"        param3++;\n" + 		// relevant because unboxing is involved
1951
				"    }\n" + 
1952
				"   public void foo(int param1, int param2) {\n" + // warn
1953
				"        boolean b=false;\n" + 
1954
				"        b|=true;\n" + 			// not a relevant usage
1955
				"        param1++;\n" + 		// not a relevant usage
1956
				"        param2 += 1;\n" + 		// not a relevant usage
1957
				"    }\n" +
1958
				"   public void bar(int param1, int param2, Integer param3) {\n" + // implementing method, so dont warn
1959
				"        param1++;\n" + 		// not a relevant usage
1960
				"        param2 += 1;\n" + 		// not a relevant usage
1961
				"        param3++;\n" + 		// relevant because unboxing is involved
1962
				"    }\n" +
1963
				"}\n" +
1964
				"interface Y{\n" +
1965
				"	public void foo(int param1, int param2, Integer param3);" +
1966
				"}\n" +
1967
				"abstract class A{\n" +
1968
				"	public abstract void bar(int param1, int param2, Integer param3);" +
1969
				"}\n"
1970
			},
1971
			"----------\n" + 
1972
			"1. WARNING in X.java (at line 3)\n" + 
1973
			"	boolean b=false;\n" + 
1974
			"	        ^\n" + 
1975
			"The local variable b is never used\n" + 
1976
			"----------\n" + 
1977
			"2. WARNING in X.java (at line 9)\n" + 
1978
			"	public void foo(int param1, int param2) {\n" + 
1979
			"	                    ^^^^^^\n" + 
1980
			"The parameter param1 is never used\n" + 
1981
			"----------\n" + 
1982
			"3. WARNING in X.java (at line 9)\n" + 
1983
			"	public void foo(int param1, int param2) {\n" + 
1984
			"	                                ^^^^^^\n" + 
1985
			"The parameter param2 is never used\n" + 
1986
			"----------\n" + 
1987
			"4. WARNING in X.java (at line 10)\n" + 
1988
			"	boolean b=false;\n" + 
1989
			"	        ^\n" + 
1990
			"The local variable b is never used\n" + 
1991
			"----------\n",
1992
			null/*classLibraries*/,
1993
			true/*shouldFlushOutputDirectory*/,
1994
			customOptions);
1995
}
1996
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
1997
// To verify that unused parameter warning is not shown for an overriding method's parameter when
1998
// CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete is disabled
1999
public void test0049() {
2000
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
2001
		return;
2002
	Map customOptions = getCompilerOptions();
2003
	customOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING);
2004
	customOptions.put(CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete, CompilerOptions.DISABLED);
2005
	customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
2006
	this.runNegativeTest(
2007
			new String[] {
2008
				"X.java",
2009
				"public class X extends A {\n" + 
2010
				"   public void foo(int param1, int param2, Integer param3) {\n" + // overriding method, so dont warn
2011
				"        boolean b=false;\n" + 
2012
				"        b|=true;\n" + 			// not a relevant usage
2013
				"        param1++;\n" + 		// not a relevant usage
2014
				"        param2 += 1;\n" + 		// not a relevant usage
2015
				"        param3++;\n" + 		// relevant because unboxing is involved
2016
				"    }\n" + 
2017
				"   public void foo(int param1, Integer param3) {\n" + // overriding method, so dont warn
2018
				"        param1++;\n" + 		// not a relevant usage
2019
				"        param3++;\n" + 		// relevant because unboxing is involved
2020
				"    }\n" + 
2021
				"}\n" +
2022
				"class A{\n" +
2023
				"   public void foo(int param1, int param2, Integer param3) {\n" +
2024
				"        param1 -=1;\n" + 		// not a relevant usage
2025
				"        param2--;\n" + 		// not a relevant usage
2026
				"        param3--;\n" + 		// relevant because unboxing is involved
2027
				"    }\n" + 
2028
				"}\n"
2029
			},
2030
			"----------\n" + 
2031
			"1. WARNING in X.java (at line 3)\n" + 
2032
			"	boolean b=false;\n" + 
2033
			"	        ^\n" + 
2034
			"The local variable b is never used\n" + 
2035
			"----------\n" + 
2036
			"2. WARNING in X.java (at line 9)\n" + 
2037
			"	public void foo(int param1, Integer param3) {\n" + 
2038
			"	                    ^^^^^^\n" + 
2039
			"The parameter param1 is never used\n" + 
2040
			"----------\n" + 
2041
			"3. WARNING in X.java (at line 15)\n" + 
2042
			"	public void foo(int param1, int param2, Integer param3) {\n" + 
2043
			"	                    ^^^^^^\n" + 
2044
			"The parameter param1 is never used\n" + 
2045
			"----------\n" + 
2046
			"4. WARNING in X.java (at line 15)\n" + 
2047
			"	public void foo(int param1, int param2, Integer param3) {\n" + 
2048
			"	                                ^^^^^^\n" + 
2049
			"The parameter param2 is never used\n" + 
2050
			"----------\n",
2051
			null/*classLibraries*/,
2052
			true/*shouldFlushOutputDirectory*/,
2053
			customOptions);
2054
}
2055
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
2056
// To verify that unused local warning is not shown for locals declared in unreachable code
2057
public void test0050() {
2058
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
2059
		return;
2060
	Map customOptions = getCompilerOptions();
2061
	customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
2062
	this.runNegativeTest(
2063
			new String[] {
2064
				"X.java",
2065
				"class X {\n" + 
2066
				"    int foo() {\n" + 
2067
				"        int i=1;\n" +
2068
				"		 if (false) {\n" + 
2069
				"        	boolean b=false;\n" + // don't complain as unused
2070
				"        	b|=true;\n" +
2071
				"		 }\n" + 			// not a relevant usage
2072
				"        int k = 2;\n" + 
2073
				"        --k;\n" + 			// not a relevant usage
2074
				"        k+=3;\n" + 		// not a relevant usage
2075
				"        Integer j = 3;\n" + 
2076
				"        j++;\n" + 			// relevant because unboxing is involved
2077
				"        return i++;\n" + 	// value after increment is used
2078
				"    }\n" + 
2079
				"}"
2080
			},
2081
			"----------\n" + 
2082
			"1. WARNING in X.java (at line 4)\n" + 
2083
			"	if (false) {\n" + 
2084
			"        	boolean b=false;\n" + 
2085
			"        	b|=true;\n" + 
2086
			"		 }\n" + 
2087
			"	           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
2088
			"Dead code\n" + 
2089
			"----------\n" + 
2090
			"2. WARNING in X.java (at line 8)\n" + 
2091
			"	int k = 2;\n" + 
2092
			"	    ^\n" + 
2093
			"The local variable k is never used\n" + 
2094
			"----------\n",
2095
			null/*classLibraries*/,
2096
			true/*shouldFlushOutputDirectory*/,
2097
			customOptions);
2098
}
2099
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
2100
// To verify that we dont throw CCE if we're looking for uselessly read arguments in a constructor
2101
public void test0051() {
2102
	Map customOptions = getCompilerOptions();
2103
	customOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING);
2104
	this.runNegativeTest(
2105
			new String[] {
2106
				"X.java",
2107
				"class X {\n" + 
2108
				"    X(int abc) {\n" + 
2109
				"        abc++;\n" +	// not a relevant usage
2110
				"    }\n" + 
2111
				"}"
2112
			},
2113
			"----------\n" + 
2114
			"1. WARNING in X.java (at line 2)\n" + 
2115
			"	X(int abc) {\n" + 
2116
			"	      ^^^\n" + 
2117
			"The parameter abc is never used\n" + 
2118
			"----------\n",
2119
			null/*classLibraries*/,
2120
			true/*shouldFlushOutputDirectory*/,
2121
			customOptions);
2122
}
1686
}
2123
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java (-1 / +2 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
package org.eclipse.jdt.core.tests.compiler.regression;
12
13
Lines 660-666 Link Here
660
			"1. WARNING in bug\\C.java (at line 3)\n" +
661
			"1. WARNING in bug\\C.java (at line 3)\n" +
661
			"	private static B b;\n" +
662
			"	private static B b;\n" +
662
			"	                 ^\n" +
663
			"	                 ^\n" +
663
			"The field C.b is never read locally\n" +
664
			"The private field C.b is never used\n" +
664
			"----------\n");
665
			"----------\n");
665
	}
666
	}
666
667

Return to bug 185682