Search in sources :

Example 46 with CUCorrectionProposal

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());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) CUCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 47 with CUCorrectionProposal

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 });
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) CUCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 48 with CUCorrectionProposal

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());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) CUCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 49 with CUCorrectionProposal

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());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) CUCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 50 with CUCorrectionProposal

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());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) CUCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

CUCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal)290 ArrayList (java.util.ArrayList)285 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)285 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)284 Test (org.junit.Test)284 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)228 AssistContext (org.eclipse.jdt.internal.ui.text.correction.AssistContext)57 List (java.util.List)48 Hashtable (java.util.Hashtable)47 ProblemLocation (org.eclipse.jdt.internal.ui.text.correction.ProblemLocation)7 Ignore (org.junit.Ignore)7 ASTRewriteCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal)6 ChangeCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal)6 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)5 CorrectPackageDeclarationProposal (org.eclipse.jdt.internal.ui.text.correction.proposals.CorrectPackageDeclarationProposal)4 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)3 Iterator (java.util.Iterator)2 ASTNode (org.eclipse.jdt.core.dom.ASTNode)2 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)2 IDocument (org.eclipse.jface.text.IDocument)2