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

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

Introduction

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

Prototype

String COMPILER_PB_UNQUALIFIED_FIELD_ACCESS

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

Click Source Link

Document

Compiler option ID: Reporting Unqualified Access to Field.

Usage

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

License:Open Source License

@Test
public void testUnqualifiedFieldAccess1() throws Exception {
    Hashtable hashtable = JavaCore.getOptions();
    hashtable.put(JavaCore.COMPILER_PB_UNQUALIFIED_FIELD_ACCESS, JavaCore.ERROR);
    JavaCore.setOptions(hashtable);/*from   w  w  w.  ja v  a2s .  com*/

    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 int count;\n");
    buf.append("    public E(int i) {\n");
    buf.append("        count= 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);

    String[] expecteds = new String[1];
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    private int count;\n");
    buf.append("    public E(int i) {\n");
    buf.append("        this.count= i;\n");
    buf.append("    }\n");
    buf.append("}\n");
    expecteds[0] = buf.toString();
    assertExpectedExistInProposals(proposals, expecteds);
}

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

License:Open Source License

@Test
public void testUnqualifiedFieldAccess2() throws Exception {
    Hashtable hashtable = JavaCore.getOptions();
    hashtable.put(JavaCore.COMPILER_PB_UNQUALIFIED_FIELD_ACCESS, JavaCore.ERROR);
    JavaCore.setOptions(hashtable);//  w ww  .  j a v  a  2  s  .  co m

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class F {\n");
    buf.append("    public int count;\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 {\n");
    buf.append("    private F f= new F();\n");
    buf.append("    public E(int i) {\n");
    buf.append("        f.count= 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);

    String[] expecteds = new String[1];
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    private F f= new F();\n");
    buf.append("    public E(int i) {\n");
    buf.append("        this.f.count= i;\n");
    buf.append("    }\n");
    buf.append("}\n");
    expecteds[0] = buf.toString();
    assertExpectedExistInProposals(proposals, expecteds);
}

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

License:Open Source License

@Test
public void testUnqualifiedFieldAccess3() 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);/*from  w  w  w .j  av a 2  s  . com*/

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class F {\n");
    buf.append("    public void setCount(int i) {}\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 {\n");
    buf.append("    private F f= new F();\n");
    buf.append("    public E(int i) {\n");
    buf.append("        f.setCount(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);

    String[] expecteds = new String[1];
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    private F f= new F();\n");
    buf.append("    public E(int i) {\n");
    buf.append("        this.f.setCount(i);\n");
    buf.append("    }\n");
    buf.append("}\n");
    expecteds[0] = buf.toString();
    assertExpectedExistInProposals(proposals, expecteds);
}

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

License:Open Source License

@Test
public void testUnqualifiedFieldAccess4() 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);//from www  .  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("public class E {\n");
    buf.append("    private int count;\n");
    buf.append("    public E(int i) {\n");
    buf.append("        class Inner {\n");
    buf.append("            public void foo() {\n");
    buf.append("               count= 1;\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 {\n");
    buf.append("    private int count;\n");
    buf.append("    public E(int i) {\n");
    buf.append("        class Inner {\n");
    buf.append("            public void foo() {\n");
    buf.append("               E.this.count= 1;\n");
    buf.append("            }\n");
    buf.append("        }\n");
    buf.append("    }\n");
    buf.append("}\n");
    expecteds[0] = buf.toString();
    assertExpectedExistInProposals(proposals, expecteds);
}

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

License:Open Source License

@Test
public void testUnqualifiedFieldAccess_bug50960() 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);//from  ww  w  .  j  ava  2 s .  co m

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class F {\n");
    buf.append("    private int count;\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("    private int count;\n");
    buf.append("    public E(int i) {\n");
    buf.append("        count= 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);
    assertNumberOfProposals(proposals, 1);
    assertCorrectLabels(proposals);

    String[] expecteds = new String[1];
    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E extends F {\n");
    buf.append("    private int count;\n");
    buf.append("    public E(int i) {\n");
    buf.append("        this.count= 1;\n");
    buf.append("    }\n");
    buf.append("}\n");
    expecteds[0] = buf.toString();
    assertExpectedExistInProposals(proposals, expecteds);
}

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

License:Open Source License

@Test
public void testUnqualifiedFieldAccess_bug88313() 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);//  w  w w.ja v  a2 s . co m

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class F {\n");
    buf.append("    protected Object someObject;\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("    public void foo() {\n");
    buf.append("        new Object() {\n");
    buf.append("            public String toString() {\n");
    buf.append("                return someObject.getClass().getName();\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 extends F {\n");
    buf.append("    public void foo() {\n");
    buf.append("        new Object() {\n");
    buf.append("            public String toString() {\n");
    buf.append("                return E.this.someObject.getClass().getName();\n");
    buf.append("            }\n");
    buf.append("         };\n");
    buf.append("    }\n");
    buf.append("}\n");
    expecteds[0] = buf.toString();
    assertExpectedExistInProposals(proposals, expecteds);
}

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

License:Open Source License

@Test
@Ignore/*w  w  w.  ja v  a2 s . com*/
public void testUnqualifiedFieldAccess_bug115277() 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 F {\n");
    buf.append("    public abstract class E1Inner1 {\n");
    buf.append("        public abstract void foo();\n");
    buf.append("        protected int n;\n");
    buf.append("    }\n");
    buf.append("    public abstract class E1Inner2 {\n");
    buf.append("        public abstract void run();\n");
    buf.append("    }\n");
    buf.append("    public void foo() {\n");
    buf.append("        E1Inner1 inner= new E1Inner1() {\n");
    buf.append("            public void foo() {\n");
    buf.append("                E1Inner2 inner2= new E1Inner2() {\n");
    buf.append("                    public void run() {\n");
    buf.append("                        System.out.println(n);\n");
    buf.append("                    }\n");
    buf.append("                };\n");
    buf.append("            }\n");
    buf.append("        };\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("F.java", buf.toString(), false, null);

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

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

License:Open Source License

@Test
public void testUnqualifiedFieldAccess_bug138325_1() 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);//w  w w.  ja  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 E<T> {\n");
    buf.append("    public int i;\n");
    buf.append("    public void foo() {\n");
    buf.append("        System.out.println(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);

    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("        System.out.println(this.i);\n");
    buf.append("    }\n");
    buf.append("}\n");
    expecteds[0] = buf.toString();
    assertExpectedExistInProposals(proposals, expecteds);
}

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

License:Open Source License

@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);//from w  ww .  jav  a 2s  . c om

    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);
}

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

License:Open Source License

@Test
public void testUnqualifiedFieldAccessWithGenerics() 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);/*from   ww w .  j a va  2s  .com*/

    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class F<T> {\n");
    buf.append("    protected T someObject;\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<T> extends F<String> {\n");
    buf.append("    public void foo() {\n");
    buf.append("        class X {\n");
    buf.append("            public String toString() {\n");
    buf.append("                return someObject.getClass().getName();\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> extends F<String> {\n");
    buf.append("    public void foo() {\n");
    buf.append("        class X {\n");
    buf.append("            public String toString() {\n");
    buf.append("                return E.this.someObject.getClass().getName();\n");
    buf.append("            }\n");
    buf.append("         };\n");
    buf.append("    }\n");
    buf.append("}\n");
    expecteds[0] = buf.toString();
    assertExpectedExistInProposals(proposals, expecteds);
}