use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class LocalCorrectionsQuickFixTest method testUndefinedConstructorWithLineBreaks.
@Test
public void testUndefinedConstructorWithLineBreaks() throws Exception {
Hashtable hashtable = JavaCore.getOptions();
hashtable.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "30");
String optionValue = DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_DEFAULT);
hashtable.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_CONSTRUCTOR_DECLARATION, optionValue);
hashtable.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_EXPLICIT_CONSTRUCTOR_CALL, optionValue);
JavaCore.setOptions(hashtable);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class F {\n");
buf.append(" public F(Runnable runnable, boolean isGreen, boolean isBlue, boolean isRed) {\n");
buf.append(" }\n");
buf.append("}\n");
pack1.createCompilationUnit("F.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E extends F {\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 extends F {\n");
buf.append("\n");
buf.append(" public E(\n");
buf.append(" Runnable runnable,\n");
buf.append(" boolean isGreen,\n");
buf.append(" boolean isBlue,\n");
buf.append(" boolean isRed) {\n");
buf.append(" super(\n");
buf.append(" runnable,\n");
buf.append(" isGreen,\n");
buf.append(" isBlue,\n");
buf.append(" isRed);\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class LocalCorrectionsQuickFixTest method testUnimplementedMethods_bug113665.
@Test
public void testUnimplementedMethods_bug113665() throws Exception {
IPackageFragment pack2 = fSourceFolder.createPackageFragment("test2", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test2;\n");
buf.append("public interface F {\n");
buf.append(" public void c() throws Exception;\n");
buf.append(" public void e();\n");
buf.append("}\n");
pack2.createCompilationUnit("F.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package test2;\n");
buf.append("public class A implements F {\n");
buf.append(" public void c() throws Exception, RuntimeException { }\n");
buf.append("}\n");
ICompilationUnit cu = pack2.createCompilationUnit("A.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot);
assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
String preview1 = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test2;\n");
buf.append("public class A implements F {\n");
buf.append(" public void c() throws Exception, RuntimeException { }\n");
buf.append("\n");
buf.append(" public void e() {\n");
buf.append(" }\n");
buf.append("}\n");
String expected1 = buf.toString();
proposal = (CUCorrectionProposal) proposals.get(1);
String preview2 = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test2;\n");
buf.append("public abstract class A implements F {\n");
buf.append(" public void c() throws Exception, RuntimeException { }\n");
buf.append("}\n");
String expected2 = buf.toString();
assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
}
use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class LocalCorrectionsQuickFixTest method testIndirectStaticAccess_bug40880.
@Test
public void testIndirectStaticAccess_bug40880() throws Exception {
Hashtable hashtable = JavaCore.getOptions();
hashtable.put(JavaCore.COMPILER_PB_INDIRECT_STATIC_ACCESS, JavaCore.ERROR);
JavaCore.setOptions(hashtable);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("class FileType {\n");
buf.append(" public String extension;\n");
buf.append("}\n");
pack1.createCompilationUnit("FileType.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("interface ToolConfigurationSettingsConstants {\n");
buf.append(" FileType FILE_TYPE = null;\n");
buf.append("}\n");
pack1.createCompilationUnit("ToolConfigurationSettingsConstants.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("interface ToolUserSettingsConstants extends ToolConfigurationSettingsConstants {\n");
buf.append("}\n");
pack1.createCompilationUnit("ToolUserSettingsConstants.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" ToolUserSettingsConstants.FILE_TYPE.extension.toLowerCase();\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() {\n");
buf.append(" ToolConfigurationSettingsConstants.FILE_TYPE.extension.toLowerCase();\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testOuterLocalMustBeFinal.
@Test
public void testOuterLocalMustBeFinal() 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(" public void foo() {\n");
buf.append(" int i= 9;\n");
buf.append(" Runnable run= new Runnable() {\n");
buf.append(" public void run() {\n");
buf.append(" int x= 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);
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() {\n");
buf.append(" final int i= 9;\n");
buf.append(" Runnable run= new Runnable() {\n");
buf.append(" public void run() {\n");
buf.append(" int x= i;\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testNeedToEmulateFieldRead.
@Test
public void testNeedToEmulateFieldRead() 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(" int x= fCount;\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(" int x= fCount;\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());
}
Aggregations