Search in sources :

Example 96 with Hashtable

use of java.util.Hashtable in project che by eclipse.

the class LocalCorrectionsQuickFixTest method testRemoveDeadCodeIfThen2.

@Test
public void testRemoveDeadCodeIfThen2() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_DEAD_CODE, 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("    public void foo() {\n");
    buf.append("        Object o = new Object();\n");
    buf.append("        if (o != null) {\n");
    buf.append("            if (o == null) {\n");
    buf.append("            	System.out.println(\"hello\");\n");
    buf.append("        	} else {\n");
    buf.append("            	System.out.println(\"bye\");\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, 2);
    assertCorrectLabels(proposals);
    CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
    String preview1 = getPreviewContent(proposal);
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        Object o = new Object();\n");
    buf.append("        if (o != null) {\n");
    buf.append("            System.out.println(\"bye\");\n");
    buf.append("        }\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 test1;\n");
    buf.append("public class E {\n");
    buf.append("    @SuppressWarnings(\"unused\")\n");
    buf.append("    public void foo() {\n");
    buf.append("        Object o = new Object();\n");
    buf.append("        if (o != null) {\n");
    buf.append("            if (o == null) {\n");
    buf.append("            	System.out.println(\"hello\");\n");
    buf.append("        	} else {\n");
    buf.append("            	System.out.println(\"bye\");\n");
    buf.append("        	}\n");
    buf.append("        }\n");
    buf.append("    }\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) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 97 with Hashtable

use of java.util.Hashtable in project che by eclipse.

the class LocalCorrectionsQuickFixTest method testUnusedObjectAllocation2.

@Test
public void testUnusedObjectAllocation2() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_UNUSED_OBJECT_ALLOCATION, JavaCore.WARNING);
    JavaCore.setOptions(options);
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        /*a*/new Exception()/*b*/;/*c*/\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, 6);
    String[] expected = new String[6];
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        /*a*/throw new Exception()/*b*/;/*c*/\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[0] = buf.toString();
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[1] = buf.toString();
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("\n");
    buf.append("public class E {\n");
    buf.append("    @SuppressWarnings(\"unused\")\n");
    buf.append("    public void foo() {\n");
    buf.append("        /*a*/new Exception()/*b*/;/*c*/\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[2] = buf.toString();
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        /*a*/return new Exception()/*b*/;/*c*/\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[3] = buf.toString();
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        /*a*/Exception exception = new Exception()/*b*/;/*c*/\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[4] = buf.toString();
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("\n");
    buf.append("public class E {\n");
    buf.append("    private Exception exception;\n");
    buf.append("\n");
    buf.append("    public void foo() {\n");
    buf.append("        /*a*/exception = new Exception()/*b*/;/*c*/\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[5] = 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 98 with Hashtable

use of java.util.Hashtable in project che by eclipse.

the class LocalCorrectionsQuickFixTest method testUnusedVariable.

@Test
public void testUnusedVariable() 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("        boolean res= process();\n");
    buf.append("        res= (super.hashCode() == 1);\n");
    buf.append("    }\n");
    buf.append("    public boolean process() {\n");
    buf.append("        return 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, 2);
    assertCorrectLabels(proposals);
    String[] expected = new String[2];
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        process();\n");
    buf.append("        (super.hashCode() == 1);\n");
    buf.append("    }\n");
    buf.append("    public boolean process() {\n");
    buf.append("        return true;\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[0] = buf.toString();
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("    }\n");
    buf.append("    public boolean process() {\n");
    buf.append("        return true;\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 99 with Hashtable

use of java.util.Hashtable in project che by eclipse.

the class LocalCorrectionsQuickFixTest method testUnnecessaryCast1.

@Test
public void testUnnecessaryCast1() 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(int i) {\n");
    buf.append("        int s = (int) i;\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(int i) {\n");
    buf.append("        int s = i;\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 100 with Hashtable

use of java.util.Hashtable in project che by eclipse.

the class LocalCorrectionsQuickFixTest method testUnqualifiedFieldAccess_bug138325_2.

@Test
public void testUnqualifiedFieldAccess_bug138325_2() throws Exception {
    Hashtable hashtable = JavaCore.getOptions();
    hashtable.put(JavaCore.COMPILER_PB_UNQUALIFIED_FIELD_ACCESS, JavaCore.ERROR);
    hashtable.put(JavaCore.COMPILER_PB_FIELD_HIDING, 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 int i;\n");
    buf.append("    public void foo() {\n");
    buf.append("        Runnable runnable = new Runnable() {\n");
    buf.append("            public void run() {\n");
    buf.append("                System.out.println(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);
    String[] expecteds = new String[1];
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E<T> {\n");
    buf.append("    public int i;\n");
    buf.append("    public void foo() {\n");
    buf.append("        Runnable runnable = new Runnable() {\n");
    buf.append("            public void run() {\n");
    buf.append("                System.out.println(E.this.i);\n");
    buf.append("            }\n");
    buf.append("        };\n");
    buf.append("    }\n");
    buf.append("}\n");
    expecteds[0] = buf.toString();
    assertExpectedExistInProposals(proposals, expecteds);
}
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)

Aggregations

Hashtable (java.util.Hashtable)1752 Test (org.junit.Test)374 ArrayList (java.util.ArrayList)355 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)219 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)142 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)137 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)136 HashMap (java.util.HashMap)104 IOException (java.io.IOException)91 Dictionary (java.util.Dictionary)91 Vector (java.util.Vector)88 File (java.io.File)86 Map (java.util.Map)84 Bundle (org.osgi.framework.Bundle)84 BundleContext (org.osgi.framework.BundleContext)78 Configuration (org.osgi.service.cm.Configuration)75 Enumeration (java.util.Enumeration)70 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)70 State (org.eclipse.osgi.service.resolver.State)70 ServiceRegistration (org.osgi.framework.ServiceRegistration)65