Revert eeafa6d90df04799bdbc84b253f50d4f1ea630a2 from orig (parts of
which were applied manually) because this will come in through merging
with master.
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java
index cf0d06f..ab52ffb 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java
@@ -23,8 +23,6 @@
* bug 370639 - [compiler][resource] restore the default for resource leak warnings
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
* bug 388996 - [compiler][resource] Incorrect 'potential resource leak'
- * Jesper S Moller <jesper@selskabet.org> - Contributions for
- * bug 378674 - "The method can be declared as static" is wrong
* Andy Clement - Contributions for
* Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work)
*******************************************************************************/
@@ -140,9 +138,7 @@
if (this.binding.declaringClass.isMemberType() && !this.binding.declaringClass.isStatic()) {
// allocating a non-static member type without an enclosing instance of parent type
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335845
- currentScope.tagAsAccessingEnclosingInstanceStateOf(this.binding.declaringClass.enclosingType(), false /* type variable access */);
- // Reviewed for https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674 :
- // The corresponding problem (when called from static) is not produced until during code generation
+ currentScope.resetDeclaringClassMethodStaticFlag(this.binding.declaringClass.enclosingType());
}
manageEnclosingInstanceAccessIfNecessary(currentScope, flowInfo);
manageSyntheticAccessIfNecessary(currentScope, flowInfo);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java
index c6cbad8..e06f7f7 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java
@@ -169,6 +169,17 @@
flowInfo.markAsDefinitelyAssigned(this.binding);
}
}
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682
+ if (!this.binding.isStatic()) {
+ if (this.receiver.isThis()) {
+ currentScope.resetDeclaringClassMethodStaticFlag(this.binding.declaringClass);
+ }
+ } else if (this.receiver.isThis()) {
+ if ((this.receiver.bits & ASTNode.IsImplicitThis) == 0) {
+ // explicit this, not allowed in static context
+ currentScope.resetDeclaringClassMethodStaticFlag(this.binding.declaringClass);
+ }
+ }
return flowInfo;
}
@@ -181,6 +192,10 @@
this.receiver.analyseCode(currentScope, flowContext, flowInfo, nonStatic);
if (nonStatic) {
this.receiver.checkNPE(currentScope, flowContext, flowInfo);
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682
+ if (this.receiver.isThis()) {
+ currentScope.resetDeclaringClassMethodStaticFlag(this.binding.declaringClass);
+ }
}
if (valueRequired || currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java
index aeb7037..c3cd483 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java
@@ -214,6 +214,11 @@
if (nonStatic) {
this.receiver.checkNPE(currentScope, flowContext, flowInfo);
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682
+ if (this.receiver.isThis() || this.receiver.isSuper()) {
+ // accessing non-static method without an object
+ currentScope.resetDeclaringClassMethodStaticFlag(this.actualReceiverType);
+ }
}
if (this.arguments != null) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
index f64a4ec..24a8edb 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java
@@ -22,11 +22,9 @@
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
* bug 388996 - [compiler][resource] Incorrect 'potential resource leak'
* bug 395977 - [compiler][resource] Resource leak warning behavior possibly incorrect for anonymous inner class
- * Jesper S Moller <jesper@selskabet.org> - Contributions for
- * bug 378674 - "The method can be declared as static" is wrong
* Andy Clement - Contributions for
* Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work)
- ******************************************************************************/
+ *******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
import org.eclipse.jdt.internal.compiler.ASTVisitor;
@@ -149,9 +147,7 @@
ReferenceBinding superclass = this.binding.declaringClass.superclass();
if (superclass != null && superclass.isMemberType() && !superclass.isStatic()) {
// creating an anonymous type of a non-static member type without an enclosing instance of parent type
- currentScope.tagAsAccessingEnclosingInstanceStateOf(superclass.enclosingType(), false /* type variable access */);
- // Reviewed for https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674 :
- // The corresponding problem (when called from static) is not produced until during code generation
+ currentScope.resetDeclaringClassMethodStaticFlag(superclass.enclosingType());
}
}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java
index 66ae0de..9649267 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java
@@ -23,8 +23,6 @@
* bug 382721 - [1.8][compiler] Effectively final variables needs special treatment
* bug 331649 - [compiler][null] consider null annotations for fields
* bug 383368 - [compiler][null] syntactic null analysis for field references
- * Jesper S Moller <jesper@selskabet.org> - Contributions for
- * bug 378674 - "The method can be declared as static" is wrong
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -132,6 +130,9 @@
currentScope.problemReporter().uninitializedBlankFinalField(lastFieldBinding, this);
}
}
+ if (!lastFieldBinding.isStatic()) {
+ currentScope.resetDeclaringClassMethodStaticFlag(lastFieldBinding.declaringClass);
+ }
break;
case Binding.LOCAL :
// first binding is a local variable
@@ -239,6 +240,9 @@
}
}
}
+ if (!fieldBinding.isStatic()) {
+ currentScope.resetDeclaringClassMethodStaticFlag(fieldBinding.declaringClass);
+ }
break;
case Binding.LOCAL : // reading a local variable
LocalVariableBinding localBinding;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedThisReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedThisReference.java
index 943fed7..780b153 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedThisReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedThisReference.java
@@ -141,8 +141,6 @@
scope.problemReporter().noSuchEnclosingInstance(type, this, false);
// otherwise problem will be reported by the caller
return this.resolvedType;
- } else {
- scope.tagAsAccessingEnclosingInstanceStateOf(this.currentCompatibleType, false /* type variable access */);
}
// Ensure one cannot write code like: B() { super(B.this); }
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java
index f432e65..5cdbf8a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java
@@ -18,9 +18,7 @@
* bug 185682 - Increment/decrement operators mark local variables as read
* bug 331649 - [compiler][null] consider null annotations for fields
* bug 383368 - [compiler][null] syntactic null analysis for field references
- * Jesper S Moller - <jesper@selskabet.org> - Contributions for
- * bug 382721 - [1.8][compiler] Effectively final variables needs special treatment
- * bug 378674 - "The method can be declared as static" is wrong
+ * Jesper S Moller - <jesper@selskabet.org> - Contributions for bug 382721 - [1.8][compiler] Effectively final variables needs special treatment
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -100,6 +98,10 @@
currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
}
}
+ if (!fieldBinding.isStatic()) {
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682
+ currentScope.resetDeclaringClassMethodStaticFlag(fieldBinding.declaringClass);
+ }
manageSyntheticAccessIfNecessary(currentScope, flowInfo, true /*read-access*/);
break;
case Binding.LOCAL : // reading a local variable
@@ -147,6 +149,10 @@
// record assignment for detecting uninitialized non-null fields:
flowInfo.markAsDefinitelyAssigned(fieldBinding);
}
+ if (!fieldBinding.isStatic()) {
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682
+ currentScope.resetDeclaringClassMethodStaticFlag(fieldBinding.declaringClass);
+ }
break;
case Binding.LOCAL : // assigning to a local variable
LocalVariableBinding localBinding = (LocalVariableBinding) this.binding;
@@ -203,6 +209,10 @@
currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
}
}
+ if (!fieldBinding.isStatic()) {
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682
+ currentScope.resetDeclaringClassMethodStaticFlag(fieldBinding.declaringClass);
+ }
break;
case Binding.LOCAL : // reading a local variable
LocalVariableBinding localBinding;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java
index 51ffe15..cdc45ae 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -23,8 +23,6 @@
* bug 379784 - [compiler] "Method can be static" is not getting reported
* bug 394768 - [compiler][resource] Incorrect resource leak warning when creating stream in conditional
* bug 404649 - [1.8][compiler] detect illegal reference to indirect or redundant super
- * Jesper S Moller <jesper@selskabet.org> - Contributions for
- * bug 378674 - "The method can be declared as static" is wrong
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.lookup;
@@ -721,8 +719,6 @@
field.declaringClass,
CharOperation.concatWith(CharOperation.subarray(compoundName, 0, currentIndex), '.'),
ProblemReasons.NonStaticReferenceInStaticContext);
- // Since a qualified reference must be for a static member, it won't affect static-ness of the enclosing method,
- // so we don't have to call resetEnclosingMethodStaticFlag() in this case
return binding;
}
if ((mask & Binding.TYPE) != 0 && (binding instanceof ReferenceBinding)) {