View | Details | Raw Unified | Return to bug 335780 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/ThisReference.java (-1 / +10 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 127-130 Link Here
127
		visitor.visit(this, blockScope);
127
		visitor.visit(this, blockScope);
128
		visitor.endVisit(this, blockScope);
128
		visitor.endVisit(this, blockScope);
129
	}
129
	}
130
131
	public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
132
		if (!isImplicitThis()) {
133
			// explicit this reference, not allowed in static context
134
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335780
135
			currentScope.resetEnclosingMethodStaticFlag();
136
		}
137
		return super.analyseCode(currentScope, flowContext, flowInfo);
138
	}
130
}
139
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java (+61 lines)
Lines 6868-6871 Link Here
6868
		compilerOptions /* custom options */
6868
		compilerOptions /* custom options */
6869
	);
6869
	);
6870
}
6870
}
6871
6872
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335780
6873
// For this reference as an argument of a message send, method can't be static
6874
public void test124a() {
6875
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
6876
		return;
6877
	Map compilerOptions = getCompilerOptions();
6878
	compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR);
6879
	compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR);
6880
	compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE);
6881
	this.runNegativeTest(
6882
		new String[] {
6883
				"X.java", 
6884
				"public class X {\n" +
6885
				"	public void method1() {\n" + 	// don't warn
6886
				"		Foo.m(this);\n" +
6887
				"	}\n" +
6888
				"static class Foo{\n" + 
6889
				"	static void m(X bug) {\n" + 
6890
				"		\n" +
6891
				"	}\n" + 
6892
				"}\n" +
6893
				"}"
6894
		},
6895
		"",
6896
		null /* no extra class libraries */,
6897
		true /* flush output directory */,
6898
		compilerOptions /* custom options */
6899
	);
6900
}
6901
6902
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335780
6903
// For this reference as an argument of a message send, method can't be static
6904
public void test124b() {
6905
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
6906
		return;
6907
	Map compilerOptions = getCompilerOptions();
6908
	compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR);
6909
	compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR);
6910
	compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE);
6911
	this.runNegativeTest(
6912
		new String[] {
6913
				"X.java", 
6914
				"public class X {\n" +
6915
				"   public static X xField;" +
6916
				"	public void method1() {\n" + 	// don't warn
6917
				"		Foo.m(this.xField);\n" +
6918
				"	}\n" +
6919
				"static class Foo{\n" + 
6920
				"	static void m(X bug) {\n" + 
6921
				"		\n" +
6922
				"	}\n" + 
6923
				"}\n" +
6924
				"}"
6925
		},
6926
		"",
6927
		null /* no extra class libraries */,
6928
		true /* flush output directory */,
6929
		compilerOptions /* custom options */
6930
	);
6931
}
6871
}
6932
}

Return to bug 335780