class PmdValidator implements ResourceValidator {

    @Override
    @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
    public Collection<Violation> validate(final Collection<File> files) {
        final SourceValidator validator = new SourceValidator(this.env);
        final Collection<DataSource> sources = new LinkedList<>();
        for (final File file : files) {
            sources.add(new FileDataSource(file));
        }
        final Collection<RuleViolation> breaches = validator.validate(
            sources, this.env.basedir().getPath()
        );
        final Collection<Violation> violations = new LinkedList<>();
        for (final RuleViolation breach : breaches) {
            violations.add(
                new Violation.Default(
                    this.name(),
                    breach.getRule().getName(),
                    breach.getFilename(),
                    String.format(
                        "%d-%d",
                        breach.getBeginLine(), breach.getEndLine()
                    ),
                    breach.getDescription()
                )
            );
        }
        return violations;
    }

}

class PmdValidatorTest {

    private static final String STATIC_ACCESS;
    private static final String CODE_IN_CON;
    private static final String NO_CON_INIT;
    private static final String MULT_CON_INIT;
    private static final String BRACKETS;
    private static final String PLAIN_ASSERTIONS;
    private static final String STATIC_METHODS;
    private static final String FILES_CREATE_ERR;

    @Test
    @SuppressWarnings("PMD.AvoidDuplicateLiterals")
    public void doesNotComplainAboutConstantsInInnerClasses() throws Exception {

        final String file = "src/main/java/foo/Foo.java";
        final Environment env = new Environment.Mock().withFile(
            file,
            Joiner.on('\n').join(
                "package foo;",
                "interface Foo {",
                "  final class Bar implements Foo {",
                "    private static final Pattern TEST =",
                "      Pattern.compile(\"hey\");",
                "    public String doSomething() {",
                "      return Foo.Bar.TEST.toString();",
                "    }",
                "  }",
                "}"
            )
        );
        MatcherAssert.assertThat(
            new PmdValidator(env).validate(
                Collections.singletonList(new File(env.basedir(), file))
            ),
            Matchers.<Violation>empty()
        );
    }

}