aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java25
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java15
2 files changed, 40 insertions, 0 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index 51f5ab4c..fbd63911 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -24,6 +24,7 @@ package lombok.eclipse.handlers;
import static lombok.eclipse.Eclipse.fromQualifiedName;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
@@ -48,6 +49,7 @@ import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.NullLiteral;
import org.eclipse.jdt.internal.compiler.ast.OperatorIds;
import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
+import org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation;
import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
import org.eclipse.jdt.internal.compiler.ast.Statement;
import org.eclipse.jdt.internal.compiler.ast.StringLiteral;
@@ -55,6 +57,7 @@ import org.eclipse.jdt.internal.compiler.ast.ThrowStatement;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
+import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
/**
* Container for static utility methods useful to handlers written for eclipse.
@@ -256,6 +259,7 @@ public class EclipseHandlerUtil {
* Inserts a field into an existing type. The type must represent a {@code TypeDeclaration}.
*/
public static void injectField(EclipseNode type, FieldDeclaration field) {
+ field.annotations = createSuppressWarningsAll(field, field.annotations);
TypeDeclaration parent = (TypeDeclaration) type.get();
if (parent.fields == null) {
@@ -275,6 +279,7 @@ public class EclipseHandlerUtil {
* Inserts a method into an existing type. The type must represent a {@code TypeDeclaration}.
*/
public static void injectMethod(EclipseNode type, AbstractMethodDeclaration method) {
+ method.annotations = createSuppressWarningsAll(method, method.annotations);
TypeDeclaration parent = (TypeDeclaration) type.get();
if (parent.methods == null) {
@@ -305,6 +310,26 @@ public class EclipseHandlerUtil {
type.add(method, Kind.METHOD).recursiveSetHandled();
}
+ private static final char[] ALL = "all".toCharArray();
+
+ private static Annotation[] createSuppressWarningsAll(ASTNode source, Annotation[] originalAnnotationArray) {
+ int pS = source.sourceStart, pE = source.sourceEnd;
+ long p = (long)pS << 32 | pE;
+ long[] poss = new long[3];
+ Arrays.fill(poss, p);
+ QualifiedTypeReference suppressWarningsType = new QualifiedTypeReference(TypeConstants.JAVA_LANG_SUPPRESSWARNINGS, poss);
+ Eclipse.setGeneratedBy(suppressWarningsType, source);
+ SingleMemberAnnotation ann = new SingleMemberAnnotation(suppressWarningsType, pS);
+ ann.declarationSourceEnd = pE;
+ ann.memberValue = new StringLiteral(ALL, pS, pE, 0);
+ Eclipse.setGeneratedBy(ann, source);
+ Eclipse.setGeneratedBy(ann.memberValue, source);
+ if (originalAnnotationArray == null) return new Annotation[] { ann };
+ Annotation[] newAnnotationArray = Arrays.copyOf(originalAnnotationArray, originalAnnotationArray.length + 1);
+ newAnnotationArray[originalAnnotationArray.length] = ann;
+ return newAnnotationArray;
+ }
+
/**
* Searches the given field node for annotations and returns each one that matches the provided regular expression pattern.
*
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index 499340bc..ccd5647c 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -32,6 +32,8 @@ import lombok.javac.JavacNode;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.TypeTags;
import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCLiteral;
+import com.sun.tools.javac.tree.JCTree.JCModifiers;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
@@ -270,6 +272,7 @@ public class JavacHandlerUtil {
public static void injectField(JavacNode typeNode, JCVariableDecl field) {
JCClassDecl type = (JCClassDecl) typeNode.get();
+ addSuppressWarningsAll(field.mods, typeNode, field.pos);
type.defs = type.defs.append(field);
typeNode.add(field, Kind.FIELD).recursiveSetHandled();
@@ -300,11 +303,23 @@ public class JavacHandlerUtil {
}
}
+ addSuppressWarningsAll(method.mods, typeNode, method.pos);
type.defs = type.defs.append(method);
typeNode.add(method, Kind.METHOD).recursiveSetHandled();
}
+ private static void addSuppressWarningsAll(JCModifiers mods, JavacNode node, int pos) {
+ TreeMaker maker = node.getTreeMaker();
+ JCExpression suppressWarningsType = chainDots(maker, node, "java", "lang", "SuppressWarnings");
+ JCLiteral allLiteral = maker.Literal("all");
+ suppressWarningsType.pos = pos;
+ allLiteral.pos = pos;
+ JCAnnotation annotation = maker.Annotation(suppressWarningsType, List.<JCExpression>of(allLiteral));
+ annotation.pos = pos;
+ mods.annotations = mods.annotations.append(annotation);
+ }
+
private static List<JCTree> addAllButOne(List<JCTree> defs, int idx) {
List<JCTree> out = List.nil();
int i = 0;