aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/handlers
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2010-07-18 01:26:02 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2010-07-18 01:26:02 +0200
commita5e19958f6ae0f734d0ac28772725be3afd7e27d (patch)
treebc735cc3fa22d0ccf1944a60ada38f4fd27125cc /src/core/lombok/eclipse/handlers
parenta1629c55acd5a2eda29e777541885d428e0f5df4 (diff)
downloadlombok-a5e19958f6ae0f734d0ac28772725be3afd7e27d.tar.gz
lombok-a5e19958f6ae0f734d0ac28772725be3afd7e27d.tar.bz2
lombok-a5e19958f6ae0f734d0ac28772725be3afd7e27d.zip
All generated fields and methods now get a @SuppressWarnings("all").
Implements issue #47.
Diffstat (limited to 'src/core/lombok/eclipse/handlers')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java25
1 files changed, 25 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.
*