Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 181232 Details for
Bug 185682
Increment/decrement operators mark local variables as read
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
updated patch - covering also private fields
bug_185682_v4.patch (text/plain), 58.89 KB, created by
Stephan Herrmann
on 2010-10-19 19:11:35 EDT
(
hide
)
Description:
updated patch - covering also private fields
Filename:
MIME Type:
Creator:
Stephan Herrmann
Created:
2010-10-19 19:11:35 EDT
Size:
58.89 KB
patch
obsolete
>### 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 19 Oct 2010 23:05:17 -0000 >@@ -359,6 +359,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 19 Oct 2010 23:05:18 -0000 >@@ -357,11 +357,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 19 Oct 2010 23:05:20 -0000 >@@ -290,6 +290,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 +341,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 +585,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 19 Oct 2010 23:05:20 -0000 >@@ -97,7 +97,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 19 Oct 2010 23:05:22 -0000 >@@ -380,6 +380,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 +435,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 +727,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 +962,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 19 Oct 2010 23:05:24 -0000 >@@ -7,7 +7,8 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >- * Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 292478 - Report potentially null across variable assignment >+ * Stephan Herrmann <stephan@cs.tu-berlin.de> - 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. */ >+private 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 = ((MethodDeclaration)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 19 Oct 2010 23:05:24 -0000 >@@ -32,6 +32,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 19 Oct 2010 23:05:25 -0000 >@@ -332,7 +332,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.422 >diff -u -r1.422 ProblemReporter.java >--- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 21 Sep 2010 14:02:58 -0000 1.422 >+++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 19 Oct 2010 23:05:38 -0000 >@@ -194,6 +194,7 @@ > case IProblem.UnusedPrivateConstructor: > case IProblem.UnusedPrivateMethod: > case IProblem.UnusedPrivateField: >+ case IProblem.UnusedScopedField: > case IProblem.UnusedPrivateType: > return CompilerOptions.UnusedPrivateMember; > >@@ -7246,7 +7247,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; >@@ -7265,7 +7269,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 19 Oct 2010 23:05:39 -0000 >@@ -65,13 +65,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 19 Oct 2010 23:05:39 -0000 >@@ -325,7 +325,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 19 Oct 2010 23:05:40 -0000 >@@ -463,7 +463,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 +510,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 19 Oct 2010 23:05:41 -0000 >@@ -101,7 +101,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.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 19 Oct 2010 23:06:04 -0000 >@@ -9355,7 +9355,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 19 Oct 2010 23:06:07 -0000 >@@ -223,12 +223,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 +238,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 +253,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 19 Oct 2010 23:06:24 -0000 >@@ -11334,7 +11334,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 +11374,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 +11397,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 +11425,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 +11448,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 19 Oct 2010 23:06:29 -0000 >@@ -848,6 +848,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 +1483,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/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 19 Oct 2010 23:06:40 -0000 >@@ -7190,12 +7190,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 19 Oct 2010 23:06:42 -0000 >@@ -279,7 +279,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 +290,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 +301,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 +312,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/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 19 Oct 2010 23:06:46 -0000 >@@ -94,7 +94,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 +344,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 +2263,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 +2654,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 +3264,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 +3298,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 +3338,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 +3363,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 +3393,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 +3435,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 +3455,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 19 Oct 2010 23:06:46 -0000 >@@ -185,7 +185,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 19 Oct 2010 23:06:49 -0000 >@@ -7,19 +7,21 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Stephan Herrmann <stephan@cs.tu-berlin.de> - 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). */ >@@ -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 read\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 6)\n" + >+ " int k = 2;\n" + >+ " ^\n" + >+ "The local variable k is never read\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 read\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 read\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 3)\n" + >+ " boolean b=false;\n" + >+ " ^\n" + >+ "The local variable b is never read\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 read\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 read\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 read\n" + >+ "----------\n" + >+ "4. WARNING in X.java (at line 10)\n" + >+ " boolean b=false;\n" + >+ " ^\n" + >+ "The local variable b is never read\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 read\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 read\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 read\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 read\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 read\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 19 Oct 2010 23:06:51 -0000 >@@ -660,7 +660,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"); > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 185682
:
174421
|
178716
|
178806
|
181232
|
181235
|
181303
|
181409
|
181419
|
181439
|
181481
|
181557