### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/ThisReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ThisReference.java,v retrieving revision 1.37 diff -u -r1.37 ThisReference.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ThisReference.java 7 Mar 2009 01:08:07 -0000 1.37 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ThisReference.java 1 Feb 2011 09:02:35 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 @@ -127,4 +127,13 @@ visitor.visit(this, blockScope); visitor.endVisit(this, blockScope); } + + public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { + if ((this.bits & ASTNode.IsImplicitThis) == 0) { + // explicit this reference, not allowed in static context + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=335780 + currentScope.resetEnclosingMethodStaticFlag(); + } + return super.analyseCode(currentScope, flowContext, flowInfo); + } } #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java,v retrieving revision 1.40 diff -u -r1.40 ProblemTypeAndMethodTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java 14 Jan 2011 15:34:15 -0000 1.40 +++ src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java 1 Feb 2011 09:02:37 -0000 @@ -6633,4 +6633,65 @@ compilerOptions /* custom options */ ); } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335780 +// For this reference as an argument of a message send, method can't be static +public void test124a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void method1() {\n" + // don't warn + " Foo.m(this);\n" + + " }\n" + + "static class Foo{\n" + + " static void m(X bug) {\n" + // warn + " \n" + + " }\n" + + "}\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335780 +// For this reference as an argument of a message send, method can't be static +public void test124b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static X xField;" + + " public void method1() {\n" + // don't warn + " Foo.m(this.xField);\n" + + " }\n" + + "static class Foo{\n" + + " static void m(X bug) {\n" + // warn + " \n" + + " }\n" + + "}\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} }