mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 10:15:53 +00:00
Addresses issue #5:
hitting 'find callers' on a @Data annotation should find callers of the (static) constructor. Right now it'll find callers to the *static* constructor ONLY. Letting it find callers of the public constructor if there is no static constructor just doesn't work.
This commit is contained in:
1 parent
dfbc6a79e7
commit
f74109fdc8
2 files changed
+28
-22
No files matched your search
@@ -129,6 +129,22 @@ public class HandleData implements EclipseAnnotationHandler<Data> {
|
||||
injectMethod(typeNode, toString);
|
||||
}
|
||||
|
||||
if ( methodExists("equals", typeNode) == MemberExistsResult.NOT_EXISTS ) {
|
||||
MethodDeclaration equals = createEquals(typeNode, nodesForEquality, ast);
|
||||
injectMethod(typeNode, equals);
|
||||
}
|
||||
|
||||
if ( methodExists("hashCode", typeNode) == MemberExistsResult.NOT_EXISTS ) {
|
||||
MethodDeclaration hashCode = createHashCode(typeNode, nodesForEquality, ast);
|
||||
injectMethod(typeNode, hashCode);
|
||||
}
|
||||
|
||||
//Careful: Generate the public static constructor (if there is one) LAST, so that any attempt to
|
||||
//'find callers' on the annotation node will find callers of the constructor, which is by far the
|
||||
//most useful of the many methods built by @Data. This trick won't work for the non-static constructor,
|
||||
//for whatever reason, though you can find callers of that one by focussing on the class name itself
|
||||
//and hitting 'find callers'.
|
||||
|
||||
if ( constructorExists(typeNode) == MemberExistsResult.NOT_EXISTS ) {
|
||||
ConstructorDeclaration constructor = createConstructor(
|
||||
ann.staticConstructor().length() == 0, typeNode, nodesForConstructor, ast);
|
||||
@@ -143,16 +159,6 @@ public class HandleData implements EclipseAnnotationHandler<Data> {
|
||||
}
|
||||
}
|
||||
|
||||
if ( methodExists("equals", typeNode) == MemberExistsResult.NOT_EXISTS ) {
|
||||
MethodDeclaration equals = createEquals(typeNode, nodesForEquality, ast);
|
||||
injectMethod(typeNode, equals);
|
||||
}
|
||||
|
||||
if ( methodExists("hashCode", typeNode) == MemberExistsResult.NOT_EXISTS ) {
|
||||
MethodDeclaration hashCode = createHashCode(typeNode, nodesForEquality, ast);
|
||||
injectMethod(typeNode, hashCode);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -92,18 +92,6 @@ public class HandleData implements JavacAnnotationHandler<Data> {
|
||||
if ( !isFinal ) new HandleSetter().generateSetterForField(child, annotationNode.get());
|
||||
}
|
||||
|
||||
String staticConstructorName = annotation.getInstance().staticConstructor();
|
||||
|
||||
if ( constructorExists(typeNode) == MemberExistsResult.NOT_EXISTS ) {
|
||||
JCMethodDecl constructor = createConstructor(staticConstructorName.equals(""), typeNode, nodesForConstructor);
|
||||
injectMethod(typeNode, constructor);
|
||||
}
|
||||
|
||||
if ( !staticConstructorName.isEmpty() && methodExists("of", typeNode) == MemberExistsResult.NOT_EXISTS ) {
|
||||
JCMethodDecl staticConstructor = createStaticConstructor(staticConstructorName, typeNode, nodesForConstructor);
|
||||
injectMethod(typeNode, staticConstructor);
|
||||
}
|
||||
|
||||
if ( methodExists("equals", typeNode) == MemberExistsResult.NOT_EXISTS ) {
|
||||
JCMethodDecl method = createEquals(typeNode, nodesForEquality);
|
||||
injectMethod(typeNode, method);
|
||||
@@ -119,6 +107,18 @@ public class HandleData implements JavacAnnotationHandler<Data> {
|
||||
injectMethod(typeNode, method);
|
||||
}
|
||||
|
||||
String staticConstructorName = annotation.getInstance().staticConstructor();
|
||||
|
||||
if ( constructorExists(typeNode) == MemberExistsResult.NOT_EXISTS ) {
|
||||
JCMethodDecl constructor = createConstructor(staticConstructorName.equals(""), typeNode, nodesForConstructor);
|
||||
injectMethod(typeNode, constructor);
|
||||
}
|
||||
|
||||
if ( !staticConstructorName.isEmpty() && methodExists("of", typeNode) == MemberExistsResult.NOT_EXISTS ) {
|
||||
JCMethodDecl staticConstructor = createStaticConstructor(staticConstructorName, typeNode, nodesForConstructor);
|
||||
injectMethod(typeNode, staticConstructor);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user