From e25c3b79ad6215c8aa9430c6af273967943424bf Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 11 Jul 2005 10:51:20 +0000 Subject: [PATCH] generics: writes out correct class signature --- .../org/aspectj/weaver/bcel/LazyClassGen.java | 139 +++++++++++++----- 1 file changed, 102 insertions(+), 37 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java index 4989b6483..eb4792722 100644 --- a/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java +++ b/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java @@ -1,5 +1,5 @@ /* ******************************************************************* - * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). + * Copyright (c) 2002 Contributors * All rights reserved. * This program and the accompanying materials are made available * under the terms of the Common Public License v1.0 @@ -7,7 +7,8 @@ * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * PARC initial implementation + * PARC initial implementation + * Andy Clement 6Jul05 generics - signature attribute * ******************************************************************/ @@ -35,6 +36,7 @@ import org.aspectj.apache.bcel.classfile.ConstantUtf8; import org.aspectj.apache.bcel.classfile.Field; import org.aspectj.apache.bcel.classfile.JavaClass; import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.apache.bcel.classfile.Signature; import org.aspectj.apache.bcel.classfile.Unknown; import org.aspectj.apache.bcel.classfile.annotation.Annotation; import org.aspectj.apache.bcel.generic.ClassGen; @@ -74,11 +76,29 @@ import org.aspectj.weaver.World; */ public final class LazyClassGen { - // ---- JSR 45 info - int highestLineNumber = 0; + int highestLineNumber = 0; // ---- JSR 45 info private SortedMap /* */ inlinedFiles = new TreeMap(); + private boolean regenerateGenericSignatureAttribute = false; + + private BcelObjectType myType; // XXX is not set for types we create + private ClassGen myGen; + private ConstantPoolGen constantPoolGen; + + private List /*LazyMethodGen*/ methodGens = new ArrayList(); + private List /*LazyClassGen*/ classGens = new ArrayList(); + private List /*AnnotationGen*/ annotations = new ArrayList(); + private int childCounter = 0; + + private InstructionFactory fact; + + private boolean isSerializable = false; + private boolean hasSerialVersionUIDField = false; + private boolean hasClinit = false; + + // --- + static class InlinedSourceFileInfo { int highestLineNumber; int offset; // calculated @@ -202,24 +222,11 @@ public final class LazyClassGen { out.println(); } - private BcelObjectType myType; // XXX is not set for types we create - private ClassGen myGen; - private ConstantPoolGen constantPoolGen; - - private List /*LazyMethodGen*/ methodGens = new ArrayList(); - private List /*LazyClassGen*/ classGens = new ArrayList(); - private List /*AnnotationGen*/ annotations = new ArrayList(); - private int childCounter = 0; public int getNewGeneratedNameTag() { return childCounter++; } - private InstructionFactory fact; - - private boolean isSerializable = false; - private boolean hasSerialVersionUIDField = false; - private boolean hasClinit = false; // ---- public LazyClassGen( @@ -232,6 +239,7 @@ public final class LazyClassGen { myGen = new ClassGen(class_name, super_class_name, file_name, access_flags, interfaces); constantPoolGen = myGen.getConstantPool(); fact = new InstructionFactory(myGen, constantPoolGen); + regenerateGenericSignatureAttribute = true; } //Non child type, so it comes from a real type in the world. @@ -454,28 +462,83 @@ public final class LazyClassGen { // myGen.addAttribute(getSourceDebugExtensionAttribute()); } -// TODO asc generics, fix up the declared signature attribute (dont need this just yet...) -// Attribute sigAttribute = null; -// Attribute[] as = myGen.getAttributes(); -// for (int i = 0; i < as.length; i++) { -// Attribute attribute = as[i]; -// if (attribute.getName().equals("Signature")) sigAttribute = attribute; -// } -// if (sigAttribute!=null) { -// // Got it -// myGen.removeAttribute(sigAttribute); -// -// int nameIndex = constantPoolGen.addUtf8("Signature"); -// String data = ((Signature)sigAttribute).getSignature()+"LJ;" + */ + private Signature createSignatureAttribute(String signature) { + int nameIndex = constantPoolGen.addUtf8("Signature"); + int sigIndex = constantPoolGen.addUtf8(signature); + return new Signature(nameIndex,2,sigIndex,constantPoolGen.getConstantPool()); + } + /** * */ @@ -518,12 +581,14 @@ public final class LazyClassGen { } public void addInterface(TypeX typeX, ISourceLocation sourceLocation) { + regenerateGenericSignatureAttribute = true; myGen.addInterface(typeX.getRawName()); if (!typeX.equals(TypeX.SERIALIZABLE)) warnOnAddedInterface(typeX.getName(),sourceLocation); } public void setSuperClass(TypeX typeX) { + regenerateGenericSignatureAttribute = true; myGen.setSuperclassName(typeX.getName()); } -- 2.39.5