use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testSuppressNLSWarningAnnotation5.
@Test
public void testSuppressNLSWarningAnnotation5() throws Exception {
Hashtable options = JavaCore.getOptions();
options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING);
options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.WARNING);
JavaCore.setOptions(options);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1; \n");
buf.append("import java.util.ArrayList;\n");
buf.append("\n");
buf.append("public class A {\n");
buf.append(" public void foo(ArrayList<String> c) {\n");
// two warnings on this -> only one proposal!
buf.append(" new ArrayList(c);\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("A.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot, 2);
assertCorrectLabels(proposals);
assertNumberOfProposals(proposals, 1);
String[] expected = new String[1];
buf = new StringBuffer();
buf.append("package test1; \n");
buf.append("import java.util.ArrayList;\n");
buf.append("\n");
buf.append("public class A {\n");
buf.append(" @SuppressWarnings(\"unchecked\")\n");
buf.append(" public void foo(ArrayList<String> c) {\n");
buf.append(" new ArrayList(c);\n");
buf.append(" }\n");
buf.append("}\n");
expected[0] = buf.toString();
assertExpectedExistInProposals(proposals, expected);
}
use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testNeedToEmulateConstructorAccess.
@Test
public void testNeedToEmulateConstructorAccess() throws Exception {
Hashtable hashtable = JavaCore.getOptions();
hashtable.put(JavaCore.COMPILER_PB_SYNTHETIC_ACCESS_EMULATION, 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 {\n");
buf.append(" public void x() {\n");
buf.append(" Runnable r= new Runnable() {\n");
buf.append(" public void run() {\n");
buf.append(" E e= new E();\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append(" private E() {\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(" public void x() {\n");
buf.append(" Runnable r= new Runnable() {\n");
buf.append(" public void run() {\n");
buf.append(" E e= new E();\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append(" E() {\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testMethodOverrideDeprecated1.
@Test
public void testMethodOverrideDeprecated1() 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(" 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(" @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(" @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.dom.CompilationUnit in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testOverridesStaticMethod.
@Test
public void testOverridesStaticMethod() throws Exception {
IPackageFragment pack2 = fSourceFolder.createPackageFragment("test2", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test2;\n");
buf.append("public class C {\n");
buf.append(" public static void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
pack2.createCompilationUnit("C.java", buf.toString(), false, null);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import test2.C;\n");
buf.append("public class E extends C {\n");
buf.append(" public 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 test2;\n");
buf.append("public class C {\n");
buf.append(" public void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testInvalidMemberInterfaceModifiers.
@Test
public void testInvalidMemberInterfaceModifiers() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public interface E {\n");
buf.append(" private interface Inner {\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 interface E {\n");
buf.append(" interface Inner {\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
Aggregations