use of java.util.Hashtable in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testSuppressWarningsForFieldVariables.
@Test
public void testSuppressWarningsForFieldVariables() throws Exception {
Hashtable options = JavaCore.getOptions();
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.*;\n");
buf.append("\n");
buf.append("public class A {\n");
buf.append(" List<String> myList = new ArrayList();\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("A.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot, 1);
assertCorrectLabels(proposals);
assertNumberOfProposals(proposals, 3);
String[] expected = new String[1];
buf = new StringBuffer();
buf.append("package test1; \n");
buf.append("import java.util.*;\n");
buf.append("\n");
buf.append("public class A {\n");
buf.append(" @SuppressWarnings(\"unchecked\")\n");
buf.append(" List<String> myList = new ArrayList();\n");
buf.append("}\n");
expected[0] = buf.toString();
assertExpectedExistInProposals(proposals, expected);
}
use of java.util.Hashtable in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testNeedToEmulateFieldWrite.
@Test
public void testNeedToEmulateFieldWrite() 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(" fCount= 2;\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append(" private int fCount; {\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(" fCount= 2;\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append(" int fCount; {\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of java.util.Hashtable in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method setUp.
// public static Test suite() {
// return setUpTest(new TestSuite(THIS));
// }
//
// public static Test setUpTest(Test test) {
// return new ProjectTestSetup(test);
// }
@Before
public void setUp() throws Exception {
super.setUp();
Hashtable options = TestOptions.getDefaultOptions();
options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE, JavaCore.DO_NOT_INSERT);
options.put(JavaCore.COMPILER_PB_STATIC_ACCESS_RECEIVER, JavaCore.ERROR);
options.put(JavaCore.COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD, JavaCore.ERROR);
JavaCore.setOptions(options);
IPreferenceStore store = JavaPlugin.getDefault().getPreferenceStore();
store.setValue(PreferenceConstants.CODEGEN_ADD_COMMENTS, false);
fJProject1 = ProjectTestSetup.getProject();
StubUtility.setCodeTemplate(CodeTemplateContextType.METHODSTUB_ID, "", null);
StubUtility.setCodeTemplate(CodeTemplateContextType.CONSTRUCTORSTUB_ID, "", null);
fSourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
}
use of java.util.Hashtable in project che by eclipse.
the class LocalCorrectionsQuickFixTest method testUnnecessaryInstanceof2.
@Test
public void testUnnecessaryInstanceof2() throws Exception {
Hashtable hashtable = JavaCore.getOptions();
hashtable.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, 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 foo(String b) {\n");
buf.append(" if (b instanceof String && b.getClass() != null) {\n");
buf.append(" System.out.println();\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);
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 foo(String b) {\n");
buf.append(" if (b != null && b.getClass() != null) {\n");
buf.append(" System.out.println();\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of java.util.Hashtable in project che by eclipse.
the class LocalCorrectionsQuickFixTest method testUnusedVariableBug120579.
@Test
public void testUnusedVariableBug120579() throws Exception {
Hashtable hashtable = JavaCore.getOptions();
hashtable.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR);
hashtable.put(JavaCore.COMPILER_PB_UNUSED_PARAMETER, 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 foo() {\n");
buf.append(" char[] array= new char[0];\n");
buf.append(" for (char element: array) {}\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, 0);
assertCorrectLabels(proposals);
}
Aggregations