### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/core/compiler/IProblem.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java,v retrieving revision 1.222 diff -u -r1.222 IProblem.java --- compiler/org/eclipse/jdt/core/compiler/IProblem.java 7 Sep 2010 13:39:18 -0000 1.222 +++ compiler/org/eclipse/jdt/core/compiler/IProblem.java 21 Oct 2010 14:33:50 -0000 @@ -117,6 +117,7 @@ * MissingSynchronizedModifierInInheritedMethod * Stephan Herrmann - added the following constants * UnusedObjectAllocation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.core.compiler; @@ -359,6 +360,8 @@ int DuplicateBlankFinalFieldInitialization = FieldRelated + 82; /** @since 3.6 */ int UnresolvedVariable = FieldRelated + 83; + /** @since 3.7 */ + int UnusedScopedField = Internal + FieldRelated + 84; // variable hiding /** @since 3.0 */ Index: compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java,v retrieving revision 1.103 diff -u -r1.103 ASTNode.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 10 May 2010 20:47:58 -0000 1.103 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 21 Oct 2010 14:33:50 -0000 @@ -9,6 +9,7 @@ * IBM Corporation - initial API and implementation * Matt McCutchen - partial fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=122995 * Karen Moore - fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=207411 + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -357,11 +358,17 @@ return this; } - public final boolean isFieldUseDeprecated(FieldBinding field, Scope scope, boolean isStrictlyAssigned) { - // ignore references insing Javadoc comments - if ((this.bits & ASTNode.InsideJavadoc) == 0 && !isStrictlyAssigned && field.isOrEnclosedByPrivateType() && !scope.isDefinedInField(field)) { - // ignore cases where field is used from inside itself - field.original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed; + public final boolean isFieldUseDeprecated(FieldBinding field, Scope scope, int filteredBits) { + if ((this.bits & ASTNode.InsideJavadoc) == 0 // ignore references inside Javadoc comments + && (filteredBits & IsStrictlyAssigned) == 0 // ignore write access + && field.isOrEnclosedByPrivateType() + && !scope.isDefinedInField(field)) // ignore cases where field is used from inside itself + { + if (((filteredBits & IsCompoundAssigned) != 0)) + // used, but usage may not be relevant + field.original().modifiers |= ExtraCompilerModifiers.AccCompoundUsed; + else + field.original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed; } if ((field.modifiers & ExtraCompilerModifiers.AccRestrictedAccess) != 0) { Index: compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java,v retrieving revision 1.129 diff -u -r1.129 FieldReference.java --- compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java 21 Feb 2010 03:31:46 -0000 1.129 +++ compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java 21 Oct 2010 14:33:50 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -290,6 +291,10 @@ public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) { boolean isStatic; + if (!valueRequired) { + // check if compound assignment is the only usage of a private field + SingleNameReference.reportOnlyUselesslyReadPrivateField(currentScope, this, this.binding); + } FieldBinding codegenBinding = this.binding.original(); this.receiver.generateCode(currentScope, codeStream, !(isStatic = codegenBinding.isStatic())); if (isStatic) { @@ -337,6 +342,10 @@ public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) { boolean isStatic; + if (!valueRequired) { + // check if postIncrement is the only usage of a private field + SingleNameReference.reportOnlyUselesslyReadPrivateField(currentScope, this, this.binding); + } FieldBinding codegenBinding = this.binding.original(); this.receiver.generateCode(currentScope, codeStream, !(isStatic = codegenBinding.isStatic())); if (isStatic) { @@ -577,7 +586,7 @@ if (this.actualReceiverType != oldReceiverType && this.receiver.postConversionType(scope) != this.actualReceiverType) { // record need for explicit cast at codegen since receiver could not handle it this.bits |= NeedReceiverGenericCast; } - if (isFieldUseDeprecated(fieldBinding, scope, (this.bits & ASTNode.IsStrictlyAssigned) !=0)) { + if (isFieldUseDeprecated(fieldBinding, scope, this.bits)) { scope.problemReporter().deprecatedField(fieldBinding, this); } boolean isImplicitThisRcv = this.receiver.isImplicitThis(); Index: compiler/org/eclipse/jdt/internal/compiler/ast/JavadocFieldReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocFieldReference.java,v retrieving revision 1.31 diff -u -r1.31 JavadocFieldReference.java --- compiler/org/eclipse/jdt/internal/compiler/ast/JavadocFieldReference.java 24 Nov 2008 10:21:23 -0000 1.31 +++ compiler/org/eclipse/jdt/internal/compiler/ast/JavadocFieldReference.java 21 Oct 2010 14:33:50 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -97,7 +98,7 @@ } this.binding = (FieldBinding) fieldBinding; - if (isFieldUseDeprecated(this.binding, scope, (this.bits & IsStrictlyAssigned) != 0)) { + if (isFieldUseDeprecated(this.binding, scope, this.bits)) { scope.problemReporter().javadocDeprecatedField(this.binding, this, scope.getDeclarationModifiers()); } return this.resolvedType = this.binding.type; Index: compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java,v retrieving revision 1.147 diff -u -r1.147 QualifiedNameReference.java --- compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java 21 Sep 2010 14:02:57 -0000 1.147 +++ compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java 21 Oct 2010 14:33:50 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -380,6 +381,10 @@ public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) { FieldBinding lastFieldBinding = generateReadSequence(currentScope, codeStream); + if (!valueRequired) { + // check if compound assignment is the only usage of a private field + SingleNameReference.reportOnlyUselesslyReadPrivateField(currentScope, this, lastFieldBinding); + } boolean isFirst = lastFieldBinding == this.binding && (this.indexOfFirstFieldBinding == 1 || lastFieldBinding.declaringClass == currentScope.enclosingReceiverType()) && this.otherBindings == null; // could be dup: next.next.next @@ -431,6 +436,10 @@ public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) { FieldBinding lastFieldBinding = generateReadSequence(currentScope, codeStream); + if (!valueRequired) { + // check if this post increment is the only usage of a private field + SingleNameReference.reportOnlyUselesslyReadPrivateField(currentScope, this, lastFieldBinding); + } boolean isFirst = lastFieldBinding == this.binding && (this.indexOfFirstFieldBinding == 1 || lastFieldBinding.declaringClass == currentScope.enclosingReceiverType()) && this.otherBindings == null; // could be dup: next.next.next @@ -719,7 +728,7 @@ } } // only last field is actually a write access if any - if (isFieldUseDeprecated(field, scope, (this.bits & ASTNode.IsStrictlyAssigned) !=0 && index+1 == length)) { + if (isFieldUseDeprecated(field, scope, index+1 == length ? this.bits : 0)) { scope.problemReporter().deprecatedField(field, this); } // constant propagation can only be performed as long as the previous one is a constant too. @@ -954,7 +963,7 @@ && (!fieldBinding.isStatic() || methodScope.isStatic)) { scope.problemReporter().forwardReference(this, this.indexOfFirstFieldBinding-1, fieldBinding); } - if (isFieldUseDeprecated(fieldBinding, scope, (this.bits & ASTNode.IsStrictlyAssigned) != 0 && this.indexOfFirstFieldBinding == this.tokens.length)) { + if (isFieldUseDeprecated(fieldBinding, scope, this.indexOfFirstFieldBinding == this.tokens.length ? this.bits : 0)) { scope.problemReporter().deprecatedField(fieldBinding, this); } if (fieldBinding.isStatic()) { Index: compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java,v retrieving revision 1.124 diff -u -r1.124 SingleNameReference.java --- compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java 23 Sep 2010 12:03:42 -0000 1.124 +++ compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java 21 Oct 2010 14:33:50 -0000 @@ -7,7 +7,8 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Stephan Herrmann - Contribution for bug 292478 - Report potentially null across variable assignment + * Stephan Herrmann - Contribution for bug 292478 - Report potentially null across variable assignment, + * Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -23,6 +24,7 @@ import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.ClassScope; +import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding; import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; @@ -78,10 +80,14 @@ currentScope.problemReporter().uninitializedLocalVariable(localBinding, this); // we could improve error msg here telling "cannot use compound assignment on final local variable" } - if (isReachable) { - localBinding.useFlag = LocalVariableBinding.USED; - } else if (localBinding.useFlag == LocalVariableBinding.UNUSED) { - localBinding.useFlag = LocalVariableBinding.FAKE_USED; + if (localBinding.useFlag != LocalVariableBinding.USED) { + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 + // access from compound assignment does not prevent "unused" warning, unless unboxing is involved: + if (isReachable && (this.implicitConversion & TypeIds.UNBOXING) != 0) { + localBinding.useFlag = LocalVariableBinding.USED; + } else { + localBinding.useFlag = LocalVariableBinding.FAKE_USED; + } } } } @@ -204,7 +210,7 @@ } } - if (isFieldUseDeprecated(fieldBinding, scope, (this.bits & ASTNode.IsStrictlyAssigned) !=0)) + if (isFieldUseDeprecated(fieldBinding, scope, this.bits)) scope.problemReporter().deprecatedField(fieldBinding, this); if ((this.bits & ASTNode.IsStrictlyAssigned) == 0 @@ -462,6 +468,21 @@ * are optimized in one access: e.g "a = a + 1" optimized into "a++". */ public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) { + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 + if (!valueRequired) { + switch (this.bits & ASTNode.RestrictiveFlagMASK) { + case Binding.LOCAL: + LocalVariableBinding localBinding = (LocalVariableBinding) this.binding; + if (localBinding.useFlag == LocalVariableBinding.FAKE_USED) { + // compound assignment is the only usage of this local + reportOnlyUselesslyReadLocal(currentScope, localBinding); + } + break; + case Binding.FIELD: + // check if compound assignment is the only usage of a private field + reportOnlyUselesslyReadPrivateField(currentScope, this, (FieldBinding)this.binding); + } + } this.generateCompoundAssignment( currentScope, codeStream, @@ -599,7 +620,12 @@ public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) { switch (this.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD : // assigning to a field - FieldBinding codegenField = (((FieldBinding)this.binding).original()); + FieldBinding fieldBinding = (FieldBinding)this.binding; + if (!valueRequired) { + // check if postIncrement is the only usage of a private field + reportOnlyUselesslyReadPrivateField(currentScope, this, fieldBinding); + } + FieldBinding codegenField = fieldBinding.original(); if (codegenField.isStatic()) { if ((this.syntheticAccessors == null) || (this.syntheticAccessors[SingleNameReference.READ] == null)) { TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenField, this.actualReceiverType, true /* implicit this */); @@ -662,6 +688,12 @@ return; case Binding.LOCAL : // assigning to a local variable LocalVariableBinding localBinding = (LocalVariableBinding) this.binding; + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 + if (!valueRequired && localBinding.useFlag == LocalVariableBinding.FAKE_USED) { + // postIncrement is the only usage of this local + reportOnlyUselesslyReadLocal(currentScope, localBinding); + } + // using incr bytecode if possible if (localBinding.type == TypeBinding.INT) { if (valueRequired) { @@ -837,6 +869,49 @@ return null; } +/* report a local/arg that is only read from a 'special operator', + * i.e., in a postIncrement expression or a compound assignment, + * where the information is never flowing out off the local/arg. */ +static void reportOnlyUselesslyReadLocal(BlockScope currentScope, LocalVariableBinding localBinding) { + if (localBinding.declaration == null) + return; // secret local + if ((localBinding.declaration.bits & ASTNode.IsLocalDeclarationReachable) == 0) + return; // declaration is unreachable + if (localBinding.declaration instanceof Argument) { + // check compiler options to report against unused arguments + if (currentScope instanceof MethodScope) { + MethodBinding method = ((AbstractMethodDeclaration)currentScope.referenceContext()).binding; + + boolean shouldReport = !method.isMain(); + if (method.isImplementing()) { + shouldReport &= currentScope.compilerOptions().reportUnusedParameterWhenImplementingAbstract; + } else if (method.isOverriding()) { + shouldReport &= currentScope.compilerOptions().reportUnusedParameterWhenOverridingConcrete; + } + + if (shouldReport) { + // report the case of an argument that is unread except through a special operator + currentScope.problemReporter().unusedArgument(localBinding.declaration); + } + } + } else { + // report the case of a local variable that is unread except for a special operator + currentScope.problemReporter().unusedLocalVariable(localBinding.declaration); + } + localBinding.useFlag = LocalVariableBinding.USED; // don't report again +} + +/* report if a private field is only read from a 'special operator', + * i.e., in a postIncrement expression or a compound assignment, + * where the information is never flowing out off the field. */ +static void reportOnlyUselesslyReadPrivateField(BlockScope currentScope, Reference reference, FieldBinding fieldBinding) { + if (fieldBinding.isUsedOnlyInCompound() && fieldBinding.isOrEnclosedByPrivateType() && (reference.implicitConversion & TypeIds.UNBOXING) == 0) { + // compoundAssignment/postIncrement is the only usage of this field + currentScope.problemReporter().unusedPrivateField(fieldBinding.sourceField()); + fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; // don't report again + } +} + public TypeBinding resolveType(BlockScope scope) { // for code gen, harm the restrictiveFlag Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ExtraCompilerModifiers.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ExtraCompilerModifiers.java,v retrieving revision 1.9 diff -u -r1.9 ExtraCompilerModifiers.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ExtraCompilerModifiers.java 7 Mar 2009 01:08:09 -0000 1.9 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ExtraCompilerModifiers.java 21 Oct 2010 14:33:50 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; @@ -32,6 +33,7 @@ final int AccBlankFinal = ASTNode.Bit27; // for blank final variables final int AccIsDefaultConstructor = ASTNode.Bit27; // for default constructor final int AccLocallyUsed = ASTNode.Bit28; // used to diagnose unused private/local members + final int AccCompoundUsed = ASTNode.Bit25; // used to diagnose private members used only in a compound expression/assignment final int AccVisibilityMASK = ClassFileConstants.AccPublic | ClassFileConstants.AccProtected | ClassFileConstants.AccPrivate; final int AccOverriding = ASTNode.Bit29; // record fact a method overrides another one Index: compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java,v retrieving revision 1.59 diff -u -r1.59 FieldBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java 11 Nov 2009 05:40:46 -0000 1.59 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java 21 Oct 2010 14:33:51 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; @@ -332,7 +333,13 @@ */ public final boolean isUsed() { - return (this.modifiers & ExtraCompilerModifiers.AccLocallyUsed) != 0; + return (this.modifiers & (ExtraCompilerModifiers.AccLocallyUsed | ExtraCompilerModifiers.AccCompoundUsed)) != 0; +} +/* Answer true if the only use of this field is in compound assignment or post increment + */ + +public final boolean isUsedOnlyInCompound() { + return (this.modifiers & (ExtraCompilerModifiers.AccLocallyUsed | ExtraCompilerModifiers.AccCompoundUsed)) == ExtraCompilerModifiers.AccCompoundUsed; } /* Answer true if the receiver has protected visibility */ Index: compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java,v retrieving revision 1.423 diff -u -r1.423 ProblemReporter.java --- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 20 Oct 2010 05:46:48 -0000 1.423 +++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 21 Oct 2010 14:33:51 -0000 @@ -9,6 +9,7 @@ * IBM Corporation - initial API and implementation * Benjamin Muskalla - Contribution for bug 239066 * Stephan Herrmann - Contribution for bug 236385 + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.internal.compiler.problem; @@ -194,6 +195,7 @@ case IProblem.UnusedPrivateConstructor: case IProblem.UnusedPrivateMethod: case IProblem.UnusedPrivateField: + case IProblem.UnusedScopedField: case IProblem.UnusedPrivateType: return CompilerOptions.UnusedPrivateMember; @@ -7250,7 +7252,10 @@ } public void unusedPrivateField(FieldDeclaration fieldDecl) { - int severity = computeSeverity(IProblem.UnusedPrivateField); + int problemId = (fieldDecl.modifiers & ClassFileConstants.AccPrivate) != 0 + ? IProblem.UnusedPrivateField + : IProblem.UnusedScopedField; + int severity = computeSeverity(problemId); if (severity == ProblemSeverities.Ignore) return; FieldBinding field = fieldDecl.binding; @@ -7269,7 +7274,7 @@ return; // do not report unused serialPersistentFields field } this.handle( - IProblem.UnusedPrivateField, + problemId, new String[] { new String(field.declaringClass.readableName()), new String(field.name), Index: compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties,v retrieving revision 1.258 diff -u -r1.258 messages.properties --- compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 7 Sep 2010 13:39:18 -0000 1.258 +++ compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 21 Oct 2010 14:33:51 -0000 @@ -8,6 +8,7 @@ # Contributors: # IBM Corporation - initial API and implementation # Benjamin Muskalla - Contribution for bug 239066 +# Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read ############################################################################### 0 = {0} 1 = super cannot be used in java.lang.Object @@ -49,8 +50,8 @@ 58 = The final local variable {0} cannot be assigned. It must be blank and not using a compound assignment 59 = The parameter {0} should not be assigned 60 = The final local variable {0} cannot be assigned, since it is defined in an enclosing type -61 = The local variable {0} is never read -62 = The parameter {0} is never read +61 = The local variable {0} is never used +62 = The parameter {0} is never used 63 = The code of method {0}({1}) is exceeding the 65535 bytes limit 64 = The code for the static initializer is exceeding the 65535 bytes limit 65 = Too many parameters, parameter {0} is exceeding the limit of 255 words eligible for method parameters @@ -65,13 +66,14 @@ 74 = Cannot make a static reference to the non-static field {0} 75 = Cannot reference a field before it is defined 76 = The static field {0}.{1} should be accessed in a static way -77 = The field {0}.{1} is never read locally +77 = The private field {0}.{1} is never used 78 = The static field {0}.{1} should be accessed directly 79 = Unqualified access to the field {0}.{1} 80 = The final field {0}.{1} cannot be assigned 81 = The blank final field {0} may not have been initialized 82 = The final field {0} may already have been assigned 83 = {0} cannot be resolved to a variable +84 = The field {0}.{1} is never used locally 90 = The local variable {0} is hiding another local variable defined in an enclosing type scope 91 = The local variable {0} is hiding a field from type {1} Index: eval/org/eclipse/jdt/internal/eval/CodeSnippetFieldReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/CodeSnippetFieldReference.java,v retrieving revision 1.46 diff -u -r1.46 CodeSnippetFieldReference.java --- eval/org/eclipse/jdt/internal/eval/CodeSnippetFieldReference.java 7 Mar 2009 01:08:09 -0000 1.46 +++ eval/org/eclipse/jdt/internal/eval/CodeSnippetFieldReference.java 21 Oct 2010 14:33:51 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.internal.eval; @@ -325,7 +326,7 @@ return null; } - if (isFieldUseDeprecated(this.binding, scope, (this.bits & IsStrictlyAssigned) !=0)) { + if (isFieldUseDeprecated(this.binding, scope, this.bits)) { scope.problemReporter().deprecatedField(this.binding, this); } // check for this.x in static is done in the resolution of the receiver Index: eval/org/eclipse/jdt/internal/eval/CodeSnippetQualifiedNameReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/CodeSnippetQualifiedNameReference.java,v retrieving revision 1.59 diff -u -r1.59 CodeSnippetQualifiedNameReference.java --- eval/org/eclipse/jdt/internal/eval/CodeSnippetQualifiedNameReference.java 18 Nov 2008 20:23:11 -0000 1.59 +++ eval/org/eclipse/jdt/internal/eval/CodeSnippetQualifiedNameReference.java 21 Oct 2010 14:33:51 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.internal.eval; @@ -463,7 +464,7 @@ } } // only last field is actually a write access if any - if (isFieldUseDeprecated((FieldBinding) this.binding, scope, (this.bits & IsStrictlyAssigned) !=0 && this.indexOfFirstFieldBinding == length)) { + if (isFieldUseDeprecated((FieldBinding) this.binding, scope, this.indexOfFirstFieldBinding == length ? this.bits : 0)) { scope.problemReporter().deprecatedField((FieldBinding) this.binding, this); } } @@ -510,7 +511,7 @@ } if (field.isValidBinding()) { // only last field is actually a write access if any - if (isFieldUseDeprecated(field, scope, (this.bits & IsStrictlyAssigned) !=0 && index+1 == length)) { + if (isFieldUseDeprecated(field, scope, index+1 == length ? this.bits : 0)) { scope.problemReporter().deprecatedField(field, this); } // constant propagation can only be performed as long as the previous one is a constant too. Index: eval/org/eclipse/jdt/internal/eval/CodeSnippetSingleNameReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/CodeSnippetSingleNameReference.java,v retrieving revision 1.58 diff -u -r1.58 CodeSnippetSingleNameReference.java --- eval/org/eclipse/jdt/internal/eval/CodeSnippetSingleNameReference.java 7 Mar 2009 00:59:03 -0000 1.58 +++ eval/org/eclipse/jdt/internal/eval/CodeSnippetSingleNameReference.java 21 Oct 2010 14:33:51 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.internal.eval; @@ -101,7 +102,7 @@ } this.constant = fieldBinding.constant(); - if (isFieldUseDeprecated(fieldBinding, scope, (this.bits & IsStrictlyAssigned) !=0)) { + if (isFieldUseDeprecated(fieldBinding, scope, this.bits)) { scope.problemReporter().deprecatedField(fieldBinding, this); } return fieldBinding.type; #P org.eclipse.jdt.core.tests Index: Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/InitializationTest.java =================================================================== RCS file: /home/cvs/numbat/org.eclipse.jdt.core.tests/Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/InitializationTest.java,v retrieving revision 1.128 diff -u -r1.128 InitializationTest.java --- Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/InitializationTest.java 27 May 2010 14:12:25 -0000 1.128 +++ Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/InitializationTest.java 21 Oct 2010 14:33:52 -0000 @@ -817,7 +817,7 @@ "4. WARNING in CheckBlankFinals.java (at line 12)\n" + " final int a; // never initialized \n" + " ^\n" + - "The field LocA.a is never read locally\n" + + "The field LocA.a is never used locally\n" + "----------\n" + "5. WARNING in CheckBlankFinals.java (at line 13)\n" + " class LocB { \n" + @@ -827,7 +827,7 @@ "6. WARNING in CheckBlankFinals.java (at line 14)\n" + " final int b; \n" + " ^\n" + - "The field LocA.LocB.b is never read locally\n" + + "The field LocA.LocB.b is never used locally\n" + "----------\n"); } /** @@ -872,7 +872,7 @@ "3. WARNING in CheckBlankFinals1.java (at line 9)\n" + " final int a; // never initialized\n" + " ^\n" + - "The field LocA.a is never read locally\n" + + "The field LocA.a is never used locally\n" + "----------\n" + "4. WARNING in CheckBlankFinals1.java (at line 10)\n" + " class LocB {\n" + @@ -882,7 +882,7 @@ "5. WARNING in CheckBlankFinals1.java (at line 11)\n" + " final int b; \n" + " ^\n" + - "The field LocA.LocB.b is never read locally\n" + + "The field LocA.LocB.b is never used locally\n" + "----------\n"); } /** @@ -920,7 +920,7 @@ "3. WARNING in CheckBlankFinals2.java (at line 6)\n" + " final int a; // never initialized\n" + " ^\n" + - "The field LocA.a is never read locally\n" + + "The field LocA.a is never used locally\n" + "----------\n" + "4. WARNING in CheckBlankFinals2.java (at line 7)\n" + " class LocB {\n" + @@ -935,7 +935,7 @@ "6. WARNING in CheckBlankFinals2.java (at line 8)\n" + " final int b; // never initialized\n" + " ^\n" + - "The field LocA.LocB.b is never read locally\n" + + "The field LocA.LocB.b is never used locally\n" + "----------\n"); } /** @@ -972,7 +972,7 @@ "3. WARNING in CheckBlankFinals3.java (at line 6)\n" + " final int b; \n" + " ^\n" + - "The field MemberB.b is never read locally\n" + + "The field MemberB.b is never used locally\n" + "----------\n"); } /** @@ -1056,7 +1056,7 @@ "1. WARNING in Outer.java (at line 6)\n" + " int n = count; \n" + " ^\n" + - "The field Local.n is never read locally\n" + + "The field Local.n is never used locally\n" + "----------\n" + "2. ERROR in Outer.java (at line 6)\n" + " int n = count; \n" + @@ -1158,7 +1158,7 @@ "3. WARNING in Outer12.java (at line 8)\n" + " int n = count + count; // another compiler rejects\n" + " ^\n" + - "The field Local2.n is never read locally\n" + + "The field Local2.n is never used locally\n" + "----------\n" + "4. ERROR in Outer12.java (at line 8)\n" + " int n = count + count; // another compiler rejects\n" + @@ -5328,12 +5328,12 @@ "2. WARNING in Test2.java (at line 8)\n" + " final int innerField = 0;\n" + " ^^^^^^^^^^\n" + - "The field new Test2(){}.innerField is never read locally\n" + + "The field new Test2(){}.innerField is never used locally\n" + "----------\n" + "3. WARNING in Test2.java (at line 9)\n" + " final int innerField21;\n" + " ^^^^^^^^^^^^\n" + - "The field new Test2(){}.innerField21 is never read locally\n" + + "The field new Test2(){}.innerField21 is never used locally\n" + "----------\n"); } public void test184() { @@ -5359,12 +5359,12 @@ "2. WARNING in Test2.java (at line 5)\n" + " final int innerField;\n" + " ^^^^^^^^^^\n" + - "The field new Test2(){}.innerField is never read locally\n" + + "The field new Test2(){}.innerField is never used locally\n" + "----------\n" + "3. WARNING in Test2.java (at line 6)\n" + " final int innerField21 = 0;\n" + " ^^^^^^^^^^^^\n" + - "The field new Test2(){}.innerField21 is never read locally\n" + + "The field new Test2(){}.innerField21 is never used locally\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=88562 @@ -5417,7 +5417,7 @@ "1. WARNING in X.java (at line 2)\n" + " private boolean isDbUpdate;\n" + " ^^^^^^^^^^\n" + - "The field X.isDbUpdate is never read locally\n" + + "The private field X.isDbUpdate is never used\n" + "----------\n" + "2. ERROR in X.java (at line 5)\n" + " Zork z;\n" + @@ -5752,7 +5752,7 @@ "1. WARNING in X.java (at line 3)\n" + " private final Object mDependent = new Object() {\n" + " ^^^^^^^^^^\n" + - "The field X.mDependent is never read locally\n" + + "The private field X.mDependent is never used\n" + "----------\n" + "2. WARNING in X.java (at line 5)\n" + " Object o1 = mObj;\n" + @@ -5767,7 +5767,7 @@ "4. WARNING in X.java (at line 7)\n" + " Object o2 = mObj;\n" + " ^^\n" + - "The field new Object(){}.o2 is never read locally\n" + + "The field new Object(){}.o2 is never used locally\n" + "----------\n" + "5. WARNING in X.java (at line 7)\n" + " Object o2 = mObj;\n" + @@ -5817,7 +5817,7 @@ "1. WARNING in X.java (at line 3)\n" + " private final Object mDependent = new Object() {\n" + " ^^^^^^^^^^\n" + - "The field X.mDependent is never read locally\n" + + "The private field X.mDependent is never used\n" + "----------\n" + "2. WARNING in X.java (at line 5)\n" + " Object o1 = mObj;\n" + @@ -5842,7 +5842,7 @@ "6. WARNING in X.java (at line 8)\n" + " Object o2 = mObj = \"2\";\n" + " ^^\n" + - "The field new Object(){}.o2 is never read locally\n" + + "The field new Object(){}.o2 is never used locally\n" + "----------\n" + "7. WARNING in X.java (at line 8)\n" + " Object o2 = mObj = \"2\";\n" + @@ -5960,7 +5960,7 @@ "2. WARNING in X.java (at line 5)\n" + " int j = hello;\n" + " ^\n" + - "The field new Object(){}.j is never read locally\n" + + "The field new Object(){}.j is never used locally\n" + "----------\n" + "3. ERROR in X.java (at line 5)\n" + " int j = hello;\n" + @@ -5993,7 +5993,7 @@ "2. WARNING in X.java (at line 6)\n" + " int j = hello;\n" + " ^\n" + - "The field new Object(){}.j is never read locally\n" + + "The field new Object(){}.j is never used locally\n" + "----------\n" + "3. ERROR in X.java (at line 6)\n" + " int j = hello;\n" + @@ -6025,7 +6025,7 @@ "1. WARNING in X.java (at line 6)\n" + " int i = X.this.hello;\n" + " ^\n" + - "The field new Object(){}.i is never read locally\n" + + "The field new Object(){}.i is never used locally\n" + "----------\n" + "2. ERROR in X.java (at line 9)\n" + " public X(int a) {\n" + @@ -6035,7 +6035,7 @@ "3. WARNING in X.java (at line 11)\n" + " int j = X.this.hello;\n" + " ^\n" + - "The field new Object(){}.j is never read locally\n" + + "The field new Object(){}.j is never used locally\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=257716 - variation @@ -6064,7 +6064,7 @@ "1. WARNING in X.java (at line 7)\n" + " int i = x.hello;\n" + " ^\n" + - "The field new Object(){}.i is never read locally\n" + + "The field new Object(){}.i is never used locally\n" + "----------\n" + "2. ERROR in X.java (at line 10)\n" + " public X(int a) {\n" + @@ -6074,7 +6074,7 @@ "3. WARNING in X.java (at line 13)\n" + " int j = x.hello;\n" + " ^\n" + - "The field new Object(){}.j is never read locally\n" + + "The field new Object(){}.j is never used locally\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=257716 - variation @@ -6113,12 +6113,12 @@ "3. WARNING in X.java (at line 7)\n" + " int i = hello;\n" + " ^\n" + - "The field new Object(){}.i is never read locally\n" + + "The field new Object(){}.i is never used locally\n" + "----------\n" + "4. WARNING in X.java (at line 12)\n" + " int j = hello;\n" + " ^\n" + - "The field new Object(){}.j is never read locally\n" + + "The field new Object(){}.j is never used locally\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=257716 - variation @@ -6155,12 +6155,12 @@ "2. WARNING in X.java (at line 6)\n" + " Object o = new Object() {\n" + " ^\n" + - "The field Local.o is never read locally\n" + + "The field Local.o is never used locally\n" + "----------\n" + "3. WARNING in X.java (at line 7)\n" + " int i = hello;\n" + " ^\n" + - "The field new Object(){}.i is never read locally\n" + + "The field new Object(){}.i is never used locally\n" + "----------\n" + "4. ERROR in X.java (at line 11)\n" + " public X(int a) {\n" + @@ -6175,12 +6175,12 @@ "6. WARNING in X.java (at line 13)\n" + " Object o = new Object() {\n" + " ^\n" + - "The field Local.o is never read locally\n" + + "The field Local.o is never used locally\n" + "----------\n" + "7. WARNING in X.java (at line 14)\n" + " int j = hello;\n" + " ^\n" + - "The field new Object(){}.j is never read locally\n" + + "The field new Object(){}.j is never used locally\n" + "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=257716 - variation @@ -6220,7 +6220,7 @@ "1. WARNING in X.java (at line 10)\n" + " int i = new Object() {\n" + " ^\n" + - "The field new X(){}.i is never read locally\n" + + "The field new X(){}.i is never used locally\n" + "----------\n" + "2. ERROR in X.java (at line 15)\n" + " public X(int i) {\n" + @@ -6230,7 +6230,7 @@ "3. WARNING in X.java (at line 21)\n" + " int k = new Object() { \n" + " ^\n" + - "The field new X(){}.k is never read locally\n" + + "The field new X(){}.k is never used locally\n" + "----------\n" + "4. ERROR in X.java (at line 22)\n" + " int l = hello + world; \n" + Index: Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java =================================================================== RCS file: /home/cvs/numbat/org.eclipse.jdt.core.tests/Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java,v retrieving revision 1.342 diff -u -r1.342 NegativeTest.java --- Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java 13 Sep 2010 13:26:17 -0000 1.342 +++ Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java 21 Oct 2010 14:33:52 -0000 @@ -11404,7 +11404,7 @@ "1. WARNING in Test.java (at line 12)\n" + " int i = 0; \n" + " ^\n" + - "The local variable i is never read\n" + + "The local variable i is never used\n" + "----------\n", null, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); } @@ -11542,7 +11542,7 @@ "3. WARNING in X.java (at line 28)\n" + " Object obj = \"dummy\"; \n" + " ^^^\n" + - "The local variable obj is never read\n" + + "The local variable obj is never used\n" + "----------\n" + "4. WARNING in X.java (at line 36)\n" + " if (false) { \n" + @@ -12408,7 +12408,7 @@ "1. ERROR in p\\X.java (at line 3)\n" + " void unused(int someParam0) {} \n" + " ^^^^^^^^^^\n" + - "The parameter someParam0 is never read\n" + + "The parameter someParam0 is never used\n" + "----------\n", JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); } @@ -12449,22 +12449,22 @@ "1. ERROR in p\\X.java (at line 3)\n" + " void unused(int someParam0) {} \n" + " ^^^^^^^^^^\n" + - "The parameter someParam0 is never read\n" + + "The parameter someParam0 is never used\n" + "----------\n" + "2. ERROR in p\\X.java (at line 7)\n" + " public void concrete(int someParam3){} \n" + " ^^^^^^^^^^\n" + - "The parameter someParam3 is never read\n" + + "The parameter someParam3 is never used\n" + "----------\n" + "3. ERROR in p\\X.java (at line 10)\n" + " public void foo(int someParam4) {} \n" + " ^^^^^^^^^^\n" + - "The parameter someParam4 is never read\n" + + "The parameter someParam4 is never used\n" + "----------\n" + "4. ERROR in p\\X.java (at line 12)\n" + " public void concrete(int someParam6) {} \n" + " ^^^^^^^^^^\n" + - "The parameter someParam6 is never read\n" + + "The parameter someParam6 is never used\n" + "----------\n", JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); } @@ -12505,22 +12505,22 @@ "1. ERROR in p\\X.java (at line 3)\n" + " void unused(int someParam0) {} \n" + " ^^^^^^^^^^\n" + - "The parameter someParam0 is never read\n" + + "The parameter someParam0 is never used\n" + "----------\n" + "2. ERROR in p\\X.java (at line 5)\n" + " public void foo(int someParam1) {} \n" + " ^^^^^^^^^^\n" + - "The parameter someParam1 is never read\n" + + "The parameter someParam1 is never used\n" + "----------\n" + "3. ERROR in p\\X.java (at line 7)\n" + " public void concrete(int someParam3){} \n" + " ^^^^^^^^^^\n" + - "The parameter someParam3 is never read\n" + + "The parameter someParam3 is never used\n" + "----------\n" + "4. ERROR in p\\X.java (at line 11)\n" + " public void bar(int someParam5) {} \n" + " ^^^^^^^^^^\n" + - "The parameter someParam5 is never read\n" + + "The parameter someParam5 is never used\n" + "----------\n", JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); } @@ -15039,7 +15039,7 @@ "1. ERROR in X.java (at line 6)\n" + " private final int unused = 0;\n" + " ^^^^^^\n" + - "The field X.unused is never read locally\n" + + "The private field X.unused is never used\n" + "----------\n", JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); } #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java,v retrieving revision 1.218 diff -u -r1.218 AnnotationTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java 22 Jun 2010 02:31:11 -0000 1.218 +++ src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java 21 Oct 2010 14:33:52 -0000 @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Stephan Herrmann - Contribution for bug 295551 + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -9355,7 +9356,7 @@ "1. ERROR in A.java (at line 3)\n" + " private int i;\n" + " ^\n" + - "The field A.i is never read locally\n" + + "The private field A.i is never used\n" + "----------\n"; runNegativeTest( true, Index: src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java,v retrieving revision 1.65 diff -u -r1.65 AssignmentTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java 21 Jan 2010 16:48:42 -0000 1.65 +++ src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java 21 Oct 2010 14:33:52 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -223,12 +224,12 @@ "1. WARNING in X.java (at line 4)\n" + " private final Object o;\n" + " ^\n" + - "The field X.Test1.o is never read locally\n" + + "The private field X.Test1.o is never used\n" + "----------\n" + "2. WARNING in X.java (at line 13)\n" + " private final Object o;\n" + " ^\n" + - "The field X.Test2.o is never read locally\n" + + "The private field X.Test2.o is never used\n" + "----------\n" + "3. ERROR in X.java (at line 25)\n" + " System.out.println(o); // illegal; o is not definitely assigned\n" + @@ -238,7 +239,7 @@ "4. WARNING in X.java (at line 42)\n" + " private final Object o;\n" + " ^\n" + - "The field X.Test5.o is never read locally\n" + + "The private field X.Test5.o is never used\n" + "----------\n" + "5. ERROR in X.java (at line 44)\n" + " Test5() {\n" + @@ -253,7 +254,7 @@ "7. WARNING in X.java (at line 52)\n" + " private final Object o;\n" + " ^\n" + - "The field X.Test6.o is never read locally\n" + + "The private field X.Test6.o is never used\n" + "----------\n" + "8. ERROR in X.java (at line 59)\n" + " other.o = new Object(); // illegal! other.o is not assignable\n" + Index: src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java,v retrieving revision 1.215 diff -u -r1.215 BatchCompilerTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 6 Oct 2010 13:57:31 -0000 1.215 +++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 21 Oct 2010 14:33:52 -0000 @@ -10,6 +10,7 @@ * Benjamin Muskalla - Contribution for bug 239066 * Stephan Herrmann - Contribution for bug 236385 * Stephan Herrmann - Contribution for bug 295551 + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -2879,7 +2880,7 @@ "7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/Z.java (at line 58)\n" + " final XX l1 = (XX) i.getKey();\n" + " ^^\n" + - "The local variable l1 is never read\n" + + "The local variable l1 is never used\n" + "----------\n" + "8. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/Z.java (at line 58)\n" + " final XX l1 = (XX) i.getKey();\n" + @@ -3059,7 +3060,7 @@ "7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/Z.java (at line 58)\n" + " final XX l1 = (XX) i.getKey();\n" + " ^^\n" + - "The local variable l1 is never read\n" + + "The local variable l1 is never used\n" + "----------\n" + "8. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/Z.java (at line 58)\n" + " final XX l1 = (XX) i.getKey();\n" + @@ -6228,7 +6229,7 @@ "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " String u;\n" + " ^\n" + - "The local variable u is never read\n" + + "The local variable u is never used\n" + "----------\n" + "2 problems (2 warnings)", true); @@ -6315,7 +6316,7 @@ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " String u;\n" + " ^\n" + - "The local variable u is never read\n" + + "The local variable u is never used\n" + "----------\n" + "1 problem (1 warning)", true); @@ -6347,7 +6348,7 @@ "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " String u;\n" + " ^\n" + - "The local variable u is never read\n" + + "The local variable u is never used\n" + "----------\n" + "2 problems (2 warnings)", true); @@ -6374,7 +6375,7 @@ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " String u;\n" + " ^\n" + - "The local variable u is never read\n" + + "The local variable u is never used\n" + "----------\n" + "1 problem (1 warning)", true); @@ -6400,7 +6401,7 @@ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " String u;\n" + " ^\n" + - "The local variable u is never read\n" + + "The local variable u is never used\n" + "----------\n" + "1 problem (1 warning)", true); @@ -6431,7 +6432,7 @@ "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " String u;\n" + " ^\n" + - "The local variable u is never read\n" + + "The local variable u is never used\n" + "----------\n" + "2 problems (2 warnings)", true); @@ -6463,7 +6464,7 @@ "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " String u;\n" + " ^\n" + - "The local variable u is never read\n" + + "The local variable u is never used\n" + "----------\n" + "2 problems (2 warnings)", true); @@ -7564,7 +7565,7 @@ "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" + " int j;\n" + " ^\n" + - "The local variable j is never read\n" + + "The local variable j is never used\n" + "----------\n" + "4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " this.bar();\n" + @@ -7627,7 +7628,7 @@ "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private void foo(int i) throws java.io.IOException {\n" + " ^\n" + - "The parameter i is never read\n" + + "The parameter i is never used\n" + "----------\n" + "4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private void foo(int i) throws java.io.IOException {\n" + @@ -7637,7 +7638,7 @@ "5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" + " int j;\n" + " ^\n" + - "The local variable j is never read\n" + + "The local variable j is never used\n" + "----------\n" + "6. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " this.bar();\n" + @@ -7682,7 +7683,7 @@ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private void foo(int i) throws java.io.IOException {\n" + " ^\n" + - "The parameter i is never read\n" + + "The parameter i is never used\n" + "----------\n" + "1 problem (1 warning)", true); @@ -7787,7 +7788,7 @@ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" + " int j;\n" + " ^\n" + - "The local variable j is never read\n" + + "The local variable j is never used\n" + "----------\n" + "1 problem (1 warning)", true); @@ -7942,7 +7943,7 @@ "4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" + " int j;\n" + " ^\n" + - "The local variable j is never read\n" + + "The local variable j is never used\n" + "----------\n" + "5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " this.bar();\n" + @@ -7992,7 +7993,7 @@ "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private void foo(int i) throws java.io.IOException {\n" + " ^\n" + - "The parameter i is never read\n" + + "The parameter i is never used\n" + "----------\n" + "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private void foo(int i) throws java.io.IOException {\n" + @@ -8002,7 +8003,7 @@ "4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" + " int j;\n" + " ^\n" + - "The local variable j is never read\n" + + "The local variable j is never used\n" + "----------\n" + "5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " this.bar();\n" + @@ -8057,7 +8058,7 @@ "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private void foo(int i) throws java.io.IOException {\n" + " ^\n" + - "The parameter i is never read\n" + + "The parameter i is never used\n" + "----------\n" + "4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private void foo(int i) throws java.io.IOException {\n" + @@ -8067,7 +8068,7 @@ "5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" + " int j;\n" + " ^\n" + - "The local variable j is never read\n" + + "The local variable j is never used\n" + "----------\n" + "6. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " this.bar();\n" + @@ -8117,7 +8118,7 @@ "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private void foo(int i) throws java.io.IOException {\n" + " ^\n" + - "The parameter i is never read\n" + + "The parameter i is never used\n" + "----------\n" + "4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private void foo(int i) throws java.io.IOException {\n" + @@ -8172,7 +8173,7 @@ "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private void foo(int i) throws java.io.IOException {\n" + " ^\n" + - "The parameter i is never read\n" + + "The parameter i is never used\n" + "----------\n" + "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private void foo(int i) throws java.io.IOException {\n" + @@ -8182,7 +8183,7 @@ "4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" + " int j;\n" + " ^\n" + - "The local variable j is never read\n" + + "The local variable j is never used\n" + "----------\n" + "5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " this.bar();\n" + @@ -8237,12 +8238,12 @@ "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private void foo(int i) throws java.io.IOException {\n" + " ^\n" + - "The parameter i is never read\n" + + "The parameter i is never used\n" + "----------\n" + "4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" + " int j;\n" + " ^\n" + - "The local variable j is never read\n" + + "The local variable j is never used\n" + "----------\n" + "5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " this.bar();\n" + @@ -8297,7 +8298,7 @@ "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private void foo(int i) throws java.io.IOException {\n" + " ^\n" + - "The parameter i is never read\n" + + "The parameter i is never used\n" + "----------\n" + "4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private void foo(int i) throws java.io.IOException {\n" + @@ -8307,7 +8308,7 @@ "5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" + " int j;\n" + " ^\n" + - "The local variable j is never read\n" + + "The local variable j is never used\n" + "----------\n" + "6. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 6)\n" + " next: for (;;) {\n" + @@ -8380,7 +8381,7 @@ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " public void foo(int i) {\n" + " ^\n" + - "The parameter i is never read\n" + + "The parameter i is never used\n" + "----------\n" + "1 problem (1 warning)", true); @@ -8471,7 +8472,7 @@ "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " public void foo(int i) {\n" + " ^\n" + - "The parameter i is never read\n" + + "The parameter i is never used\n" + "----------\n" + "2 problems (2 warnings)", true); @@ -8497,7 +8498,7 @@ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " public void foo(int i) {\n" + " ^\n" + - "The parameter i is never read\n" + + "The parameter i is never used\n" + "----------\n" + "1 problem (1 warning)", true); @@ -8979,7 +8980,7 @@ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + " public void foo(int i) {\n" + " ^\n" + - "The parameter i is never read\n" + + "The parameter i is never used\n" + "----------\n" + "1 problem (1 warning)", true); @@ -11334,7 +11335,7 @@ "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private int i;\n" + " ^\n" + - "The field X.i is never read locally\n" + + "The private field X.i is never used\n" + "----------\n" + "2 problems (1 error, 1 warning)", true); @@ -11374,7 +11375,7 @@ "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private int i;\n" + " ^\n" + - "The field X.i is never read locally\n" + + "The private field X.i is never used\n" + "----------\n" + "1 problem (1 error)", true); @@ -11397,7 +11398,7 @@ "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private int i;\n" + " ^\n" + - "The field X.i is never read locally\n" + + "The private field X.i is never used\n" + "----------\n" + "1 problem (1 error)", true); @@ -11425,7 +11426,7 @@ "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private int i;\n" + " ^\n" + - "The field X.i is never read locally\n" + + "The private field X.i is never used\n" + "----------\n" + "2 problems (1 error, 1 warning)", true); @@ -11448,7 +11449,7 @@ "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + " private int i;\n" + " ^\n" + - "The field X.i is never read locally\n" + + "The private field X.i is never used\n" + "----------\n" + "1 problem (1 error)", true); Index: src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java,v retrieving revision 1.37 diff -u -r1.37 CompilerInvocationTests.java --- src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java 7 Sep 2010 13:39:17 -0000 1.37 +++ src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java 21 Oct 2010 14:33:52 -0000 @@ -9,6 +9,7 @@ * IBM Corporation - initial API and implementation * Benjamin Muskalla - Contribution for bug 239066 * Stephan Herrmann - Contribution for bug 236385 + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -848,6 +849,7 @@ expectedProblemAttributes.put("UnusedObjectAllocation", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("UnusedScopedField", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); expectedProblemAttributes.put("UnusedPrivateType", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); expectedProblemAttributes.put("UnusedTypeArgumentsForConstructorInvocation", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); @@ -1482,6 +1484,7 @@ expectedProblemAttributes.put("UnusedObjectAllocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_OBJECT_ALLOCATION)); expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER)); expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER)); + expectedProblemAttributes.put("UnusedScopedField", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER)); expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER)); expectedProblemAttributes.put("UnusedPrivateType", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER)); expectedProblemAttributes.put("UnusedTypeArgumentsForConstructorInvocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_TYPE_ARGUMENTS_FOR_METHOD_INVOCATION)); Index: src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java,v retrieving revision 1.108 diff -u -r1.108 Compliance_1_4.java --- src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java 1 Jul 2010 04:39:13 -0000 1.108 +++ src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java 21 Oct 2010 14:33:53 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -1713,7 +1714,7 @@ "1. WARNING in p\\A.java (at line 6)\n" + " private int i;\n" + " ^\n" + - "The field A.i is never read locally\n" + + "The private field A.i is never used\n" + "----------\n" + "2. ERROR in p\\A.java (at line 8)\n" + " int x = i;\n" + @@ -1946,7 +1947,7 @@ "3. WARNING in p\\FieldQualification.java (at line 6)\n" + " String field = \"Enclosing field for anonymous type\";\n" + " ^^^^^\n" + - "The field Local.field is never read locally\n" + + "The field Local.field is never used locally\n" + "----------\n" + "4. WARNING in p\\FieldQualification.java (at line 7)\n" + " void foo() {\n" + Index: src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java,v retrieving revision 1.71 diff -u -r1.71 JavadocBugsTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java 18 Mar 2010 16:22:36 -0000 1.71 +++ src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java 21 Oct 2010 14:33:53 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -7190,12 +7191,12 @@ "1. WARNING in X.java (at line 2)\n" + " private int unused1;\n" + " ^^^^^^^\n" + - "The field X.unused1 is never read locally\n" + + "The private field X.unused1 is never used\n" + "----------\n" + "2. WARNING in X.java (at line 7)\n" + " private int unused2;\n" + " ^^^^^^^\n" + - "The field X.unused2 is never read locally\n" + + "The private field X.unused2 is never used\n" + "----------\n", null, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings Index: src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java,v retrieving revision 1.51 diff -u -r1.51 JavadocTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java 11 May 2010 18:53:50 -0000 1.51 +++ src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java 21 Oct 2010 14:33:53 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -279,7 +280,7 @@ "1. WARNING in test\\AbstractVisibility.java (at line 5)\n" + " public int avf_public = avf_private;\n" + " ^^^^^^^^^^\n" + - "The field AbstractVisibility.AvcPrivate.avf_public is never read locally\n" + + "The field AbstractVisibility.AvcPrivate.avf_public is never used locally\n" + "----------\n" + "2. WARNING in test\\AbstractVisibility.java (at line 10)\n" + " public int avm_public() {\n" + @@ -290,7 +291,7 @@ "1. WARNING in test\\Visibility.java (at line 5)\n" + " public int vf_public = vf_private;\n" + " ^^^^^^^^^\n" + - "The field Visibility.VcPrivate.vf_public is never read locally\n" + + "The field Visibility.VcPrivate.vf_public is never used locally\n" + "----------\n" + "2. WARNING in test\\Visibility.java (at line 11)\n" + " public int vm_public() {\n" + @@ -301,7 +302,7 @@ "1. WARNING in test\\copy\\VisibilityPackage.java (at line 5)\n" + " public int vf_public = vf_private;\n" + " ^^^^^^^^^\n" + - "The field VisibilityPackage.VpPrivate.vf_public is never read locally\n" + + "The field VisibilityPackage.VpPrivate.vf_public is never used locally\n" + "----------\n" + "2. WARNING in test\\copy\\VisibilityPackage.java (at line 10)\n" + " public int vm_public() {\n" + @@ -312,7 +313,7 @@ "1. WARNING in test\\copy\\VisibilityPublic.java (at line 5)\n" + " public int vf_public = vf_private;\n" + " ^^^^^^^^^\n" + - "The field VisibilityPublic.VpPrivate.vf_public is never read locally\n" + + "The field VisibilityPublic.VpPrivate.vf_public is never used locally\n" + "----------\n" + "2. WARNING in test\\copy\\VisibilityPublic.java (at line 10)\n" + " public int vm_public() {\n" + Index: src/org/eclipse/jdt/core/tests/compiler/regression/LocalVariableTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalVariableTest.java,v retrieving revision 1.18 diff -u -r1.18 LocalVariableTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/LocalVariableTest.java 27 Jun 2008 16:04:44 -0000 1.18 +++ src/org/eclipse/jdt/core/tests/compiler/regression/LocalVariableTest.java 21 Oct 2010 14:33:53 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. + * Copyright (c) 2005, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -411,7 +412,7 @@ "1. ERROR in X.java (at line 7)\n" + " void bar(int value) { // X#bar(...)\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n", // javac options JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); @@ -469,17 +470,17 @@ "1. ERROR in X.java (at line 5)\n" + " void foo(int value) { // X#foo(...)\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n" + "2. ERROR in X.java (at line 7)\n" + " void bar(int value) { // X#bar(...)\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n" + "3. ERROR in X.java (at line 24)\n" + " void parent(int value) { /* Parent#parent(...) */}\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n", // javac options JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); @@ -537,17 +538,17 @@ "1. ERROR in X.java (at line 5)\n" + " void foo(int value) { // X#foo(...)\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n" + "2. ERROR in X.java (at line 7)\n" + " void bar(int value) { // X#bar(...)\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n" + "3. ERROR in X.java (at line 24)\n" + " void parent(int value) { /* Parent#parent(...) */}\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n", // javac options JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); @@ -605,32 +606,32 @@ "1. ERROR in X.java (at line 5)\n" + " void foo(int value) { // X#foo(...)\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n" + "2. ERROR in X.java (at line 7)\n" + " void bar(int value) { // X#bar(...)\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n" + "3. ERROR in X.java (at line 10)\n" + " void top(int value) { /* X#top(...)*/}\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n" + "4. ERROR in X.java (at line 11)\n" + " void parent(int value) { /* X#parent(...) */}\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n" + "5. ERROR in X.java (at line 12)\n" + " public void doit(int value) { /* X#doit(...) */}\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n" + "6. ERROR in X.java (at line 24)\n" + " void parent(int value) { /* Parent#parent(...) */}\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n", // javac options JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); @@ -683,32 +684,32 @@ "1. ERROR in X.java (at line 3)\n" + " void foo(int value) { // X#foo(...)\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n" + "2. ERROR in X.java (at line 5)\n" + " void bar(int value) { // X#bar(...)\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n" + "3. ERROR in X.java (at line 9)\n" + " void top(int value) { /* X#top(...)*/}\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n" + "4. ERROR in X.java (at line 11)\n" + " void parent(int value) { /* X#parent(...) */}\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n" + "5. ERROR in X.java (at line 13)\n" + " public void doit(int value) { /* X#doit(...) */}\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n" + "6. ERROR in X.java (at line 21)\n" + " void parent(int value) { /* Parent#parent(...) */}\n" + " ^^^^^\n" + - "The parameter value is never read\n" + + "The parameter value is never used\n" + "----------\n", // javac options JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); Index: src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java,v retrieving revision 1.86 diff -u -r1.86 LookupTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java 13 Jul 2010 03:55:58 -0000 1.86 +++ src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java 21 Oct 2010 14:33:53 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -94,7 +95,7 @@ "1. WARNING in p1\\A.java (at line 3)\n" + " private int value; \n" + " ^^^^^\n" + - "The field A.value is never read locally\n" + + "The private field A.value is never used\n" + "----------\n" + "2. ERROR in p1\\A.java (at line 6)\n" + " value = 2; \n" + @@ -344,7 +345,7 @@ "1. WARNING in p1\\A.java (at line 3)\n" + " private String success = \"SUCCESS\"; \n" + " ^^^^^^^\n" + - "The field A.success is never read locally\n" + + "The private field A.success is never used\n" + "----------\n" + "2. ERROR in p1\\A.java (at line 7)\n" + " public void aTask() {System.out.println(A.success);}\n" + @@ -2263,7 +2264,7 @@ "1. WARNING in com\\internap\\other\\ScopeExample.java (at line 4)\r\n" + " private static final String LOGGER = \"FAILED\";\r\n" + " ^^^^^^\n" + - "The field ScopeExample.LOGGER is never read locally\n" + + "The private field ScopeExample.LOGGER is never used\n" + "----------\n" + "2. ERROR in com\\internap\\other\\ScopeExample.java (at line 8)\r\n" + " System.out.println(LOGGER);\r\n" + @@ -2654,7 +2655,7 @@ "1. WARNING in X.java (at line 2)\n" + " private String value;\n" + " ^^^^^\n" + - "The field D.value is never read locally\n" + + "The private field D.value is never used\n" + "----------\n" + "2. ERROR in X.java (at line 13)\n" + " super(getValue());\n" + @@ -3264,12 +3265,12 @@ "2. WARNING in B.java (at line 3)\n" + " public final String length = \"very long\";\n" + " ^^^^^^\n" + - "The field A.B.length is never read locally\n" + + "The field A.B.length is never used locally\n" + "----------\n" + "3. WARNING in B.java (at line 5)\n" + " private int [] B = new int[5];\n" + " ^\n" + - "The field A.B is never read locally\n" + + "The private field A.B is never used\n" + "----------\n" + "4. ERROR in B.java (at line 9)\n" + " System.out.println(A.B.length);\n" + @@ -3298,12 +3299,12 @@ "1. WARNING in B.java (at line 3)\n" + " private final String length = \"very long\";\n" + " ^^^^^^\n" + - "The field A.B.length is never read locally\n" + + "The private field A.B.length is never used\n" + "----------\n" + "2. WARNING in B.java (at line 5)\n" + " private int [] B = new int[5];\n" + " ^\n" + - "The field A.B is never read locally\n" + + "The private field A.B is never used\n" + "----------\n" + "3. ERROR in B.java (at line 9)\n" + " System.out.println(A.B.length);\n" + @@ -3338,17 +3339,17 @@ "1. WARNING in A.java (at line 2)\n" + " private int x;\n" + " ^\n" + - "The field A.x is never read locally\n" + + "The private field A.x is never used\n" + "----------\n" + "2. WARNING in A.java (at line 4)\n" + " private int x;\n" + " ^\n" + - "The field A.B.x is never read locally\n" + + "The private field A.B.x is never used\n" + "----------\n" + "3. WARNING in A.java (at line 5)\n" + " private C c = new C() {\n" + " ^\n" + - "The field A.B.c is never read locally\n" + + "The private field A.B.c is never used\n" + "----------\n" + "4. WARNING in A.java (at line 6)\n" + " void foo() {\n" + @@ -3363,7 +3364,7 @@ "6. WARNING in A.java (at line 12)\n" + " private int x;\n" + " ^\n" + - "The field A.C.x is never read locally\n" + + "The private field A.C.x is never used\n" + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=316956 @@ -3393,17 +3394,17 @@ "1. WARNING in A.java (at line 2)\n" + " private int x;\n" + " ^\n" + - "The field A.x is never read locally\n" + + "The private field A.x is never used\n" + "----------\n" + "2. WARNING in A.java (at line 4)\n" + " private int x;\n" + " ^\n" + - "The field A.B.x is never read locally\n" + + "The private field A.B.x is never used\n" + "----------\n" + "3. WARNING in A.java (at line 5)\n" + " private C c = new C() {\n" + " ^\n" + - "The field A.B.c is never read locally\n" + + "The private field A.B.c is never used\n" + "----------\n" + "4. WARNING in A.java (at line 6)\n" + " void foo() {\n" + @@ -3435,12 +3436,12 @@ "1. WARNING in A.java (at line 2)\n" + " private int x;\n" + " ^\n" + - "The field A.x is never read locally\n" + + "The private field A.x is never used\n" + "----------\n" + "2. WARNING in A.java (at line 3)\n" + " private C c = new C() {\n" + " ^\n" + - "The field A.c is never read locally\n" + + "The private field A.c is never used\n" + "----------\n" + "3. WARNING in A.java (at line 4)\n" + " void foo() {\n" + @@ -3455,7 +3456,7 @@ "5. WARNING in A.java (at line 9)\n" + " private int x;\n" + " ^\n" + - "The field A.C.x is never read locally\n" + + "The private field A.C.x is never used\n" + "----------\n"); } public static Class testClass() { return LookupTest.class; Index: src/org/eclipse/jdt/core/tests/compiler/regression/ProblemConstructorTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemConstructorTest.java,v retrieving revision 1.24 diff -u -r1.24 ProblemConstructorTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/ProblemConstructorTest.java 28 Apr 2009 17:17:33 -0000 1.24 +++ src/org/eclipse/jdt/core/tests/compiler/regression/ProblemConstructorTest.java 21 Oct 2010 14:33:53 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -185,7 +186,7 @@ "3. WARNING in X.java (at line 6)\n" + " public int unusedField = 0;\n" + " ^^^^^^^^^^^\n" + - "The field X.M.unusedField is never read locally\n" + + "The field X.M.unusedField is never used locally\n" + "----------\n" + "4. WARNING in X.java (at line 7)\n" + " public class N {}\n" + Index: src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java,v retrieving revision 1.25 diff -u -r1.25 ProgrammingProblemsTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java 23 Sep 2010 12:03:44 -0000 1.25 +++ src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java 21 Oct 2010 14:33:53 -0000 @@ -7,19 +7,21 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; import java.util.HashMap; import java.util.Map; +import junit.framework.Test; + import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.internal.compiler.CompilationResult; import org.eclipse.jdt.internal.compiler.ICompilerRequestor; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; -import junit.framework.Test; /* Collects potential programming problems tests that are not segregated in a * dedicated test class (aka NullReferenceTest). */ @@ -143,7 +145,7 @@ "1. WARNING in X.java (at line 2)\r\n" + " public void foo(boolean b) {\r\n" + " ^\n" + - "The parameter b is never read\n" + + "The parameter b is never used\n" + "----------\n" /* expectedCompilerLog */, "" /* expectedOutputString */, false /* forceExecution */, @@ -214,7 +216,7 @@ "1. WARNING in X.java (at line 3)\n" + " public void foo(boolean b) {\n" + " ^\n" + - "The parameter b is never read\n" + + "The parameter b is never used\n" + "----------\n" /* expectedCompilerLog */, "" /* expectedOutputString */, false /* forceExecution */, @@ -279,7 +281,7 @@ "1. ERROR in X.java (at line 2)\r\n" + " public void foo(boolean b) {\r\n" + " ^\n" + - "The parameter b is never read\n" + + "The parameter b is never used\n" + "----------\n" /* expectedCompilerLog */, "" /* expectedOutputString */, false /* forceExecution */, @@ -555,7 +557,7 @@ "1. WARNING in X.java (at line 3)\n" + " void foo(int unused) throws IOException {}\n" + " ^^^^^^\n" + - "The parameter unused is never read\n" + + "The parameter unused is never used\n" + "----------\n" + "2. ERROR in X.java (at line 3)\n" + " void foo(int unused) throws IOException {}\n" + @@ -594,7 +596,7 @@ "1. WARNING in X.java (at line 3)\n" + " void foo(int unused) throws IOException {}\n" + " ^^^^^^\n" + - "The parameter unused is never read\n" + + "The parameter unused is never used\n" + "----------\n" + "2. WARNING in X.java (at line 3)\n" + " void foo(int unused) throws IOException {}\n" + @@ -631,7 +633,7 @@ "1. ERROR in X.java (at line 2)\n" + " public X(boolean b) {\n" + " ^\n" + - "The parameter b is never read\n" + + "The parameter b is never used\n" + "----------\n" /* expectedCompilerLog */, "" /* expectedOutputString */, false /* forceExecution */, @@ -1683,4 +1685,409 @@ "The assignment to variable nvx has no effect\n" + "----------\n"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +public void test0046() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " int foo() {\n" + + " int i=1;\n" + + " boolean b=false;\n" + + " b|=true;\n" + // not a relevant usage + " int k = 2;\n" + + " --k;\n" + // not a relevant usage + " k+=3;\n" + // not a relevant usage + " Integer j = 3;\n" + + " j++;\n" + // relevant because unboxing is involved + " return i++;\n" + // value after increment is used + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " boolean b=false;\n" + + " ^\n" + + "The local variable b is never used\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " int k = 2;\n" + + " ^\n" + + "The local variable k is never used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +// variant with private fields instead of locals +public void test0046_field() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " private int i=1;\n" + + " private boolean b=false;\n" + + " private int k = 2;\n" + + " private Integer j = 3;\n" + + " int foo() {\n" + + " b|=true;\n" + // not a relevant usage + " --k;\n" + // not a relevant usage + " k+=3;\n" + // not a relevant usage + " j++;\n" + // relevant because unboxing is involved + " return i++;\n" + // value after increment is used + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " private boolean b=false;\n" + + " ^\n" + + "The private field X.b is never used\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " private int k = 2;\n" + + " ^\n" + + "The private field X.k is never used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +// variant with private fields instead of locals - this-qualified access +public void test0046_field_this_qualified() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " private int i=1;\n" + + " private boolean b=false;\n" + + " private int k = 2;\n" + + " private Integer j = 3;\n" + + " int foo() {\n" + + " this.b|=true;\n" + // not a relevant usage + " --this.k;\n" + // not a relevant usage + " getThis().k+=3;\n" + // not a relevant usage + " this.j++;\n" + // relevant because unboxing is involved + " return this.i++;\n" + // value after increment is used + " }\n" + + " X getThis() { return this; }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " private boolean b=false;\n" + + " ^\n" + + "The private field X.b is never used\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " private int k = 2;\n" + + " ^\n" + + "The private field X.k is never used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +// variant with private fields instead of locals - regular qualified access +public void test0046_field_qualified() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " private int i=1;\n" + + " private boolean b=false;\n" + + " private int k = 2;\n" + + " private Integer j = 3;\n" + + " int foo(X that) {\n" + + " that.b|=true;\n" + // not a relevant usage + " --that.k;\n" + // not a relevant usage + " that.k+=3;\n" + // not a relevant usage + " that.j++;\n" + // relevant because unboxing is involved + " return that.i++;\n" + // value after increment is used + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " private boolean b=false;\n" + + " ^\n" + + "The private field X.b is never used\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " private int k = 2;\n" + + " ^\n" + + "The private field X.k is never used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +// variant with fields inside a private type +public void test0046_field_in_private_type() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " private class Y {\n" + + " int i=1;\n" + + " public boolean b=false;\n" + + " protected int k = 2;\n" + + " Integer j = 3;\n" + + " }\n" + + " int foo(Y y) {\n" + + " y.b|=true;\n" + // not a relevant usage + " --y.k;\n" + // not a relevant usage + " y.k+=3;\n" + // not a relevant usage + " y.j++;\n" + // relevant because unboxing is involved + " return y.i++;\n" + // value after increment is used + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public boolean b=false;\n" + + " ^\n" + + "The field X.Y.b is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " protected int k = 2;\n" + + " ^\n" + + "The field X.Y.k is never used locally\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +public void test0047() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(int param1, int param2, Integer param3) {\n" + + " boolean b=false;\n" + + " b|=true;\n" + // not a relevant usage + " param1++;\n" + // not a relevant usage + " param2 += 1;\n" + // not a relevant usage + " param3++;\n" + // relevant because unboxing is involved + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo(int param1, int param2, Integer param3) {\n" + + " ^^^^^^\n" + + "The parameter param1 is never used\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " void foo(int param1, int param2, Integer param3) {\n" + + " ^^^^^^\n" + + "The parameter param2 is never used\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " boolean b=false;\n" + + " ^\n" + + "The local variable b is never used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +// To verify that unused parameter warning is not shown for an implementing method's parameter when +// CompilerOptions.OPTION_ReportUnusedParameterWhenImplementingAbstract is disabled +public void test0048() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING); + customOptions.put(CompilerOptions.OPTION_ReportUnusedParameterWhenImplementingAbstract, CompilerOptions.DISABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends A implements Y{\n" + + " public void foo(int param1, int param2, Integer param3) {\n" + // implementing method, so dont warn + " boolean b=false;\n" + + " b|=true;\n" + // not a relevant usage + " param1++;\n" + // not a relevant usage + " param2 += 1;\n" + // not a relevant usage + " param3++;\n" + // relevant because unboxing is involved + " }\n" + + " public void foo(int param1, int param2) {\n" + // warn + " boolean b=false;\n" + + " b|=true;\n" + // not a relevant usage + " param1++;\n" + // not a relevant usage + " param2 += 1;\n" + // not a relevant usage + " }\n" + + " public void bar(int param1, int param2, Integer param3) {\n" + // implementing method, so dont warn + " param1++;\n" + // not a relevant usage + " param2 += 1;\n" + // not a relevant usage + " param3++;\n" + // relevant because unboxing is involved + " }\n" + + "}\n" + + "interface Y{\n" + + " public void foo(int param1, int param2, Integer param3);" + + "}\n" + + "abstract class A{\n" + + " public abstract void bar(int param1, int param2, Integer param3);" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " boolean b=false;\n" + + " ^\n" + + "The local variable b is never used\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " public void foo(int param1, int param2) {\n" + + " ^^^^^^\n" + + "The parameter param1 is never used\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " public void foo(int param1, int param2) {\n" + + " ^^^^^^\n" + + "The parameter param2 is never used\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " boolean b=false;\n" + + " ^\n" + + "The local variable b is never used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +// To verify that unused parameter warning is not shown for an overriding method's parameter when +// CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete is disabled +public void test0049() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING); + customOptions.put(CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete, CompilerOptions.DISABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends A {\n" + + " public void foo(int param1, int param2, Integer param3) {\n" + // overriding method, so dont warn + " boolean b=false;\n" + + " b|=true;\n" + // not a relevant usage + " param1++;\n" + // not a relevant usage + " param2 += 1;\n" + // not a relevant usage + " param3++;\n" + // relevant because unboxing is involved + " }\n" + + " public void foo(int param1, Integer param3) {\n" + // overriding method, so dont warn + " param1++;\n" + // not a relevant usage + " param3++;\n" + // relevant because unboxing is involved + " }\n" + + "}\n" + + "class A{\n" + + " public void foo(int param1, int param2, Integer param3) {\n" + + " param1 -=1;\n" + // not a relevant usage + " param2--;\n" + // not a relevant usage + " param3--;\n" + // relevant because unboxing is involved + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " boolean b=false;\n" + + " ^\n" + + "The local variable b is never used\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " public void foo(int param1, Integer param3) {\n" + + " ^^^^^^\n" + + "The parameter param1 is never used\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " public void foo(int param1, int param2, Integer param3) {\n" + + " ^^^^^^\n" + + "The parameter param1 is never used\n" + + "----------\n" + + "4. WARNING in X.java (at line 15)\n" + + " public void foo(int param1, int param2, Integer param3) {\n" + + " ^^^^^^\n" + + "The parameter param2 is never used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +// To verify that unused local warning is not shown for locals declared in unreachable code +public void test0050() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " int foo() {\n" + + " int i=1;\n" + + " if (false) {\n" + + " boolean b=false;\n" + // don't complain as unused + " b|=true;\n" + + " }\n" + // not a relevant usage + " int k = 2;\n" + + " --k;\n" + // not a relevant usage + " k+=3;\n" + // not a relevant usage + " Integer j = 3;\n" + + " j++;\n" + // relevant because unboxing is involved + " return i++;\n" + // value after increment is used + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false) {\n" + + " boolean b=false;\n" + + " b|=true;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " int k = 2;\n" + + " ^\n" + + "The local variable k is never used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} } \ No newline at end of file Index: src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java,v retrieving revision 1.79 diff -u -r1.79 StaticImportTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java 15 Apr 2010 15:18:23 -0000 1.79 +++ src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java 21 Oct 2010 14:33:53 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -660,7 +661,7 @@ "1. WARNING in bug\\C.java (at line 3)\n" + " private static B b;\n" + " ^\n" + - "The field C.b is never read locally\n" + + "The private field C.b is never used\n" + "----------\n"); } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java,v retrieving revision 1.157 diff -u -r1.157 ReconcilerTests.java --- src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java 20 Oct 2010 05:46:56 -0000 1.157 +++ src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java 21 Oct 2010 14:33:53 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read *******************************************************************************/ package org.eclipse.jdt.core.tests.model; @@ -4555,7 +4556,7 @@ "1. WARNING in /Reconciler1415/src/p1/X.java (at line 5)\n" + " String s = (String) context.getService(string); \n" + " ^\n" + - "The local variable s is never read\n" + + "The local variable s is never used\n" + "----------\n" ); } finally { @@ -4622,7 +4623,7 @@ "1. WARNING in /Reconciler1415/src/p1/X.java (at line 5)\n" + " String s = (String) context.getService(string); \n" + " ^\n" + - "The local variable s is never read\n" + + "The local variable s is never used\n" + "----------\n" ); } finally { @@ -4729,7 +4730,7 @@ "1. WARNING in /Reconciler1415/src/p1/X.java (at line 5)\n" + " Collection c = p2.X.getX(); \n" + " ^\n" + - "The local variable c is never read\n" + + "The local variable c is never used\n" + "----------\n" ); } finally { @@ -4797,7 +4798,7 @@ "1. WARNING in /Reconciler15API/src/p2/X.java (at line 3)\n" + " private p1.X x = p1.X.getX();\n" + " ^\n" + - "The field X.x is never read locally\n" + + "The private field X.x is never used\n" + "----------\n" ); } finally { @@ -4866,7 +4867,7 @@ "1. WARNING in /Reconciler1415/src/p1/X.java (at line 5)\n" + " private List [] l2 = List.getBackArray(l);\n" + " ^^\n" + - "The field X.l2 is never read locally\n" + + "The private field X.l2 is never used\n" + "----------\n" ); } finally { @@ -4941,7 +4942,7 @@ "1. WARNING in /Reconciler1415/src/p1/X.java (at line 4)\n" + " private int unused = 0;\n" + " ^^^^^^\n" + - "The field X.unused is never read locally\n" + + "The private field X.unused is never used\n" + "----------\n" ); } finally {