Search in sources :

Example 1 with ConfigurationResolver

use of lombok.core.configuration.ConfigurationResolver in project lombok by rzwitserloot.

the class AbstractRunTests method createTester.

public final FileTester createTester(final DirectoryRunner.TestParams params, final File file, String platform, int version) throws IOException {
    ConfigurationKeysLoader.LoaderLoader.loadAllConfigurationKeys();
    AssertionError directiveFailure = null;
    LombokTestSource sourceDirectives = null;
    try {
        sourceDirectives = LombokTestSource.readDirectives(file);
        if (sourceDirectives.isIgnore())
            return null;
        if (!sourceDirectives.versionWithinLimit(version))
            return null;
        if (!sourceDirectives.runOnPlatform(platform))
            return null;
    } catch (AssertionError ae) {
        directiveFailure = ae;
    }
    String fileName = file.getName();
    final LombokTestSource expected = LombokTestSource.read(params.getAfterDirectory(), params.getMessagesDirectory(), fileName);
    if (expected.isIgnore())
        return null;
    if (!expected.versionWithinLimit(params.getVersion()))
        return null;
    if (!expected.versionWithinLimit(version))
        return null;
    final LombokTestSource sourceDirectives_ = sourceDirectives;
    final AssertionError directiveFailure_ = directiveFailure;
    return new FileTester() {

        @Override
        public void runTest() throws Throwable {
            if (directiveFailure_ != null)
                throw directiveFailure_;
            LinkedHashSet<CompilerMessage> messages = new LinkedHashSet<CompilerMessage>();
            StringWriter writer = new StringWriter();
            LombokConfiguration.overrideConfigurationResolverFactory(new ConfigurationResolverFactory() {

                @Override
                public ConfigurationResolver createResolver(AST<?, ?, ?> ast) {
                    return sourceDirectives_.getConfiguration();
                }
            });
            boolean changed = transformCode(messages, writer, file, sourceDirectives_.getSpecifiedEncoding(), sourceDirectives_.getFormatPreferences());
            boolean forceUnchanged = sourceDirectives_.forceUnchanged() || sourceDirectives_.isSkipCompareContent();
            if (params.expectChanges() && !forceUnchanged && !changed)
                messages.add(new CompilerMessage(-1, -1, true, "not flagged modified"));
            if (!params.expectChanges() && changed)
                messages.add(new CompilerMessage(-1, -1, true, "unexpected modification"));
            compare(file.getName(), expected, writer.toString(), messages, params.printErrors(), sourceDirectives_.isSkipCompareContent() || expected.isSkipCompareContent());
        }
    };
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CompilerMessage(lombok.javac.CapturingDiagnosticListener.CompilerMessage) ConfigurationResolverFactory(lombok.core.configuration.ConfigurationResolverFactory) FileTester(lombok.DirectoryRunner.FileTester) StringWriter(java.io.StringWriter) ConfigurationResolver(lombok.core.configuration.ConfigurationResolver)

Aggregations

StringWriter (java.io.StringWriter)1 LinkedHashSet (java.util.LinkedHashSet)1 FileTester (lombok.DirectoryRunner.FileTester)1 ConfigurationResolver (lombok.core.configuration.ConfigurationResolver)1 ConfigurationResolverFactory (lombok.core.configuration.ConfigurationResolverFactory)1 CompilerMessage (lombok.javac.CapturingDiagnosticListener.CompilerMessage)1