mirror of
https://github.com/tiennm99/lombok.git
synced 2026-09-08 12:19:14 +00:00
Add tests for Locked annotations
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
// version 14:
|
||||
public record LockedInRecord(String a, String b) {
|
||||
public void foo() {
|
||||
String foo = "bar";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
class LockedName {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private final java.util.concurrent.locks.ReentrantLock basicLock = new java.util.concurrent.locks.ReentrantLock();
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private final java.util.concurrent.locks.ReentrantReadWriteLock rwLock = new java.util.concurrent.locks.ReentrantReadWriteLock();
|
||||
|
||||
void test() {
|
||||
this.basicLock.lock();
|
||||
try {
|
||||
System.out.println("one");
|
||||
} finally {
|
||||
this.basicLock.unlock();
|
||||
}
|
||||
}
|
||||
void test2() {
|
||||
this.rwLock.readLock().lock();
|
||||
try {
|
||||
System.out.println("two");
|
||||
} finally {
|
||||
this.rwLock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
void test3() {
|
||||
this.rwLock.writeLock().lock();
|
||||
try {
|
||||
System.out.println("three");
|
||||
} finally {
|
||||
this.rwLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
class LockedOnStatic<Z> {
|
||||
static class Inner {
|
||||
private static final java.util.concurrent.locks.ReentrantLock LCK = new java.util.concurrent.locks.ReentrantLock();
|
||||
public void foo() {
|
||||
LockedOnStatic.Inner.LCK.lock();
|
||||
try {
|
||||
System.out.println();
|
||||
} finally {
|
||||
LockedOnStatic.Inner.LCK.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
class Inner2 {
|
||||
private final java.util.concurrent.locks.ReentrantLock LCK = new java.util.concurrent.locks.ReentrantLock();
|
||||
public void foo() {
|
||||
this.LCK.lock();
|
||||
try {
|
||||
System.out.println();
|
||||
} finally {
|
||||
this.LCK.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
class LockedPlain {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private final java.util.concurrent.locks.ReentrantLock lock = new java.util.concurrent.locks.ReentrantLock();
|
||||
void test() {
|
||||
this.lock.lock();
|
||||
try {
|
||||
System.out.println("one");
|
||||
} finally {
|
||||
this.lock.unlock();
|
||||
}
|
||||
}
|
||||
void test2() {
|
||||
this.lock.lock();
|
||||
try {
|
||||
System.out.println("two");
|
||||
} finally {
|
||||
this.lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
class LockedPlainStatic {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private static final java.util.concurrent.locks.ReentrantLock LOCK = new java.util.concurrent.locks.ReentrantLock();
|
||||
static void test() {
|
||||
LockedPlainStatic.LOCK.lock();
|
||||
try {
|
||||
System.out.println("three");
|
||||
} finally {
|
||||
LockedPlainStatic.LOCK.unlock();
|
||||
}
|
||||
}
|
||||
static void test2() {
|
||||
LockedPlainStatic.LOCK.lock();
|
||||
try {
|
||||
System.out.println("four");
|
||||
} finally {
|
||||
LockedPlainStatic.LOCK.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
class LockedPlainRead {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private static final java.util.concurrent.locks.ReentrantReadWriteLock LOCK = new java.util.concurrent.locks.ReentrantReadWriteLock();
|
||||
static void test() {
|
||||
LockedPlainRead.LOCK.readLock().lock();
|
||||
try {
|
||||
System.out.println("five");
|
||||
} finally {
|
||||
LockedPlainRead.LOCK.readLock().unlock();
|
||||
}
|
||||
}
|
||||
static void test2() {
|
||||
LockedPlainRead.LOCK.readLock().lock();
|
||||
try {
|
||||
System.out.println("six");
|
||||
} finally {
|
||||
LockedPlainRead.LOCK.readLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
class LockedPlainWrite {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private final java.util.concurrent.locks.ReentrantReadWriteLock lock = new java.util.concurrent.locks.ReentrantReadWriteLock();
|
||||
void test() {
|
||||
this.lock.writeLock().lock();
|
||||
try {
|
||||
System.out.println("seven");
|
||||
} finally {
|
||||
this.lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
void test2() {
|
||||
this.lock.writeLock().lock();
|
||||
try {
|
||||
System.out.println("eight");
|
||||
} finally {
|
||||
this.lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
class LockedGeneratedStaticMismatch {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private static final java.util.concurrent.locks.ReentrantLock LOCK = new java.util.concurrent.locks.ReentrantLock();
|
||||
static void test() {
|
||||
LockedGeneratedStaticMismatch.LOCK.lock();
|
||||
try {
|
||||
System.out.println("one");
|
||||
} finally {
|
||||
LockedGeneratedStaticMismatch.LOCK.unlock();
|
||||
}
|
||||
}
|
||||
void test2() {
|
||||
System.out.println("two");
|
||||
}
|
||||
}
|
||||
class LockedUserStaticMismatch {
|
||||
private static final java.util.concurrent.locks.ReentrantLock userLock = new java.util.concurrent.locks.ReentrantLock();
|
||||
static void test() {
|
||||
LockedUserStaticMismatch.userLock.lock();
|
||||
try {
|
||||
System.out.println("one");
|
||||
} finally {
|
||||
LockedUserStaticMismatch.userLock.unlock();
|
||||
}
|
||||
}
|
||||
void test2() {
|
||||
LockedUserStaticMismatch.userLock.lock();
|
||||
try {
|
||||
System.out.println("two");
|
||||
} finally {
|
||||
LockedUserStaticMismatch.userLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
class LockedGeneratedTypeMismatch {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private final java.util.concurrent.locks.ReentrantLock lock = new java.util.concurrent.locks.ReentrantLock();
|
||||
void test() {
|
||||
this.lock.lock();
|
||||
try {
|
||||
System.out.println("one");
|
||||
} finally {
|
||||
this.lock.unlock();
|
||||
}
|
||||
}
|
||||
void test2() {
|
||||
System.out.println("two");
|
||||
}
|
||||
}
|
||||
class LockedUserTypeMismatch {
|
||||
private final java.util.concurrent.locks.ReentrantLock userLock = new java.util.concurrent.locks.ReentrantLock();
|
||||
void test() {
|
||||
this.userLock.lock();
|
||||
try {
|
||||
System.out.println("one");
|
||||
} finally {
|
||||
this.userLock.unlock();
|
||||
}
|
||||
}
|
||||
void test2() {
|
||||
this.userLock.readLock().lock();
|
||||
try {
|
||||
System.out.println("two");
|
||||
} finally {
|
||||
this.userLock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import lombok.experimental.Locked;
|
||||
public record LockedInRecord(java lock, String a) {
|
||||
private final java.util.concurrent.locks.ReentrantLock lock = new java.util.concurrent.locks.ReentrantLock();
|
||||
/* Implicit */ private final String a;
|
||||
/* Implicit */ private final String b;
|
||||
public LockedInRecord(String a, String b) {
|
||||
super();
|
||||
.a = a;
|
||||
.b = b;
|
||||
}
|
||||
public @Locked void foo() {
|
||||
String foo = "bar";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
class LockedName {
|
||||
private final java.util.concurrent.locks.ReentrantLock basicLock = new java.util.concurrent.locks.ReentrantLock();
|
||||
private final java.util.concurrent.locks.ReentrantReadWriteLock rwLock = new java.util.concurrent.locks.ReentrantReadWriteLock();
|
||||
LockedName() {
|
||||
super();
|
||||
}
|
||||
@lombok.experimental.Locked("basicLock") void test() {
|
||||
this.basicLock.lock();
|
||||
try
|
||||
{
|
||||
System.out.println("one");
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.basicLock.unlock();
|
||||
}
|
||||
}
|
||||
@lombok.experimental.Locked.Read("rwLock") void test2() {
|
||||
this.rwLock.readLock().lock();
|
||||
try
|
||||
{
|
||||
System.out.println("two");
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.rwLock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
@lombok.experimental.Locked.Write("rwLock") void test3() {
|
||||
this.rwLock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
System.out.println("three");
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.rwLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
class LockedOnStatic<Z> {
|
||||
static class Inner {
|
||||
private static final java.util.concurrent.locks.ReentrantLock LCK = new java.util.concurrent.locks.ReentrantLock();
|
||||
<clinit>() {
|
||||
}
|
||||
Inner() {
|
||||
super();
|
||||
}
|
||||
public @lombok.experimental.Locked("LCK") void foo() {
|
||||
LockedOnStatic.Inner.LCK.lock();
|
||||
try
|
||||
{
|
||||
System.out.println();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LockedOnStatic.Inner.LCK.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
class Inner2 {
|
||||
private final java.util.concurrent.locks.ReentrantLock LCK = new java.util.concurrent.locks.ReentrantLock();
|
||||
Inner2() {
|
||||
super();
|
||||
}
|
||||
public @lombok.experimental.Locked("LCK") void foo() {
|
||||
this.LCK.lock();
|
||||
try
|
||||
{
|
||||
System.out.println();
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.LCK.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
LockedOnStatic() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import lombok.experimental.Locked;
|
||||
class LockedPlain {
|
||||
private final java.util.concurrent.locks.ReentrantLock lock = new java.util.concurrent.locks.ReentrantLock();
|
||||
LockedPlain() {
|
||||
super();
|
||||
}
|
||||
@lombok.experimental.Locked void test() {
|
||||
this.lock.lock();
|
||||
try
|
||||
{
|
||||
System.out.println("one");
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.lock.unlock();
|
||||
}
|
||||
}
|
||||
@Locked void test2() {
|
||||
this.lock.lock();
|
||||
try
|
||||
{
|
||||
System.out.println("two");
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
class LockedPlainStatic {
|
||||
private static final java.util.concurrent.locks.ReentrantLock LOCK = new java.util.concurrent.locks.ReentrantLock();
|
||||
<clinit>() {
|
||||
}
|
||||
LockedPlainStatic() {
|
||||
super();
|
||||
}
|
||||
static @lombok.experimental.Locked void test() {
|
||||
LockedPlainStatic.LOCK.lock();
|
||||
try
|
||||
{
|
||||
System.out.println("three");
|
||||
}
|
||||
finally
|
||||
{
|
||||
LockedPlainStatic.LOCK.unlock();
|
||||
}
|
||||
}
|
||||
static @Locked void test2() {
|
||||
LockedPlainStatic.LOCK.lock();
|
||||
try
|
||||
{
|
||||
System.out.println("four");
|
||||
}
|
||||
finally
|
||||
{
|
||||
LockedPlainStatic.LOCK.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
class LockedPlainRead {
|
||||
private static final java.util.concurrent.locks.ReentrantReadWriteLock LOCK = new java.util.concurrent.locks.ReentrantReadWriteLock();
|
||||
<clinit>() {
|
||||
}
|
||||
LockedPlainRead() {
|
||||
super();
|
||||
}
|
||||
static @lombok.experimental.Locked.Read void test() {
|
||||
LockedPlainRead.LOCK.readLock().lock();
|
||||
try
|
||||
{
|
||||
System.out.println("five");
|
||||
}
|
||||
finally
|
||||
{
|
||||
LockedPlainRead.LOCK.readLock().unlock();
|
||||
}
|
||||
}
|
||||
static @Locked.Read void test2() {
|
||||
LockedPlainRead.LOCK.readLock().lock();
|
||||
try
|
||||
{
|
||||
System.out.println("six");
|
||||
}
|
||||
finally
|
||||
{
|
||||
LockedPlainRead.LOCK.readLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
class LockedPlainWrite {
|
||||
private final java.util.concurrent.locks.ReentrantReadWriteLock lock = new java.util.concurrent.locks.ReentrantReadWriteLock();
|
||||
LockedPlainWrite() {
|
||||
super();
|
||||
}
|
||||
@lombok.experimental.Locked.Write void test() {
|
||||
this.lock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
System.out.println("seven");
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
@Locked.Write void test2() {
|
||||
this.lock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
System.out.println("eight");
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
class LockedGeneratedStaticMismatch {
|
||||
private static final java.util.concurrent.locks.ReentrantLock LOCK = new java.util.concurrent.locks.ReentrantLock();
|
||||
<clinit>() {
|
||||
}
|
||||
LockedGeneratedStaticMismatch() {
|
||||
super();
|
||||
}
|
||||
static @lombok.experimental.Locked void test() {
|
||||
LockedGeneratedStaticMismatch.LOCK.lock();
|
||||
try
|
||||
{
|
||||
System.out.println("one");
|
||||
}
|
||||
finally
|
||||
{
|
||||
LockedGeneratedStaticMismatch.LOCK.unlock();
|
||||
}
|
||||
}
|
||||
@lombok.experimental.Locked("LOCK") void test2() {
|
||||
System.out.println("two");
|
||||
}
|
||||
}
|
||||
class LockedUserStaticMismatch {
|
||||
private static final java.util.concurrent.locks.ReentrantLock userLock = new java.util.concurrent.locks.ReentrantLock();
|
||||
<clinit>() {
|
||||
}
|
||||
LockedUserStaticMismatch() {
|
||||
super();
|
||||
}
|
||||
static @lombok.experimental.Locked("userLock") void test() {
|
||||
LockedUserStaticMismatch.userLock.lock();
|
||||
try
|
||||
{
|
||||
System.out.println("one");
|
||||
}
|
||||
finally
|
||||
{
|
||||
LockedUserStaticMismatch.userLock.unlock();
|
||||
}
|
||||
}
|
||||
@lombok.experimental.Locked("userLock") void test2() {
|
||||
LockedUserStaticMismatch.userLock.lock();
|
||||
try
|
||||
{
|
||||
System.out.println("two");
|
||||
}
|
||||
finally
|
||||
{
|
||||
LockedUserStaticMismatch.userLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
class LockedGeneratedTypeMismatch {
|
||||
private final java.util.concurrent.locks.ReentrantLock lock = new java.util.concurrent.locks.ReentrantLock();
|
||||
LockedGeneratedTypeMismatch() {
|
||||
super();
|
||||
}
|
||||
@lombok.experimental.Locked void test() {
|
||||
this.lock.lock();
|
||||
try
|
||||
{
|
||||
System.out.println("one");
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.lock.unlock();
|
||||
}
|
||||
}
|
||||
@lombok.experimental.Locked.Read void test2() {
|
||||
System.out.println("two");
|
||||
}
|
||||
}
|
||||
class LockedUserTypeMismatch {
|
||||
private final java.util.concurrent.locks.ReentrantLock userLock = new java.util.concurrent.locks.ReentrantLock();
|
||||
LockedUserTypeMismatch() {
|
||||
super();
|
||||
}
|
||||
@lombok.experimental.Locked("userLock") void test() {
|
||||
this.userLock.lock();
|
||||
try
|
||||
{
|
||||
System.out.println("one");
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.userLock.unlock();
|
||||
}
|
||||
}
|
||||
@lombok.experimental.Locked.Read("userLock") void test2() {
|
||||
this.userLock.readLock().lock();
|
||||
try
|
||||
{
|
||||
System.out.println("two");
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.userLock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// version 14:
|
||||
|
||||
import lombok.experimental.Locked;
|
||||
|
||||
public record LockedInRecord(String a, String b) {
|
||||
@Locked
|
||||
public void foo() {
|
||||
String foo = "bar";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class LockedName {
|
||||
@lombok.experimental.Locked("basicLock") void test() {
|
||||
System.out.println("one");
|
||||
}
|
||||
@lombok.experimental.Locked.Read("rwLock") void test2() {
|
||||
System.out.println("two");
|
||||
}
|
||||
@lombok.experimental.Locked.Write("rwLock") void test3() {
|
||||
System.out.println("three");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
class LockedOnStatic<Z> {
|
||||
static class Inner {
|
||||
private static final java.util.concurrent.locks.ReentrantLock LCK = new java.util.concurrent.locks.ReentrantLock();
|
||||
@lombok.experimental.Locked("LCK")
|
||||
public void foo() {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
class Inner2 {
|
||||
private final java.util.concurrent.locks.ReentrantLock LCK = new java.util.concurrent.locks.ReentrantLock();
|
||||
@lombok.experimental.Locked("LCK")
|
||||
public void foo() {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import lombok.experimental.Locked;
|
||||
class LockedPlain {
|
||||
@lombok.experimental.Locked void test() {
|
||||
System.out.println("one");
|
||||
}
|
||||
@Locked void test2() {
|
||||
System.out.println("two");
|
||||
}
|
||||
}
|
||||
class LockedPlainStatic {
|
||||
@lombok.experimental.Locked static void test() {
|
||||
System.out.println("three");
|
||||
}
|
||||
@Locked static void test2() {
|
||||
System.out.println("four");
|
||||
}
|
||||
}
|
||||
class LockedPlainRead {
|
||||
@lombok.experimental.Locked.Read static void test() {
|
||||
System.out.println("five");
|
||||
}
|
||||
@Locked.Read static void test2() {
|
||||
System.out.println("six");
|
||||
}
|
||||
}
|
||||
class LockedPlainWrite {
|
||||
@lombok.experimental.Locked.Write void test() {
|
||||
System.out.println("seven");
|
||||
}
|
||||
@Locked.Write void test2() {
|
||||
System.out.println("eight");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
class LockedGeneratedStaticMismatch {
|
||||
@lombok.experimental.Locked static void test() {
|
||||
System.out.println("one");
|
||||
}
|
||||
@lombok.experimental.Locked("LOCK") void test2() {
|
||||
System.out.println("two");
|
||||
}
|
||||
}
|
||||
class LockedUserStaticMismatch {
|
||||
private static final java.util.concurrent.locks.ReentrantLock userLock = new java.util.concurrent.locks.ReentrantLock();
|
||||
@lombok.experimental.Locked("userLock") static void test() {
|
||||
System.out.println("one");
|
||||
}
|
||||
@lombok.experimental.Locked("userLock") void test2() {
|
||||
System.out.println("two");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
class LockedGeneratedTypeMismatch {
|
||||
@lombok.experimental.Locked void test() {
|
||||
System.out.println("one");
|
||||
}
|
||||
@lombok.experimental.Locked.Read void test2() {
|
||||
System.out.println("two");
|
||||
}
|
||||
}
|
||||
class LockedUserTypeMismatch {
|
||||
private final java.util.concurrent.locks.ReentrantLock userLock = new java.util.concurrent.locks.ReentrantLock();
|
||||
@lombok.experimental.Locked("userLock") void test() {
|
||||
System.out.println("one");
|
||||
}
|
||||
@lombok.experimental.Locked.Read("userLock") void test2() {
|
||||
System.out.println("two");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
5 @Locked is legal only on methods in classes and enums.
|
||||
@@ -0,0 +1 @@
|
||||
5 The generated field LOCK does not match the static status of this method
|
||||
@@ -0,0 +1 @@
|
||||
5 Expected field lock to be of type java.util.concurrent.locks.ReentrantReadWriteLock but got type java.util.concurrent.locks.ReentrantLock! Did you mix @Locked with @Locked.Read/Write on the same generated field?
|
||||
@@ -0,0 +1 @@
|
||||
6 @Locked is legal only on methods in classes and enums.
|
||||
@@ -0,0 +1 @@
|
||||
5 The generated field LOCK does not match the static status of this method
|
||||
@@ -0,0 +1,2 @@
|
||||
5 Expected field lock to be of type java.util.concurrent.locks.ReentrantReadWriteLock but got type java.util.concurrent.locks.ReentrantLock! Did you mix @Locked with @Locked.Read/Write on the same generated field?
|
||||
14 The method readLock() is undefined for the type ReentrantLock
|
||||
@@ -0,0 +1,2 @@
|
||||
27 cannot find symbol
|
||||
31 cannot find symbol
|
||||
Reference in New Issue
Block a user