mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 16:15:16 +00:00
Do not generate @ConstructorProperties for method-local classes
This commit is contained in:
1 parent
9bc4632315
commit
acb0e52bc0
5 files changed
+292
-4
No files matched your search
@@ -256,13 +256,20 @@ public class HandleConstructor {
|
||||
constructor.statements = nullChecks.isEmpty() ? null : nullChecks.toArray(new Statement[nullChecks.size()]);
|
||||
constructor.arguments = params.isEmpty() ? null : params.toArray(new Argument[params.size()]);
|
||||
|
||||
if (!suppressConstructorProperties && level != AccessLevel.PRIVATE) {
|
||||
if (!suppressConstructorProperties && level != AccessLevel.PRIVATE && !isLocalType(type)) {
|
||||
constructor.annotations = createConstructorProperties(source, constructor.annotations, fields);
|
||||
}
|
||||
|
||||
return constructor;
|
||||
}
|
||||
|
||||
private boolean isLocalType(EclipseNode type) {
|
||||
Kind kind = type.up().getKind();
|
||||
if (kind == Kind.COMPILATION_UNIT) return false;
|
||||
if (kind == Kind.TYPE) return isLocalType(type.up());
|
||||
return true;
|
||||
}
|
||||
|
||||
private MethodDeclaration createStaticConstructor(AccessLevel level, String name, EclipseNode type, Collection<EclipseNode> fields, ASTNode source) {
|
||||
int pS = source.sourceStart, pE = source.sourceEnd;
|
||||
long p = (long)pS << 32 | pE;
|
||||
|
||||
@@ -26,16 +26,18 @@ import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.core.AST.Kind;
|
||||
import lombok.core.AnnotationValues;
|
||||
import lombok.core.AST.Kind;
|
||||
import lombok.core.handlers.TransformationsUtil;
|
||||
import lombok.javac.Javac;
|
||||
import lombok.javac.JavacAnnotationHandler;
|
||||
import lombok.javac.JavacNode;
|
||||
import lombok.javac.handlers.JavacHandlerUtil.MemberExistsResult;
|
||||
|
||||
import org.mangosdk.spi.ProviderFor;
|
||||
|
||||
import com.sun.tools.javac.code.Flags;
|
||||
import com.sun.tools.javac.tree.TreeMaker;
|
||||
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
|
||||
import com.sun.tools.javac.tree.JCTree.JCAssign;
|
||||
import com.sun.tools.javac.tree.JCTree.JCBlock;
|
||||
@@ -50,7 +52,6 @@ import com.sun.tools.javac.tree.JCTree.JCStatement;
|
||||
import com.sun.tools.javac.tree.JCTree.JCTypeApply;
|
||||
import com.sun.tools.javac.tree.JCTree.JCTypeParameter;
|
||||
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
|
||||
import com.sun.tools.javac.tree.TreeMaker;
|
||||
import com.sun.tools.javac.util.List;
|
||||
|
||||
public class HandleConstructor {
|
||||
@@ -197,7 +198,7 @@ public class HandleConstructor {
|
||||
}
|
||||
|
||||
JCModifiers mods = maker.Modifiers(toJavacModifier(level));
|
||||
if (!suppressConstructorProperties && level != AccessLevel.PRIVATE) {
|
||||
if (!suppressConstructorProperties && level != AccessLevel.PRIVATE && !isLocalType(typeNode)) {
|
||||
addConstructorProperties(mods, typeNode, fields);
|
||||
}
|
||||
|
||||
@@ -205,6 +206,13 @@ public class HandleConstructor {
|
||||
null, type.typarams, params, List.<JCExpression>nil(), maker.Block(0L, nullChecks.appendList(assigns)), null);
|
||||
}
|
||||
|
||||
private boolean isLocalType(JavacNode type) {
|
||||
Kind kind = type.up().getKind();
|
||||
if (kind == Kind.COMPILATION_UNIT) return false;
|
||||
if (kind == Kind.TYPE) return isLocalType(type.up());
|
||||
return true;
|
||||
}
|
||||
|
||||
private JCMethodDecl createStaticConstructor(String name, AccessLevel level, JavacNode typeNode, List<JavacNode> fields) {
|
||||
TreeMaker maker = typeNode.getTreeMaker();
|
||||
JCClassDecl type = (JCClassDecl) typeNode.get();
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
class DataOnLocalClass1 {
|
||||
public static void main(String[] args) {
|
||||
class Local {
|
||||
final int x;
|
||||
String name;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public Local(final int x) {
|
||||
this.x = x;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public boolean equals(final java.lang.Object o) {
|
||||
if (o == this) return true;
|
||||
if (o == null) return false;
|
||||
if (o.getClass() != this.getClass()) return false;
|
||||
final Local other = (Local)o;
|
||||
if (this.getX() != other.getX()) return false;
|
||||
if (this.getName() == null ? other.getName() != null : !this.getName().equals(other.getName())) return false;
|
||||
return true;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public int hashCode() {
|
||||
final int PRIME = 31;
|
||||
int result = 1;
|
||||
result = result * PRIME + this.getX();
|
||||
result = result * PRIME + (this.getName() == null ? 0 : this.getName().hashCode());
|
||||
return result;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "Local(x=" + this.getX() + ", name=" + this.getName() + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class DataOnLocalClass2 {
|
||||
{
|
||||
class Local {
|
||||
final int x;
|
||||
class InnerLocal {
|
||||
@lombok.NonNull
|
||||
String name;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public InnerLocal(@lombok.NonNull final String name) {
|
||||
if (name == null) throw new java.lang.NullPointerException("name");
|
||||
this.name = name;
|
||||
}
|
||||
@lombok.NonNull
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public void setName(@lombok.NonNull final String name) {
|
||||
if (name == null) throw new java.lang.NullPointerException("name");
|
||||
this.name = name;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public boolean equals(final java.lang.Object o) {
|
||||
if (o == this) return true;
|
||||
if (o == null) return false;
|
||||
if (o.getClass() != this.getClass()) return false;
|
||||
final InnerLocal other = (InnerLocal)o;
|
||||
if (this.getName() == null ? other.getName() != null : !this.getName().equals(other.getName())) return false;
|
||||
return true;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public int hashCode() {
|
||||
final int PRIME = 31;
|
||||
int result = 1;
|
||||
result = result * PRIME + (this.getName() == null ? 0 : this.getName().hashCode());
|
||||
return result;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "InnerLocal(name=" + this.getName() + ")";
|
||||
}
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public Local(final int x) {
|
||||
this.x = x;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public boolean equals(final java.lang.Object o) {
|
||||
if (o == this) return true;
|
||||
if (o == null) return false;
|
||||
if (o.getClass() != this.getClass()) return false;
|
||||
final Local other = (Local)o;
|
||||
if (this.getX() != other.getX()) return false;
|
||||
return true;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public int hashCode() {
|
||||
final int PRIME = 31;
|
||||
int result = 1;
|
||||
result = result * PRIME + this.getX();
|
||||
return result;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "Local(x=" + this.getX() + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
import lombok.Data;
|
||||
class DataOnLocalClass1 {
|
||||
DataOnLocalClass1() {
|
||||
super();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
@Data class Local {
|
||||
final int x;
|
||||
String name;
|
||||
public @java.lang.SuppressWarnings("all") Local(final int x) {
|
||||
super();
|
||||
this.x = x;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") int getX() {
|
||||
return this.x;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") String getName() {
|
||||
return this.name;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
|
||||
if ((o == this))
|
||||
return true;
|
||||
if ((o == null))
|
||||
return false;
|
||||
if ((o.getClass() != this.getClass()))
|
||||
return false;
|
||||
final Local other = (Local) o;
|
||||
if ((this.getX() != other.getX()))
|
||||
return false;
|
||||
if (((this.getName() == null) ? (other.getName() != null) : (! this.getName().equals(other.getName()))))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
|
||||
final int PRIME = 31;
|
||||
int result = 1;
|
||||
result = ((result * PRIME) + this.getX());
|
||||
result = ((result * PRIME) + ((this.getName() == null) ? 0 : this.getName().hashCode()));
|
||||
return result;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
|
||||
return (((("Local(x=" + this.getX()) + ", name=") + this.getName()) + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class DataOnLocalClass2 {
|
||||
{
|
||||
@Data class Local {
|
||||
@Data class InnerLocal {
|
||||
@lombok.NonNull String name;
|
||||
public @java.lang.SuppressWarnings("all") InnerLocal(final @lombok.NonNull String name) {
|
||||
super();
|
||||
if ((name == null))
|
||||
throw new java.lang.NullPointerException("name");
|
||||
this.name = name;
|
||||
}
|
||||
public @lombok.NonNull @java.lang.SuppressWarnings("all") String getName() {
|
||||
return this.name;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") void setName(final @lombok.NonNull String name) {
|
||||
if ((name == null))
|
||||
throw new java.lang.NullPointerException("name");
|
||||
this.name = name;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
|
||||
if ((o == this))
|
||||
return true;
|
||||
if ((o == null))
|
||||
return false;
|
||||
if ((o.getClass() != this.getClass()))
|
||||
return false;
|
||||
final InnerLocal other = (InnerLocal) o;
|
||||
if (((this.getName() == null) ? (other.getName() != null) : (! this.getName().equals(other.getName()))))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
|
||||
final int PRIME = 31;
|
||||
int result = 1;
|
||||
result = ((result * PRIME) + ((this.getName() == null) ? 0 : this.getName().hashCode()));
|
||||
return result;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
|
||||
return (("InnerLocal(name=" + this.getName()) + ")");
|
||||
}
|
||||
}
|
||||
final int x;
|
||||
public @java.lang.SuppressWarnings("all") Local(final int x) {
|
||||
super();
|
||||
this.x = x;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") int getX() {
|
||||
return this.x;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
|
||||
if ((o == this))
|
||||
return true;
|
||||
if ((o == null))
|
||||
return false;
|
||||
if ((o.getClass() != this.getClass()))
|
||||
return false;
|
||||
final Local other = (Local) o;
|
||||
if ((this.getX() != other.getX()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
|
||||
final int PRIME = 31;
|
||||
int result = 1;
|
||||
result = ((result * PRIME) + this.getX());
|
||||
return result;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
|
||||
return (("Local(x=" + this.getX()) + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
DataOnLocalClass2() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import lombok.Data;
|
||||
class DataOnLocalClass1 {
|
||||
public static void main(String[] args) {
|
||||
@Data class Local {
|
||||
final int x;
|
||||
String name;
|
||||
}
|
||||
}
|
||||
}
|
||||
class DataOnLocalClass2 {
|
||||
{
|
||||
@Data class Local {
|
||||
final int x;
|
||||
@Data class InnerLocal {
|
||||
@lombok.NonNull String name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user