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 52077 Details for
Bug 156736
[compiler] Add compiler option to warn overriding methods that do not call super
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix
patch_156736.txt (text/plain), 20.36 KB, created by
Olivier Thomann
on 2006-10-16 17:24:27 EDT
(
hide
)
Description:
Proposed fix
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2006-10-16 17:24:27 EDT
Size:
20.36 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java,v >retrieving revision 1.27 >diff -u -r1.27 TagBits.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java 25 Apr 2006 19:36:31 -0000 1.27 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java 16 Oct 2006 21:27:42 -0000 >@@ -27,6 +27,8 @@ > long IsBinaryBinding = ASTNode.Bit7; > > long HasInconsistentHierarchy = ASTNode.Bit8; // for binary type binding only >+ >+ long OverridingMethodWithSupercall = ASTNode.Bit8; // method binding only > > // for the type cycle hierarchy check used by ClassScope > long BeginHierarchyCheck = ASTNode.Bit9; // type >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.180 >diff -u -r1.180 IProblem.java >--- compiler/org/eclipse/jdt/core/compiler/IProblem.java 13 Sep 2006 02:25:45 -0000 1.180 >+++ compiler/org/eclipse/jdt/core/compiler/IProblem.java 16 Oct 2006 21:27:42 -0000 >@@ -735,7 +735,8 @@ > int IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod = MethodRelated + 414; > /** @since 3.1 */ > int IllegalVararg = MethodRelated + 415; >- >+ int OverridingMethodWithoutSupercall = MethodRelated + 416; >+ > // code snippet support > int CodeSnippetMissingClass = Internal + 420; > int CodeSnippetMissingMethod = Internal + 421; >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.208 >diff -u -r1.208 messages.properties >--- compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 13 Sep 2006 02:25:45 -0000 1.208 >+++ compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 16 Oct 2006 21:27:43 -0000 >@@ -336,12 +336,13 @@ > 407 = This static method cannot hide the instance method from {0} > 408 = The static method {0} conflicts with the abstract method in {1} > 409 = Cannot reduce the visibility of the inherited method from {0} >-410 = The method {0} does not override the inherited method from {1} since it is private to a different package. >-411 = This class must implement the inherited abstract method {1}, but cannot override it since it is not visible from {0}. Either make the type abstract or make the inherited method visible. >+410 = The method {0} does not override the inherited method from {1} since it is private to a different package >+411 = This class must implement the inherited abstract method {1}, but cannot override it since it is not visible from {0}. Either make the type abstract or make the inherited method visible > 412 = The method {0} overrides a deprecated method from {1} > 413 = The return type is incompatible with {0}, thus this interface cannot be implemented > 414 = Exception {0} is not compatible with throws clause in {1}, thus this interface cannot be implemented > 415 = The variable argument type {0} of the method {1} must be the last parameter >+416 = The method {0} is overriding a method without making a super call > > 420 = Code snippet support cannot find the class {0} > 421 = Code snippet support cannot find the method {0}.{1}({2}) >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.323 >diff -u -r1.323 ProblemReporter.java >--- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 29 Sep 2006 18:38:45 -0000 1.323 >+++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 16 Oct 2006 21:27:43 -0000 >@@ -361,6 +361,7 @@ > case (int)(CompilerOptions.NullReference >>> 32): > case (int)(CompilerOptions.IncompleteEnumSwitch >>> 32): > case (int)(CompilerOptions.FallthroughCase >>> 32): >+ case (int)(CompilerOptions.OverridingMethodWithoutSupercall >>> 32): > return CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM; > > case (int)(CompilerOptions.TypeParameterHiding >>> 32): >@@ -4895,6 +4896,26 @@ > localMethod.sourceStart(), > localMethod.sourceEnd()); > } >+public void overridesMethodWithoutSuperCall(MethodBinding localMethod) { >+ this.handle( >+ IProblem.OverridingMethodWithoutSupercall, >+ new String[] { >+ new String( >+ CharOperation.concat( >+ localMethod.declaringClass.readableName(), >+ localMethod.readableName(), >+ '.')) >+ }, >+ new String[] { >+ new String( >+ CharOperation.concat( >+ localMethod.declaringClass.shortReadableName(), >+ localMethod.shortReadableName(), >+ '.')) >+ }, >+ localMethod.sourceStart(), >+ localMethod.sourceEnd()); >+} > public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) { > String[] arguments = new String[] {CharOperation.toString(compUnitDecl.currentPackage.tokens)}; > this.handle( >Index: formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java,v >retrieving revision 1.56 >diff -u -r1.56 DefaultCodeFormatter.java >--- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java 21 Jun 2006 17:05:04 -0000 1.56 >+++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java 16 Oct 2006 21:27:43 -0000 >@@ -327,6 +327,7 @@ > optionsMap.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.DISABLED); > optionsMap.put(CompilerOptions.OPTION_ReportMethodWithConstructorName, CompilerOptions.IGNORE); > optionsMap.put(CompilerOptions.OPTION_ReportOverridingPackageDefaultMethod, CompilerOptions.IGNORE); >+ optionsMap.put(CompilerOptions.OPTION_ReportOverridingMethodWithoutSuperCall, CompilerOptions.IGNORE); > optionsMap.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); > optionsMap.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.DISABLED); > optionsMap.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, CompilerOptions.DISABLED); >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.569 >diff -u -r1.569 messages.properties >--- batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 10 Oct 2006 17:26:44 -0000 1.569 >+++ batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 16 Oct 2006 21:27:42 -0000 >@@ -230,6 +230,7 @@ > \ noEffectAssign + assignment without effect\n\ > \ null missing or redundant null check\n\ > \ over-ann missing @Override annotation\n\ >+\ overridingNoSuper overriding a method without making a super call\n\ > \ paramAssign assignment to a parameter\n\ > \ pkgDefaultMethod + attempt to override package-default method\n\ > \ raw + usage of raw type\n\ >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.263 >diff -u -r1.263 Main.java >--- batch/org/eclipse/jdt/internal/compiler/batch/Main.java 16 Oct 2006 19:04:39 -0000 1.263 >+++ batch/org/eclipse/jdt/internal/compiler/batch/Main.java 16 Oct 2006 21:27:42 -0000 >@@ -1645,6 +1645,10 @@ > this.options.put( > CompilerOptions.OPTION_ReportFallthroughCase, > isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); >+ } else if (token.equals("overridingNoSuper")) { //$NON-NLS-1$ >+ this.options.put( >+ CompilerOptions.OPTION_ReportOverridingMethodWithoutSuperCall, >+ isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); > } else { > throw new InvalidInputException(this.bind("configure.invalidWarning", token)); //$NON-NLS-1$ > } >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.554 >diff -u -r1.554 JavaCore.java >--- model/org/eclipse/jdt/core/JavaCore.java 6 Oct 2006 17:43:34 -0000 1.554 >+++ model/org/eclipse/jdt/core/JavaCore.java 16 Oct 2006 21:27:43 -0000 >@@ -675,6 +675,12 @@ > /** > * Possible configurable option ID. > * @see #getDefaultOptions() >+ * @since 3.3 >+ */ >+ public static final String COMPILER_PB_OVERRIDING_METHOD_WITHOUT_SUPER_CALL = PLUGIN_ID + ".compiler.problem.overridingMethodWithoutSupercall"; //$NON-NLS-1$ >+ /** >+ * Possible configurable option ID. >+ * @see #getDefaultOptions() > */ > public static final String CORE_JAVA_BUILD_ORDER = PLUGIN_ID + ".computeJavaBuildOrder"; //$NON-NLS-1$ > /** >@@ -2321,6 +2327,13 @@ > * - possible values: { "error", "warning", "ignore" } > * - default: "ignore" > * >+ * COMPILER / Reporting Overriding method that doesn't call the super method >+ * When enabled, the compiler will issue an error or a warning if a method is overriding a method from the super class >+ * without calling the super method. >+ * - option id: "org.eclipse.jdt.core.compiler.problem.overridingMethodWithoutSupercall" >+ * - possible values: { "error", "warning", "ignore" } >+ * - default: "ignore" >+ * > * BUILDER / Specifying Filters for Resource Copying Control > * Allow to specify some filters to control the resource copy process. > * - option id: "org.eclipse.jdt.core.builder.resourceCopyExclusionFilter" >Index: compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java,v >retrieving revision 1.114 >diff -u -r1.114 MessageSend.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java 16 Oct 2006 19:39:36 -0000 1.114 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java 16 Oct 2006 21:27:42 -0000 >@@ -414,13 +414,14 @@ > } > return this.resolvedType; > } >+ final CompilerOptions compilerOptions = scope.compilerOptions(); > if (!binding.isStatic()) { > // the "receiver" must not be a type, in other words, a NameReference that the TC has bound to a Type > if (receiverIsType) { > scope.problemReporter().mustUseAStaticMethod(this, binding); > if (this.actualReceiverType.isRawType() > && (this.receiver.bits & IgnoreRawTypeCheck) == 0 >- && scope.compilerOptions().getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore) { >+ && compilerOptions.getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore) { > scope.problemReporter().rawTypeReference(this.receiver, this.actualReceiverType); > } > } else { >@@ -457,7 +458,7 @@ > // from 1.5 compliance on, array#clone() returns the array type (but binding still shows Object) > if (actualReceiverType.isArrayType() > && this.binding.parameters == Binding.NO_PARAMETERS >- && scope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_5 >+ && compilerOptions.complianceLevel >= ClassFileConstants.JDK1_5 > && CharOperation.equals(this.binding.selector, CLONE)) { > this.resolvedType = actualReceiverType; > } else { >@@ -465,6 +466,15 @@ > if (returnType != null) returnType = returnType.capture(scope, this.sourceEnd); > this.resolvedType = returnType; > } >+ if (receiver.isSuper() && compilerOptions.getSeverity(CompilerOptions.OverridingMethodWithoutSupercall) != ProblemSeverities.Ignore) { >+ if (scope.methodScope().referenceContext instanceof AbstractMethodDeclaration) { >+ MethodBinding currentMethodBinding = ((AbstractMethodDeclaration) scope.methodScope().referenceContext).binding; >+ if (CharOperation.equals(this.binding.selector, currentMethodBinding.selector) >+ && this.binding.areParametersEqual(currentMethodBinding)) { >+ currentMethodBinding.tagBits |= TagBits.OverridingMethodWithSupercall; >+ } >+ } >+ } > return this.resolvedType; > } > >Index: compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java,v >retrieving revision 1.56 >diff -u -r1.56 MethodDeclaration.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java 13 Oct 2006 19:20:46 -0000 1.56 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java 16 Oct 2006 21:27:42 -0000 >@@ -17,9 +17,11 @@ > import org.eclipse.jdt.internal.compiler.flow.ExceptionHandlingFlowContext; > import org.eclipse.jdt.internal.compiler.flow.FlowInfo; > import org.eclipse.jdt.internal.compiler.flow.InitializationFlowContext; >+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; > import org.eclipse.jdt.internal.compiler.lookup.*; > import org.eclipse.jdt.internal.compiler.parser.*; > import org.eclipse.jdt.internal.compiler.problem.AbortMethod; >+import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; > > public class MethodDeclaration extends AbstractMethodDeclaration { > >@@ -142,9 +144,10 @@ > } > > // check @Override annotation >+ final CompilerOptions compilerOptions = this.scope.compilerOptions(); > checkOverride: { > if (this.binding == null) break checkOverride; >- if (this.scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_5) break checkOverride; >+ if (compilerOptions.sourceLevel < ClassFileConstants.JDK1_5) break checkOverride; > int bindingModifiers = this.binding.modifiers; > boolean hasOverrideAnnotation = (this.binding.tagBits & TagBits.AnnotationOverride) != 0; > boolean isInterfaceMethod = this.binding.declaringClass.isInterface(); >@@ -157,7 +160,7 @@ > this.scope.problemReporter().missingOverrideAnnotation(this); > } > } >- >+ > // by grammatical construction, interface methods are always abstract > switch (TypeDeclaration.kind(this.scope.referenceType().modifiers)) { > case TypeDeclaration.ENUM_DECL : >@@ -176,7 +179,16 @@ > this.scope.problemReporter().methodNeedingNoBody(this); > } > } >- super.resolveStatements(); >+ super.resolveStatements(); >+ >+ // TagBits.OverridingMethodWithSupercall is set during the resolveStatements() call >+ if (compilerOptions.getSeverity(CompilerOptions.OverridingMethodWithoutSupercall) != ProblemSeverities.Ignore) { >+ int bindingModifiers = this.binding.modifiers; >+ if ((bindingModifiers & ExtraCompilerModifiers.AccOverriding) != 0 >+ && (this.binding.tagBits & TagBits.OverridingMethodWithSupercall) == 0) { >+ this.scope.problemReporter().overridesMethodWithoutSuperCall(this.binding); >+ } >+ } > } > > public void traverse( >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.170 >diff -u -r1.170 CompilerOptions.java >--- compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 3 Oct 2006 15:18:47 -0000 1.170 >+++ compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 16 Oct 2006 21:27:42 -0000 >@@ -105,6 +105,7 @@ > public static final String OPTION_FatalOptionalError = "org.eclipse.jdt.core.compiler.problem.fatalOptionalError"; //$NON-NLS-1$ > public static final String OPTION_ReportParameterAssignment = "org.eclipse.jdt.core.compiler.problem.parameterAssignment"; //$NON-NLS-1$ > public static final String OPTION_ReportFallthroughCase = "org.eclipse.jdt.core.compiler.problem.fallthroughCase"; //$NON-NLS-1$ >+ public static final String OPTION_ReportOverridingMethodWithoutSuperCall = "org.eclipse.jdt.core.compiler.problem.overridingMethodWithoutSupercall"; //$NON-NLS-1$ > > // Backward compatibility > public static final String OPTION_ReportInvalidAnnotation = "org.eclipse.jdt.core.compiler.problem.invalidAnnotation"; //$NON-NLS-1$ >@@ -187,6 +188,7 @@ > public static final long UnusedLabel = ASTNode.Bit47L; > public static final long ParameterAssignment = ASTNode.Bit48L; > public static final long FallthroughCase = ASTNode.Bit49L; >+ public static final long OverridingMethodWithoutSupercall = ASTNode.Bit50L; > > // Default severity level for handlers > public long errorThreshold = 0; >@@ -406,6 +408,7 @@ > optionsMap.put(OPTION_ReportUnhandledWarningToken, getSeverityString(UnhandledWarningToken)); > optionsMap.put(OPTION_ReportParameterAssignment, getSeverityString(ParameterAssignment)); > optionsMap.put(OPTION_ReportFallthroughCase, getSeverityString(FallthroughCase)); >+ optionsMap.put(OPTION_ReportOverridingMethodWithoutSuperCall, getSeverityString(OverridingMethodWithoutSupercall)); > return optionsMap; > } > >@@ -647,6 +650,7 @@ > if ((optionValue = optionsMap.get(OPTION_ReportUnusedLabel)) != null) updateSeverity(UnusedLabel, optionValue); > if ((optionValue = optionsMap.get(OPTION_ReportParameterAssignment)) != null) updateSeverity(ParameterAssignment, optionValue); > if ((optionValue = optionsMap.get(OPTION_ReportFallthroughCase)) != null) updateSeverity(FallthroughCase, optionValue); >+ if ((optionValue = optionsMap.get(OPTION_ReportOverridingMethodWithoutSuperCall)) != null) updateSeverity(OverridingMethodWithoutSupercall, optionValue); > > // Javadoc options > if ((optionValue = optionsMap.get(OPTION_DocCommentSupport)) != null) { >@@ -914,6 +918,7 @@ > OPTION_ReportUnusedPrivateMember, > OPTION_ReportVarargsArgumentNeedCast, > OPTION_ReportUnhandledWarningToken, >+ OPTION_ReportOverridingMethodWithoutSuperCall > }; > return result; > } >#P org.eclipse.jdt.core.tests.compiler >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.75 >diff -u -r1.75 BatchCompilerTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 3 Oct 2006 15:19:13 -0000 1.75 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 16 Oct 2006 21:27:44 -0000 >@@ -1030,6 +1030,7 @@ > " noEffectAssign + assignment without effect\n" + > " null missing or redundant null check\n" + > " over-ann missing @Override annotation\n" + >+ " overridingNoSuper overriding a method without making a super call\n" + > " paramAssign assignment to a parameter\n" + > " pkgDefaultMethod + attempt to override package-default method\n" + > " raw + usage of raw type\n" + >@@ -1168,6 +1169,7 @@ > " <option key=\"org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion\" value=\"warning\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral\" value=\"ignore\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.nullReference\" value=\"ignore\"/>\n" + >+ " <option key=\"org.eclipse.jdt.core.compiler.problem.overridingMethodWithoutSupercall\" value=\"ignore\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod\" value=\"warning\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.parameterAssignment\" value=\"ignore\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment\" 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 156736
:
52077
|
52122
|
52261