Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorM N Palat2013-07-11 11:17:39 +0000
committerM N Palat2013-07-11 11:17:39 +0000
commit328c06fa136c963530115a367863b6a931384871 (patch)
treef01986499e174f594ec28f42dee179229ed0f487 /org.eclipse.jdt.core
parent7a4894572c8dc97616c8aa59652842aae37320e6 (diff)
downloadeclipse.jdt.core-328c06fa136c963530115a367863b6a931384871.tar.gz
eclipse.jdt.core-328c06fa136c963530115a367863b6a931384871.tar.xz
eclipse.jdt.core-328c06fa136c963530115a367863b6a931384871.zip
Fix for Bug 4009077">4009077 [1.8][compiler] Illegal combination of modifiers on
interface methods produces confusing diagnostics
Diffstat (limited to 'org.eclipse.jdt.core')
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java6
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java18
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java25
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties12
4 files changed, 49 insertions, 12 deletions
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 6fac35dffa..f52ea75d66 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
@@ -1693,7 +1693,7 @@ void setSourceStart(int sourceStart);
// default methods:
/** @since 3.9 BETA_JAVA8 */
- int IllegalModifierForInterfaceDefaultMethod = MethodRelated + 1050;
+ int IllegalModifierForInterfaceMethod18 = MethodRelated + 1050;
/** @since 3.9 BETA_JAVA8 */
int DefaultMethodOverridesObjectMethod = MethodRelated + 1051;
@@ -1708,6 +1708,10 @@ void setSourceStart(int sourceStart);
int SuperAccessCannotBypassDirectSuper = TypeRelated + 1054;
/** @since 3.9 BETA_JAVA8 */
int SuperCallCannotBypassOverride = MethodRelated + 1055;
+ /** @since 3.9 BETA_JAVA8 */
+ int IllegalModifierCombinationForInterfaceMethod = MethodRelated + 1056;
+ /** @since 3.9 BETA_JAVA8 */
+ int IllegalAbstractStrictfpModifierCombinationForInterfaceMethod = MethodRelated + 1057;
/**
* External problems -- These are problems defined by other plugins
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java
index d1e06dfb62..843981786f 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java
@@ -179,10 +179,22 @@ private void checkAndSetModifiersForMethod(MethodBinding methodBinding) {
if (declaringClass.isInterface()) {
int expectedModifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract;
boolean isDefaultMethod = (modifiers & ExtraCompilerModifiers.AccDefaultMethod) != 0; // no need to check validity, is done by the parser
+ boolean reportIllegalModifierCombination = false;
+ boolean isJDK18orGreater = false;
if (compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8 && !declaringClass.isAnnotationType()) {
+ expectedModifiers |= ClassFileConstants.AccStrictfp
+ | ExtraCompilerModifiers.AccDefaultMethod | ClassFileConstants.AccStatic;
+ isJDK18orGreater = true;
if (!methodBinding.isAbstract()) {
- expectedModifiers |= ClassFileConstants.AccStrictfp
- | (isDefaultMethod ? ExtraCompilerModifiers.AccDefaultMethod : ClassFileConstants.AccStatic);
+ reportIllegalModifierCombination = isDefaultMethod && methodBinding.isStatic();
+ } else {
+ reportIllegalModifierCombination = isDefaultMethod || methodBinding.isStatic();
+ if (methodBinding.isStrictfp()) {
+ problemReporter().illegalAbstractModifierCombinationForMethod((AbstractMethodDeclaration) this.referenceContext);
+ }
+ }
+ if (reportIllegalModifierCombination) {
+ problemReporter().illegalModifierCombinationForInterfaceMethod((AbstractMethodDeclaration) this.referenceContext);
}
// Kludge - The AccDefaultMethod bit is outside the lower 16 bits and got removed earlier. Putting it back.
if (isDefaultMethod) {
@@ -193,7 +205,7 @@ private void checkAndSetModifiersForMethod(MethodBinding methodBinding) {
if ((declaringClass.modifiers & ClassFileConstants.AccAnnotation) != 0)
problemReporter().illegalModifierForAnnotationMember((AbstractMethodDeclaration) this.referenceContext);
else
- problemReporter().illegalModifierForInterfaceMethod((AbstractMethodDeclaration) this.referenceContext, isDefaultMethod);
+ problemReporter().illegalModifierForInterfaceMethod((AbstractMethodDeclaration) this.referenceContext, isJDK18orGreater);
}
return;
}
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 1ac82209b0..d4af206f88 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
@@ -2442,6 +2442,15 @@ public void illegalAbstractModifierCombinationForMethod(ReferenceBinding type, A
methodDecl.sourceStart,
methodDecl.sourceEnd);
}
+public void illegalAbstractModifierCombinationForMethod(AbstractMethodDeclaration methodDecl) {
+ String[] arguments = new String[] {new String(methodDecl.selector)};
+ this.handle(
+ IProblem.IllegalAbstractStrictfpModifierCombinationForInterfaceMethod,
+ arguments,
+ arguments,
+ methodDecl.sourceStart,
+ methodDecl.sourceEnd);
+}
public void illegalAccessFromTypeVariable(TypeVariableBinding variable, ASTNode location) {
if ((location.bits & ASTNode.InsideJavadoc)!= 0) {
javadocInvalidReference(location.sourceStart, location.sourceEnd);
@@ -2568,6 +2577,16 @@ public void illegalModifierCombinationFinalVolatileForField(ReferenceBinding typ
fieldDecl.sourceStart,
fieldDecl.sourceEnd);
}
+public void illegalModifierCombinationForInterfaceMethod(AbstractMethodDeclaration methodDecl) {
+ String[] arguments = new String[] {new String(methodDecl.selector)};
+ this.handle(
+ IProblem.IllegalModifierCombinationForInterfaceMethod,
+ arguments,
+ arguments,
+ methodDecl.sourceStart,
+ methodDecl.sourceEnd);
+}
+
public void illegalModifierForAnnotationField(FieldDeclaration fieldDecl) {
String name = new String(fieldDecl.name);
this.handle(
@@ -2685,12 +2704,12 @@ public void illegalModifierForInterfaceField(FieldDeclaration fieldDecl) {
fieldDecl.sourceStart,
fieldDecl.sourceEnd);
}
-public void illegalModifierForInterfaceMethod(AbstractMethodDeclaration methodDecl, boolean isDefaultMethod) {
+public void illegalModifierForInterfaceMethod(AbstractMethodDeclaration methodDecl, boolean isJDK18orGreater) {
// cannot include parameter types since they are not resolved yet
// and the error message would be too long
this.handle(
- isDefaultMethod
- ? IProblem.IllegalModifierForInterfaceDefaultMethod
+ isJDK18orGreater
+ ? IProblem.IllegalModifierForInterfaceMethod18
: IProblem.IllegalModifierForInterfaceMethod,
new String[] {
new String(methodDecl.selector)
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 88c5c2a20f..f2b733358b 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
@@ -273,8 +273,8 @@
301 = Duplicate modifier for the type {0}
302 = Illegal modifier for the class {0}; only public, abstract & final are permitted
303 = Illegal modifier for the interface {0}; only public & abstract are permitted
-304 = Illegal modifier for the member class {0}; only public, protected, private, static, abstract & final are permitted
-305 = Illegal modifier for the member interface {0}; only public, protected, private, static & abstract are permitted
+304 = Illegal modifier for the member class {0}; only public, protected, private, abstract, static & final are permitted
+305 = Illegal modifier for the member interface {0}; only public, protected, private, abstract & static are permitted
306 = Illegal modifier for the local class {0}; only abstract or final is permitted
307 = Access restriction: {0}
308 = The class {0} can be either abstract or final, not both
@@ -332,7 +332,7 @@
355 = Duplicate method {0}({2}) in type {1}
356 = Illegal modifier for parameter {0}; only final is permitted
357 = Duplicate modifier for the method {1} in type {0}
-358 = Illegal modifier for the method {0}; only public, protected, private, static, final, abstract, synchronized, strictfp & native are permitted
+358 = Illegal modifier for the method {0}; only public, protected, private, abstract, static, final, synchronized, native & strictfp are permitted
359 = Illegal modifier for the interface method {0}; only public & abstract are permitted
360 = The method {1} in type {0} can only set one of public / protected / private
361 = The method {1} cannot be declared static; static methods can only be declared in a static or top level type
@@ -578,7 +578,7 @@
601 = Extended dimensions are illegal in an annotation attribute declaration
602 = Package annotations must be in file package-info.java
603 = Illegal modifier for the annotation type {0}; only public & abstract are permitted
-604 = Illegal modifier for the member annotation type {0}; only public, protected, private, static & abstract are permitted
+604 = Illegal modifier for the member annotation type {0}; only public, protected, private, abstract & static are permitted
605 = Invalid type {0} for the annotation attribute {2}.{1}; only primitive type, String, Class, annotation, enumeration are permitted or 1-dimensional arrays thereof
606 = Cycle detected: the annotation type {0} cannot contain attributes of the annotation type itself
607 = Cycle detected: a cycle exists between annotation attributes of {0} and {1}
@@ -787,12 +787,14 @@
# Default methods:
# variant of 359:
-1050 = Illegal modifier for the interface method {0}; only public, abstract and strictfp are permitted
+1050 = Illegal modifier for the interface method {0}; only public, abstract, default, static and strictfp are permitted
1051 = A default method cannot override a method from java.lang.Object
1052 = The default method {0} inherited from {1} conflicts with another method inherited from {2}
1053 = Duplicate default methods named {0} with the parameters ({1}) and ({2}) are inherited from the types {3} and {4}
1054 = Illegal reference to super type {0}, cannot bypass the more specific direct super type {1}
1055 = Illegal reference to super method {0} from type {1}, cannot bypass the more specific override from type {2}
+1056 = Illegal combination of modifiers for the interface method {0}; only one of abstract, default, or static permitted
+1057 = Illegal modifiers for the interface method {0}; strictfp is not permitted for abstract interface methods
### ELABORATIONS
## Access restrictions

Back to the top