diff options
author | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2020-02-06 23:57:30 +0100 |
---|---|---|
committer | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2020-02-06 23:57:30 +0100 |
commit | 8943b49dfed95228e324422435a77597a95943c0 (patch) | |
tree | eeaadb526286cb8947abe06fb49379b8f3309b55 /src/core/lombok/eclipse | |
parent | 2e06cb3ff19fb25b709ddfe5513a953c3d658b2e (diff) | |
download | lombok-8943b49dfed95228e324422435a77597a95943c0.tar.gz lombok-8943b49dfed95228e324422435a77597a95943c0.tar.bz2 lombok-8943b49dfed95228e324422435a77597a95943c0.zip |
[fixes #880] get rid of an unchecked cast warning for `@Getter(lazy=true)`
Diffstat (limited to 'src/core/lombok/eclipse')
-rw-r--r-- | src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java | 5 | ||||
-rw-r--r-- | src/core/lombok/eclipse/handlers/HandleGetter.java | 14 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index bdb88299..25999e85 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -1904,7 +1904,8 @@ public class EclipseHandlerUtil { return typeNode.add(type, Kind.TYPE); } - private static final char[] ALL = "all".toCharArray(); + static final char[] ALL = "all".toCharArray(); + static final char[] UNCHECKED = "unchecked".toCharArray(); private static final char[] JUSTIFICATION = "justification".toCharArray(); private static final char[] GENERATED_CODE = "generated code".toCharArray(); private static final char[] LOMBOK = "lombok".toCharArray(); @@ -1934,7 +1935,7 @@ public class EclipseHandlerUtil { return result; } - private static Annotation[] addAnnotation(ASTNode source, Annotation[] originalAnnotationArray, char[][] annotationTypeFqn, ASTNode arg) { + static Annotation[] addAnnotation(ASTNode source, Annotation[] originalAnnotationArray, char[][] annotationTypeFqn, ASTNode arg) { char[] simpleName = annotationTypeFqn[annotationTypeFqn.length - 1]; if (originalAnnotationArray != null) for (Annotation ann : originalAnnotationArray) { diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java index 7ba84cdc..58401ac1 100644 --- a/src/core/lombok/eclipse/handlers/HandleGetter.java +++ b/src/core/lombok/eclipse/handlers/HandleGetter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2019 The Project Lombok Authors. + * Copyright (C) 2009-2020 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -46,6 +46,7 @@ import lombok.eclipse.agent.PatchDelegate; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AllocationExpression; import org.eclipse.jdt.internal.compiler.ast.Annotation; +import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer; import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference; import org.eclipse.jdt.internal.compiler.ast.Assignment; import org.eclipse.jdt.internal.compiler.ast.BinaryExpression; @@ -66,6 +67,7 @@ import org.eclipse.jdt.internal.compiler.ast.ReturnStatement; import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; import org.eclipse.jdt.internal.compiler.ast.Statement; +import org.eclipse.jdt.internal.compiler.ast.StringLiteral; import org.eclipse.jdt.internal.compiler.ast.SynchronizedStatement; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; @@ -241,8 +243,10 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> { TypeReference returnType = copyType(((FieldDeclaration) fieldNode.get()).type, source); Statement[] statements; + boolean addSuppressWarningsUnchecked = false; if (lazy) { statements = createLazyGetterBody(source, fieldNode); + addSuppressWarningsUnchecked = true; } else { statements = createSimpleGetterBody(source, fieldNode); } @@ -276,6 +280,14 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> { deprecated); } + if (addSuppressWarningsUnchecked) { + ArrayInitializer arr = new ArrayInitializer(); + arr.expressions = new Expression[2]; + arr.expressions[0] = new StringLiteral(ALL, 0, 0, 0); + arr.expressions[1] = new StringLiteral(UNCHECKED, 0, 0, 0); + method.annotations = addAnnotation(source, method.annotations, TypeConstants.JAVA_LANG_SUPPRESSWARNINGS, arr); + } + method.traverse(new SetGeneratedByVisitor(source), parent.scope); return method; } |