aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2015-02-02 00:17:51 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2015-02-02 00:17:51 +0100
commit209654f19e69932fcc35fade290b878f85f30d81 (patch)
tree28abb993fda924daf3b60ce508487f827b848349 /src/core
parente5860edabe31f3b6ceabd91f9cbcadf3d4d0315a (diff)
downloadlombok-209654f19e69932fcc35fade290b878f85f30d81.tar.gz
lombok-209654f19e69932fcc35fade290b878f85f30d81.tar.bz2
lombok-209654f19e69932fcc35fade290b878f85f30d81.zip
[i702] findbugs suppress warnings now available via config key.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/lombok/ConfigurationKeys.java9
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java53
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java20
3 files changed, 66 insertions, 16 deletions
diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java
index e18fe66c..3e2330fd 100644
--- a/src/core/lombok/ConfigurationKeys.java
+++ b/src/core/lombok/ConfigurationKeys.java
@@ -44,6 +44,15 @@ public class ConfigurationKeys {
*/
public static final ConfigurationKey<Boolean> ADD_GENERATED_ANNOTATIONS = new ConfigurationKey<Boolean>("lombok.addGeneratedAnnotation", "Generate @javax.annotation.Generated on all generated code (default: true).") {};
+ /**
+ * lombok configuration: {@code lombok.extern.findbugs.addSuppressFBWarnings} = {@code true} | {@code false}.
+ *
+ * If {@code true}, lombok generates {@code edu.umd.cs.findbugs.annotations.SuppressFBWarnings} on all fields, methods, and types that are generated.
+ *
+ * NB: If you enable this option, findbugs must be on the source or classpath, or you'll get errors that the type {@code SuppressFBWarnings} cannot be found.
+ */
+ public static final ConfigurationKey<Boolean> ADD_FINDBUGS_SUPPRESSWARNINGS_ANNOTATIONS = new ConfigurationKey<Boolean>("lombok.extern.findbugs.addSuppressFBWarnings", "Generate @edu.umd.cs.findbugs.annotations.SuppressFBWArnings on all generated code (default: false).") {};
+
// ----- *ArgsConstructor -----
/**
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index 23a5f4bc..836a51c6 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -1215,7 +1215,7 @@ public class EclipseHandlerUtil {
* The field carries the &#64;{@link SuppressWarnings}("all") annotation.
*/
public static EclipseNode injectFieldAndMarkGenerated(EclipseNode type, FieldDeclaration field) {
- field.annotations = addSuppressWarningsAll(field, field.annotations);
+ field.annotations = addSuppressWarningsAll(type, field, field.annotations);
field.annotations = addGenerated(type, field, field.annotations);
return injectField(type, field);
}
@@ -1261,7 +1261,7 @@ public class EclipseHandlerUtil {
* Inserts a method into an existing type. The type must represent a {@code TypeDeclaration}.
*/
public static EclipseNode injectMethod(EclipseNode type, AbstractMethodDeclaration method) {
- method.annotations = addSuppressWarningsAll(method, method.annotations);
+ method.annotations = addSuppressWarningsAll(type, method, method.annotations);
method.annotations = addGenerated(type, method, method.annotations);
TypeDeclaration parent = (TypeDeclaration) type.get();
@@ -1304,7 +1304,7 @@ public class EclipseHandlerUtil {
* @param type New type (class, interface, etc) to inject.
*/
public static EclipseNode injectType(final EclipseNode typeNode, final TypeDeclaration type) {
- type.annotations = addSuppressWarningsAll(type, type.annotations);
+ type.annotations = addSuppressWarningsAll(typeNode, type, type.annotations);
type.annotations = addGenerated(typeNode, type, type.annotations);
TypeDeclaration parent = (TypeDeclaration) typeNode.get();
@@ -1321,11 +1321,21 @@ public class EclipseHandlerUtil {
}
private static final char[] ALL = "all".toCharArray();
+ private static final char[] JUSTIFICATION = "justification".toCharArray();
+ private static final char[] GENERATED_CODE = "generated code".toCharArray();
private static final char[] LOMBOK = "lombok".toCharArray();
private static final char[][] JAVAX_ANNOTATION_GENERATED = Eclipse.fromQualifiedName("javax.annotation.Generated");
+ private static final char[][] EDU_UMD_CS_FINDBUGS_ANNOTATIONS_SUPPRESSFBWARNINGS = Eclipse.fromQualifiedName("edu.umd.cs.findbugs.annotations.SuppressFBWarnings");
- public static Annotation[] addSuppressWarningsAll(ASTNode source, Annotation[] originalAnnotationArray) {
- return addAnnotation(source, originalAnnotationArray, TypeConstants.JAVA_LANG_SUPPRESSWARNINGS, new StringLiteral(ALL, 0, 0, 0));
+ public static Annotation[] addSuppressWarningsAll(EclipseNode node, ASTNode source, Annotation[] originalAnnotationArray) {
+ Annotation[] anns = addAnnotation(source, originalAnnotationArray, TypeConstants.JAVA_LANG_SUPPRESSWARNINGS, new StringLiteral(ALL, 0, 0, 0));
+
+ if (Boolean.TRUE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_FINDBUGS_SUPPRESSWARNINGS_ANNOTATIONS))) {
+ MemberValuePair mvp = new MemberValuePair(JUSTIFICATION, 0, 0, new StringLiteral(GENERATED_CODE, 0, 0, 0));
+ anns = addAnnotation(source, anns, EDU_UMD_CS_FINDBUGS_ANNOTATIONS_SUPPRESSFBWARNINGS, mvp);
+ }
+
+ return anns;
}
public static Annotation[] addGenerated(EclipseNode node, ASTNode source, Annotation[] originalAnnotationArray) {
@@ -1333,7 +1343,7 @@ public class EclipseHandlerUtil {
return addAnnotation(source, originalAnnotationArray, JAVAX_ANNOTATION_GENERATED, new StringLiteral(LOMBOK, 0, 0, 0));
}
- private static Annotation[] addAnnotation(ASTNode source, Annotation[] originalAnnotationArray, char[][] annotationTypeFqn, Expression arg) {
+ private static Annotation[] addAnnotation(ASTNode source, Annotation[] originalAnnotationArray, char[][] annotationTypeFqn, ASTNode arg) {
char[] simpleName = annotationTypeFqn[annotationTypeFqn.length - 1];
if (originalAnnotationArray != null) for (Annotation ann : originalAnnotationArray) {
@@ -1353,15 +1363,32 @@ public class EclipseHandlerUtil {
long p = (long)pS << 32 | pE;
long[] poss = new long[annotationTypeFqn.length];
Arrays.fill(poss, p);
- QualifiedTypeReference suppressWarningsType = new QualifiedTypeReference(annotationTypeFqn, poss);
- setGeneratedBy(suppressWarningsType, source);
- SingleMemberAnnotation ann = new SingleMemberAnnotation(suppressWarningsType, pS);
- ann.declarationSourceEnd = pE;
- if (arg != null) {
+ QualifiedTypeReference qualifiedType = new QualifiedTypeReference(annotationTypeFqn, poss);
+ setGeneratedBy(qualifiedType, source);
+ Annotation ann;
+ if (arg instanceof Expression) {
+ SingleMemberAnnotation sma = new SingleMemberAnnotation(qualifiedType, pS);
+ sma.declarationSourceEnd = pE;
arg.sourceStart = pS;
arg.sourceEnd = pE;
- ann.memberValue = arg;
- setGeneratedBy(ann.memberValue, source);
+ sma.memberValue = (Expression) arg;
+ setGeneratedBy(sma.memberValue, source);
+ ann = sma;
+ } else if (arg instanceof MemberValuePair) {
+ NormalAnnotation na = new NormalAnnotation(qualifiedType, pS);
+ na.declarationSourceEnd = pE;
+ arg.sourceStart = pS;
+ arg.sourceEnd = pE;
+ na.memberValuePairs = new MemberValuePair[] {(MemberValuePair) arg};
+ setGeneratedBy(na.memberValuePairs[0], source);
+ setGeneratedBy(na.memberValuePairs[0].value, source);
+ na.memberValuePairs[0].value.sourceStart = pS;
+ na.memberValuePairs[0].value.sourceEnd = pE;
+ ann = na;
+ } else {
+ MarkerAnnotation ma = new MarkerAnnotation(qualifiedType, pS);
+ ma.declarationSourceEnd = pE;
+ ann = ma;
}
setGeneratedBy(ann, source);
if (originalAnnotationArray == null) return new Annotation[] { ann };
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index 599a4753..a073ac0d 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -953,12 +953,20 @@ public class JavacHandlerUtil {
public static void addSuppressWarningsAll(JCModifiers mods, JavacNode node, int pos, JCTree source, Context context) {
if (!LombokOptionsFactory.getDelombokOptions(context).getFormatPreferences().generateSuppressWarnings()) return;
addAnnotation(mods, node, pos, source, context, "java.lang.SuppressWarnings", node.getTreeMaker().Literal("all"));
+
+ if (Boolean.TRUE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_FINDBUGS_SUPPRESSWARNINGS_ANNOTATIONS))) {
+ JavacTreeMaker maker = node.getTreeMaker();
+ JCExpression arg = maker.Assign(maker.Ident(node.toName("justification")), maker.Literal("generated code"));
+ addAnnotation(mods, node, pos, source, context, "edu.umd.cs.findbugs.annotations.SuppressFBWarnings", arg);
+ }
}
public static void addGenerated(JCModifiers mods, JavacNode node, int pos, JCTree source, Context context) {
- if (Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_GENERATED_ANNOTATIONS))) return;
if (!LombokOptionsFactory.getDelombokOptions(context).getFormatPreferences().generateGenerated()) return;
- addAnnotation(mods, node, pos, source, context, "javax.annotation.Generated", node.getTreeMaker().Literal("lombok"));
+
+ if (!Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_GENERATED_ANNOTATIONS))) {
+ addAnnotation(mods, node, pos, source, context, "javax.annotation.Generated", node.getTreeMaker().Literal("lombok"));
+ }
}
private static void addAnnotation(JCModifiers mods, JavacNode node, int pos, JCTree source, Context context, String annotationTypeFqn, JCExpression arg) {
@@ -981,7 +989,13 @@ public class JavacHandlerUtil {
JavacTreeMaker maker = node.getTreeMaker();
JCExpression annType = isJavaLangBased ? genJavaLangTypeRef(node, simpleName) : chainDotsString(node, annotationTypeFqn);
annType.pos = pos;
- if (arg != null) arg.pos = pos;
+ if (arg != null) {
+ arg.pos = pos;
+ if (arg instanceof JCAssign) {
+ ((JCAssign) arg).lhs.pos = pos;
+ ((JCAssign) arg).rhs.pos = pos;
+ }
+ }
List<JCExpression> argList = arg != null ? List.of(arg) : List.<JCExpression>nil();
JCAnnotation annotation = recursiveSetGeneratedBy(maker.Annotation(annType, argList), source, context);
annotation.pos = pos;