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

Collapse All | Expand All

(-)Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java (+62 lines)
Lines 16235-16238 Link Here
16235
	);
16235
	);
16236
16236
16237
}
16237
}
16238
16239
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=190970
16240
public void test445() {
16241
	Map customOptions = getCompilerOptions();
16242
	customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
16243
	this.runNegativeTest(new String[] {
16244
		"pkg/X.java",
16245
		"package pkg;\n" +
16246
		"\n" +
16247
		"public class X {\n" +
16248
		"private int unused;" +
16249
		"/**" +
16250
		"* Same value as {@link #unused}" +
16251
		"*/" +
16252
		"private int unused2;" +
16253
		"}\n",
16254
	},
16255
	"----------\n" + 
16256
	"1. WARNING in pkg\\X.java (at line 4)\n" + 
16257
	"	private int unused;/*** Same value as {@link #unused}*/private int unused2;}\n" + 
16258
	"	            ^^^^^^\n" + 
16259
	"The field X.unused is never read locally\n" + 
16260
	"----------\n" + 
16261
	"2. WARNING in pkg\\X.java (at line 4)\n" + 
16262
	"	private int unused;/*** Same value as {@link #unused}*/private int unused2;}\n" + 
16263
	"	                                                                   ^^^^^^^\n" + 
16264
	"The field X.unused2 is never read locally\n" + 
16265
	"----------\n"
16266
);
16267
16268
}
16269
16270
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190970
16271
public void test446() {
16272
	Map customOptions = getCompilerOptions();
16273
	customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
16274
	this.runNegativeTest(new String[] {
16275
		"pkg/X.java",
16276
		"package pkg;\n" +
16277
		"\n" +
16278
		"public class X {\n" +
16279
		"/**" +
16280
		"* Same value as {@link #unused}" +
16281
		"*/" +
16282
		"private int unused;" +
16283
		"private int unused2;" +
16284
		"}\n",
16285
	},
16286
	"----------\n" + 
16287
	"1. WARNING in pkg\\X.java (at line 4)\n" + 
16288
	"	/*** Same value as {@link #unused}*/private int unused;private int unused2;}\n" + 
16289
	"	                                                ^^^^^^\n" + 
16290
	"The field X.unused is never read locally\n" + 
16291
	"----------\n" + 
16292
	"2. WARNING in pkg\\X.java (at line 4)\n" + 
16293
	"	/*** Same value as {@link #unused}*/private int unused;private int unused2;}\n" + 
16294
	"	                                                                   ^^^^^^^\n" + 
16295
	"The field X.unused2 is never read locally\n" + 
16296
	"----------\n"
16297
);
16298
16299
}
16238
}
16300
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/JavadocFieldReference.java (-1 / +26 lines)
Lines 11-16 Link Here
11
package org.eclipse.jdt.internal.compiler.ast;
11
package org.eclipse.jdt.internal.compiler.ast;
12
12
13
import org.eclipse.jdt.internal.compiler.ASTVisitor;
13
import org.eclipse.jdt.internal.compiler.ASTVisitor;
14
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
14
import org.eclipse.jdt.internal.compiler.impl.Constant;
15
import org.eclipse.jdt.internal.compiler.impl.Constant;
15
import org.eclipse.jdt.internal.compiler.lookup.*;
16
import org.eclipse.jdt.internal.compiler.lookup.*;
16
17
Lines 95-101 Link Here
95
		}
96
		}
96
		this.binding = (FieldBinding) fieldBinding;
97
		this.binding = (FieldBinding) fieldBinding;
97
98
98
		if (isFieldUseDeprecated(this.binding, scope, (this.bits & IsStrictlyAssigned) != 0)) {
99
		if (fieldCanBeUsedAsReference(this.binding, scope, (this.bits & IsStrictlyAssigned) != 0)) {
99
			scope.problemReporter().javadocDeprecatedField(this.binding, this, scope.getDeclarationModifiers());
100
			scope.problemReporter().javadocDeprecatedField(this.binding, this, scope.getDeclarationModifiers());
100
		}
101
		}
101
		return this.resolvedType = this.binding.type;
102
		return this.resolvedType = this.binding.type;
Lines 144-147 Link Here
144
		}
145
		}
145
		visitor.endVisit(this, scope);
146
		visitor.endVisit(this, scope);
146
	}
147
	}
148
	/*
149
	 * @ASTNode#isFieldUseDeprecated(FieldBinding, Scope, boolean)
150
	 * Do not modify field modifiers when searching for reference in Javadoc
151
	 */
152
	public final boolean fieldCanBeUsedAsReference(FieldBinding field, Scope scope, boolean isStrictlyAssigned) {
153
154
		if ((field.modifiers & ExtraCompilerModifiers.AccRestrictedAccess) != 0) {
155
			AccessRestriction restriction =
156
				scope.environment().getAccessRestriction(field.declaringClass.erasure());
157
			if (restriction != null) {
158
				scope.problemReporter().forbiddenReference(field, this,
159
						restriction.getFieldAccessMessageTemplate(), restriction.getProblemId());
160
			}
161
		}
162
163
		if (!field.isViewedAsDeprecated()) return false;
164
165
		// inside same unit - no report
166
		if (scope.isDefinedInSameUnit(field.declaringClass)) return false;
167
168
		// if context is deprecated, may avoid reporting
169
		if (!scope.compilerOptions().reportDeprecationInsideDeprecatedCode && scope.isInsideDeprecatedCode()) return false;
170
		return true;
171
	}
147
}
172
}

Return to bug 190970