From 268bc634b712439433e52e679ee23fa77f329a56 Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Wed, 7 Aug 2024 15:43:15 +0200 Subject: [PATCH] Set assertIdentifier & enumIdentifier options to "error" by default Both options are still present in compiler/core code, but shouldn't be set to any other value as "error". For now we will ignore any provided values and use "error" by default. See https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2536 --- .../org/eclipse/jdt/internal/compiler/batch/Main.java | 4 ++-- .../jdt/internal/compiler/impl/CompilerOptions.java | 10 ++++------ .../tests/compiler/regression/BatchCompilerTest.java | 4 ++-- .../core/tests/formatter/FormatterCommentsTests.java | 4 ++-- .../formatter/FormatterMassiveRegressionTests.java | 4 ++-- .../tests/performance/FullSourceWorkspaceTests.java | 2 -- .../model/org/eclipse/jdt/core/JavaCore.java | 4 ++-- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java index 1e02b7e6206..f3799ddfa8b 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java @@ -3869,7 +3869,7 @@ private void handleErrorOrWarningToken(String token, boolean isEnabling, int sev setSeverity(CompilerOptions.OPTION_ReportMissingJavadocComments, severity, isEnabling); return; } else if (token.equals("assertIdentifier")) { //$NON-NLS-1$ - setSeverity(CompilerOptions.OPTION_ReportAssertIdentifier, severity, isEnabling); + // error by default, no other values accepted return; } else if (token.equals("allDeadCode")) { //$NON-NLS-1$ setSeverity(CompilerOptions.OPTION_ReportDeadCode, severity, isEnabling); @@ -3966,7 +3966,7 @@ private void handleErrorOrWarningToken(String token, boolean isEnabling, int sev setSeverity(CompilerOptions.OPTION_ReportUndocumentedEmptyBlock, severity, isEnabling); return; } else if (token.equals("enumIdentifier")) { //$NON-NLS-1$ - setSeverity(CompilerOptions.OPTION_ReportEnumIdentifier, severity, isEnabling); + // error by default, no other values accepted return; } else if (token.equals("exports")) { //$NON-NLS-1$ setSeverity(CompilerOptions.OPTION_ReportAPILeak, severity, isEnabling); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java index 6228791ec0d..b589d0e3961 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java @@ -1012,7 +1012,6 @@ public static long versionToJdkLevel(String versionID, boolean supportUnreleased public static String[] warningOptionNames() { String[] result = { OPTION_ReportAnnotationSuperInterface, - OPTION_ReportAssertIdentifier, OPTION_ReportAutoboxing, OPTION_ReportComparingIdentical, OPTION_ReportDeadCode, @@ -1022,7 +1021,6 @@ public static String[] warningOptionNames() { OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, OPTION_ReportDiscouragedReference, OPTION_ReportEmptyStatement, - OPTION_ReportEnumIdentifier, OPTION_ReportFallthroughCase, OPTION_ReportFieldHiding, OPTION_ReportFinallyBlockNotCompletingNormally, @@ -1372,8 +1370,8 @@ public Map getMap() { optionsMap.put(OPTION_ReportTypeParameterHiding, getSeverityString(TypeHiding)); optionsMap.put(OPTION_ReportPossibleAccidentalBooleanAssignment, getSeverityString(AccidentalBooleanAssign)); optionsMap.put(OPTION_ReportEmptyStatement, getSeverityString(EmptyStatement)); - optionsMap.put(OPTION_ReportAssertIdentifier, getSeverityString(AssertUsedAsAnIdentifier)); - optionsMap.put(OPTION_ReportEnumIdentifier, getSeverityString(EnumUsedAsAnIdentifier)); + optionsMap.put(OPTION_ReportAssertIdentifier, ERROR); + optionsMap.put(OPTION_ReportEnumIdentifier, ERROR); optionsMap.put(OPTION_ReportUndocumentedEmptyBlock, getSeverityString(UndocumentedEmptyBlock)); optionsMap.put(OPTION_ReportUnnecessaryTypeCheck, getSeverityString(UnnecessaryTypeCheck)); optionsMap.put(OPTION_ReportUnnecessaryElse, getSeverityString(UnnecessaryElse)); @@ -1956,8 +1954,8 @@ public void set(Map optionsMap) { if ((optionValue = optionsMap.get(OPTION_ReportPossibleAccidentalBooleanAssignment)) != null) updateSeverity(AccidentalBooleanAssign, optionValue); if ((optionValue = optionsMap.get(OPTION_ReportEmptyStatement)) != null) updateSeverity(EmptyStatement, optionValue); if ((optionValue = optionsMap.get(OPTION_ReportNonExternalizedStringLiteral)) != null) updateSeverity(NonExternalizedString, optionValue); - if ((optionValue = optionsMap.get(OPTION_ReportAssertIdentifier)) != null) updateSeverity(AssertUsedAsAnIdentifier, optionValue); - if ((optionValue = optionsMap.get(OPTION_ReportEnumIdentifier)) != null) updateSeverity(EnumUsedAsAnIdentifier, optionValue); + if ((optionValue = optionsMap.get(OPTION_ReportAssertIdentifier)) != null) updateSeverity(AssertUsedAsAnIdentifier, ERROR); + if ((optionValue = optionsMap.get(OPTION_ReportEnumIdentifier)) != null) updateSeverity(EnumUsedAsAnIdentifier, ERROR); if ((optionValue = optionsMap.get(OPTION_ReportNonStaticAccessToStatic)) != null) updateSeverity(NonStaticAccessToStatic, optionValue); if ((optionValue = optionsMap.get(OPTION_ReportIndirectStaticAccess)) != null) updateSeverity(IndirectStaticAccess, optionValue); if ((optionValue = optionsMap.get(OPTION_ReportIncompatibleNonInheritedInterfaceMethod)) != null) updateSeverity(IncompatibleNonInheritedInterfaceMethod, optionValue); 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 8d1d7cc914f..5a3ae00ea6e 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 @@ -1051,7 +1051,7 @@ public void test013() { "