<?xml version="1.0" encoding="UTF-8"?>
<test-data
    xmlns="http://pmd.sourceforge.net/rule-tests"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
    <test-code>
        <description><![CDATA[
inner class accesses private field from outer class
     ]]></description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>8</expected-linenumbers>
        <code><![CDATA[
public class Foo {
 private int field;
 
 public class InnerClass {
   private long innerField;
   
   InnerClass() {
     innerField = Foo.this.field; // violation, accesing a private field
   }
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
inner class accesses private field from outer class unqualified
     ]]></description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>8</expected-linenumbers>
        <code><![CDATA[
public class Foo {
 private int field;
 
 public class InnerClass {
   private long innerField;
   
   InnerClass() {
     innerField = field; // violation, accesing a private field
   }
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
outer class accesses private field from inner class
     ]]></description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>9</expected-linenumbers>
        <code><![CDATA[
public class Foo {
 private int field;
 
 public class InnerClass {
   private long innerField;
 }
 
 long method() {
   return new InnerClass().innerField; // violation, accesing a private field
 }
}
     ]]></code>
    </test-code>
        <test-code>
        <description><![CDATA[
non private fields are ok
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
 public int publicField;
 protected int protectedField;
 /* package */ int packageField;
 
 public class InnerClass {
   private long innerField;
   
   InnerClass() {
     innerField = Foo.this.publicField; // this is ok
     innerField += Foo.this.protectedField; // this is ok
     innerField += Foo.this.packageField; // this is ok
   }
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
inner class accesses private method of outer class, unqualified
     ]]></description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>4</expected-linenumbers>
        <code><![CDATA[
public class Foo {
 public class InnerClass {
   private void secret() {
     outerSecret(); // violation, accesing a private method
   }
 }
 
 private void outerSecret() {
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
inner class accesses private method of outer class, qualified
     ]]></description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>4</expected-linenumbers>
        <code><![CDATA[
public class Foo {
 public class InnerClass {
   private void secret() {
     Foo.this.outerSecret(); // violation, accesing a private method
   }
 }
 
 private void outerSecret() {
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
outer class accesses private method of inner class
     ]]></description>
        <expected-problems>1</expected-problems>
        <expected-linenumbers>8</expected-linenumbers>
        <code><![CDATA[
public class Foo {
 public class InnerClass {
   private void secret() {
   }
 }
 
 private void outerSecret() {
   new InnerClass().secret(); // violation, accesing a private method
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
inner class accesses non-private methods of outer class
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo {
 public class InnerClass {
   private void secret() {
     outerPublic(); // this is ok
     outerProtected(); // this is ok
     outerPackage(); // this is ok
   }
 }
 
 public void outerPublic() {
 }
 
 protected void outerProtected() {
 }
 
 /* package */ void outerPackage() {
 }
}
     ]]></code>
    </test-code>
    <test-code>
        <description><![CDATA[
#274 - Method inside static inner class incorrectly reported as generating accessor methods
     ]]></description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class Foo implements Parcelable {
    public static final Creator<Foo> CREATOR = new Creator<Foo>() {
        @Override
        public Foo createFromParcel(Parcel source) {
            return new Foo(source.readString(),
                          getBooleanForInt(source.readInt()),
                          source.readLong());
        }

        @Override
        public Foo[] newArray(int size) {
            return new Foo[size];
        }

        private boolean getBooleanForInt(int value) {
            return value == 1;
        }
    };
}
     ]]></code>
    </test-code>
</test-data>
