Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark injected fields as generated #3673

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/core/lombok/eclipse/handlers/HandleLockedUtil.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
* Copyright (C) 2024 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/* Copyright (C) 2021-2023 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -117,7 +138,7 @@ private static char[] createLockField(String name, EclipseNode annotationNode, c
lockAlloc.type = setGeneratedBy(new QualifiedTypeReference(lockImplClass, new long[] { 0, 0, 0, 0, 0 }), source);
fieldDecl.type = setGeneratedBy(new QualifiedTypeReference(lockTypeClass, new long[] { 0, 0, 0, 0, 0 }), source);
fieldDecl.initialization = lockAlloc;
injectField(annotationNode.up().up(), fieldDecl);
injectFieldAndMarkGenerated(annotationNode.up().up(), fieldDecl);
}

return lockName;
Expand Down
6 changes: 2 additions & 4 deletions src/core/lombok/eclipse/handlers/HandleLog.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2021 The Project Lombok Authors.
* Copyright (C) 2010-2024 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
Expand Down Expand Up @@ -109,9 +109,7 @@ public static void processAnnotation(LoggingFramework framework, AnnotationValue
ClassLiteralAccess loggingType = selfType(owner, source);
FieldDeclaration fieldDeclaration = createField(framework, source, loggingType, logFieldName.getName(), useStatic, loggerTopic);
fieldDeclaration.traverse(new SetGeneratedByVisitor(source), typeDecl.staticInitializerScope);
// TODO temporary workaround for issue 290. https://github.com/projectlombok/lombok/issues/290
// injectFieldSuppressWarnings(owner, fieldDeclaration);
injectField(owner, fieldDeclaration);
injectFieldAndMarkGenerated(owner, fieldDeclaration);
owner.rebuild();
break;
default:
Expand Down
4 changes: 1 addition & 3 deletions src/core/lombok/eclipse/handlers/HandleSynchronized.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ public char[] createLockField(AnnotationValues<Synchronized> annotation, Eclipse
fieldDecl.type = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, new long[] { 0, 0, 0 });
setGeneratedBy(fieldDecl.type, source);
fieldDecl.initialization = arrayAlloc;
// TODO temporary workaround for issue 290. https://github.com/projectlombok/lombok/issues/290
// injectFieldSuppressWarnings(annotationNode.up().up(), fieldDecl);
injectField(annotationNode.up().up(), fieldDecl);
injectFieldAndMarkGenerated(annotationNode.up().up(), fieldDecl);
}

return lockName;
Expand Down
12 changes: 6 additions & 6 deletions test/transform/resource/after-ecj/InjectField.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
@Log enum InjectField1 {
A(),
B(),
private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(InjectField1.class.getName());
private final java.lang.Object $lock = new java.lang.Object[0];
private static final java.lang.Object $LOCK = new java.lang.Object[0];
private static final @java.lang.SuppressWarnings("all") @lombok.Generated java.util.logging.Logger log = java.util.logging.Logger.getLogger(InjectField1.class.getName());
private final @java.lang.SuppressWarnings("all") @lombok.Generated java.lang.Object $lock = new java.lang.Object[0];
private static final @java.lang.SuppressWarnings("all") @lombok.Generated java.lang.Object $LOCK = new java.lang.Object[0];
private static final String LOG_MESSAGE = "static initializer";
private String fieldA;
static {
Expand All @@ -32,8 +32,8 @@
}
}
@Log class InjectField2 {
private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(InjectField2.class.getName());
private final java.lang.Object $lock = new java.lang.Object[0];
private static final @java.lang.SuppressWarnings("all") @lombok.Generated java.util.logging.Logger log = java.util.logging.Logger.getLogger(InjectField2.class.getName());
private final @java.lang.SuppressWarnings("all") @lombok.Generated java.lang.Object $lock = new java.lang.Object[0];
private static final String LOG_MESSAGE = "static initializer";
static {
log.log(Level.FINE, LOG_MESSAGE);
Expand All @@ -51,7 +51,7 @@
}
}
@Log class InjectField3 {
private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(InjectField3.class.getName());
private static final @java.lang.SuppressWarnings("all") @lombok.Generated java.util.logging.Logger log = java.util.logging.Logger.getLogger(InjectField3.class.getName());
static {
log.log(Level.FINE, "static initializer");
}
Expand Down
6 changes: 3 additions & 3 deletions test/transform/resource/after-ecj/LockedInInitializer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import lombok.Locked;
public class LockedInInitializer {
public static final Runnable LOCKED = new Runnable() {
private final java.util.concurrent.locks.Lock $lock = new java.util.concurrent.locks.ReentrantLock();
private final @java.lang.SuppressWarnings("all") @lombok.Generated java.util.concurrent.locks.Lock $lock = new java.util.concurrent.locks.ReentrantLock();
public @Override @Locked void run() {
this.$lock.lock();
try
Expand All @@ -15,7 +15,7 @@ public class LockedInInitializer {
}
};
public static final Runnable LOCKED_READ = new Runnable() {
private final java.util.concurrent.locks.ReadWriteLock $lock = new java.util.concurrent.locks.ReentrantReadWriteLock();
private final @java.lang.SuppressWarnings("all") @lombok.Generated java.util.concurrent.locks.ReadWriteLock $lock = new java.util.concurrent.locks.ReentrantReadWriteLock();
public @Override @Locked.Read void run() {
this.$lock.readLock().lock();
try
Expand All @@ -29,7 +29,7 @@ public class LockedInInitializer {
}
};
public static final Runnable LOCKED_WRITE = new Runnable() {
private final java.util.concurrent.locks.ReadWriteLock $lock = new java.util.concurrent.locks.ReentrantReadWriteLock();
private final @java.lang.SuppressWarnings("all") @lombok.Generated java.util.concurrent.locks.ReadWriteLock $lock = new java.util.concurrent.locks.ReentrantReadWriteLock();
public @Override @Locked.Write void run() {
this.$lock.writeLock().lock();
try
Expand Down
2 changes: 1 addition & 1 deletion test/transform/resource/after-ecj/LockedInRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
public record LockedInRecord(String a, String b) {
/* Implicit */ private final String a;
/* Implicit */ private final String b;
private final java.util.concurrent.locks.Lock $lock = new java.util.concurrent.locks.ReentrantLock();
private final @java.lang.SuppressWarnings("all") @lombok.Generated java.util.concurrent.locks.Lock $lock = new java.util.concurrent.locks.ReentrantLock();
public @Locked void foo() {
String foo = "bar";
}
Expand Down
8 changes: 4 additions & 4 deletions test/transform/resource/after-ecj/LockedPlain.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import lombok.Locked;
class LockedPlain {
private final java.util.concurrent.locks.Lock $lock = new java.util.concurrent.locks.ReentrantLock();
private final @java.lang.SuppressWarnings("all") @lombok.Generated java.util.concurrent.locks.Lock $lock = new java.util.concurrent.locks.ReentrantLock();
LockedPlain() {
super();
}
Expand Down Expand Up @@ -28,7 +28,7 @@ class LockedPlain {
}
}
class LockedPlainStatic {
private static final java.util.concurrent.locks.Lock $LOCK = new java.util.concurrent.locks.ReentrantLock();
private static final @java.lang.SuppressWarnings("all") @lombok.Generated java.util.concurrent.locks.Lock $LOCK = new java.util.concurrent.locks.ReentrantLock();
<clinit>() {
}
LockedPlainStatic() {
Expand Down Expand Up @@ -58,7 +58,7 @@ class LockedPlainStatic {
}
}
class LockedPlainRead {
private static final java.util.concurrent.locks.ReadWriteLock $LOCK = new java.util.concurrent.locks.ReentrantReadWriteLock();
private static final @java.lang.SuppressWarnings("all") @lombok.Generated java.util.concurrent.locks.ReadWriteLock $LOCK = new java.util.concurrent.locks.ReentrantReadWriteLock();
<clinit>() {
}
LockedPlainRead() {
Expand Down Expand Up @@ -88,7 +88,7 @@ class LockedPlainRead {
}
}
class LockedPlainWrite {
private final java.util.concurrent.locks.ReadWriteLock $lock = new java.util.concurrent.locks.ReentrantReadWriteLock();
private final @java.lang.SuppressWarnings("all") @lombok.Generated java.util.concurrent.locks.ReadWriteLock $lock = new java.util.concurrent.locks.ReentrantReadWriteLock();
LockedPlainWrite() {
super();
}
Expand Down
2 changes: 1 addition & 1 deletion test/transform/resource/after-ecj/LockedStaticMix.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class LockedGeneratedStaticMismatch {
private static final java.util.concurrent.locks.Lock $LOCK = new java.util.concurrent.locks.ReentrantLock();
private static final @java.lang.SuppressWarnings("all") @lombok.Generated java.util.concurrent.locks.Lock $LOCK = new java.util.concurrent.locks.ReentrantLock();
<clinit>() {
}
LockedGeneratedStaticMismatch() {
Expand Down
2 changes: 1 addition & 1 deletion test/transform/resource/after-ecj/LockedTypeMismatch.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class LockedGeneratedTypeMismatch {
private final java.util.concurrent.locks.Lock $lock = new java.util.concurrent.locks.ReentrantLock();
private final @java.lang.SuppressWarnings("all") @lombok.Generated java.util.concurrent.locks.Lock $lock = new java.util.concurrent.locks.ReentrantLock();
LockedGeneratedTypeMismatch() {
super();
}
Expand Down
10 changes: 5 additions & 5 deletions test/transform/resource/after-ecj/LoggerCommons.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import lombok.extern.apachecommons.CommonsLog;
@lombok.extern.apachecommons.CommonsLog class LoggerCommons {
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(LoggerCommons.class);
private static final @java.lang.SuppressWarnings("all") @lombok.Generated org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(LoggerCommons.class);
<clinit>() {
}
LoggerCommons() {
super();
}
}
@CommonsLog class LoggerCommonsWithImport {
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(LoggerCommonsWithImport.class);
private static final @java.lang.SuppressWarnings("all") @lombok.Generated org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(LoggerCommonsWithImport.class);
<clinit>() {
}
LoggerCommonsWithImport() {
super();
}
}
@CommonsLog(topic = "DifferentName") class LoggerCommonsWithDifferentName {
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog("DifferentName");
private static final @java.lang.SuppressWarnings("all") @lombok.Generated org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog("DifferentName");
<clinit>() {
}
LoggerCommonsWithDifferentName() {
super();
}
}
@CommonsLog(topic = LoggerCommonsWithStaticField.TOPIC) class LoggerCommonsWithStaticField {
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(LoggerCommonsWithStaticField.TOPIC);
private static final @java.lang.SuppressWarnings("all") @lombok.Generated org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(LoggerCommonsWithStaticField.TOPIC);
static final String TOPIC = "StaticField";
<clinit>() {
}
LoggerCommonsWithStaticField() {
super();
}
}
}
4 changes: 2 additions & 2 deletions test/transform/resource/after-ecj/LoggerConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@lombok.extern.slf4j.Slf4j class LoggerWithConfig {
private final org.slf4j.Logger myLogger = org.slf4j.LoggerFactory.getLogger(LoggerWithConfig.class);
private final @java.lang.SuppressWarnings("all") @lombok.Generated org.slf4j.Logger myLogger = org.slf4j.LoggerFactory.getLogger(LoggerWithConfig.class);
LoggerWithConfig() {
super();
}
}
}
4 changes: 2 additions & 2 deletions test/transform/resource/after-ecj/LoggerCustom.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@lombok.CustomLog class LoggerCustomLog {
private static final MyLogger log = MyLoggerFactory.create(LoggerCustomLog.class);
private static final @java.lang.SuppressWarnings("all") @lombok.Generated MyLogger log = MyLoggerFactory.create(LoggerCustomLog.class);
<clinit>() {
}
LoggerCustomLog() {
Expand All @@ -18,4 +18,4 @@ class MyLogger {
MyLogger() {
super();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package before;
@lombok.CustomLog class LoggerCustomLog {
private static final before.MyLogger log = before.MyLoggerFactory.create(LoggerCustomLog.class);
private static final @java.lang.SuppressWarnings("all") @lombok.Generated before.MyLogger log = before.MyLoggerFactory.create(LoggerCustomLog.class);
<clinit>() {
}
LoggerCustomLog() {
Expand All @@ -19,4 +19,4 @@ class MyLogger {
MyLogger() {
super();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@lombok.CustomLog(topic = "t") class LoggerCustomLog {
private static final MyLoggerFactory log = MyLoggerFactory.create(LoggerCustomLog.class.getName(), "t", null, LoggerCustomLog.class, "t");
private static final @java.lang.SuppressWarnings("all") @lombok.Generated MyLoggerFactory log = MyLoggerFactory.create(LoggerCustomLog.class.getName(), "t", null, LoggerCustomLog.class, "t");
<clinit>() {
}
LoggerCustomLog() {
super();
}
}
@lombok.CustomLog(topic = LoggerCustomLogWithStaticField.TOPIC) class LoggerCustomLogWithStaticField {
private static final MyLoggerFactory log = MyLoggerFactory.create(LoggerCustomLogWithStaticField.class.getName(), LoggerCustomLogWithStaticField.TOPIC, null, LoggerCustomLogWithStaticField.class, LoggerCustomLogWithStaticField.TOPIC);
private static final @java.lang.SuppressWarnings("all") @lombok.Generated MyLoggerFactory log = MyLoggerFactory.create(LoggerCustomLogWithStaticField.class.getName(), LoggerCustomLogWithStaticField.TOPIC, null, LoggerCustomLogWithStaticField.class, LoggerCustomLogWithStaticField.TOPIC);
static final String TOPIC = "StaticField";
<clinit>() {
}
Expand Down
10 changes: 5 additions & 5 deletions test/transform/resource/after-ecj/LoggerFlogger.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import lombok.extern.flogger.Flogger;
@lombok.extern.flogger.Flogger class LoggerFlogger {
private static final com.google.common.flogger.FluentLogger log = com.google.common.flogger.FluentLogger.forEnclosingClass();
private static final @java.lang.SuppressWarnings("all") @lombok.Generated com.google.common.flogger.FluentLogger log = com.google.common.flogger.FluentLogger.forEnclosingClass();
<clinit>() {
}
LoggerFlogger() {
super();
}
}
@Flogger class LoggerFloggerWithImport {
private static final com.google.common.flogger.FluentLogger log = com.google.common.flogger.FluentLogger.forEnclosingClass();
private static final @java.lang.SuppressWarnings("all") @lombok.Generated com.google.common.flogger.FluentLogger log = com.google.common.flogger.FluentLogger.forEnclosingClass();
<clinit>() {
}
LoggerFloggerWithImport() {
Expand All @@ -17,7 +17,7 @@
}
class LoggerFloggerOuter {
static @lombok.extern.flogger.Flogger class Inner {
private static final com.google.common.flogger.FluentLogger log = com.google.common.flogger.FluentLogger.forEnclosingClass();
private static final @java.lang.SuppressWarnings("all") @lombok.Generated com.google.common.flogger.FluentLogger log = com.google.common.flogger.FluentLogger.forEnclosingClass();
<clinit>() {
}
Inner() {
Expand All @@ -30,7 +30,7 @@ class LoggerFloggerOuter {
}
@Flogger enum LoggerFloggerWithEnum {
CONSTANT(),
private static final com.google.common.flogger.FluentLogger log = com.google.common.flogger.FluentLogger.forEnclosingClass();
private static final @java.lang.SuppressWarnings("all") @lombok.Generated com.google.common.flogger.FluentLogger log = com.google.common.flogger.FluentLogger.forEnclosingClass();
<clinit>() {
}
LoggerFloggerWithEnum() {
Expand All @@ -40,7 +40,7 @@ class LoggerFloggerOuter {
class LoggerFloggerWithInnerEnum {
@Flogger enum Inner {
CONSTANT(),
private static final com.google.common.flogger.FluentLogger log = com.google.common.flogger.FluentLogger.forEnclosingClass();
private static final @java.lang.SuppressWarnings("all") @lombok.Generated com.google.common.flogger.FluentLogger log = com.google.common.flogger.FluentLogger.forEnclosingClass();
<clinit>() {
}
Inner() {
Expand Down
5 changes: 2 additions & 3 deletions test/transform/resource/after-ecj/LoggerFloggerRecord.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// version 19:
import lombok.extern.flogger.Flogger;
class LoggerFloggerRecord {
public @Flogger record Inner(String x) {
/* Implicit */ private final String x;
private static final com.google.common.flogger.FluentLogger log = com.google.common.flogger.FluentLogger.forEnclosingClass();
private static final @java.lang.SuppressWarnings("all") @lombok.Generated com.google.common.flogger.FluentLogger log = com.google.common.flogger.FluentLogger.forEnclosingClass();
<clinit>() {
}
}
LoggerFloggerRecord() {
super();
}
}
}
Loading
Loading