use of org.eclipse.jdt.core.dom.CompilationUnit in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testInvalidEnumModifier2.
@Test
public void testInvalidEnumModifier2() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("r", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package r;\n");
buf.append("\n");
buf.append("public abstract enum E {\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, 1);
String[] expected = new String[1];
buf = new StringBuffer();
buf.append("package r;\n");
buf.append("\n");
buf.append("public enum E {\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 testNeedToEmulateFieldReadInGeneric.
@Test
public void testNeedToEmulateFieldReadInGeneric() 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<T> {\n");
buf.append(" public void x() {\n");
buf.append(" Runnable r= new Runnable() {\n");
buf.append(" public void run() {\n");
buf.append(" T x= fCount;\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append(" private T 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<T> {\n");
buf.append(" public void x() {\n");
buf.append(" Runnable r= new Runnable() {\n");
buf.append(" public void run() {\n");
buf.append(" T x= fCount;\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append(" T fCount; {\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 testUnusedSuppressWarnings2.
@Test
public void testUnusedSuppressWarnings2() throws Exception {
Hashtable hashtable = JavaCore.getOptions();
hashtable.put(JavaCore.COMPILER_PB_UNHANDLED_WARNING_TOKEN, JavaCore.IGNORE);
hashtable.put(JavaCore.COMPILER_PB_UNUSED_WARNING_TOKEN, JavaCore.WARNING);
JavaCore.setOptions(hashtable);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("p", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package p;\n");
buf.append("\n");
buf.append("@SuppressWarnings(\"unused\")\n");
buf.append("public class 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);
assertCorrectLabels(proposals);
assertNumberOfProposals(proposals, 1);
String[] expected = new String[1];
buf = new StringBuffer();
buf.append("package p;\n");
buf.append("\n");
buf.append("public class E {\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 testSuppressNLSWarningAnnotation1.
@Test
@Ignore
public void testSuppressNLSWarningAnnotation1() throws Exception {
Hashtable options = JavaCore.getOptions();
options.put(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.WARNING);
JavaCore.setOptions(options);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" static {\n");
buf.append(" @SuppressWarnings(\"unused\") String str= \"foo\";");
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, 4);
assertCorrectLabels(proposals);
String[] expected = new String[2];
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" static {\n");
buf.append(" @SuppressWarnings({\"unused\", \"nls\"}) String str= \"foo\";");
buf.append(" }\n");
buf.append("}\n");
expected[0] = buf.toString();
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("@SuppressWarnings(\"nls\")\n");
buf.append("public class E {\n");
buf.append(" static {\n");
buf.append(" @SuppressWarnings(\"unused\") String str= \"foo\";");
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 testInvalidClassFieldModifiers.
@Test
public void testInvalidClassFieldModifiers() 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(" strictfp public native int i;\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 int i;\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
Aggregations