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

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

Introduction

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

Prototype

String COMPILER_PB_NON_NLS_STRING_LITERAL

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

Click Source Link

Document

Compiler option ID: Reporting Non-Externalized String Literal.

Usage

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

License:Open Source License

@Test
public void testUnnessecaryNLSTag1() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.WARNING);
    JavaCore.setOptions(options);/*from  w ww .  j  ava2 s  .com*/

    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("    String e;    //$NON-NLS-1$\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, 2);

    String[] expected = new String[2];
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("\n");
    buf.append("public class E {\n");
    buf.append("    String e;\n");
    buf.append("}\n");
    expected[0] = buf.toString();

    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("\n");
    buf.append("@SuppressWarnings(\"nls\")\n");
    buf.append("public class E {\n");
    buf.append("    String e;    //$NON-NLS-1$\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 testUnnessecaryNLSTag2() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.WARNING);
    JavaCore.setOptions(options);/*from   www. j av  a 2  s .  c  o m*/

    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("    String e; //   //$NON-NLS-1$\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, 2);

    String[] expected = new String[2];
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("\n");
    buf.append("public class E {\n");
    buf.append("    String e; //\n");
    buf.append("}\n");
    expected[0] = buf.toString();

    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("\n");
    buf.append("@SuppressWarnings(\"nls\")\n");
    buf.append("public class E {\n");
    buf.append("    String e; //   //$NON-NLS-1$\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 testUnnessecaryNLSTag3() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.WARNING);
    JavaCore.setOptions(options);/*from  w ww.j  a v a2  s  . com*/

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        foo(); //$NON-NLS-1$ // more comment\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, 2);

    String[] expected = new String[2];
    buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        foo(); // more comment\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[0] = buf.toString();

    buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("public class E {\n");
    buf.append("    @SuppressWarnings(\"nls\")\n");
    buf.append("    public void foo() {\n");
    buf.append("        foo(); //$NON-NLS-1$ // more comment\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 testUnnessecaryNLSTag4() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.WARNING);
    JavaCore.setOptions(options);/*from ww w .j a  va  2 s. c o  m*/

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        foo(); //$NON-NLS-1$ more comment   \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, 2);

    String[] expected = new String[2];
    buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        foo(); // more comment   \n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[0] = buf.toString();

    buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("public class E {\n");
    buf.append("    @SuppressWarnings(\"nls\")\n");
    buf.append("    public void foo() {\n");
    buf.append("        foo(); //$NON-NLS-1$ more comment   \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 testUnnessecaryNLSTag5() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.WARNING);
    JavaCore.setOptions(options);//from   w w  w .ja  va2  s. c om

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        foo(); //$NON-NLS-1$     \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, 2);

    String[] expected = new String[2];
    buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        foo();\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[0] = buf.toString();

    buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("public class E {\n");
    buf.append("    @SuppressWarnings(\"nls\")\n");
    buf.append("    public void foo() {\n");
    buf.append("        foo(); //$NON-NLS-1$     \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 testUnnessecaryNLSTag6() throws Exception {
    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.WARNING);
    JavaCore.setOptions(options);/*from w  w  w  . ja  va  2  s. c  o  m*/

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        foo(); //$NON-NLS-1$ / more\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, 2);

    String[] expected = new String[2];
    buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        foo(); // / more\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[0] = buf.toString();

    buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("public class E {\n");
    buf.append("    @SuppressWarnings(\"nls\")\n");
    buf.append("    public void foo() {\n");
    buf.append("        foo(); //$NON-NLS-1$ / more\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[1] = buf.toString();

    assertExpectedExistInProposals(proposals, expected);
}

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

License:Open Source License

@Test
@Ignore//from   w ww  .  j a v a 2s.c o m
public void testSuppressNLSWarningAnnotation1() throws Exception {

    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, 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("    static {\n");
    buf.append("        @SuppressWarnings(\"unused\") String str= \"foo\";");
    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, 4);
    assertCorrectLabels(proposals);
    String[] expected = new String[2];
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    static {\n");
    buf.append("        @SuppressWarnings({\"unused\", \"nls\"}) String str= \"foo\";");
    buf.append("    }\n");
    buf.append("}\n");
    expected[0] = buf.toString();

    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("@SuppressWarnings(\"nls\")\n");
    buf.append("public class E {\n");
    buf.append("    static {\n");
    buf.append("        @SuppressWarnings(\"unused\") String str= \"foo\";");
    buf.append("    }\n");
    buf.append("}\n");
    expected[1] = buf.toString();
    assertExpectedExistInProposals(proposals, expected);
}

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

License:Open Source License

@Test
@Ignore//from  w  ww .  j  av  a 2 s  .c  om
public void testSuppressNLSWarningAnnotation2() throws Exception {

    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, 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("    private class Q {\n");
    buf.append("        String s = \"\";\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, 3);
    assertCorrectLabels(proposals);

    buf = new StringBuffer();
    buf.append("package test1; \n");
    buf.append("public class E {\n");
    buf.append("    private class Q {\n");
    buf.append("        @SuppressWarnings(\"nls\")\n");
    buf.append("        String s = \"\";\n");
    buf.append("    }\n");
    buf.append("}\n");
    assertExpectedExistInProposals(proposals, new String[] { buf.toString() });
}

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

License:Open Source License

@Test
@Ignore/* w  w w . jav a  2s  . c  o m*/
public void testSuppressNLSWarningAnnotation3() throws Exception {

    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, 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("    String s = \"\";\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, 3);
    assertCorrectLabels(proposals);

    buf = new StringBuffer();
    buf.append("package test1; \n");
    buf.append("public class E {\n");
    buf.append("    @SuppressWarnings(\"nls\")\n");
    buf.append("    String s = \"\";\n");
    buf.append("}\n");
    assertExpectedExistInProposals(proposals, new String[] { buf.toString() });
}

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

License:Open Source License

@Test
@Ignore//ww w.j a v  a 2 s  . c om
public void testSuppressNLSWarningAnnotation4() throws Exception {

    Hashtable options = JavaCore.getOptions();
    options.put(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, 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("        @SuppressWarnings(\"unused\") String s = \"\";\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, 4);
    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("        @SuppressWarnings({\"unused\", \"nls\"}) String s = \"\";\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("    @SuppressWarnings(\"nls\")\n");
    buf.append("    public void foo() {\n");
    buf.append("        @SuppressWarnings(\"unused\") String s = \"\";\n");
    buf.append("    }\n");
    buf.append("}\n");
    expected[1] = buf.toString();
    assertExpectedExistInProposals(proposals, expected);
}