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 148659 Details for
Bug 106478
[compiler] warning on unary + operator
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix + regression tests
patch_106478.txt (text/plain), 16.82 KB, created by
Olivier Thomann
on 2009-10-02 11:43:48 EDT
(
hide
)
Description:
Proposed fix + regression tests
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2009-10-02 11:43:48 EDT
Size:
16.82 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: batch/org/eclipse/jdt/internal/compiler/batch/Main.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java,v >retrieving revision 1.342 >diff -u -r1.342 Main.java >--- batch/org/eclipse/jdt/internal/compiler/batch/Main.java 22 Sep 2009 14:56:46 -0000 1.342 >+++ batch/org/eclipse/jdt/internal/compiler/batch/Main.java 2 Oct 2009 15:46:25 -0000 >@@ -3474,6 +3474,11 @@ > CompilerOptions.OPTION_ReportUnnecessaryElse, > isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); > return; >+ } else if (token.equals("unnecessaryOperator")) {//$NON-NLS-1$ >+ this.options.put( >+ CompilerOptions.OPTION_ReportUnnecessaryOperator, >+ isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); >+ return; > } else if (token.equals("unusedThrown")) { //$NON-NLS-1$ > this.options.put( > CompilerOptions.OPTION_ReportUnusedDeclaredThrownException, >Index: batch/org/eclipse/jdt/internal/compiler/batch/messages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties,v >retrieving revision 1.844 >diff -u -r1.844 messages.properties >--- batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 29 Sep 2009 15:47:17 -0000 1.844 >+++ batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 2 Oct 2009 15:46:25 -0000 >@@ -287,6 +287,7 @@ > \ typeHiding + type parameter hiding another type\n\ > \ unchecked + unchecked type operation\n\ > \ unnecessaryElse unnecessary else clause\n\ >+\ unnecessaryOperator unnecessary ''+'' operator for unary expression\n\ > \ unqualifiedField unqualified reference to field\n\ > \ unused macro for unusedArgument, unusedImport, unusedLabel,\n\ > \ unusedLocal, unusedPrivate, unusedThrown,\n\ >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.215 >diff -u -r1.215 IProblem.java >--- compiler/org/eclipse/jdt/core/compiler/IProblem.java 22 Sep 2009 14:56:46 -0000 1.215 >+++ compiler/org/eclipse/jdt/core/compiler/IProblem.java 2 Oct 2009 15:46:25 -0000 >@@ -591,6 +591,8 @@ > int InvalidHighSurrogate = Syntax + Internal + 264; > /** @since 3.2 */ > int UnnecessaryNLSTag = Internal + 265; >+ /** @since 3.6 */ >+ int UnnecessaryOperator = Internal + 266; > > // type related problems > /** @since 3.1 */ >Index: compiler/org/eclipse/jdt/internal/compiler/ast/UnaryExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/UnaryExpression.java,v >retrieving revision 1.53 >diff -u -r1.53 UnaryExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/UnaryExpression.java 7 Mar 2009 00:58:59 -0000 1.53 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/UnaryExpression.java 2 Oct 2009 15:46:25 -0000 >@@ -235,9 +235,14 @@ > case TWIDDLE : > tableId = LEFT_SHIFT; > break; >+ case PLUS : >+ tableId = PLUS; >+ scope.problemReporter().unnecessaryOperator(this); >+ break; > default : >+ // minus case > tableId = MINUS; >- } //+ and - cases >+ } > > // the code is an int > // (cast) left Op (cast) rigth --> result >Index: compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java,v >retrieving revision 1.219 >diff -u -r1.219 CompilerOptions.java >--- compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 23 Sep 2009 17:03:36 -0000 1.219 >+++ compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 2 Oct 2009 15:46:25 -0000 >@@ -125,7 +125,8 @@ > public static final String OPTION_ReportMissingSynchronizedOnInheritedMethod = "org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod"; //$NON-NLS-1$ > public static final String OPTION_ReportMissingHashCodeMethod = "org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod"; //$NON-NLS-1$ > public static final String OPTION_ReportDeadCode = "org.eclipse.jdt.core.compiler.problem.deadCode"; //$NON-NLS-1$ >- public static final String OPTION_ReportDeadCodeInTrivialIfStatement = "org.eclipse.jdt.core.compiler.problem.deadCodeInTrivialIfStatement"; //$NON-NLS-1$ >+ public static final String OPTION_ReportDeadCodeInTrivialIfStatement = "org.eclipse.jdt.core.compiler.problem.deadCodeInTrivialIfStatement"; //$NON-NLS-1$ >+ public static final String OPTION_ReportUnnecessaryOperator = "org.eclipse.jdt.core.compiler.problem.unnecessaryOperator"; //$NON-NLS-1$ > > // Backward compatibility > public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$ >@@ -230,6 +231,7 @@ > // group 2 > public static final int ShouldImplementHashcode = IrritantSet.GROUP2 | ASTNode.Bit1; > public static final int DeadCode = IrritantSet.GROUP2 | ASTNode.Bit2; >+ public static final int UnnecessaryOperator = IrritantSet.GROUP2 | ASTNode.Bit3; > > // Severity level for handlers > /** >@@ -512,6 +514,8 @@ > return OPTION_ReportMissingHashCodeMethod; > case DeadCode : > return OPTION_ReportDeadCode; >+ case UnnecessaryOperator : >+ return OPTION_ReportUnnecessaryOperator; > } > return null; > } >@@ -595,6 +599,7 @@ > OPTION_ReportAssertIdentifier, > OPTION_ReportAutoboxing, > OPTION_ReportDeadCode, >+ OPTION_ReportUnnecessaryOperator, > OPTION_ReportDeprecation, > OPTION_ReportDiscouragedReference, > OPTION_ReportEmptyStatement, >@@ -887,6 +892,7 @@ > optionsMap.put(OPTION_ReportMissingHashCodeMethod, getSeverityString(ShouldImplementHashcode)); > optionsMap.put(OPTION_ReportDeadCode, getSeverityString(DeadCode)); > optionsMap.put(OPTION_ReportDeadCodeInTrivialIfStatement, this.reportDeadCodeInTrivialIfStatement ? ENABLED : DISABLED); >+ optionsMap.put(OPTION_ReportUnnecessaryOperator, getSeverityString(UnnecessaryOperator)); > return optionsMap; > } > >@@ -1280,6 +1286,7 @@ > if ((optionValue = optionsMap.get(OPTION_ReportMissingSynchronizedOnInheritedMethod)) != null) updateSeverity(MissingSynchronizedModifierInInheritedMethod, optionValue); > if ((optionValue = optionsMap.get(OPTION_ReportMissingHashCodeMethod)) != null) updateSeverity(ShouldImplementHashcode, optionValue); > if ((optionValue = optionsMap.get(OPTION_ReportDeadCode)) != null) updateSeverity(DeadCode, optionValue); >+ if ((optionValue = optionsMap.get(OPTION_ReportUnnecessaryOperator)) != null) updateSeverity(UnnecessaryOperator, optionValue); > > // Javadoc options > if ((optionValue = optionsMap.get(OPTION_DocCommentSupport)) != null) { >Index: compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java,v >retrieving revision 1.4 >diff -u -r1.4 IrritantSet.java >--- compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java 23 Sep 2009 17:03:36 -0000 1.4 >+++ compiler/org/eclipse/jdt/internal/compiler/impl/IrritantSet.java 2 Oct 2009 15:46:25 -0000 >@@ -96,7 +96,7 @@ > | CompilerOptions.ComparingIdentical) > // group-2 warnings enabled by default > .set(CompilerOptions.DeadCode); >- >+ > ALL.setAll(); > HIDING > .set(CompilerOptions.FieldHiding) >@@ -212,9 +212,7 @@ > return this; > boolean wasNoOp = true; > for (int i = 0; i < GROUP_MAX; i++) { >- int otherIrritant = other.bits[i] & ~GROUP_MASK; // erase the >- // group >- // bits >+ int otherIrritant = other.bits[i] & ~GROUP_MASK; // erase the group bits > if ((this.bits[i] & otherIrritant) != otherIrritant) { > wasNoOp = false; > this.bits[i] |= otherIrritant; >@@ -225,8 +223,7 @@ > > public IrritantSet setAll() { > for (int i = 0; i < GROUP_MAX; i++) { >- this.bits[i] |= 0xFFFFFFFF & ~GROUP_MASK; // erase the group >- // bits; >+ this.bits[i] |= 0xFFFFFFFF & ~GROUP_MASK; // erase the group bits; > } > return this; > } >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.394 >diff -u -r1.394 ProblemReporter.java >--- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 22 Sep 2009 14:56:46 -0000 1.394 >+++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 2 Oct 2009 15:46:26 -0000 >@@ -411,6 +411,9 @@ > > case IProblem.DeadCode: > return CompilerOptions.DeadCode; >+ >+ case IProblem.UnnecessaryOperator : >+ return CompilerOptions.UnnecessaryOperator; > } > return 0; > } >@@ -481,6 +484,7 @@ > case CompilerOptions.UnusedWarningToken : > case CompilerOptions.UnusedLabel : > case CompilerOptions.RedundantSuperinterface : >+ case CompilerOptions.UnnecessaryOperator : > return CategorizedProblem.CAT_UNNECESSARY_CODE; > > case CompilerOptions.UsingDeprecatedAPI : >@@ -6731,6 +6735,16 @@ > sourceStart, > sourceEnd); > } >+public void unnecessaryOperator(UnaryExpression expression) { >+ int severity = computeSeverity(IProblem.UnnecessaryOperator); >+ if (severity == ProblemSeverities.Ignore) return; >+ this.handle( >+ IProblem.UnnecessaryOperator, >+ NoArgument, >+ NoArgument, >+ expression.sourceStart, >+ expression.sourceEnd); >+} > public void unnecessaryTypeArgumentsForMethodInvocation(MethodBinding method, TypeBinding[] genericTypeArguments, TypeReference[] typeArguments) { > String methodName = method.isConstructor() > ? new String(method.declaringClass.shortReadableName()) >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.249 >diff -u -r1.249 messages.properties >--- compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 22 Sep 2009 14:56:46 -0000 1.249 >+++ compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 2 Oct 2009 15:46:26 -0000 >@@ -223,6 +223,7 @@ > 263 = Invalid low surrogate: must be within 0xDC00 and 0xDFFF > 264 = Invalid high surrogate: must be within 0xD800 and 0xDBFF > 265 = Unnecessary $NON-NLS$ tag >+266 = Unnecessary operator > > 280 = Discouraged access: {0} > >Index: model/org/eclipse/jdt/core/JavaCore.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java,v >retrieving revision 1.638 >diff -u -r1.638 JavaCore.java >--- model/org/eclipse/jdt/core/JavaCore.java 23 Sep 2009 13:41:12 -0000 1.638 >+++ model/org/eclipse/jdt/core/JavaCore.java 2 Oct 2009 15:46:26 -0000 >@@ -742,6 +742,18 @@ > */ > public static final String COMPILER_PB_UNNECESSARY_ELSE = PLUGIN_ID + ".compiler.problem.unnecessaryElse"; //$NON-NLS-1$ > /** >+ * Compiler option ID: Reporting Unnecessary Operator. >+ * <p>When enabled, the compiler will issue an error or a warning when an unary expression is using a '+' operator.</p> >+ * <dl> >+ * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.problem.unnecessaryOperator"</code></dd> >+ * <dt>Possible values:</dt><dd><code>{ "error", "warning", "ignore" }</code></dd> >+ * <dt>Default:</dt><dd><code>"ignore"</code></dd> >+ * </dl> >+ * @since 3.6 >+ * @category CompilerOptionID >+ */ >+ public static final String COMPILER_PB_UNNECESSARY_OPERATOR = PLUGIN_ID + ".compiler.problem.unnecessaryOperator"; //$NON-NLS-1$ >+ /** > * Compiler option ID: Reporting Undocumented Empty Block. > * <p>When enabled, the compiler will issue an error or a warning when an empty block is detected and it is not > * documented with any comment. >#P org.eclipse.jdt.core.tests.compiler >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.59 >diff -u -r1.59 AssignmentTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java 24 Sep 2009 20:56:47 -0000 1.59 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java 2 Oct 2009 15:46:27 -0000 >@@ -33,7 +33,7 @@ > // All specified tests which does not belong to the class are skipped... > static { > // TESTS_NAMES = new String[] { "test000" }; >-// TESTS_NUMBERS = new int[] { 67 }; >+// TESTS_NUMBERS = new int[] { 69 }; > // TESTS_RANGE = new int[] { 11, -1 }; > } > public static Test suite() { >@@ -45,8 +45,7 @@ > * http://bugs.eclipse.org/bugs/show_bug.cgi?id=27235 > */ > public void test001() { >- this.runConformTest( >- new String[] { >+ this.runConformTest( new String[] { > "X.java", > "public class X { \n" + > " int i; \n" + >@@ -1954,6 +1953,58 @@ > options > ); > } >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106478 >+public void test068() { >+ Map options = getCompilerOptions(); >+ options.put(CompilerOptions.OPTION_ReportUnnecessaryOperator, CompilerOptions.ERROR); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public boolean test() {\n" + >+ " int i = 0;\n" + >+ " i =+ 1;\n" + >+ " System.out.println(i);\n" + >+ " }\n" + >+ "}" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\n" + >+ " i =+ 1;\n" + >+ " ^^^\n" + >+ "Unnecessary operator\n" + >+ "----------\n", >+ null, >+ true, >+ options >+ ); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106478 >+public void test069() { >+ Map options = getCompilerOptions(); >+ options.put(CompilerOptions.OPTION_ReportUnnecessaryOperator, CompilerOptions.ERROR); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public boolean test() {\n" + >+ " int i = 0;\n" + >+ " i = +1;\n" + >+ " System.out.println(i);\n" + >+ " }\n" + >+ "}" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\n" + >+ " i = +1;\n" + >+ " ^^\n" + >+ "Unnecessary operator\n" + >+ "----------\n", >+ null, >+ true, >+ options >+ ); >+} > public static Class testClass() { > return AssignmentTest.class; > } >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.195 >diff -u -r1.195 BatchCompilerTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 23 Sep 2009 16:27:19 -0000 1.195 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 2 Oct 2009 15:46:27 -0000 >@@ -1692,6 +1692,7 @@ > " typeHiding + type parameter hiding another type\n" + > " unchecked + unchecked type operation\n" + > " unnecessaryElse unnecessary else clause\n" + >+ " unnecessaryOperator unnecessary ''+'' operator for unary expression\n" + > " unqualifiedField unqualified reference to field\n" + > " unused macro for unusedArgument, unusedImport, unusedLabel,\n" + > " unusedLocal, unusedPrivate, unusedThrown,\n" + >@@ -1838,6 +1839,7 @@ > " <option key=\"org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock\" value=\"ignore\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.unhandledWarningToken\" value=\"warning\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.unnecessaryElse\" value=\"ignore\"/>\n" + >+ " <option key=\"org.eclipse.jdt.core.compiler.problem.unnecessaryOperator\" value=\"ignore\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck\" value=\"ignore\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess\" value=\"ignore\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException\" value=\"ignore\"/>\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 106478
: 148659