diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-09-03 01:44:59 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-09-03 01:44:59 +0200 |
commit | f1124aad02569c983cb8979445245141bf029a88 (patch) | |
tree | 80d25bb1dddcfce46931f298b6f70ebdbd2e3e13 /src/lombok/eclipse/handlers/PKG.java | |
parent | 6b7919166e9a550d7d2b1f7156c794e76905fcab (diff) | |
download | lombok-f1124aad02569c983cb8979445245141bf029a88.tar.gz lombok-f1124aad02569c983cb8979445245141bf029a88.tar.bz2 lombok-f1124aad02569c983cb8979445245141bf029a88.zip |
Addressed issue #32: The @EqualsAndHashCode and @ToString annotations now support explicitly listing the fields to use, via the new 'of' parameter.
We've also added any fields that start with $ to the default excludes list. Lombok itself can generate these fields ($lock of @Synchronized, for example), and in general they probably should count as effectively not part of the class.
Diffstat (limited to 'src/lombok/eclipse/handlers/PKG.java')
-rw-r--r-- | src/lombok/eclipse/handlers/PKG.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/lombok/eclipse/handlers/PKG.java b/src/lombok/eclipse/handlers/PKG.java index 98c60524..58fac4a1 100644 --- a/src/lombok/eclipse/handlers/PKG.java +++ b/src/lombok/eclipse/handlers/PKG.java @@ -33,6 +33,7 @@ import lombok.core.TransformationsUtil; import lombok.core.AST.Kind; import lombok.eclipse.Eclipse; import lombok.eclipse.EclipseAST; +import lombok.eclipse.EclipseAST.Node; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; @@ -54,6 +55,7 @@ import org.eclipse.jdt.internal.compiler.ast.StringLiteral; 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; class PKG { private PKG() {} @@ -273,4 +275,27 @@ class PKG { ann.bits |= ASTNode.HasBeenGenerated; return ann; } + + static List<Integer> createListOfNonExistentFields(List<String> list, Node type, boolean excludeStandard, boolean excludeTransient) { + boolean[] matched = new boolean[list.size()]; + + for ( Node child : type.down() ) { + if ( list.isEmpty() ) break; + if ( child.getKind() != Kind.FIELD ) continue; + if ( excludeStandard ) { + if ( (((FieldDeclaration)child.get()).modifiers & ClassFileConstants.AccStatic) != 0 ) continue; + if ( child.getName().startsWith("$") ) continue; + } + if ( excludeTransient && (((FieldDeclaration)child.get()).modifiers & ClassFileConstants.AccTransient) != 0 ) continue; + int idx = list.indexOf(child.getName()); + if ( idx > -1 ) matched[idx] = true; + } + + List<Integer> problematic = new ArrayList<Integer>(); + for ( int i = 0 ; i < list.size() ; i++ ) { + if ( !matched[i] ) problematic.add(i); + } + + return problematic; + } } |