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 ((this.bits & ASTNode.IsImplicitThis) == 0) {
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 6633-6636 Link Here
6633
		compilerOptions /* custom options */
6633
		compilerOptions /* custom options */
6634
	);
6634
	);
6635
}
6635
}
6636
6637
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335780
6638
// For this reference as an argument of a message send, method can't be static
6639
public void test124a() {
6640
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
6641
		return;
6642
	Map compilerOptions = getCompilerOptions();
6643
	compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR);
6644
	compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR);
6645
	compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE);
6646
	this.runNegativeTest(
6647
		new String[] {
6648
				"X.java", 
6649
				"public class X {\n" +
6650
				"	public void method1() {\n" + 	// don't warn
6651
				"		Foo.m(this);\n" +
6652
				"	}\n" +
6653
				"static class Foo{\n" + 
6654
				"	static void m(X bug) {\n" + 	// warn
6655
				"		\n" +
6656
				"	}\n" + 
6657
				"}\n" +
6658
				"}"
6659
		},
6660
		"",
6661
		null /* no extra class libraries */,
6662
		true /* flush output directory */,
6663
		compilerOptions /* custom options */
6664
	);
6665
}
6666
6667
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335780
6668
// For this reference as an argument of a message send, method can't be static
6669
public void test124b() {
6670
	if (this.complianceLevel < ClassFileConstants.JDK1_5)
6671
		return;
6672
	Map compilerOptions = getCompilerOptions();
6673
	compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR);
6674
	compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR);
6675
	compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE);
6676
	this.runNegativeTest(
6677
		new String[] {
6678
				"X.java", 
6679
				"public class X {\n" +
6680
				"   public static X xField;" +
6681
				"	public void method1() {\n" + 	// don't warn
6682
				"		Foo.m(this.xField);\n" +
6683
				"	}\n" +
6684
				"static class Foo{\n" + 
6685
				"	static void m(X bug) {\n" + 	// warn
6686
				"		\n" +
6687
				"	}\n" + 
6688
				"}\n" +
6689
				"}"
6690
		},
6691
		"",
6692
		null /* no extra class libraries */,
6693
		true /* flush output directory */,
6694
		compilerOptions /* custom options */
6695
	);
6696
}
6636
}
6697
}

Return to bug 335780