mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-15 08:17:18 +00:00
Create Clinit if you create a static field and it doesn't yet exist
This commit is contained in:
1 parent
a48c335c7d
commit
0c7b29f8e7
10 files changed
+57
No files matched your search
@@ -23,6 +23,7 @@ package lombok.eclipse.handlers;
|
||||
|
||||
import static lombok.eclipse.Eclipse.*;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -42,6 +43,7 @@ import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.AllocationExpression;
|
||||
import org.eclipse.jdt.internal.compiler.ast.Annotation;
|
||||
import org.eclipse.jdt.internal.compiler.ast.Clinit;
|
||||
import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.EqualExpression;
|
||||
import org.eclipse.jdt.internal.compiler.ast.Expression;
|
||||
@@ -429,9 +431,24 @@ public class EclipseHandlerUtil {
|
||||
parent.fields = newArray;
|
||||
}
|
||||
|
||||
if ((field.modifiers & Modifier.STATIC) != 0) {
|
||||
if (!hasClinit(parent)) {
|
||||
parent.addClinit();
|
||||
}
|
||||
}
|
||||
|
||||
type.add(field, Kind.FIELD).recursiveSetHandled();
|
||||
}
|
||||
|
||||
private static boolean hasClinit(TypeDeclaration parent) {
|
||||
if (parent.methods == null) return false;
|
||||
|
||||
for (AbstractMethodDeclaration method : parent.methods) {
|
||||
if (method instanceof Clinit) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a method into an existing type. The type must represent a {@code TypeDeclaration}.
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
@lombok.commons.Log class LoggerCommons {
|
||||
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(LoggerCommons.class);
|
||||
<clinit>() {
|
||||
}
|
||||
LoggerCommons() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@lombok.commons.Log(String.class) class LoggerCommonsString {
|
||||
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(String.class);
|
||||
<clinit>() {
|
||||
}
|
||||
LoggerCommonsString() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@lombok.commons.Log(java.lang.String.class) class LoggerCommonsJavaLangString {
|
||||
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(java.lang.String.class);
|
||||
<clinit>() {
|
||||
}
|
||||
LoggerCommonsJavaLangString() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
@lombok.jul.Log class LoggerJul {
|
||||
private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger("LoggerJul");
|
||||
<clinit>() {
|
||||
}
|
||||
LoggerJul() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@lombok.jul.Log(String.class) class LoggerJulString {
|
||||
private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger("String");
|
||||
<clinit>() {
|
||||
}
|
||||
LoggerJulString() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@lombok.jul.Log(java.lang.String.class) class LoggerJulJavaLangString {
|
||||
private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger("java.lang.String");
|
||||
<clinit>() {
|
||||
}
|
||||
LoggerJulJavaLangString() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
@lombok.log4j.Log class LoggerLog4j {
|
||||
private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(LoggerLog4j.class);
|
||||
<clinit>() {
|
||||
}
|
||||
LoggerLog4j() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@lombok.log4j.Log(String.class) class LoggerLog4jString {
|
||||
private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(String.class);
|
||||
<clinit>() {
|
||||
}
|
||||
LoggerLog4jString() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@lombok.log4j.Log(java.lang.String.class) class LoggerLog4jJavaLangString {
|
||||
private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(java.lang.String.class);
|
||||
<clinit>() {
|
||||
}
|
||||
LoggerLog4jJavaLangString() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
@lombok.slf4j.Log class LoggerSlf4j {
|
||||
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerSlf4j.class);
|
||||
<clinit>() {
|
||||
}
|
||||
LoggerSlf4j() {
|
||||
super();
|
||||
}
|
||||
@@ -7,6 +9,8 @@
|
||||
class LoggerSlf4jOuter {
|
||||
static @lombok.slf4j.Log class Inner {
|
||||
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerSlf4jOuter.Inner.class);
|
||||
<clinit>() {
|
||||
}
|
||||
Inner() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
@lombok.slf4j.Log(String[].class) class LoggerSlf4jClassOfArray {
|
||||
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(String[].class);
|
||||
<clinit>() {
|
||||
}
|
||||
LoggerSlf4jClassOfArray() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
interface LoggerSlf4jTypesInterfaceOuter {
|
||||
@lombok.slf4j.Log class Inner {
|
||||
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerSlf4jTypesInterfaceOuter.Inner.class);
|
||||
<clinit>() {
|
||||
}
|
||||
Inner() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -1,23 +1,31 @@
|
||||
@lombok.slf4j.Log(String.class) class LoggerSlf4jWithClass {
|
||||
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(String.class);
|
||||
<clinit>() {
|
||||
}
|
||||
LoggerSlf4jWithClass() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@lombok.slf4j.Log(java.util.List.class) class LoggerSlf4jWithClassList {
|
||||
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(java.util.List.class);
|
||||
<clinit>() {
|
||||
}
|
||||
LoggerSlf4jWithClassList() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@lombok.slf4j.Log(value = java.lang.String.class) class LoggerSlf4jWithClassValue {
|
||||
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(java.lang.String.class);
|
||||
<clinit>() {
|
||||
}
|
||||
LoggerSlf4jWithClassValue() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@lombok.slf4j.Log(void.class) class LoggerSlf4jWithClassVoid {
|
||||
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerSlf4jWithClassVoid.class);
|
||||
<clinit>() {
|
||||
}
|
||||
LoggerSlf4jWithClassVoid() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package before;
|
||||
@lombok.slf4j.Log class LoggerSlf4jWithPackage {
|
||||
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(before.LoggerSlf4jWithPackage.class);
|
||||
<clinit>() {
|
||||
}
|
||||
LoggerSlf4jWithPackage() {
|
||||
super();
|
||||
}
|
||||
@@ -8,6 +10,8 @@ package before;
|
||||
class LoggerSlf4jWithPackageOuter {
|
||||
static @lombok.slf4j.Log class Inner {
|
||||
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(before.LoggerSlf4jWithPackageOuter.Inner.class);
|
||||
<clinit>() {
|
||||
}
|
||||
Inner() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ class SynchronizedPlain1 {
|
||||
}
|
||||
class SynchronizedPlain2 {
|
||||
private static final @java.lang.SuppressWarnings("all") java.lang.Object $LOCK = new java.lang.Object[0];
|
||||
<clinit>() {
|
||||
}
|
||||
SynchronizedPlain2() {
|
||||
super();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user