aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMajoj Palat2012-10-12 01:50:53 (EDT)
committerSrikanth2012-10-12 01:50:53 (EDT)
commit363f295181efb5d08470dfb8bacfcdd493852030 (patch)
tree35e924818f4dccc1632adba98bdcf8eee93b4511
parent5a4a2929d0aaba1a7f6b87488d0054e129a55977 (diff)
downloadeclipse.jdt.core-363f295181efb5d08470dfb8bacfcdd493852030.zip
eclipse.jdt.core-363f295181efb5d08470dfb8bacfcdd493852030.tar.gz
eclipse.jdt.core-363f295181efb5d08470dfb8bacfcdd493852030.tar.bz2
Fixed bug 385780: No warning for unused generic parameters
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java109
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java2
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java1
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java51
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java11
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java12
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java12
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java11
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java1
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java15
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties1
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java1
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java15
16 files changed, 240 insertions, 12 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
index 91b69db..43e258b 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
@@ -1991,7 +1991,8 @@ public void test012b(){
" <option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract\" value=\"disabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete\" value=\"disabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.unusedPrivateMember\" value=\"warning\"/>\n" +
- " <option key=\"org.eclipse.jdt.core.compiler.problem.unusedTypeArgumentsForMethodInvocation\" value=\"warning\"/>\n" +
+ " <option key=\"org.eclipse.jdt.core.compiler.problem.unusedTypeArgumentsForMethodInvocation\" value=\"warning\"/>\n" +
+ " <option key=\"org.eclipse.jdt.core.compiler.problem.unusedTypeParameter\" value=\"ignore\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.unusedWarningToken\" value=\"warning\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast\" value=\"warning\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.processAnnotations\" value=\"disabled\"/>\n" +
@@ -7758,7 +7759,12 @@ public void test191_warn_options() {
" ^^^^\n" +
"The label next is never explicitly referenced\n" +
"----------\n" +
- "7 problems (7 warnings)",
+ "8. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 14)\n" +
+ " <T> void bar() {\n" +
+ " ^\n" +
+ "Unused type parameter T\n" +
+ "----------\n" +
+ "8 problems (8 warnings)",
true);
}
// -warn option - regression tests
@@ -8063,7 +8069,12 @@ public void test199_warn_options() {
" ^^^^\n" +
"The label next is never explicitly referenced\n" +
"----------\n" +
- "6 problems (6 warnings)",
+ "7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 14)\n" +
+ " <T> void bar() {\n" +
+ " ^\n" +
+ "Unused type parameter T\n" +
+ "----------\n" +
+ "7 problems (7 warnings)",
true);
}
// -warn option - regression tests
@@ -8123,7 +8134,12 @@ public void test200_warn_options() {
" ^^^^\n" +
"The label next is never explicitly referenced\n" +
"----------\n" +
- "6 problems (6 warnings)",
+ "7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 14)\n" +
+ " <T> void bar() {\n" +
+ " ^\n" +
+ "Unused type parameter T\n" +
+ "----------\n" +
+ "7 problems (7 warnings)",
true);
}
// -warn option - regression tests
@@ -8183,7 +8199,12 @@ public void test201_warn_options() {
" ^^^^^^\n" +
"Unused type arguments for the non generic method bar() of type X; it should not be parameterized with arguments <String>\n" +
"----------\n" +
- "6 problems (6 warnings)",
+ "7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 14)\n" +
+ " <T> void bar() {\n" +
+ " ^\n" +
+ "Unused type parameter T\n" +
+ "----------\n" +
+ "7 problems (7 warnings)",
true);
}
// -warn option - regression tests
@@ -8243,7 +8264,12 @@ public void test202_warn_options() {
" ^^^^\n" +
"The label next is never explicitly referenced\n" +
"----------\n" +
- "6 problems (6 warnings)",
+ "7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 14)\n" +
+ " <T> void bar() {\n" +
+ " ^\n" +
+ "Unused type parameter T\n" +
+ "----------\n" +
+ "7 problems (7 warnings)",
true);
}
// -warn option - regression tests
@@ -8303,7 +8329,12 @@ public void test203_warn_options() {
" ^^^^\n" +
"The label next is never explicitly referenced\n" +
"----------\n" +
- "6 problems (6 warnings)",
+ "7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 14)\n" +
+ " <T> void bar() {\n" +
+ " ^\n" +
+ "Unused type parameter T\n" +
+ "----------\n" +
+ "7 problems (7 warnings)",
true);
}
// -warn option - regression tests
@@ -8363,7 +8394,12 @@ public void test204_warn_options() {
" ^^^^\n" +
"The label next is never explicitly referenced\n" +
"----------\n" +
- "6 problems (6 warnings)",
+ "7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 14)\n" +
+ " <T> void bar() {\n" +
+ " ^\n" +
+ "Unused type parameter T\n" +
+ "----------\n" +
+ "7 problems (7 warnings)",
true);
}
// -warn option - regression tests
@@ -8423,7 +8459,12 @@ public void test205_warn_options() {
" ^^^^\n" +
"The label next is never explicitly referenced\n" +
"----------\n" +
- "6 problems (6 warnings)",
+ "7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 14)\n" +
+ " <T> void bar() {\n" +
+ " ^\n" +
+ "Unused type parameter T\n" +
+ "----------\n" +
+ "7 problems (7 warnings)",
true);
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=211588
@@ -13591,4 +13632,54 @@ public void testBug375366c() throws IOException {
"3 problems (3 errors)",
false/*don't flush*/);
}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=385780
+public void test385780_warn_option() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X<T> {\n"+
+ "public <S> X() {\n"+
+ "}\n"+
+ "public void ph(int t) {\n"+
+ "}\n"+
+ "}\n"+
+ "interface doNothingInterface<T> {\n"+
+ "}\n"+
+ "class doNothing {\n"+
+ "public <T> void doNothingMethod() {"+
+ "}\n"+
+ "}\n"+
+ "class noerror {\n"+
+ "public <T> void doNothing(T t) {"+
+ "}"+
+ "}\n"
+ },
+ "\"" + OUTPUT_DIR + File.separator + "X.java\""
+ + " -warn:unusedTypeParameter -proc:none -1.7 -d \"" + OUTPUT_DIR + "\"",
+ "",
+ "----------\n" +
+ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 1)\n" +
+ " public class X<T> {\n" +
+ " ^\n" +
+ "Unused type parameter T\n" +
+ "----------\n" +
+ "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 2)\n" +
+ " public <S> X() {\n" +
+ " ^\n" +
+ "Unused type parameter S\n" +
+ "----------\n" +
+ "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 7)\n" +
+ " interface doNothingInterface<T> {\n" +
+ " ^\n" +
+ "Unused type parameter T\n" +
+ "----------\n" +
+ "4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 10)\n" +
+ " public <T> void doNothingMethod() {}\n" +
+ " ^\n" +
+ "Unused type parameter T\n" +
+ "----------\n" +
+ "4 problems (4 warnings)",
+ true);
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
index cf5f3b6..f87f753 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
@@ -920,6 +920,7 @@ public void test011_problem_categories() {
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));
+ expectedProblemAttributes.put("UnusedTypeParameter", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
expectedProblemAttributes.put("UnusedTypeArgumentsForMethodInvocation", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("UnusedWarningToken", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE));
expectedProblemAttributes.put("UseAssertAsAnIdentifier", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE));
@@ -1625,6 +1626,7 @@ public void test012_compiler_problems_tuning() {
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));
+ expectedProblemAttributes.put("UnusedTypeParameter", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_TYPE_PARAMETER));
expectedProblemAttributes.put("UnusedTypeArgumentsForMethodInvocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_TYPE_ARGUMENTS_FOR_METHOD_INVOCATION));
expectedProblemAttributes.put("UnusedWarningToken", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_WARNING_TOKEN));
expectedProblemAttributes.put("UseAssertAsAnIdentifier", new ProblemAttributes(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER));
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
index f6efde5..7275093 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
@@ -50,6 +50,7 @@ public class GenericTypeTest extends AbstractComparableTest {
options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE);
options.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.IGNORE);
options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportUnusedTypeParameter, CompilerOptions.IGNORE);
return options;
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
index 00813bf..ffc6b67 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
@@ -44,6 +44,7 @@ public class GenericsRegressionTest extends AbstractComparableTest {
protected Map getCompilerOptions() {
Map compilerOptions = super.getCompilerOptions();
compilerOptions.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.DISABLED);
+ compilerOptions.put(CompilerOptions.OPTION_ReportUnusedTypeParameter,CompilerOptions.IGNORE);
return compilerOptions;
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=322531
@@ -2598,4 +2599,54 @@ public void test375394a() {
"C is a raw type. References to generic type C<T> should be parameterized\n" +
"----------\n");
}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=385780
+public void test385780() {
+ Map customOptions = getCompilerOptions();
+ customOptions.put(
+ CompilerOptions.OPTION_ReportUnusedTypeParameter,
+ CompilerOptions.ERROR);
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X<T> {\n"+
+ "public <S> X() {\n"+
+ "}\n"+
+ "public void ph(int t) {\n"+
+ "}\n"+
+ "}\n"+
+ "interface doNothingInterface<T> {\n"+
+ "}\n"+
+ "class doNothing {\n"+
+ "public <T> void doNothingMethod() {"+
+ "}\n"+
+ "}\n"+
+ "class noerror {\n"+
+ "public <T> void doNothing(T t) {"+
+ "}"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 1)\n" +
+ " public class X<T> {\n" +
+ " ^\n" +
+ "Unused type parameter T\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 2)\n" +
+ " public <S> X() {\n" +
+ " ^\n" +
+ "Unused type parameter S\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 7)\n" +
+ " interface doNothingInterface<T> {\n" +
+ " ^\n" +
+ "Unused type parameter T\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 10)\n" +
+ " public <T> void doNothingMethod() {}\n" +
+ " ^\n" +
+ "Unused type parameter T\n" +
+ "----------\n",
+ null, true, customOptions);
+}
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java
index 308dc97..886530e 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java
@@ -3852,10 +3852,14 @@ private void handleErrorOrWarningToken(String token, boolean isEnabling, int sev
setSeverity(CompilerOptions.OPTION_ReportUnusedLabel, severity, isEnabling);
setSeverity(CompilerOptions.OPTION_ReportUnusedTypeArgumentsForMethodInvocation, severity, isEnabling);
setSeverity(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, severity, isEnabling);
+ setSeverity(CompilerOptions.OPTION_ReportUnusedTypeParameter, severity,isEnabling); //TODO - Enable this when tests are modified at ui addition.
return;
} else if (token.equals("unusedParam")) { //$NON-NLS-1$
setSeverity(CompilerOptions.OPTION_ReportUnusedParameter, severity, isEnabling);
return;
+ } else if (token.equals("unusedTypeParameter")) { //$NON-NLS-1$
+ setSeverity(CompilerOptions.OPTION_ReportUnusedTypeParameter, severity, isEnabling);
+ return;
} else if (token.equals("unusedParamIncludeDoc")) { //$NON-NLS-1$
this.options.put(
CompilerOptions.OPTION_ReportUnusedParameterIncludeDocCommentReference,
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
index 46093f9..9dfff59 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
@@ -1293,6 +1293,8 @@ void setSourceStart(int sourceStart);
*/
/** @since 3.4 */
int UnusedTypeArgumentsForConstructorInvocation = MethodRelated + 660;
+ /** @since 3.9 */
+ int UnusedTypeParameter = TypeRelated + 661;
/**
* Corrupted binaries
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java
index 89b6aba..cb5d6ff 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java
@@ -493,6 +493,10 @@ public abstract class ASTNode implements TypeConstants, TypeIds {
return false;
ReferenceBinding refType = (ReferenceBinding) type;
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=385780
+ if (refType instanceof TypeVariableBinding) {
+ refType.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
+ }
// ignore references insing Javadoc comments
if ((this.bits & ASTNode.InsideJavadoc) == 0 && refType.isOrEnclosedByPrivateType() && !scope.isDefinedInType(refType)) {
// ignore cases where type is used from inside itself
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
index 89ac33a..63a1948 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
@@ -89,7 +89,16 @@ public void analyseCode(ClassScope classScope, InitializationFlowContext initial
if (isRecursive(null /*lazy initialized visited list*/)) {
this.scope.problemReporter().recursiveConstructorInvocation(this.constructorCall);
}
-
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=385780
+ if (this.typeParameters != null &&
+ !this.scope.referenceCompilationUnit().compilationResult.hasSyntaxError) {
+ for (int i = 0, length = this.typeParameters.length; i < length; ++i) {
+ TypeParameter typeParameter = this.typeParameters[i];
+ if ((typeParameter.binding.modifiers & ExtraCompilerModifiers.AccLocallyUsed) == 0) {
+ this.scope.problemReporter().unusedTypeParameter(typeParameter);
+ }
+ }
+ }
try {
ExceptionHandlingFlowContext constructorContext =
new ExceptionHandlingFlowContext(
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
index a488177..80c18ec 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
@@ -73,7 +73,17 @@ public class MethodDeclaration extends AbstractMethodDeclaration {
// may be in a non necessary <clinit> for innerclass with static final constant fields
if (this.binding.isAbstract() || this.binding.isNative())
return;
-
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=385780
+ if (this.typeParameters != null &&
+ !this.scope.referenceCompilationUnit().compilationResult.hasSyntaxError) {
+ for (int i = 0, length = this.typeParameters.length; i < length; ++i) {
+ TypeParameter typeParameter = this.typeParameters[i];
+ if ((typeParameter.binding.modifiers & ExtraCompilerModifiers.AccLocallyUsed) == 0) {
+ this.scope.problemReporter().unusedTypeParameter(typeParameter);
+ }
+ }
+ }
ExceptionHandlingFlowContext methodContext =
new ExceptionHandlingFlowContext(
flowContext,
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java
index bb1fe0f..d089b82 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java
@@ -641,6 +641,18 @@ private void internalAnalyseCode(FlowContext flowContext, FlowInfo flowInfo) {
this.scope.problemReporter().unusedPrivateType(this);
}
}
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=385780
+ if (this.typeParameters != null &&
+ !this.scope.referenceCompilationUnit().compilationResult.hasSyntaxError) {
+ for (int i = 0, length = this.typeParameters.length; i < length; ++i) {
+ TypeParameter typeParameter = this.typeParameters[i];
+ if ((typeParameter.binding.modifiers & ExtraCompilerModifiers.AccLocallyUsed) == 0) {
+ this.scope.problemReporter().unusedTypeParameter(typeParameter);
+ }
+ }
+ }
+
// for local classes we use the flowContext as our parent, but never use an initialization context for this purpose
// see Bug 360328 - [compiler][null] detect null problems in nested code (local class inside a loop)
FlowContext parentContext = (flowContext instanceof InitializationFlowContext) ? null : flowContext;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java
index ba4a32e..5b32c52 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java
@@ -125,6 +125,7 @@ public class CompilerOptions {
public static final String OPTION_SuppressWarnings = "org.eclipse.jdt.core.compiler.problem.suppressWarnings"; //$NON-NLS-1$
public static final String OPTION_SuppressOptionalErrors = "org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors"; //$NON-NLS-1$
public static final String OPTION_ReportUnhandledWarningToken = "org.eclipse.jdt.core.compiler.problem.unhandledWarningToken"; //$NON-NLS-1$
+ public static final String OPTION_ReportUnusedTypeParameter = "org.eclipse.jdt.core.compiler.problem.unusedTypeParameter"; //$NON-NLS-1$
public static final String OPTION_ReportUnusedWarningToken = "org.eclipse.jdt.core.compiler.problem.unusedWarningToken"; //$NON-NLS-1$
public static final String OPTION_ReportUnusedLabel = "org.eclipse.jdt.core.compiler.problem.unusedLabel"; //$NON-NLS-1$
public static final String OPTION_FatalOptionalError = "org.eclipse.jdt.core.compiler.problem.fatalOptionalError"; //$NON-NLS-1$
@@ -273,6 +274,7 @@ public class CompilerOptions {
public static final int RedundantNullAnnotation = IrritantSet.GROUP2 | ASTNode.Bit14;
public static final int MissingNonNullByDefaultAnnotation = IrritantSet.GROUP2 | ASTNode.Bit15;
public static final int MissingDefaultCase = IrritantSet.GROUP2 | ASTNode.Bit16;
+ public static final int UnusedTypeParameter = IrritantSet.GROUP2 | ASTNode.Bit17;
// Severity level for handlers
/**
@@ -597,6 +599,8 @@ public class CompilerOptions {
return OPTION_ReportMissingJavadocTagDescription;
case UnusedTypeArguments :
return OPTION_ReportUnusedTypeArgumentsForMethodInvocation;
+ case UnusedTypeParameter:
+ return OPTION_ReportUnusedTypeParameter;
case UnusedWarningToken :
return OPTION_ReportUnusedWarningToken;
case RedundantSuperinterface :
@@ -809,7 +813,8 @@ public class CompilerOptions {
OPTION_ReportNullSpecViolation,
OPTION_ReportNullAnnotationInferenceConflict,
OPTION_ReportNullUncheckedConversion,
- OPTION_ReportRedundantNullAnnotation
+ OPTION_ReportRedundantNullAnnotation,
+ OPTION_ReportUnusedTypeParameter,
};
return result;
}
@@ -866,6 +871,7 @@ public class CompilerOptions {
case DeadCode :
case UnusedObjectAllocation :
case RedundantSpecificationOfTypeArguments :
+ case UnusedTypeParameter:
return "unused"; //$NON-NLS-1$
case DiscouragedReference :
case ForbiddenReference :
@@ -1105,6 +1111,7 @@ public class CompilerOptions {
optionsMap.put(OPTION_NonNullAnnotationName, String.valueOf(CharOperation.concatWith(this.nonNullAnnotationName, '.')));
optionsMap.put(OPTION_NonNullByDefaultAnnotationName, String.valueOf(CharOperation.concatWith(this.nonNullByDefaultAnnotationName, '.')));
optionsMap.put(OPTION_ReportMissingNonNullByDefaultAnnotation, getSeverityString(MissingNonNullByDefaultAnnotation));
+ optionsMap.put(OPTION_ReportUnusedTypeParameter, getSeverityString(UnusedTypeParameter));
return optionsMap;
}
@@ -1558,6 +1565,7 @@ public class CompilerOptions {
if ((optionValue = optionsMap.get(OPTION_ReportUnclosedCloseable)) != null) updateSeverity(UnclosedCloseable, optionValue);
if ((optionValue = optionsMap.get(OPTION_ReportPotentiallyUnclosedCloseable)) != null) updateSeverity(PotentiallyUnclosedCloseable, optionValue);
if ((optionValue = optionsMap.get(OPTION_ReportExplicitlyClosedAutoCloseable)) != null) updateSeverity(ExplicitlyClosedAutoCloseable, optionValue);
+ if ((optionValue = optionsMap.get(OPTION_ReportUnusedTypeParameter)) != null) updateSeverity(UnusedTypeParameter, optionValue);
if (getSeverity(UnclosedCloseable) == ProblemSeverities.Ignore
&& getSeverity(PotentiallyUnclosedCloseable) == ProblemSeverities.Ignore
&& getSeverity(ExplicitlyClosedAutoCloseable) == ProblemSeverities.Ignore) {
@@ -1811,6 +1819,7 @@ public class CompilerOptions {
buf.append("\n\t- resource is not closed: ").append(getSeverityString(UnclosedCloseable)); //$NON-NLS-1$
buf.append("\n\t- resource may not be closed: ").append(getSeverityString(PotentiallyUnclosedCloseable)); //$NON-NLS-1$
buf.append("\n\t- resource should be handled by try-with-resources: ").append(getSeverityString(ExplicitlyClosedAutoCloseable)); //$NON-NLS-1$
+ buf.append("\n\t- Unused Type Parameter: ").append(getSeverityString(UnusedTypeParameter)); //$NON-NLS-1$
return buf.toString();
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java
index 38f3cc0..9d04d4d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java
@@ -142,6 +142,7 @@ public class IrritantSet {
.set(CompilerOptions.RedundantSuperinterface)
.set(CompilerOptions.DeadCode)
.set(CompilerOptions.UnusedObjectAllocation)
+ .set(CompilerOptions.UnusedTypeParameter)
.set(CompilerOptions.RedundantSpecificationOfTypeArguments);
STATIC_METHOD
.set(CompilerOptions.MethodCanBePotentiallyStatic);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
index b527025..a901cd4 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
@@ -483,6 +483,9 @@ public static int getIrritant(int problemID) {
case IProblem.MissingNonNullByDefaultAnnotationOnPackage:
case IProblem.MissingNonNullByDefaultAnnotationOnType:
return CompilerOptions.MissingNonNullByDefaultAnnotation;
+
+ case IProblem.UnusedTypeParameter:
+ return CompilerOptions.UnusedTypeParameter;
}
return 0;
}
@@ -561,6 +564,7 @@ public static int getProblemCategory(int severity, int problemID) {
case CompilerOptions.UnusedLabel :
case CompilerOptions.RedundantSuperinterface :
case CompilerOptions.RedundantSpecificationOfTypeArguments :
+ case CompilerOptions.UnusedTypeParameter:
return CategorizedProblem.CAT_UNNECESSARY_CODE;
case CompilerOptions.UsingDeprecatedAPI :
@@ -7841,6 +7845,17 @@ public void unusedPrivateType(TypeDeclaration typeDecl) {
typeDecl.sourceStart,
typeDecl.sourceEnd);
}
+public void unusedTypeParameter(TypeParameter typeParameter) {
+ int severity = computeSeverity(IProblem.UnusedTypeParameter);
+ if (severity == ProblemSeverities.Ignore) return;
+ String [] arguments = new String[] {new String(typeParameter.name)};
+ this.handle(
+ IProblem.UnusedTypeParameter,
+ arguments,
+ arguments,
+ typeParameter.sourceStart,
+ typeParameter.sourceEnd);
+}
public void unusedWarningToken(Expression token) {
String[] arguments = new String[] { token.constant.stringValue() };
this.handle(
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
index bfa5dc4..0d57bd6 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
@@ -584,6 +584,7 @@
### MORE GENERICS
660 = Unused type arguments for the non generic constructor {0}({1}) of type {2}; it should not be parameterized with arguments <{3}>
+661 = Unused type parameter {0}
### CORRUPTED BINARIES
700 = The class file {0} contains a signature ''{1}'' ill-formed at position {2}
diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java
index f987d0f..62afdf5 100644
--- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java
+++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java
@@ -341,6 +341,7 @@ public class DefaultCodeFormatter extends CodeFormatter {
optionsMap.put(CompilerOptions.OPTION_InlineJsr, CompilerOptions.DISABLED);
optionsMap.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.IGNORE);
optionsMap.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.IGNORE);
+ optionsMap.put(CompilerOptions.OPTION_ReportUnusedTypeParameter, CompilerOptions.IGNORE);
this.defaultCompilerOptions = optionsMap;
}
Object sourceOption = this.options.get(CompilerOptions.OPTION_Source);
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java
index 8130699..2125b64 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java
@@ -513,6 +513,21 @@ public final class JavaCore extends Plugin {
* @category CompilerOptionID
*/
public static final String COMPILER_PB_SYNTHETIC_ACCESS_EMULATION = PLUGIN_ID + ".compiler.problem.syntheticAccessEmulation"; //$NON-NLS-1$
+
+ /**
+ * Compiler option ID: Reporting Unused Type Parameter.
+ * <p>When enabled, the compiler will issue an error or a warning whenever it encounters an
+ * unused type parameter. </p>
+ * <dl>
+ * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.problem.unusedTypeParameter"</code></dd>
+ * <dt>Possible values:</dt><dd><code>{ "error", "warning", "ignore" }</code></dd>
+ * <dt>Default:</dt><dd><code>"ignore"</code></dd>
+ * </dl>
+ * @since 3.9
+ * @category CompilerOptionID
+ */
+ public static final String COMPILER_PB_UNUSED_TYPE_PARAMETER = PLUGIN_ID + ".compiler.problem.unusedTypeParameter"; //$NON-NLS-1$
+
/**
* Compiler option ID: Reporting Non-Externalized String Literal.
* <p>When enabled, the compiler will issue an error or a warning for non externalized