aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/eclipse/Eclipse.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-06-23 08:04:44 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-06-23 08:04:44 +0200
commit8bbdcec6fad6edf8f335f9e0c6899fddc56e07c1 (patch)
tree2f9c6d2c92f0723454eb8486e1a18dd178d0e885 /src/lombok/eclipse/Eclipse.java
parent6c82a3c780539825157f721fcfe1a8894e73b161 (diff)
downloadlombok-8bbdcec6fad6edf8f335f9e0c6899fddc56e07c1.tar.gz
lombok-8bbdcec6fad6edf8f335f9e0c6899fddc56e07c1.tar.bz2
lombok-8bbdcec6fad6edf8f335f9e0c6899fddc56e07c1.zip
Figured out that our previous act of just assigning TypeReference objects directly to other nodes (e.g. from a FieldDeclaration's type to a method argument) is NOT a good idea, as this screws up when
the TypeReference object represents a generic type (like 'T') - each instance of a generic type has a different resolution, but 1 TypeReference object can only hold 1 resolution. Thus, a copyType() method has been written, and the Handle* classes have been updated to use it. Also, generateEquals() is half-finished in HandleData.
Diffstat (limited to 'src/lombok/eclipse/Eclipse.java')
-rw-r--r--src/lombok/eclipse/Eclipse.java93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/lombok/eclipse/Eclipse.java b/src/lombok/eclipse/Eclipse.java
index 8457e28a..e717e491 100644
--- a/src/lombok/eclipse/Eclipse.java
+++ b/src/lombok/eclipse/Eclipse.java
@@ -22,14 +22,22 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
+import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference;
+import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference;
import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.ast.Literal;
import org.eclipse.jdt.internal.compiler.ast.MemberValuePair;
+import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference;
+import org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference;
import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference;
+import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
+import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
+import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
+import org.eclipse.jdt.internal.compiler.ast.Wildcard;
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
import org.osgi.framework.Bundle;
@@ -76,6 +84,91 @@ public class Eclipse {
return sb.toString();
}
+ public static TypeParameter[] copyTypeParams(TypeParameter[] params) {
+ if ( params == null ) return null;
+ TypeParameter[] out = new TypeParameter[params.length];
+ int idx = 0;
+ for ( TypeParameter param : params ) {
+ TypeParameter o = new TypeParameter();
+ o.annotations = param.annotations;
+ o.bits = param.bits;
+ o.modifiers = param.modifiers;
+ o.name = param.name;
+ o.type = copyType(param.type);
+ if ( param.bounds != null ) {
+ TypeReference[] b = new TypeReference[param.bounds.length];
+ int idx2 = 0;
+ for ( TypeReference ref : param.bounds ) b[idx2++] = copyType(ref);
+ o.bounds = b;
+ }
+ out[idx++] = o;
+ }
+ return out;
+ }
+
+ public static TypeReference copyType(TypeReference ref) {
+ if ( ref instanceof QualifiedTypeReference ) {
+ QualifiedTypeReference iRef = (QualifiedTypeReference) ref;
+ return new QualifiedTypeReference(iRef.tokens, iRef.sourcePositions);
+ }
+
+ if ( ref instanceof ArrayQualifiedTypeReference ) {
+ ArrayQualifiedTypeReference iRef = (ArrayQualifiedTypeReference) ref;
+ return new ArrayQualifiedTypeReference(iRef.tokens, iRef.dimensions(), iRef.sourcePositions);
+ }
+
+ if ( ref instanceof ParameterizedQualifiedTypeReference ) {
+ ParameterizedQualifiedTypeReference iRef = (ParameterizedQualifiedTypeReference) ref;
+ TypeReference[][] args = null;
+ if ( iRef.typeArguments != null ) {
+ args = new TypeReference[iRef.typeArguments.length][];
+ int idx = 0;
+ for ( TypeReference[] inRefArray : iRef.typeArguments ) {
+ if ( inRefArray == null ) args[idx++] = null;
+ else {
+ TypeReference[] outRefArray = new TypeReference[inRefArray.length];
+ int idx2 = 0;
+ for ( TypeReference inRef : inRefArray ) {
+ outRefArray[idx2++] = copyType(inRef);
+ }
+ args[idx++] = outRefArray;
+ }
+ }
+ }
+ return new ParameterizedQualifiedTypeReference(iRef.tokens, args, iRef.dimensions(), iRef.sourcePositions);
+ }
+
+ if ( ref instanceof SingleTypeReference ) {
+ SingleTypeReference iRef = (SingleTypeReference) ref;
+ return new SingleTypeReference(iRef.token, (long)iRef.sourceStart << 32 | iRef.sourceEnd);
+ }
+
+ if ( ref instanceof ArrayTypeReference ) {
+ ArrayTypeReference iRef = (ArrayTypeReference) ref;
+ return new ArrayTypeReference(iRef.token, iRef.dimensions(), (long)iRef.sourceStart << 32 | iRef.sourceEnd);
+ }
+
+ if ( ref instanceof ParameterizedSingleTypeReference ) {
+ ParameterizedSingleTypeReference iRef = (ParameterizedSingleTypeReference) ref;
+ TypeReference[] args = null;
+ if ( iRef.typeArguments != null ) {
+ args = new TypeReference[iRef.typeArguments.length];
+ int idx = 0;
+ for ( TypeReference inRef : iRef.typeArguments ) {
+ if ( inRef == null ) args[idx++] = null;
+ else args[idx++] = copyType(inRef);
+ }
+ }
+ return new ParameterizedSingleTypeReference(iRef.token, args, iRef.dimensions(), (long)iRef.sourceStart << 32 | iRef.sourceEnd);
+ }
+
+ if ( ref instanceof Wildcard ) {
+ return new Wildcard(((Wildcard)ref).kind);
+ }
+
+ return ref;
+ }
+
public static boolean annotationTypeMatches(Class<? extends java.lang.annotation.Annotation> type, Node node) {
if ( node.getKind() != Kind.ANNOTATION ) return false;
TypeReference typeRef = ((Annotation)node.get()).type;