Search in sources :

Example 91 with IPackageFragment

use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.

the class ModifierCorrectionsQuickFixTest method testMissingMethodDeprecationAnnotation.

@Test
public void testMissingMethodDeprecationAnnotation() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, JavaCore.ERROR);
    options.put(JavaCore.COMPILER_PB_MISSING_DEPRECATED_ANNOTATION, JavaCore.ERROR);
    JavaCore.setOptions(options);
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public final class C {\n");
    buf.append("    /**\n");
    buf.append("     * @deprecated\n");
    buf.append("     */\n");
    buf.append("    @Override\n");
    buf.append("    public String toString() {\n");
    buf.append("        return null;\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("C.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 final class C {\n");
    buf.append("    /**\n");
    buf.append("     * @deprecated\n");
    buf.append("     */\n");
    buf.append("    @Deprecated\n");
    buf.append("    @Override\n");
    buf.append("    public String toString() {\n");
    buf.append("        return null;\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 92 with IPackageFragment

use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.

the class ModifierCorrectionsQuickFixTest method testStaticMethodRequestedInOtherType.

@Test
public void testStaticMethodRequestedInOtherType() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class X {\n");
    buf.append("    public void xoo() {\n");
    buf.append("    }\n");
    buf.append("}\n");
    pack1.createCompilationUnit("X.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("         X.xoo();\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 X {\n");
    buf.append("    public static void xoo() {\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 93 with IPackageFragment

use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.

the class ModifierCorrectionsQuickFixTest method testInvalidInterfaceMethodModifiers.

@Test
public void testInvalidInterfaceMethodModifiers() 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 strictfp void foo();\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("    void foo();\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 94 with IPackageFragment

use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.

the class ModifierCorrectionsQuickFixTest method testSuppressWarningsAnonymousClass1.

@Test
public void testSuppressWarningsAnonymousClass1() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, 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("    public void foo() {\n");
    buf.append("        @SuppressWarnings(\"unused\")\n");
    buf.append("        final Object object = new Object() {\n");
    buf.append("            {\n");
    buf.append("                for (List l = new ArrayList(), x = new Vector();;) {\n");
    buf.append("                    if (l == x)\n");
    buf.append("                        break;\n");
    buf.append("                }\n");
    buf.append("            }\n");
    buf.append("        };\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, 3);
    assertCorrectLabels(proposals);
    assertNumberOfProposals(proposals, 5);
    String[] expected = new String[3];
    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("    public void foo() {\n");
    buf.append("        @SuppressWarnings(\"unused\")\n");
    buf.append("        final Object object = new Object() {\n");
    buf.append("            {\n");
    buf.append("                for (@SuppressWarnings(\"rawtypes\")\n");
    buf.append("                List l = new ArrayList(), x = new Vector();;) {\n");
    buf.append("                    if (l == x)\n");
    buf.append("                        break;\n");
    buf.append("                }\n");
    buf.append("            }\n");
    buf.append("        };\n");
    buf.append("    };\n");
    buf.append("};\n");
    expected[0] = buf.toString();
    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("    public void foo() {\n");
    buf.append("        @SuppressWarnings({\"unused\", \"rawtypes\"})\n");
    buf.append("        final Object object = new Object() {\n");
    buf.append("            {\n");
    buf.append("                for (List l = new ArrayList(), x = new Vector();;) {\n");
    buf.append("                    if (l == x)\n");
    buf.append("                        break;\n");
    buf.append("                }\n");
    buf.append("            }\n");
    buf.append("        };\n");
    buf.append("    };\n");
    buf.append("};\n");
    expected[1] = buf.toString();
    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(\"rawtypes\")\n");
    buf.append("    public void foo() {\n");
    buf.append("        @SuppressWarnings(\"unused\")\n");
    buf.append("        final Object object = new Object() {\n");
    buf.append("            {\n");
    buf.append("                for (List l = new ArrayList(), x = new Vector();;) {\n");
    buf.append("                    if (l == x)\n");
    buf.append("                        break;\n");
    buf.append("                }\n");
    buf.append("            }\n");
    buf.append("        };\n");
    buf.append("    };\n");
    buf.append("};\n");
    expected[1] = buf.toString();
    assertExpectedExistInProposals(proposals, expected);
}
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) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 95 with IPackageFragment

use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.

the class ModifierCorrectionsQuickFixTest method testStaticMethodRequestedInSameGenericType.

@Test
public void testStaticMethodRequestedInSameGenericType() throws Exception {
    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 <M> void xoo(M m) {\n");
    buf.append("    }\n");
    buf.append("    public static void foo() {\n");
    buf.append("        xoo(Boolean.TRUE);\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 static <M> void xoo(M m) {\n");
    buf.append("    }\n");
    buf.append("    public static void foo() {\n");
    buf.append("        xoo(Boolean.TRUE);\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)

Aggregations

IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1147 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1052 Test (org.junit.Test)1039 ArrayList (java.util.ArrayList)755 List (java.util.List)453 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)435 AssistContext (org.eclipse.jdt.internal.ui.text.correction.AssistContext)384 CUCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal)284 Hashtable (java.util.Hashtable)136 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)100 OrganizeImportsOperation (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation)67 IChooseImportQuery (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery)67 Ignore (org.junit.Ignore)43 IType (org.eclipse.jdt.core.IType)37 IJavaElement (org.eclipse.jdt.core.IJavaElement)32 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)24 HashMap (java.util.HashMap)23 ASTRewriteCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal)23 BaseTest (org.eclipse.che.plugin.java.server.che.BaseTest)21 Map (java.util.Map)19