use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.
the class LocalCorrectionsQuickFixTest method testUnqualifiedFieldAccess_bug138325_2.
@Test
public void testUnqualifiedFieldAccess_bug138325_2() throws Exception {
Hashtable hashtable = JavaCore.getOptions();
hashtable.put(JavaCore.COMPILER_PB_UNQUALIFIED_FIELD_ACCESS, JavaCore.ERROR);
hashtable.put(JavaCore.COMPILER_PB_FIELD_HIDING, JavaCore.ERROR);
JavaCore.setOptions(hashtable);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E<T> {\n");
buf.append(" public int i;\n");
buf.append(" public void foo() {\n");
buf.append(" Runnable runnable = new Runnable() {\n");
buf.append(" public void run() {\n");
buf.append(" System.out.println(i);\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot);
assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
String[] expecteds = new String[1];
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E<T> {\n");
buf.append(" public int i;\n");
buf.append(" public void foo() {\n");
buf.append(" Runnable runnable = new Runnable() {\n");
buf.append(" public void run() {\n");
buf.append(" System.out.println(E.this.i);\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append("}\n");
expecteds[0] = buf.toString();
assertExpectedExistInProposals(proposals, expecteds);
}
use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testInvalidParamModifiers.
@Test
public void testInvalidParamModifiers() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" private void foo(private int x) {\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot);
assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
String preview = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" private void foo(int x) {\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testExtendsFinalClass.
@Test
public void testExtendsFinalClass() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public final class C {\n");
buf.append(" protected void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
pack1.createCompilationUnit("C.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E extends C {\n");
buf.append(" protected void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot);
assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
String preview = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class C {\n");
buf.append(" protected void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testMethodOverrideDeprecated2.
@Test
public void testMethodOverrideDeprecated2() throws Exception {
Hashtable options = JavaCore.getOptions();
options.put(JavaCore.COMPILER_PB_DEPRECATION_WHEN_OVERRIDING_DEPRECATED_METHOD, JavaCore.ENABLED);
JavaCore.setOptions(options);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("pack", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("public class E {\n");
buf.append(" @Deprecated\n");
buf.append(" public void foo() {\n");
buf.append(" }\n");
buf.append("} \n");
buf.append("\n");
buf.append("class F extends E {\n");
buf.append(" /**\n");
buf.append(" */\n");
buf.append(" public void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
buf.append("\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot);
assertCorrectLabels(proposals);
assertNumberOfProposals(proposals, 2);
String[] expected = new String[2];
buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("public class E {\n");
buf.append(" @Deprecated\n");
buf.append(" public void foo() {\n");
buf.append(" }\n");
buf.append("} \n");
buf.append("\n");
buf.append("class F extends E {\n");
buf.append(" /**\n");
buf.append(" * @deprecated\n");
buf.append(" */\n");
buf.append(" @Deprecated\n");
buf.append(" public void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
buf.append("\n");
expected[0] = buf.toString();
buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("public class E {\n");
buf.append(" @Deprecated\n");
buf.append(" public void foo() {\n");
buf.append(" }\n");
buf.append("} \n");
buf.append("\n");
buf.append("class F extends E {\n");
buf.append(" /**\n");
buf.append(" */\n");
buf.append(" @SuppressWarnings(\"deprecation\")\n");
buf.append(" public void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
buf.append("\n");
expected[1] = buf.toString();
assertExpectedExistInProposals(proposals, expected);
}
use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testOverrideFinalMethod.
@Test
public void testOverrideFinalMethod() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class C {\n");
buf.append(" protected final void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
pack1.createCompilationUnit("C.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E extends C {\n");
buf.append(" protected void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot);
assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
String preview = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class C {\n");
buf.append(" protected void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
Aggregations