Example usage for org.eclipse.jdt.core JavaCore COMPILER_PB_RAW_TYPE_REFERENCE

List of usage examples for org.eclipse.jdt.core JavaCore COMPILER_PB_RAW_TYPE_REFERENCE

Introduction

In this page you can find the example usage for org.eclipse.jdt.core JavaCore COMPILER_PB_RAW_TYPE_REFERENCE.

Prototype

String COMPILER_PB_RAW_TYPE_REFERENCE

To view the source code for org.eclipse.jdt.core JavaCore COMPILER_PB_RAW_TYPE_REFERENCE.

Click Source Link

Document

Compiler option ID: Reporting Raw Type Reference.

Usage

From source file:ma.glasnost.orika.impl.generator.EclipseJdtCompiler.java

License:Apache License

private CompilerOptions getCompilerOptions() {

    Map<Object, Object> options = new HashMap<Object, Object>();

    options.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
    options.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
    options.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);

    options.put(CompilerOptions.OPTION_SuppressWarnings, CompilerOptions.ENABLED);

    options.put(CompilerOptions.OPTION_Source, JAVA_COMPILER_SOURCE_VERSION);
    options.put(CompilerOptions.OPTION_TargetPlatform, JAVA_COMPILER_CODEGEN_TARGET_PLATFORM_VERSION);
    options.put(CompilerOptions.OPTION_Encoding, JAVA_SOURCE_ENCODING);
    options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE);

    // Ignore unchecked types and raw types
    options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, CompilerOptions.IGNORE);
    options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, CompilerOptions.IGNORE);
    options.put(JavaCore.COMPILER_PB_VARARGS_ARGUMENT_NEED_CAST, CompilerOptions.IGNORE);

    return new CompilerOptions(options);
}

From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java

License:Open Source License

