Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java6
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java15
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java8
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java8
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedThisReference.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java16
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java6
8 files changed, 43 insertions, 23 deletions
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 cf0d06ffa..ab52ffb61 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 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
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 c6cbad8f4..e06f7f769 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 @@ public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowConte
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 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
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 aeb70372a..c3cd48361 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 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
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 f64a4ec85..24a8edbb4 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 @@ public static abstract class AbstractQualifiedAllocationExpression extends Alloc
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 66ae0de2f..9649267cd 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 @@ public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowConte
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 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
}
}
}
+ 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 943fed79e..780b15385 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 @@ public class QualifiedThisReference extends ThisReference {
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 f432e65ed..5cdbf8a72 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 @@ public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowConte
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 @@ public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowConte
// 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 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
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 51ffe15ae..cdc45ae89 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 @@ private Binding internalGetBinding(char[][] compoundName, int mask, InvocationSi
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)) {

Back to the top