mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 16:17:34 +00:00
All generated fields and methods now get a @SuppressWarnings("all").
Implements issue #47.
This commit is contained in:
1 parent
a1629c55ac
commit
a5e19958f6
3 files changed
+42
-1
No files matched your search
@@ -10,7 +10,8 @@ Lombok Changelog
|
||||
* FEATURE: FindBugs' `@CheckForNull` is now copied from a field to a setter's parameter and the getter method just like `@Nullable`. [Issue #128](http://code.google.com/p/projectlombok/issues/detail?id=128)
|
||||
* BUILD: dependencies are now fetched automatically via ivy, and most dependencies now include sources by default, which is particularly handy for those working on the lombok sources themselves.
|
||||
* FEATURE: Adding `@Getter` or `@Setter` to a class is now legal and is like adding those annotations to every non-static field in it. [Issue #129](http://code.google.com/p/projectlombok/issues/detail?id=129)
|
||||
* ENHANCEMENT: All generated field accesses by lombok are now qualified (like so: `this.fieldName`). For those who have a warning configured for unqualified field access, those should no longer occur. [Issue #48](http://code.google.com/p/projectlombok/issues/detail?id=129)
|
||||
* ENHANCEMENT: All field accesses generated by lombok are now qualified (like so: `this.fieldName`). For those who have a warning configured for unqualified field access, those should no longer occur. [Issue #48](http://code.google.com/p/projectlombok/issues/detail?id=48)
|
||||
* ENHANCEMENT: All fields and methods generated by lombok now get `@SuppressWarnings("all")` attached to avoid such warnings as missing javadoc, for those of you who have that warning enabled. [Issue #47](http://code.google.com/p/projectlombok/issues/detail?id=47)
|
||||
|
||||
### v0.9.2 "Hailbunny" (December 15th, 2009)
|
||||
* preliminary support for lombok on NetBeans! - thanks go to Jan Lahoda from NetBeans. [Issue #20](http://code.google.com/p/projectlombok/issues/detail?id=20)
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user