-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lombok.java
99 lines (99 loc) · 2.43 KB
/
Lombok.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import java.lang.reflect.*;
import org.lombok.annotations.Setter;
import org.lombok.annotations.Getter;
import org.lombok.annotations.Data;
import org.lombok.annotations.NoArgsConstructor;
import org.lombok.annotations.AllArgsConstructor;
import org.lombok.annotations.ToString;
/**
** Project Lombok Clone
** Author - Saksham Solanki
*Starting Date -03 Oct 2021
* Last Modified - 09 Oct 2021
@javassist - ByteCode manipulation library
*/
class Lombok
{
private static String className;
private static Class c;
private static Field[] fields;
private static Constructor[] constructors;
public static void main(String[] gg)
{
try
{
className = gg[0];
c = Class.forName(className);
fields = c.getDeclaredFields();
constructors = c.getConstructors();
boolean isClassAnnotatedWithData = false;
if(c.isAnnotationPresent(ToString.class))
{
LombokUtility.generateToString(className);
}
if(c.isAnnotationPresent(NoArgsConstructor.class))
{
if(constructors==null || constructors.length==0)
{
LombokUtility.generateNoArgumentConstructor(className);
}
}
if(c.isAnnotationPresent(AllArgsConstructor.class))
{
if(constructors==null || constructors.length==0 && fields.length>0)
{
LombokUtility.generateAllArgumentsConstructor(fields,constructors,className);
}
}
if(c.isAnnotationPresent(Data.class))
{
isClassAnnotatedWithData = true;
//generating Both Setters and Getters
LombokUtility.generateSettersAndGetters(fields,className);
}
if(c.isAnnotationPresent(Setter.class))
{
if(!isClassAnnotatedWithData)
{
//If it is not annotated with Data then generate Setters only
LombokUtility.generateSetters(fields,className);
}
}
if(c.isAnnotationPresent(Getter.class))
{
if(!isClassAnnotatedWithData)
{
//If it is not annotated with Data then generate Getters only
LombokUtility.generateGetters(fields,className);
}
}
//Generating Boiler Plate Code for Fields using Lombok
boolean isFieldAnnotatedWithData;
for(Field field : fields)
{
isFieldAnnotatedWithData = false;
if(field.isAnnotationPresent(Data.class))
{
isFieldAnnotatedWithData = true;
LombokUtility.generateSetterAndGetter(field,className);
}
if(field.isAnnotationPresent(Setter.class))
{
if(!isFieldAnnotatedWithData)
{
LombokUtility.generateSetter(field,className);
}
}
if(field.isAnnotationPresent(Getter.class))
{
if(!isFieldAnnotatedWithData)
{
LombokUtility.generateGetter(field,className);
}
}
}
}catch(Exception e) {
e.printStackTrace();
}
}
}