aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/handlers/HandleGetter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lombok/javac/handlers/HandleGetter.java')
-rw-r--r--src/core/lombok/javac/handlers/HandleGetter.java13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java
index 681865df..8615d572 100644
--- a/src/core/lombok/javac/handlers/HandleGetter.java
+++ b/src/core/lombok/javac/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
@@ -38,6 +38,7 @@ import lombok.Getter;
import lombok.core.AST.Kind;
import lombok.core.AnnotationValues;
import lombok.core.configuration.CheckerFrameworkVersion;
+import lombok.delombok.LombokOptionsFactory;
import lombok.javac.JavacAnnotationHandler;
import lombok.javac.JavacNode;
import lombok.javac.JavacTreeMaker;
@@ -231,9 +232,11 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
List<JCStatement> statements;
JCTree toClearOfMarkers = null;
+ boolean addSuppressWarningsUnchecked = false;
if (lazy && !inNetbeansEditor(field)) {
toClearOfMarkers = fieldNode.init;
statements = createLazyGetterBody(treeMaker, field, source);
+ addSuppressWarningsUnchecked = LombokOptionsFactory.getDelombokOptions(field.getContext()).getFormatPreferences().generateSuppressWarnings();
} else {
statements = createSimpleGetterBody(treeMaker, field);
}
@@ -252,11 +255,15 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
if (isFieldDeprecated(field)) annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil()));
JCMethodDecl decl = recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, methodType,
- methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source, field.getContext());
+ methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source, field.getContext());
if (toClearOfMarkers != null) recursiveSetGeneratedBy(toClearOfMarkers, null, null);
decl.mods.annotations = decl.mods.annotations.appendList(delegates);
+ if (addSuppressWarningsUnchecked) {
+ addAnnotation(decl.mods, field, source.pos, source, field.getContext(), "java.lang.SuppressWarnings", treeMaker.NewArray(null, List.<JCExpression>nil(), List.<JCExpression>of(treeMaker.Literal("all"), treeMaker.Literal("unchecked"))));
+ }
+
copyJavadoc(field, decl, CopyJavadoc.GETTER);
return decl;
}
@@ -418,7 +425,7 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
/* private final java.util.concurrent.atomic.AtomicReference<Object> fieldName = new java.util.concurrent.atomic.AtomicReference<Object>(); */ {
field.vartype = recursiveSetGeneratedBy(
- maker.TypeApply(chainDotsString(fieldNode, AR), List.<JCExpression>of(genJavaLangTypeRef(fieldNode, "Object"))), source, fieldNode.getContext());
+ maker.TypeApply(chainDotsString(fieldNode, AR), List.<JCExpression>of(genJavaLangTypeRef(fieldNode, "Object"))), source, fieldNode.getContext());
field.init = recursiveSetGeneratedBy(maker.NewClass(null, NIL_EXPRESSION, copyType(maker, field), NIL_EXPRESSION, null), source, fieldNode.getContext());
}