<?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[
Qualified this as field
            ]]>
        </description>
        <expected-problems>1</expected-problems>
        <code>
            <![CDATA[
public class Foo {
    final Foo otherFoo = Foo.this;
}
            ]]>
        </code>
    </test-code>

    <test-code>
        <description>
            <![CDATA[
Qualified this in a method
            ]]>
        </description>
        <expected-problems>1</expected-problems>
        <code>
            <![CDATA[
public class Foo {
    public void doSomething() {
         final Foo anotherFoo = Foo.this;
    }
}
            ]]>
        </code>
    </test-code>

    <test-code>
        <description>
            <![CDATA[
Qualified this in a Inner Class
            ]]>
        </description>
        <expected-problems>0</expected-problems>
        <code>
            <![CDATA[
public class Foo {
    private ActionListener returnListener() {
        return new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                doSomethingWithQualifiedThis(Foo.this);
            }
        };
    }
}
            ]]>
        </code>
    </test-code>

    <test-code>
        <description>
            <![CDATA[
Qualified this in a Nested Class
            ]]>
        </description>
        <expected-problems>0</expected-problems>
        <code>
            <![CDATA[
public class Foo {
    private class Foo3 {
        final Foo myFoo = Foo.this;
    }
}
            ]]>
        </code>
    </test-code>

    <test-code>
        <description>
            <![CDATA[
Qualified this in a Nested Class part 2
            ]]>
        </description>
        <expected-problems>1</expected-problems>
        <code>
            <![CDATA[
public class Foo {
    private class Foo2 {
        final Foo2 myFoo2 = Foo2.this;
    }
}
            ]]>
        </code>
    </test-code>

    <test-code>
        <description>
            <![CDATA[
Qualified this all in one
            ]]>
        </description>
        <expected-problems>3</expected-problems>
        <code>
            <![CDATA[
public class Foo {
    final Foo otherFoo = Foo.this;

    public void doSomething() {
         final Foo anotherFoo = Foo.this;
    }

    private ActionListener returnListener() {
        return new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                doSomethingWithQualifiedThis(Foo.this);
            }
        };
    }

    private class Foo3 {
        final Foo myFoo = Foo.this;
    }

    private class Foo2 {
        final Foo2 myFoo2 = Foo2.this;
    }
}
            ]]>
        </code>
    </test-code>

    <test-code>
        <description>#1422 UselessQualifiedThis: False positive with Java 8 Function</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[
public class ApiExceptionCtrlAdvice {
    public final List<ApiError> handleApiAggregateException(final ApiAggregateException e) {
        return e.getCauses().stream().map(
            ApiExceptionCtrlAdvice::toApiError
        ).collect(Collectors.toList());
    }
    private static ApiError toApiError(final Throwable e) {
        return new ApiError()
                .withException(e.getClass().getName())
                .withCause(Optional.ofNullable(e.getCause()).map(Throwable::getClass).map(Class::getName).orElse(EMPTY))
                .withMessage(Optional.ofNullable(e.getMessage()).orElse(EMPTY));
    }
}
        ]]></code>
    </test-code>
</test-data>