Java Code Examples for org.eclipse.jdt.core.compiler.IProblem#NonStaticOrAlienTypeReceiver

The following examples show how to use org.eclipse.jdt.core.compiler.IProblem#NonStaticOrAlienTypeReceiver . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StaticAccessQuickFixTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testNonStaticOrAlienTypeReceiver() throws Exception {
	int problem = IProblem.NonStaticOrAlienTypeReceiver;
	IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);

	StringBuilder bufA = new StringBuilder();
	bufA.append("package test1;\n");
	bufA.append("public class X {\n");
	bufA.append("  public interface I {\n");
	bufA.append("    private static void foo(){};\n");
	bufA.append("    void bar();");
	bufA.append("  }\n");
	bufA.append("  public static void main(String[] args) {\n");
	bufA.append("    I i = () -> {};\n");
	bufA.append("    i.foo();\n");
	bufA.append("  }\n");
	bufA.append("}");
	ICompilationUnit cu = pack1.createCompilationUnit("X.java", bufA.toString(), false, null);

	bufA = new StringBuilder();
	bufA.append("package test1;\n");
	bufA.append("public class X {\n");
	bufA.append("  public interface I {\n");
	bufA.append("    private static void foo(){};\n");
	bufA.append("    void bar();");
	bufA.append("  }\n");
	bufA.append("  public static void main(String[] args) {\n");
	bufA.append("    I i = () -> {};\n");
	bufA.append("    I.foo();\n");
	bufA.append("  }\n");
	bufA.append("}");

	Expected e1 = new Expected("Change access to static using 'I' (declaring type)", bufA.toString());

	assertCodeActions(cu, e1);

}
 
Example 2
Source File: CodeStyleFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isNonStaticAccess(IProblemLocation problem) {
	return (problem.getProblemId() == IProblem.NonStaticAccessToStaticField
			|| problem.getProblemId() == IProblem.NonStaticAccessToStaticMethod
			|| problem.getProblemId() == IProblem.NonStaticOrAlienTypeReceiver);
}