Implement access for eclipse

This commit is contained in:
Liam Pace authored and Reinier Zwitserloot committed 2025-09-17 22:24:00 +02:00
1 parent 7c692b559e
commit 3d15eb6782
1 file changed
+25 -13
+25 -13
View File
@@ -39,6 +39,9 @@ import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import com.sun.tools.javac.code.Flags;
import lombok.AccessLevel;
import lombok.ConfigurationKeys;
import lombok.core.AnnotationValues;
import lombok.core.configuration.IdentifierName;
@@ -57,7 +60,7 @@ public class HandleLog {
throw new UnsupportedOperationException();
}
public static void processAnnotation(LoggingFramework framework, AnnotationValues<? extends java.lang.annotation.Annotation> annotation, Annotation source, EclipseNode annotationNode) {
public static void processAnnotation(LoggingFramework framework, AccessLevel access, AnnotationValues<? extends java.lang.annotation.Annotation> annotation, Annotation source, EclipseNode annotationNode) {
EclipseNode owner = annotationNode.up();
switch (owner.getKind()) {
@@ -107,7 +110,7 @@ public class HandleLog {
}
ClassLiteralAccess loggingType = selfType(owner, source);
FieldDeclaration fieldDeclaration = createField(framework, source, loggingType, logFieldName.getName(), useStatic, loggerTopic);
FieldDeclaration fieldDeclaration = createField(framework, access, source, loggingType, logFieldName.getName(), useStatic, loggerTopic);
fieldDeclaration.traverse(new SetGeneratedByVisitor(source), typeDecl.staticInitializerScope);
injectFieldAndMarkGenerated(owner, fieldDeclaration);
owner.rebuild();
@@ -131,7 +134,16 @@ public class HandleLog {
return result;
}
private static FieldDeclaration createField(LoggingFramework framework, Annotation source, ClassLiteralAccess loggingType, String logFieldName, boolean useStatic, Expression loggerTopic) {
private static int toFlags(AccessLevel level) {
switch (level) {
case PUBLIC: return Flags.PUBLIC;
case PROTECTED: return Flags.PROTECTED;
case PRIVATE: return Flags.PUBLIC;
default: return 0;
}
}
private static FieldDeclaration createField(LoggingFramework framework, AccessLevel access, Annotation source, ClassLiteralAccess loggingType, String logFieldName, boolean useStatic, Expression loggerTopic) {
int pS = source.sourceStart, pE = source.sourceEnd;
long p = (long) pS << 32 | pE;
@@ -139,7 +151,7 @@ public class HandleLog {
FieldDeclaration fieldDecl = new FieldDeclaration(logFieldName.toCharArray(), 0, -1);
setGeneratedBy(fieldDecl, source);
fieldDecl.declarationSourceEnd = -1;
fieldDecl.modifiers = Modifier.PRIVATE | (useStatic ? Modifier.STATIC : 0) | Modifier.FINAL;
fieldDecl.modifiers = toFlags(access) | (useStatic ? Modifier.STATIC : 0) | Modifier.FINAL;
LogDeclaration logDeclaration = framework.getDeclaration();
fieldDecl.type = createTypeReference(logDeclaration.getLoggerType().getName(), source);
@@ -215,7 +227,7 @@ public class HandleLog {
public static class HandleCommonsLog extends EclipseAnnotationHandler<lombok.extern.apachecommons.CommonsLog> {
@Override public void handle(AnnotationValues<lombok.extern.apachecommons.CommonsLog> annotation, Annotation source, EclipseNode annotationNode) {
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_COMMONS_FLAG_USAGE, "@apachecommons.CommonsLog", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
processAnnotation(LoggingFramework.COMMONS, annotation, source, annotationNode);
processAnnotation(LoggingFramework.COMMONS, annotation.getInstance().access(), annotation, source, annotationNode);
}
}
@@ -226,7 +238,7 @@ public class HandleLog {
public static class HandleJulLog extends EclipseAnnotationHandler<lombok.extern.java.Log> {
@Override public void handle(AnnotationValues<lombok.extern.java.Log> annotation, Annotation source, EclipseNode annotationNode) {
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_JUL_FLAG_USAGE, "@java.Log", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
processAnnotation(LoggingFramework.JUL, annotation, source, annotationNode);
processAnnotation(LoggingFramework.JUL, annotation.getInstance().access(), annotation, source, annotationNode);
}
}
@@ -237,7 +249,7 @@ public class HandleLog {
public static class HandleLog4jLog extends EclipseAnnotationHandler<lombok.extern.log4j.Log4j> {
@Override public void handle(AnnotationValues<lombok.extern.log4j.Log4j> annotation, Annotation source, EclipseNode annotationNode) {
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_LOG4J_FLAG_USAGE, "@Log4j", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
processAnnotation(LoggingFramework.LOG4J, annotation, source, annotationNode);
processAnnotation(LoggingFramework.LOG4J, annotation.getInstance().access(), annotation, source, annotationNode);
}
}
@@ -248,7 +260,7 @@ public class HandleLog {
public static class HandleLog4j2Log extends EclipseAnnotationHandler<lombok.extern.log4j.Log4j2> {
@Override public void handle(AnnotationValues<lombok.extern.log4j.Log4j2> annotation, Annotation source, EclipseNode annotationNode) {
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_LOG4J2_FLAG_USAGE, "@Log4j2", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
processAnnotation(LoggingFramework.LOG4J2, annotation, source, annotationNode);
processAnnotation(LoggingFramework.LOG4J2, annotation.getInstance().access(), annotation, source, annotationNode);
}
}
@@ -259,7 +271,7 @@ public class HandleLog {
public static class HandleSlf4jLog extends EclipseAnnotationHandler<lombok.extern.slf4j.Slf4j> {
@Override public void handle(AnnotationValues<lombok.extern.slf4j.Slf4j> annotation, Annotation source, EclipseNode annotationNode) {
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_SLF4J_FLAG_USAGE, "@Slf4j", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
processAnnotation(LoggingFramework.SLF4J, annotation, source, annotationNode);
processAnnotation(LoggingFramework.SLF4J, annotation.getInstance().access(), annotation, source, annotationNode);
}
}
@@ -270,7 +282,7 @@ public class HandleLog {
public static class HandleXSlf4jLog extends EclipseAnnotationHandler<lombok.extern.slf4j.XSlf4j> {
@Override public void handle(AnnotationValues<lombok.extern.slf4j.XSlf4j> annotation, Annotation source, EclipseNode annotationNode) {
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_XSLF4J_FLAG_USAGE, "@XSlf4j", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
processAnnotation(LoggingFramework.XSLF4J, annotation, source, annotationNode);
processAnnotation(LoggingFramework.XSLF4J, annotation.getInstance().access(), annotation, source, annotationNode);
}
}
@@ -281,7 +293,7 @@ public class HandleLog {
public static class HandleJBossLog extends EclipseAnnotationHandler<lombok.extern.jbosslog.JBossLog> {
@Override public void handle(AnnotationValues<lombok.extern.jbosslog.JBossLog> annotation, Annotation source, EclipseNode annotationNode) {
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_JBOSSLOG_FLAG_USAGE, "@JBossLog", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
processAnnotation(LoggingFramework.JBOSSLOG, annotation, source, annotationNode);
processAnnotation(LoggingFramework.JBOSSLOG, annotation.getInstance().access(), annotation, source, annotationNode);
}
}
@@ -292,7 +304,7 @@ public class HandleLog {
public static class HandleFloggerLog extends EclipseAnnotationHandler<lombok.extern.flogger.Flogger> {
@Override public void handle(AnnotationValues<lombok.extern.flogger.Flogger> annotation, Annotation source, EclipseNode annotationNode) {
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_FLOGGER_FLAG_USAGE, "@Flogger", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
processAnnotation(LoggingFramework.FLOGGER, annotation, source, annotationNode);
processAnnotation(LoggingFramework.FLOGGER, annotation.getInstance().access(), annotation, source, annotationNode);
}
}
@@ -309,7 +321,7 @@ public class HandleLog {
return;
}
LoggingFramework framework = new LoggingFramework(lombok.CustomLog.class, logDeclaration);
processAnnotation(framework, annotation, source, annotationNode);
processAnnotation(framework, annotation.getInstance().access(), annotation, source, annotationNode);
}
}
}