@Test
public void testTypeParametersToRawTypeReference01() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING);
    JavaCore.setOptions(options);/*w  w w .j  a  v  a2 s. c om*/

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("pack", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("import java.util.List;\n");
    buf.append("public class E {\n");
    buf.append("    public void test() {\n");
    buf.append("        List l;\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, 1);

    assertCorrectLabels(proposals);
    assertNumberOfProposals(proposals, 4);

    String[] expected = new String[3];

    buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("import java.util.List;\n");
    buf.append("public class E {\n");
    buf.append("    public void test() {\n");
    buf.append("        @SuppressWarnings(\"rawtypes\")\n");
    buf.append("        List l;\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[0] = buf.toString();

    buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("import java.util.List;\n");
    buf.append("public class E {\n");
    buf.append("    @SuppressWarnings(\"rawtypes\")\n");
    buf.append("    public void test() {\n");
    buf.append("        List l;\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[1] = buf.toString();

    buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("import java.util.List;\n");
    buf.append("public class E {\n");
    buf.append("    public void test() {\n");
    buf.append("        List<?> l;\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[2] = buf.toString();

    assertExpectedExistInProposals(proposals, expected);
}

From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java

License:Open Source License

@Test
public void testTypeParametersToRawTypeReference02() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING);
    JavaCore.setOptions(options);//from w w  w  . ja v  a 2 s. c o m

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("pack", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("public class E {\n");
    buf.append("    private class E1<P1, P2> {}\n");
    buf.append("    public void test() {\n");
    buf.append("        E1 e1;\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, 1);

    assertCorrectLabels(proposals);
    assertNumberOfProposals(proposals, 4);

    String[] expected = new String[3];

    buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("public class E {\n");
    buf.append("    private class E1<P1, P2> {}\n");
    buf.append("    public void test() {\n");
    buf.append("        @SuppressWarnings(\"rawtypes\")\n");
    buf.append("        E1 e1;\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[0] = buf.toString();

    buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("public class E {\n");
    buf.append("    private class E1<P1, P2> {}\n");
    buf.append("    @SuppressWarnings(\"rawtypes\")\n");
    buf.append("    public void test() {\n");
    buf.append("        E1 e1;\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[1] = buf.toString();

    buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("public class E {\n");
    buf.append("    private class E1<P1, P2> {}\n");
    buf.append("    public void test() {\n");
    buf.append("        E1<?, ?> e1;\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[2] = buf.toString();

    assertExpectedExistInProposals(proposals, expected);
}

From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java

License:Open Source License

@Test
public void testTypeParametersToRawTypeReference06() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING);
    JavaCore.setOptions(options);//from   ww  w .j  av a 2  s .c om

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("pack", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("import java.util.ArrayList;\n");
    buf.append("import java.util.List;\n");
    buf.append("public class E {\n");
    buf.append("    private List l= new ArrayList<String>();\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);

    CompilationUnit astRoot = getASTRoot(cu);
    ArrayList proposals = collectCorrections(cu, astRoot, 1);

    assertCorrectLabels(proposals);
    assertNumberOfProposals(proposals, 4);

    String[] expected = new String[3];

    buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("import java.util.ArrayList;\n");
    buf.append("import java.util.List;\n");
    buf.append("public class E {\n");
    buf.append("    @SuppressWarnings(\"rawtypes\")\n");
    buf.append("    private List l= new ArrayList<String>();\n");
    buf.append("}\n");
    expected[0] = buf.toString();

    buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("import java.util.ArrayList;\n");
    buf.append("import java.util.List;\n");
    buf.append("public class E {\n");
    buf.append("    private List<String> l= new ArrayList<String>();\n");
    buf.append("}\n");
    expected[1] = buf.toString();

    buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("import java.util.ArrayList;\n");
    buf.append("import java.util.List;\n");
    buf.append("public class E {\n");
    buf.append("    private ArrayList<String> l= new ArrayList<String>();\n");
    buf.append("}\n");
    expected[2] = buf.toString();

    assertExpectedExistInProposals(proposals, expected);
}

From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java

License:Open Source License

@Test
public void testTypeParametersToRawTypeReference07() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING);
    JavaCore.setOptions(options);/*from  w  w w.j a  v  a 2  s  .  c  o m*/

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("pack", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("import java.util.List;\n");
    buf.append("public class E {\n");
    buf.append("    private List l;\n");
    buf.append("    private void foo() {\n");
    buf.append("        l.add(\"String\");\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, 1);

    assertCorrectLabels(proposals);
    assertNumberOfProposals(proposals, 3);

    String[] expected = new String[2];

    buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("import java.util.List;\n");
    buf.append("public class E {\n");
    buf.append("    @SuppressWarnings(\"rawtypes\")\n");
    buf.append("    private List l;\n");
    buf.append("    private void foo() {\n");
    buf.append("        l.add(\"String\");\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[0] = buf.toString();

    buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("import java.util.List;\n");
    buf.append("public class E {\n");
    buf.append("    private List<String> l;\n");
    buf.append("    private void foo() {\n");
    buf.append("        l.add(\"String\");\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[1] = buf.toString();

    assertExpectedExistInProposals(proposals, expected);
}

From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java

License:Open Source License

@Test
public void testTypeParametersToRawTypeReference09() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING);
    JavaCore.setOptions(options);/*from w w w  .j  av a 2s.co m*/

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("pack", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("import java.util.ArrayList;\n");
    buf.append("import java.util.List;\n");
    buf.append("public class E {\n");
    buf.append("    private List<String> l= new ArrayList();\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);

    CompilationUnit astRoot = getASTRoot(cu);
    ArrayList proposals = collectCorrections(cu, astRoot, 1);

    assertCorrectLabels(proposals);
    assertNumberOfProposals(proposals, 3);

    String[] expected = new String[3];

    buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("import java.util.ArrayList;\n");
    buf.append("import java.util.List;\n");
    buf.append("public class E {\n");
    buf.append("    @SuppressWarnings(\"rawtypes\")\n");
    buf.append("    private List<String> l= new ArrayList();\n");
    buf.append("}\n");
    expected[0] = buf.toString();

    buf = new StringBuffer();
    buf.append("package pack;\n");
    buf.append("import java.util.ArrayList;\n");
    buf.append("import java.util.List;\n");
    buf.append("public class E {\n");
    buf.append("    private List<String> l= new ArrayList<String>();\n");
    buf.append("}\n");
    expected[1] = buf.toString();

    assertExpectedExistInProposals(proposals, expected);
}

From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java

License:Open Source License

@Test
public void testTypeParametersToRawTypeReferenceBug212557() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING);
    JavaCore.setOptions(options);/*from   www .  j  a  v  a2 s. c om*/

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E1 {\n");
    buf.append("    public Class[] get() {\n");
    buf.append("        return null;\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E1.java", buf.toString(), false, null);

    CompilationUnit astRoot = getASTRoot(cu);
    ArrayList proposals = collectCorrections(cu, astRoot);

    assertNumberOfProposals(proposals, 2);
    assertCorrectLabels(proposals);

    String[] expected = new String[1];
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E1 {\n");
    buf.append("    @SuppressWarnings(\"rawtypes\")\n");
    buf.append("    public Class[] get() {\n");
    buf.append("        return null;\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[0] = buf.toString();

    assertExpectedExistInProposals(proposals, expected);
}

From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java

License:Open Source License

@Test
public void testTypeParametersToRawTypeReferenceBug280193() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING);
    JavaCore.setOptions(options);//from   ww w  .  j  av a  2  s. co  m

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);

    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("import java.util.List;\n");
    buf.append("\n");
    buf.append("public class E1 {\n");
    buf.append("    public void foo(List<List> list) {\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E1.java", buf.toString(), false, null);

    CompilationUnit astRoot = getASTRoot(cu);
    ArrayList proposals = collectCorrections(cu, astRoot);

    assertNumberOfProposals(proposals, 3);
    assertCorrectLabels(proposals);

    String[] expected = new String[2];
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("import java.util.List;\n");
    buf.append("\n");
    buf.append("public class E1 {\n");
    buf.append("    public void foo(@SuppressWarnings(\"rawtypes\") List<List> list) {\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[0] = buf.toString();

    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("import java.util.List;\n");
    buf.append("\n");
    buf.append("public class E1 {\n");
    buf.append("    @SuppressWarnings(\"rawtypes\")\n");
    buf.append("    public void foo(List<List> list) {\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[1] = buf.toString();

    assertExpectedExistInProposals(proposals, expected);
}

From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java

License:Open Source License

@Test
public void testCollectionsFieldMethodReplacement() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.WARNING);
    options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING);
    options.put(JavaCore.COMPILER_PB_TYPE_PARAMETER_HIDING, JavaCore.WARNING);
    JavaCore.setOptions(options);/*from  w  w  w .  j  av  a  2 s .  c om*/

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("b112441", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package b112441;\n");
    buf.append("\n");
    buf.append("import java.util.Collections;\n");
    buf.append("import java.util.Map;\n");
    buf.append("\n");
    buf.append("public class CollectionsTest {\n");
    buf.append("    Map<String,String> m=Collections.EMPTY_MAP;\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("CollectionsTest.java", buf.toString(), false, null);

    CompilationUnit astRoot = getASTRoot(cu);
    ArrayList proposals = collectCorrections(cu, astRoot);

    assertCorrectLabels(proposals);
    assertNumberOfProposals(proposals, 3);

    String[] expected = new String[1];
    buf = new StringBuffer();
    buf.append("package b112441;\n");
    buf.append("\n");
    buf.append("import java.util.Collections;\n");
    buf.append("import java.util.Map;\n");
    buf.append("\n");
    buf.append("public class CollectionsTest {\n");
    buf.append("    Map<String,String> m=Collections.emptyMap();\n");
    buf.append("}\n");
    expected[0] = buf.toString();

    assertExpectedExistInProposals(proposals, expected);
}

From source file:org.eclipse.che.jdt.quickfix.LocalCorrectionsQuickFixTest.java

License:Open Source License

@Test
public void testCollectionsFieldMethodReplacement2() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.WARNING);
    options.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING);
    options.put(JavaCore.COMPILER_PB_TYPE_PARAMETER_HIDING, JavaCore.WARNING);
    JavaCore.setOptions(options);/*from w  ww. jav  a  2s.  c  o m*/

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("p", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package p;\n");
    buf.append("\n");
    buf.append("import java.util.Collections;\n");
    buf.append("import java.util.Map;\n");
    buf.append("\n");
    buf.append("public class CollectionsTest {\n");
    buf.append("    public void foo(Map<Object, Integer> map) { };\n");
    buf.append("    {\n");
    buf.append("        foo(Collections.EMPTY_MAP);\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("CollectionsTest.java", buf.toString(), false, null);

    CompilationUnit astRoot = getASTRoot(cu);
    ArrayList proposals = collectCorrections(cu, astRoot);

    assertCorrectLabels(proposals);
    assertNumberOfProposals(proposals, 3);

    String[] expected = new String[1];
    buf = new StringBuffer();
    buf.append("package p;\n");
    buf.append("\n");
    buf.append("import java.util.Collections;\n");
    buf.append("import java.util.Map;\n");
    buf.append("\n");
    buf.append("public class CollectionsTest {\n");
    buf.append("    public void foo(Map<Object, Integer> map) { };\n");
    buf.append("    {\n");
    buf.append("        foo(Collections.<Object, Integer> emptyMap());\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[0] = buf.toString();

    assertExpectedExistInProposals(proposals, expected);
}