From 15df143df6d35dd64459d717a451a039eb26d761 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 13 Aug 2019 15:04:43 +0200 Subject: [checkerframework] A bit of a shadow feature because the checker framework folks need to do some work on their side. this update makes lombok generate a few checker framework annotations (if configured to do so) which let the checker framework add warnings and errors for example if you misuse builders, or ignore the return values of withers, etc. --- test/core/src/lombok/AbstractRunTests.java | 2 ++ test/core/src/lombok/CompilerMessageMatcher.java | 2 +- test/core/src/lombok/DirectoryRunner.java | 5 +++-- test/core/src/lombok/LombokTestSource.java | 15 ++++++++++++++- 4 files changed, 20 insertions(+), 4 deletions(-) (limited to 'test/core') diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java index fc05aea2..d223ae03 100644 --- a/test/core/src/lombok/AbstractRunTests.java +++ b/test/core/src/lombok/AbstractRunTests.java @@ -47,6 +47,7 @@ import lombok.core.configuration.ConfigurationKeysLoader; import lombok.core.configuration.ConfigurationResolver; import lombok.core.configuration.ConfigurationResolverFactory; import lombok.javac.CapturingDiagnosticListener.CompilerMessage; +import lombok.transform.TestLombokFilesIdempotent; public abstract class AbstractRunTests { private final File dumpActualFilesHere; @@ -74,6 +75,7 @@ public abstract class AbstractRunTests { if (expected.isIgnore()) return null; if (!expected.versionWithinLimit(params.getVersion())) return null; if (!expected.versionWithinLimit(version)) return null; + if (expected.isSkipIdempotent() && params instanceof TestLombokFilesIdempotent) return null; final LombokTestSource sourceDirectives_ = sourceDirectives; final AssertionError directiveFailure_ = directiveFailure; diff --git a/test/core/src/lombok/CompilerMessageMatcher.java b/test/core/src/lombok/CompilerMessageMatcher.java index 49c81b70..c00263f4 100644 --- a/test/core/src/lombok/CompilerMessageMatcher.java +++ b/test/core/src/lombok/CompilerMessageMatcher.java @@ -88,7 +88,7 @@ public class CompilerMessageMatcher { return out; } - private static final Pattern PATTERN = Pattern.compile("^(\\d+) (.*)$"); + private static final Pattern PATTERN = Pattern.compile("^(-?\\d+) (.*)$"); private static CompilerMessageMatcher read(String line) { line = line.trim(); diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java index 9410b4c7..ffadba8f 100644 --- a/test/core/src/lombok/DirectoryRunner.java +++ b/test/core/src/lombok/DirectoryRunner.java @@ -36,7 +36,8 @@ import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunNotifier; public class DirectoryRunner extends Runner { - private static final String DEBUG_FOCUS_ON_FILE = null; + /** Fill in a file name (or multiple, space separated) to reduce the testset to just the named file(s). */ + private static final String DEBUG_FOCUS_ON_FILE = ""; public enum Compiler { DELOMBOK { @@ -79,7 +80,7 @@ public class DirectoryRunner extends Runner { private static final FileFilter JAVA_FILE_FILTER = new FileFilter() { @Override public boolean accept(File file) { return file.isFile() && file.getName().endsWith(".java") && - (DEBUG_FOCUS_ON_FILE == null || file.getName().equals(DEBUG_FOCUS_ON_FILE)); + (DEBUG_FOCUS_ON_FILE.isEmpty() || (" " + DEBUG_FOCUS_ON_FILE + " ").contains(" " + file.getName() + " ")); } }; diff --git a/test/core/src/lombok/LombokTestSource.java b/test/core/src/lombok/LombokTestSource.java index 31f7db3e..ba0aa972 100644 --- a/test/core/src/lombok/LombokTestSource.java +++ b/test/core/src/lombok/LombokTestSource.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014-2015 The Project Lombok Authors. + * Copyright (C) 2014-2019 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -52,6 +52,7 @@ public class LombokTestSource { private final Map formatPreferences; private final boolean ignore; private final boolean skipCompareContent; + private final boolean skipIdempotent; private final boolean unchanged; private final int versionLowerLimit, versionUpperLimit; private final ConfigurationResolver configuration; @@ -92,6 +93,10 @@ public class LombokTestSource { return skipCompareContent; } + public boolean isSkipIdempotent() { + return skipIdempotent; + } + public String getSpecifiedEncoding() { return specifiedEncoding; } @@ -139,6 +144,7 @@ public class LombokTestSource { private static final Pattern IGNORE_PATTERN = Pattern.compile("^\\s*ignore\\s*(?:[-:].*)?$", Pattern.CASE_INSENSITIVE); private static final Pattern UNCHANGED_PATTERN = Pattern.compile("^\\s*unchanged\\s*(?:[-:].*)?$", Pattern.CASE_INSENSITIVE); private static final Pattern SKIP_COMPARE_CONTENT_PATTERN = Pattern.compile("^\\s*skip[- ]?compare[- ]?contents?\\s*(?:[-:].*)?$", Pattern.CASE_INSENSITIVE); + private static final Pattern SKIP_IDEMPOTENT_PATTERN = Pattern.compile("^\\s*skip[- ]?idempotent\\s*(?:[-:].*)?$", Pattern.CASE_INSENSITIVE); private LombokTestSource(File file, String content, List messages, List directives) { this.file = file; @@ -150,6 +156,7 @@ public class LombokTestSource { int versionUpper = Integer.MAX_VALUE; boolean ignore = false; boolean skipCompareContent = false; + boolean skipIdempotent = false; boolean unchanged = false; String encoding = null; Map formats = new HashMap(); @@ -173,6 +180,11 @@ public class LombokTestSource { continue; } + if (SKIP_IDEMPOTENT_PATTERN.matcher(directive).matches()) { + skipIdempotent = true; + continue; + } + if (lc.startsWith("platform ")) { String platformDesc = lc.substring("platform ".length()); int idx = platformDesc.indexOf(':'); @@ -223,6 +235,7 @@ public class LombokTestSource { this.versionUpperLimit = versionUpper; this.ignore = ignore; this.skipCompareContent = skipCompareContent; + this.skipIdempotent = skipIdempotent; this.unchanged = unchanged; this.platforms = platformLimit == null ? null : Arrays.asList(platformLimit); ConfigurationProblemReporter reporter = new ConfigurationProblemReporter() { -- cgit