From 8bbdcec6fad6edf8f335f9e0c6899fddc56e07c1 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 23 Jun 2009 08:04:44 +0200 Subject: 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. --- src/lombok/eclipse/Eclipse.java | 93 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) (limited to 'src/lombok/eclipse/Eclipse.java') 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 type, Node node) { if ( node.getKind() != Kind.ANNOTATION ) return false; TypeReference typeRef = ((Annotation)node.get()).type; -- cgit