this.sourcefilename = pname.replace('.', '/') + '/' + sourceFileName;
}
}
+ if (this.sourcefilename!=null && sourceContext instanceof SourceContextImpl) {
+ ((SourceContextImpl)sourceContext).setSourceFileName(this.sourcefilename);
+ }
}
public ISourceLocation getSourceLocation() {
public static final WeaverVersionInfo UNKNOWN =
new WeaverVersionInfo(WEAVER_VERSION_MAJOR_UNKNOWN,WEAVER_VERSION_MINOR_UNKNOWN);
+ public static final WeaverVersionInfo CURRENT =
+ new WeaverVersionInfo(CURRENT_VERSION_MAJOR,CURRENT_VERSION_MINOR);
// These are the versions read in from a particular class file.
private short major_version;
import java.util.List;
import java.util.Set;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
-import org.aspectj.apache.bcel.classfile.annotation.ElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.EnumElementValue;
import org.aspectj.apache.bcel.classfile.Utility;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.EnumElementValueGen;
/**
* AnnotationX instances are holders for an annotation from either Bcel or
public static final AnnotationX[] NONE = new AnnotationX[0];
- private Annotation theRealBcelAnnotation;
+ private AnnotationGen theRealBcelAnnotation;
private AnnotationAJ theRealASMAnnotation;
private int mode = -1;
private final static int MODE_ASM = 1;
private AnnotationX atTargetAnnotation = null;
private Set supportedTargets = null;
- public AnnotationX(Annotation a,World world) {
+ public AnnotationX(AnnotationGen a,World world) {
theRealBcelAnnotation = a;
signature = UnresolvedType.forSignature(theRealBcelAnnotation.getTypeSignature()).resolve(world);
mode = MODE_BCEL;
mode= MODE_ASM;
}
- public Annotation getBcelAnnotation() {
+ public AnnotationGen getBcelAnnotation() {
return theRealBcelAnnotation;
}
Set supportedTargets = new HashSet();
if (mode==MODE_BCEL) {
List values = getBcelAnnotation().getValues();
- ElementNameValuePair envp = (ElementNameValuePair)values.get(0);
- ArrayElementValue aev = (ArrayElementValue)envp.getValue();
- ElementValue[] evs = aev.getElementValuesArray();
+ ElementNameValuePairGen envp = (ElementNameValuePairGen)values.get(0);
+ ArrayElementValueGen aev = (ArrayElementValueGen)envp.getValue();
+ ElementValueGen[] evs = aev.getElementValuesArray();
for (int i = 0; i < evs.length; i++) {
- EnumElementValue ev = (EnumElementValue)evs[i];
+ EnumElementValueGen ev = (EnumElementValueGen)evs[i];
supportedTargets.add(ev.getEnumValueString());
}
} else {
import java.util.Iterator;
import java.util.List;
-import org.aspectj.apache.bcel.classfile.Field;
import org.aspectj.apache.bcel.classfile.Method;
import org.aspectj.apache.bcel.classfile.Utility;
import org.aspectj.apache.bcel.generic.Type;
* the fields' type in order to locate it. Currently just fails silently if any of the lookup code
* doesn't find anything...
*/
- public void addDeclareAnnotationRelationship(ISourceLocation sourceLocation, String typename,Field field) {
+ public void addDeclareAnnotationRelationship(ISourceLocation sourceLocation, String typename,String fieldName) {
if (!AsmManager.isCreatingModel()) return;
String pkg = null;
IProgramElement typeElem = AsmManager.getDefault().getHierarchy().findElementForType(pkg,type);
if (typeElem == null) return;
- IProgramElement fieldElem = AsmManager.getDefault().getHierarchy().findElementForSignature(typeElem,IProgramElement.Kind.FIELD,field.getName());
+ IProgramElement fieldElem = AsmManager.getDefault().getHierarchy().findElementForSignature(typeElem,IProgramElement.Kind.FIELD,fieldName);
if (fieldElem== null) return;
String targetHandle = fieldElem.getHandleIdentifier();
import java.io.IOException;
import java.util.List;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
/**
* For implementing declare @type interacting with declare @parents during compilation - we need to be
* this will allow type resolution to succeed correctly. The FakeAnnotation never makes it to disk, since the weaver
* does the job properly, attaching a real annotation.
*/
-public class FakeAnnotation extends Annotation {
+public class FakeAnnotation extends AnnotationGen {
private String name;
private String sig;
private boolean isRuntimeVisible;
public FakeAnnotation(String name,String sig,boolean isRuntimeVisible) {
- super(0,null,true);
+ super(null,null,true,null);
this.name = name;
this.sig = sig;
this.isRuntimeVisible = isRuntimeVisible;
return sig;
}
- public void addElementNameValuePair(ElementNameValuePair evp) {
+ public void addElementNameValuePair(ElementNameValuePairGen evp) {
// doesnt need to know about name/value pairs
}
- protected void dump(DataOutputStream dos) throws IOException {
+ public void dump(DataOutputStream dos) throws IOException {
// should be serialized
}
return isRuntimeVisible;
}
- protected void isRuntimeVisible(boolean b) {
+ protected void setIsRuntimeVisible(boolean b) {
}
public String toShortString() {
}
public void evictWeavingState() { realMember.evictWeavingState(); }
+
+ public Member slimline() {
+ return this;
+ }
}
additionalSignatures.add(member); // for this time
}
// if this was a parameterized type, look in the generic type that backs it too
- if (superType.isParameterizedType() && (foundMember.backingGenericMember != null)) {
- ResolvedMember member =new JoinPointSignature(foundMember.backingGenericMember,foundMember.declaringType.resolve(world));
+ if (superType.isParameterizedType() && foundMember.hasBackingGenericMember()) {
+ ResolvedMember member =new JoinPointSignature(foundMember.getBackingGenericMember(),foundMember.declaringType.resolve(world));
discoveredSignatures.add(member); // for next time we are reset
if (additionalSignatures==Collections.EMPTY_LIST) additionalSignatures=new ArrayList();
additionalSignatures.add(member); // for this time
public String[] getParameterNames(World world);
+ public Member slimline();
+
}
\ No newline at end of file
public class MemberImpl implements Comparable, AnnotatedElement,Member {
protected Kind kind;
- protected UnresolvedType declaringType;
protected int modifiers;
- protected UnresolvedType returnType;
+ protected UnresolvedType declaringType;
protected String name;
+ protected UnresolvedType returnType;
protected UnresolvedType[] parameterTypes;
private final String signature;
private String paramSignature;
}
}
+ public Member slimline() {
+ return this;
+ }
+
}
* This is the declared member, i.e. it will always correspond to an
* actual method/... declaration
*/
+
+
+
public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, AnnotatedElement, TypeVariableDeclaringElement, ResolvedMember {
-
+
+ // TESTAPI - controlling whether parameter names come out in the debug string (for testing purposes)
+ public static boolean showParameterNames = true;
+
private String[] parameterNames = null;
protected UnresolvedType[] checkedExceptions = UnresolvedType.NONE;
+// private boolean isAjSynthetic = false;
+ protected int start, end;
+ protected ISourceContext sourceContext = null;
+
+ private int bits;
+ private static final int HAS_BACKING_GENERIC_MEMBER = 0x0001;
+ private static final int IS_ANNOTATED_ELSEWHERE = 0x0002;
+ private static final int IS_ANNOTATED_ELSEWHERE_INV = 0x0ffd;
+ private static final int HAVE_CALCULATED_MY_ERASURE = 0x0004;
+ private static final int HAS_ERASURE = 0x0008;
+ private static final int IS_AJ_SYNTHETIC = 0x0010;
+ private static final int IS_AJ_SYNTHETIC_INV = 0x0fef;
+
+ protected RMMetaInfo metaInfo;
+
+ protected static class RMMetaInfo {
+ public ResolvedMember backingGenericMember;
+ public ResolvedMember myErasure;
+ }
/**
* if this member is a parameterized version of a member in a generic type,
* then this field holds a reference to the member we parameterize.
*/
- protected ResolvedMember backingGenericMember = null;
+ // protected ResolvedMember backingGenericMember = null;
protected Set annotationTypes = null;
// Some members are 'created' to represent other things (for example ITDs). These
// members have their annotations stored elsewhere, and this flag indicates that is
// the case. It is up to the caller to work out where that is!
// Once determined the caller may choose to stash the annotations in this member...
- private boolean isAnnotatedElsewhere = false; // this field is not serialized.
- private boolean isAjSynthetic = false;
-
+// private boolean isAnnotatedElsewhere = false; // this field is not serialized.
// generic methods have type variables
protected TypeVariable[] typeVariables;
-
- // these three fields hold the source location of this member
- protected int start, end;
- protected ISourceContext sourceContext = null;
+ /** converts e.g. <T extends Number>.... List<T> to just Ljava/util/List<T;>;
+ * whereas the full signature would be Ljava/util/List<T:Ljava/lang/Number;>;
+ */
+ private String myParameterSignatureWithBoundsRemoved = null;
+ /**
+ * converts e.g. <T extends Number>.... List<T> to just Ljava/util/List;
+ */
+ private String myParameterSignatureErasure = null;
+// private ResolvedMember myErasure = null;
+// private boolean calculatedMyErasure = false;
+
+
//XXX deprecate this in favor of the constructor below
public ResolvedMemberImpl(
ResolvedMember backingGenericMember)
{
this(kind, declaringType, modifiers, returnType, name, parameterTypes,checkedExceptions);
- this.backingGenericMember = backingGenericMember;
- this.isAjSynthetic = backingGenericMember.isAjSynthetic();
+ metaInfo= new RMMetaInfo();
+ bits|=HAS_BACKING_GENERIC_MEMBER;
+ metaInfo.backingGenericMember = backingGenericMember;
+ if (backingGenericMember.isAjSynthetic()) bits|=IS_AJ_SYNTHETIC;
+// this.isAjSynthetic = backingGenericMember.isAjSynthetic();
}
public ResolvedMemberImpl(
ResolvedMember member = foundMember.withSubstituteDeclaringType(declaringType);
foundMembers.add(member);
}
- if (toLookIn.isParameterizedType() && (foundMember.backingGenericMember != null)) {
- foundMembers.add(new JoinPointSignature(foundMember.backingGenericMember,foundMember.declaringType.resolve(toLookIn.getWorld())));
+ if (toLookIn.isParameterizedType() && foundMember.hasBackingGenericMember()) {
+ foundMembers.add(new JoinPointSignature(foundMember.getBackingGenericMember(),foundMember.declaringType.resolve(toLookIn.getWorld())));
}
accumulateMembersMatching(foundMember,toLookIn.getDirectSupertypes(),typesAlreadyVisited,foundMembers);
// if this was a parameterized type, look in the generic type that backs it too
// ??? true or false?
public boolean isAjSynthetic() {
- return isAjSynthetic;
+ return (bits&IS_AJ_SYNTHETIC)!=0;
+// return isAjSynthetic;
}
- protected void setAjSynthetic(boolean b) {isAjSynthetic= b;}
+ protected void setAjSynthetic(boolean b) {
+ if (b) bits|=IS_AJ_SYNTHETIC;
+ else bits&=IS_AJ_SYNTHETIC_INV;
+// isAjSynthetic= b;
+ }
public boolean hasAnnotations() {
return (annotationTypes!=null);
}
public AnnotationX[] getAnnotations() {
- if (backingGenericMember != null) return backingGenericMember.getAnnotations();
+ if ((bits&HAS_BACKING_GENERIC_MEMBER)!=0 && metaInfo.backingGenericMember!=null) return metaInfo.backingGenericMember.getAnnotations();
+// if (backingGenericMember != null) return backingGenericMember.getAnnotations();
return super.getAnnotations();
}
}
public void setAnnotatedElsewhere(boolean b) {
- isAnnotatedElsewhere = b;
+ if (b) bits|=IS_ANNOTATED_ELSEWHERE;
+ else bits&=IS_ANNOTATED_ELSEWHERE_INV;
+// isAnnotatedElsewhere = b;
}
public boolean isAnnotatedElsewhere() {
- return isAnnotatedElsewhere;
+ return (bits&IS_ANNOTATED_ELSEWHERE)!=0;
+// return isAnnotatedElsewhere;
}
/**
* A type is a supertype of itself.
*/
public ResolvedMember getErasure() {
- if (calculatedMyErasure) return myErasure;
- calculatedMyErasure = true;
+ if ((bits&HAVE_CALCULATED_MY_ERASURE)!=0) {
+ if ((bits&HAS_ERASURE)!=0) return metaInfo.myErasure;
+ return null;
+// return myErasure;
+ }
+ bits|=HAVE_CALCULATED_MY_ERASURE;
+// if (calculatedMyErasure) return myErasure;
+// calculatedMyErasure = true;
ResolvedType resolvedDeclaringType = (ResolvedType) getDeclaringType();
// this next test is fast, and the result is cached.
if (!resolvedDeclaringType.hasParameterizedSuperType()) {
// we've found the (a?) parameterized type that defines this member.
// now get the erasure of it
ResolvedMemberImpl matchingMember = (ResolvedMemberImpl) aDeclaringType.lookupMemberNoSupers(this);
- if (matchingMember != null && matchingMember.backingGenericMember != null) {
- myErasure = matchingMember.backingGenericMember;
+ if (matchingMember != null && matchingMember.hasBackingGenericMember()) {
+ ResolvedMember myErasure = matchingMember.getBackingGenericMember();
+ if (myErasure!=null) {
+ bits|=HAS_ERASURE;
+ if (metaInfo == null) metaInfo = new RMMetaInfo();
+ metaInfo.myErasure = myErasure;
+ }
return myErasure;
}
}
return null;
}
- private ResolvedMember myErasure = null;
- private boolean calculatedMyErasure = false;
public boolean hasBackingGenericMember() {
- return backingGenericMember!=null;
+ if ((bits&HAS_BACKING_GENERIC_MEMBER)==0) return false;
+ return metaInfo.backingGenericMember!=null;
}
public ResolvedMember getBackingGenericMember() {
- return backingGenericMember;
+ if ((bits&HAS_BACKING_GENERIC_MEMBER)==0) return null;
+ return metaInfo.backingGenericMember;
}
/**
}
}
- /** converts e.g. <T extends Number>.... List<T> to just Ljava/util/List<T;>;
- * whereas the full signature would be Ljava/util/List<T:Ljava/lang/Number;>;
- */
- private String myParameterSignatureWithBoundsRemoved = null;
- /**
- * converts e.g. <T extends Number>.... List<T> to just Ljava/util/List;
- */
- private String myParameterSignatureErasure = null;
// does NOT produce a meaningful java signature, but does give a unique string suitable for
// comparison.
return r.toString();
}
- // SECRETAPI - controlling whether parameter names come out in the debug string (for testing purposes)
- public static boolean showParameterNames = true;
-
public String toGenericString() {
StringBuffer buf = new StringBuffer();
buf.append(getGenericReturnType().getSimpleName());
public class SourceContextImpl implements ISourceContext {
- private AbstractReferenceTypeDelegate delegate;
+// private AbstractReferenceTypeDelegate delegate;
private int[] lineBreaks;
+ String sfname;
public SourceContextImpl(AbstractReferenceTypeDelegate delegate) {
- this.delegate = delegate;
+// this.delegate = delegate;
+ sfname = delegate.getSourcefilename();
}
public void configureFromAttribute(String name,int []linebreaks) {
- this.delegate.setSourcefilename(name);
+// this.delegate.setSourcefilename(name);
+ sfname = name;
this.lineBreaks = linebreaks;
}
+ public void setSourceFileName(String name) {
+ sfname = name;
+ }
+
private File getSourceFile() {
- return new File(delegate.getSourcefilename());
+ return new File(sfname);
+// return new File(delegate.getSourcefilename());
}
public void tidy() {}
// ---- helpers
- private static String signatureToName(String signature) {
+ public static String signatureToName(String signature) {
switch (signature.charAt(0)) {
case 'B': return "byte";
case 'C': return "char";
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.WeakHashMap;
+import java.util.Set;
import org.aspectj.asm.IHierarchy;
import org.aspectj.bridge.IMessageHandler;
import org.aspectj.weaver.reflect.ReflectionBasedReferenceTypeDelegate;
import org.aspectj.weaver.tools.Trace;
import org.aspectj.weaver.tools.TraceFactory;
+import java.util.*;
/**
* A World is a collection of known types and crosscutting members.
public boolean isJoinpointArrayConstructionEnabled() {
return optionalJoinpoint_ArrayConstruction;
}
+
public boolean isJoinpointSynchronizationEnabled() {
return optionalJoinpoint_Synchronization;
}
public static int USE_SOFT_REFS = 2; // Collected when short on memory
// SECRETAPI - Can switch to a policy of choice ;)
- public static int policy = USE_SOFT_REFS;
+ public static int policy = DONT_USE_REFS;
// Map of types that never get thrown away
private Map /* String -> ResolvedType */ tMap = new HashMap();
// Map of types that may be ejected from the cache if we need space
- private Map expendableMap = new WeakHashMap();
+ private Map expendableMap = new SoftHashMap();
+ public static class SoftHashMap extends AbstractMap {
+ private Map map;
+ private ReferenceQueue rq = new ReferenceQueue();
+
+ public SoftHashMap(Map map) { this.map = map; }
+ public SoftHashMap() { this(new HashMap()); }
+ public SoftHashMap(Map map, boolean b) { this(map); }
+
+ class SpecialValue extends SoftReference {
+ private final Object key;
+ SpecialValue(Object k,Object v) {
+ super(v,rq);
+ this.key = k;
+ }
+ }
+
+ private void processQueue() {
+ SpecialValue sv = null;
+ while ((sv = (SpecialValue)rq.poll())!=null) {
+ map.remove(sv.key);
+ }
+ }
+
+ public Object get(Object key) {
+ SpecialValue value = (SpecialValue)map.get(key);
+ if (value==null) return null;
+ if (value.get()==null) {
+ // it got GC'd
+ map.remove(value.key);
+ return null;
+ } else {
+ return value.get();
+ }
+ }
+
+ public Object put(Object k, Object v) {
+ processQueue();
+ return map.put(k, new SpecialValue(k,v));
+ }
+
+ public Set entrySet() {
+ return map.entrySet();
+ }
+
+ public void clear() {
+ processQueue();
+ Set keys = map.keySet();
+ keys.clear();
+// for (Iterator iterator = keys.iterator(); iterator.hasNext();) {
+// Object name = (Object) iterator.next();
+// map.remove(name);
+// }
+ }
+
+ public int size() {
+ processQueue();
+ return map.size();
+ }
+
+ public Object remove(Object k) {
+ processQueue();
+ SpecialValue value = (SpecialValue)map.remove(k);
+ if (value==null) return null;
+ if (value.get()!=null) {
+ return value.get();
+ }
+ return null;
+ }
+ }
+
private World w;
// profiling tools...
}
return type;
} else {
+ newkeys.add(key);
return (ResolvedType) tMap.put(key,type);
}
}
+ List /*<String> keys*/ newkeys = new ArrayList();
+
+ public void demote() {
+ // If unaffected by ITDs, get rid of it
+ int count =0;
+ for (Iterator iter = newkeys.iterator(); iter.hasNext();) {
+ String key = (String) iter.next();
+ ResolvedType type = (ResolvedType)tMap.get(key);
+ if (type==null) continue;//throw new RuntimeException("Unexpected!! "+key);
+ if (type.isAspect() ) continue;
+ if (type.equals(UnresolvedType.OBJECT)) continue;
+ if (type.isPrimitiveType()) continue;
+ List typeMungers = type.getInterTypeMungers();
+ if (typeMungers==null || typeMungers.size()==0) {
+ // demote - we can recover this
+ tMap.remove(key);
+ // extreme demotion if you dont use these next two lines!
+// if (memoryProfiling) expendableMap.put(key,new SoftReference(type,rq));
+// else expendableMap.put(key,new SoftReference(type));
+ count++;
+ }
+ }
+// System.out.print(count+" ");
+ newkeys.clear();
+ }
public void report() {
if (!memoryProfiling) return;
checkq();
}
}
+ public void demote() {
+ typeMap.demote();
+ }
+
/** Reference types we don't intend to weave may be ejected from
* the cache if we need the space.
*/
(!type.isPrimitiveType())
);
}
+
/**
* This class is used to compute and store precedence relationships between
import org.aspectj.apache.bcel.classfile.LocalVariable;
import org.aspectj.apache.bcel.classfile.LocalVariableTable;
import org.aspectj.apache.bcel.classfile.Method;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.classfile.annotation.ClassElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ClassElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations;
import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations;
import org.aspectj.apache.bcel.generic.Type;
* @return true if found
*/
private static boolean handleAspectAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeStruct struct) {
- Annotation aspect = getAnnotation(runtimeAnnotations, AjcMemberMaker.ASPECT_ANNOTATION);
+ AnnotationGen aspect = getAnnotation(runtimeAnnotations, AjcMemberMaker.ASPECT_ANNOTATION);
if (aspect != null) {
// semantic check for inheritance (only one level up)
boolean extendsAspect = false;
extendsAspect = struct.enclosingType.getSuperclass().isAspect();
}
- ElementNameValuePair aspectPerClause = getAnnotationElement(aspect, VALUE);
+ ElementNameValuePairGen aspectPerClause = getAnnotationElement(aspect, VALUE);
final PerClause perClause;
if (aspectPerClause == null) {
// empty value means singleton unless inherited
* @return true if found
*/
private static boolean handlePrecedenceAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeStruct struct) {
- Annotation aspect = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREPRECEDENCE_ANNOTATION);
+ AnnotationGen aspect = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREPRECEDENCE_ANNOTATION);
if (aspect != null) {
- ElementNameValuePair precedence = getAnnotationElement(aspect, VALUE);
+ ElementNameValuePairGen precedence = getAnnotationElement(aspect, VALUE);
if (precedence != null) {
String precedencePattern = precedence.getValue().stringifyValue();
PatternParser parser = new PatternParser(precedencePattern);
// private static boolean handleDeclareImplementsAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeFieldStruct struct) {//, ResolvedPointcutDefinition preResolvedPointcut) {
// Annotation deci = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREIMPLEMENTS_ANNOTATION);
// if (deci != null) {
-// ElementNameValuePair deciPatternNVP = getAnnotationElement(deci, VALUE);
+// ElementNameValuePairGen deciPatternNVP = getAnnotationElement(deci, VALUE);
// String deciPattern = deciPatternNVP.getValue().stringifyValue();
// if (deciPattern != null) {
// TypePattern typePattern = parseTypePattern(deciPattern, struct);
* @return true if found
*/
private static boolean handleDeclareParentsAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeFieldStruct struct) {//, ResolvedPointcutDefinition preResolvedPointcut) {
- Annotation decp = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREPARENTS_ANNOTATION);
+ AnnotationGen decp = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREPARENTS_ANNOTATION);
if (decp != null) {
- ElementNameValuePair decpPatternNVP = getAnnotationElement(decp, VALUE);
+ ElementNameValuePairGen decpPatternNVP = getAnnotationElement(decp, VALUE);
String decpPattern = decpPatternNVP.getValue().stringifyValue();
if (decpPattern != null) {
TypePattern typePattern = parseTypePattern(decpPattern, struct);
// do we have a defaultImpl=xxx.class (ie implementation)
String defaultImplClassName = null;
- ElementNameValuePair defaultImplNVP = getAnnotationElement(decp, "defaultImpl");
+ ElementNameValuePairGen defaultImplNVP = getAnnotationElement(decp, "defaultImpl");
if (defaultImplNVP != null) {
- ClassElementValue defaultImpl = (ClassElementValue) defaultImplNVP.getValue();
+ ClassElementValueGen defaultImpl = (ClassElementValueGen) defaultImplNVP.getValue();
defaultImplClassName = UnresolvedType.forSignature(defaultImpl.getClassString()).getName();
if (defaultImplClassName.equals("org.aspectj.lang.annotation.DeclareParents")) {
defaultImplClassName = null;
* @return true if found
*/
private static boolean handleBeforeAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct, ResolvedPointcutDefinition preResolvedPointcut) {
- Annotation before = getAnnotation(runtimeAnnotations, AjcMemberMaker.BEFORE_ANNOTATION);
+ AnnotationGen before = getAnnotation(runtimeAnnotations, AjcMemberMaker.BEFORE_ANNOTATION);
if (before != null) {
- ElementNameValuePair beforeAdvice = getAnnotationElement(before, VALUE);
+ ElementNameValuePairGen beforeAdvice = getAnnotationElement(before, VALUE);
if (beforeAdvice != null) {
// this/target/args binding
FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
* @return true if found
*/
private static boolean handleAfterAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct, ResolvedPointcutDefinition preResolvedPointcut) {
- Annotation after = getAnnotation(runtimeAnnotations, AjcMemberMaker.AFTER_ANNOTATION);
+ AnnotationGen after = getAnnotation(runtimeAnnotations, AjcMemberMaker.AFTER_ANNOTATION);
if (after != null) {
- ElementNameValuePair afterAdvice = getAnnotationElement(after, VALUE);
+ ElementNameValuePairGen afterAdvice = getAnnotationElement(after, VALUE);
if (afterAdvice != null) {
// this/target/args binding
FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
BcelMethod owningMethod)
throws ReturningFormalNotDeclaredInAdviceSignatureException
{
- Annotation after = getAnnotation(runtimeAnnotations, AjcMemberMaker.AFTERRETURNING_ANNOTATION);
+ AnnotationGen after = getAnnotation(runtimeAnnotations, AjcMemberMaker.AFTERRETURNING_ANNOTATION);
if (after != null) {
- ElementNameValuePair annValue = getAnnotationElement(after, VALUE);
- ElementNameValuePair annPointcut = getAnnotationElement(after, POINTCUT);
- ElementNameValuePair annReturned = getAnnotationElement(after, RETURNING);
+ ElementNameValuePairGen annValue = getAnnotationElement(after, VALUE);
+ ElementNameValuePairGen annPointcut = getAnnotationElement(after, POINTCUT);
+ ElementNameValuePairGen annReturned = getAnnotationElement(after, RETURNING);
// extract the pointcut and returned type/binding - do some checks
String pointcut = null;
BcelMethod owningMethod)
throws ThrownFormalNotDeclaredInAdviceSignatureException
{
- Annotation after = getAnnotation(runtimeAnnotations, AjcMemberMaker.AFTERTHROWING_ANNOTATION);
+ AnnotationGen after = getAnnotation(runtimeAnnotations, AjcMemberMaker.AFTERTHROWING_ANNOTATION);
if (after != null) {
- ElementNameValuePair annValue = getAnnotationElement(after, VALUE);
- ElementNameValuePair annPointcut = getAnnotationElement(after, POINTCUT);
- ElementNameValuePair annThrown = getAnnotationElement(after, THROWING);
+ ElementNameValuePairGen annValue = getAnnotationElement(after, VALUE);
+ ElementNameValuePairGen annPointcut = getAnnotationElement(after, POINTCUT);
+ ElementNameValuePairGen annThrown = getAnnotationElement(after, THROWING);
// extract the pointcut and throwned type/binding - do some checks
String pointcut = null;
* @return true if found
*/
private static boolean handleAroundAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct, ResolvedPointcutDefinition preResolvedPointcut) {
- Annotation around = getAnnotation(runtimeAnnotations, AjcMemberMaker.AROUND_ANNOTATION);
+ AnnotationGen around = getAnnotation(runtimeAnnotations, AjcMemberMaker.AROUND_ANNOTATION);
if (around != null) {
- ElementNameValuePair aroundAdvice = getAnnotationElement(around, VALUE);
+ ElementNameValuePairGen aroundAdvice = getAnnotationElement(around, VALUE);
if (aroundAdvice != null) {
// this/target/args binding
FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
* @param struct
*/
private static void handlePointcutAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct) {
- Annotation pointcut = getAnnotation(runtimeAnnotations, AjcMemberMaker.POINTCUT_ANNOTATION);
+ AnnotationGen pointcut = getAnnotation(runtimeAnnotations, AjcMemberMaker.POINTCUT_ANNOTATION);
if (pointcut != null) {
- ElementNameValuePair pointcutExpr = getAnnotationElement(pointcut, VALUE);
+ ElementNameValuePairGen pointcutExpr = getAnnotationElement(pointcut, VALUE);
// semantic check: the method must return void, or be "public static boolean" for if() support
if (!(Type.VOID.equals(struct.method.getReturnType())
* @return true if found
*/
private static boolean handleDeclareErrorOrWarningAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeFieldStruct struct) {
- Annotation error = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREERROR_ANNOTATION);
+ AnnotationGen error = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREERROR_ANNOTATION);
boolean hasError = false;
if (error != null) {
- ElementNameValuePair declareError = getAnnotationElement(error, VALUE);
+ ElementNameValuePairGen declareError = getAnnotationElement(error, VALUE);
if (declareError != null) {
if (!STRING_DESC.equals(struct.field.getSignature()) || struct.field.getConstantValue() == null) {
reportError("@DeclareError used on a non String constant field", struct);
}
}
}
- Annotation warning = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREWARNING_ANNOTATION);
+ AnnotationGen warning = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREWARNING_ANNOTATION);
boolean hasWarning = false;
if (warning != null) {
- ElementNameValuePair declareWarning = getAnnotationElement(warning, VALUE);
+ ElementNameValuePairGen declareWarning = getAnnotationElement(warning, VALUE);
if (declareWarning != null) {
if (!STRING_DESC.equals(struct.field.getSignature()) || struct.field.getConstantValue() == null) {
reportError("@DeclareWarning used on a non String constant field", struct);
* @param annotationType
* @return annotation
*/
- private static Annotation getAnnotation(RuntimeAnnotations rvs, UnresolvedType annotationType) {
+ private static AnnotationGen getAnnotation(RuntimeAnnotations rvs, UnresolvedType annotationType) {
final String annotationTypeName = annotationType.getName();
for (Iterator iterator = rvs.getAnnotations().iterator(); iterator.hasNext();) {
- Annotation rv = (Annotation) iterator.next();
+ AnnotationGen rv = (AnnotationGen) iterator.next();
if (annotationTypeName.equals(rv.getTypeName())) {
return rv;
}
* @param elementName
* @return annotation NVP
*/
- private static ElementNameValuePair getAnnotationElement(Annotation annotation, String elementName) {
+ private static ElementNameValuePairGen getAnnotationElement(AnnotationGen annotation, String elementName) {
for (Iterator iterator1 = annotation.getValues().iterator(); iterator1.hasNext();) {
- ElementNameValuePair element = (ElementNameValuePair) iterator1.next();
+ ElementNameValuePairGen element = (ElementNameValuePairGen) iterator1.next();
if (elementName.equals(element.getNameString())) {
return element;
}
*******************************************************************************/
package org.aspectj.weaver.bcel;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
import org.aspectj.apache.bcel.generic.FieldInstruction;
-import org.aspectj.apache.bcel.generic.GETFIELD;
-import org.aspectj.apache.bcel.generic.GETSTATIC;
import org.aspectj.apache.bcel.generic.Instruction;
import org.aspectj.apache.bcel.generic.InstructionConstants;
import org.aspectj.apache.bcel.generic.InstructionFactory;
import org.aspectj.apache.bcel.generic.InstructionHandle;
import org.aspectj.apache.bcel.generic.InstructionList;
import org.aspectj.apache.bcel.generic.InvokeInstruction;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
import org.aspectj.apache.bcel.generic.Type;
import org.aspectj.weaver.AjAttribute;
import org.aspectj.weaver.AjcMemberMaker;
import org.aspectj.weaver.Shadow;
import org.aspectj.weaver.UnresolvedType;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.List;
-
/**
* Looks for all access to method or field that are not public within the body of the around advices and replace
* the invocations to a wrapper call so that the around advice can further be inlined.
private void openAroundAdvice(LazyMethodGen aroundAdvice) {
InstructionHandle curr = aroundAdvice.getBody().getStart();
InstructionHandle end = aroundAdvice.getBody().getEnd();
- ConstantPoolGen cpg = aroundAdvice.getEnclosingClass().getConstantPoolGen();
+ ConstantPool cpg = aroundAdvice.getEnclosingClass().getConstantPool();
InstructionFactory factory = aroundAdvice.getEnclosingClass().getFactory();
boolean realizedCannotInline = false;
&& invoke.getSignature(cpg).equals(resolvedMember.getSignature())
&& !resolvedMember.isPublic()) {
final ResolvedMember accessor;
- if ((inst instanceof GETFIELD) || (inst instanceof GETSTATIC)) {
+ if ((inst.opcode==Constants.GETFIELD) || (inst.opcode==Constants.GETSTATIC)) {
accessor = createOrGetInlineAccessorForFieldGet(resolvedMember);
} else {
accessor = createOrGetInlineAccessorForFieldSet(resolvedMember);
// flag it synthetic, AjSynthetic
method.makeSynthetic();
method.addAttribute(
- BcelAttributes.bcelAttribute(new AjAttribute.AjSynthetic(), m_aspectGen.getConstantPoolGen())
+ BcelAttributes.bcelAttribute(new AjAttribute.AjSynthetic(), m_aspectGen.getConstantPool())
);
// flag the effective signature, so that we can deobfuscate the signature to apply method call pointcut
method.addAttribute(
BcelAttributes.bcelAttribute(
new AjAttribute.EffectiveSignatureAttribute(resolvedMember, Shadow.MethodCall, false),
- m_aspectGen.getConstantPoolGen()
+ m_aspectGen.getConstantPool()
)
);
// flag it synthetic, AjSynthetic
method.makeSynthetic();
method.addAttribute(
- BcelAttributes.bcelAttribute(new AjAttribute.AjSynthetic(), m_aspectGen.getConstantPoolGen())
+ BcelAttributes.bcelAttribute(new AjAttribute.AjSynthetic(), m_aspectGen.getConstantPool())
);
// flag the effective signature, so that we can deobfuscate the signature to apply method call pointcut
method.addAttribute(
BcelAttributes.bcelAttribute(
new AjAttribute.EffectiveSignatureAttribute(resolvedMember, Shadow.MethodCall, false),
- m_aspectGen.getConstantPoolGen()
+ m_aspectGen.getConstantPool()
)
);
// flag it synthetic, AjSynthetic
method.makeSynthetic();
method.addAttribute(
- BcelAttributes.bcelAttribute(new AjAttribute.AjSynthetic(), m_aspectGen.getConstantPoolGen())
+ BcelAttributes.bcelAttribute(new AjAttribute.AjSynthetic(), m_aspectGen.getConstantPool())
);
// flag the effective signature, so that we can deobfuscate the signature to apply method call pointcut
method.addAttribute(
BcelAttributes.bcelAttribute(
new AjAttribute.EffectiveSignatureAttribute(resolvedMember, Shadow.FieldGet, false),
- m_aspectGen.getConstantPoolGen()
+ m_aspectGen.getConstantPool()
)
);
// flag it synthetic, AjSynthetic
method.makeSynthetic();
method.addAttribute(
- BcelAttributes.bcelAttribute(new AjAttribute.AjSynthetic(), m_aspectGen.getConstantPoolGen())
+ BcelAttributes.bcelAttribute(new AjAttribute.AjSynthetic(), m_aspectGen.getConstantPool())
);
// flag the effective signature, so that we can deobfuscate the signature to apply method call pointcut
method.addAttribute(
BcelAttributes.bcelAttribute(
new AjAttribute.EffectiveSignatureAttribute(resolvedMember, Shadow.FieldSet, false),
- m_aspectGen.getConstantPoolGen()
+ m_aspectGen.getConstantPool()
)
);
import org.aspectj.weaver.ISourceContext;
import org.aspectj.weaver.Member;
import org.aspectj.weaver.ResolvedMember;
+import org.aspectj.weaver.ResolvedMemberImpl;
import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.Shadow;
import org.aspectj.weaver.ShadowMunger;
Member signature,
ResolvedType concreteAspect)
{
- super(attribute, pointcut, signature);
+ super(attribute, pointcut, (signature==null?null:signature.slimline()));
this.concreteAspect = concreteAspect;
}
int start, int end, ISourceContext sourceContext, ResolvedType concreteAspect)
{
this(new AjAttribute.AdviceAttribute(kind, pointcut, extraArgumentFlags, start, end, sourceContext),
- pointcut, signature, concreteAspect);
+ pointcut, (signature==null?null:signature.slimline()), concreteAspect);
thrownExceptions = Collections.EMPTY_LIST; //!!! interaction with unit tests
}
+
+ /**
+ * We don't always need to represent the signature with a heavyweight BcelMethod object - only if its around advice
+ * and inlining is active
+ * @param concreteAspect
+ * @param attribute
+ */
+ private static Member shrink(AdviceKind kind, ResolvedType concreteAspect, Member m) {
+ if (m==null) return null;
+ UnresolvedType dType = m.getDeclaringType();
+ // if it isnt around advice or it is but inlining is turned off then shrink it to a ResolvedMemberImpl
+ if (kind!=AdviceKind.Around ||
+ ((dType instanceof ResolvedType) && ((ResolvedType)dType).getWorld().isXnoInline())) {
+ if (m instanceof BcelMethod) {
+ BcelMethod bm = (BcelMethod)m;
+ if (bm.getMethod()!=null && bm.getMethod().getAnnotations()!=null) return m;
+ ResolvedMemberImpl simplermember = new ResolvedMemberImpl(bm.getKind(),bm.getDeclaringType(),
+ bm.getModifiers(),bm.getReturnType(),bm.getName(),
+ bm.getParameterTypes());//,bm.getExceptions(),bm.getBackingGenericMember());
+ simplermember.setParameterNames(bm.getParameterNames());
+ return simplermember;
+ }
+ }
+ return m;
+ }
// ---- implementations of ShadowMunger's methods
if (concreteAspect.getWorld().isXnoInline()) return false;
//System.err.println("isWoven? " + ((BcelObjectType)concreteAspect).getLazyClassGen().getWeaverState());
+ // if (BcelWorld.getBcelObjectType(concreteAspect).getJavaClass()==null) return true; // been evicted... CUSTARD
return BcelWorld.getBcelObjectType(concreteAspect).getLazyClassGen().isWoven();
}
import org.aspectj.apache.bcel.classfile.Attribute;
import org.aspectj.apache.bcel.classfile.Unknown;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
import org.aspectj.weaver.AjAttribute;
import org.aspectj.weaver.BCException;
import org.aspectj.weaver.ISourceContext;
return l;
}
- public static Attribute bcelAttribute(AjAttribute a, ConstantPoolGen pool) {
+ public static Attribute bcelAttribute(AjAttribute a, ConstantPool pool) {
int nameIndex = pool.addUtf8(a.getNameString());
byte[] bytes = a.getBytes();
int length = bytes.length;
- return new Unknown(nameIndex, length, bytes, pool.getConstantPool());
+ return new Unknown(nameIndex, length, bytes, pool);
}
package org.aspectj.weaver.bcel;
import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.Field;
import org.aspectj.apache.bcel.generic.FieldGen;
import org.aspectj.apache.bcel.generic.InstructionFactory;
import org.aspectj.apache.bcel.generic.InstructionList;
// Create the field declaration.
// Something like: "public static final CflowCounter ajc$cflowCounter$0;"
- Field f = new FieldGen(cflowCounterField.getModifiers(),
+ FieldGen f = new FieldGen(cflowCounterField.getModifiers(),
BcelWorld.makeBcelType(cflowCounterField.getReturnType()),
cflowCounterField.getName(),
- gen.getConstantPoolGen()).getField();
+ gen.getConstantPool());
gen.addField(f,getSourceLocation());
package org.aspectj.weaver.bcel;
import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.Field;
import org.aspectj.apache.bcel.generic.FieldGen;
import org.aspectj.apache.bcel.generic.InstructionFactory;
import org.aspectj.apache.bcel.generic.InstructionList;
LazyClassGen gen = weaver.getLazyClassGen();
if (!gen.getType().equals(cflowStackField.getDeclaringType())) return false;
- Field f = new FieldGen(cflowStackField.getModifiers(),
+ FieldGen f = new FieldGen(cflowStackField.getModifiers(),
BcelWorld.makeBcelType(cflowStackField.getReturnType()),
cflowStackField.getName(),
- gen.getConstantPoolGen()).getField();
+ gen.getConstantPool());
gen.addField(f,getSourceLocation());
LazyMethodGen clinit = gen.getAjcPreClinit(); //StaticInitializer();
import java.util.Set;
import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.Field;
import org.aspectj.apache.bcel.classfile.Method;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.generic.ANEWARRAY;
-import org.aspectj.apache.bcel.generic.BranchInstruction;
-import org.aspectj.apache.bcel.generic.CPInstruction;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
import org.aspectj.apache.bcel.generic.FieldGen;
import org.aspectj.apache.bcel.generic.FieldInstruction;
-import org.aspectj.apache.bcel.generic.GOTO;
-import org.aspectj.apache.bcel.generic.GOTO_W;
-import org.aspectj.apache.bcel.generic.INVOKESPECIAL;
-import org.aspectj.apache.bcel.generic.IndexedInstruction;
import org.aspectj.apache.bcel.generic.Instruction;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
+import org.aspectj.apache.bcel.generic.InstructionCP;
import org.aspectj.apache.bcel.generic.InstructionConstants;
import org.aspectj.apache.bcel.generic.InstructionFactory;
import org.aspectj.apache.bcel.generic.InstructionHandle;
import org.aspectj.apache.bcel.generic.InstructionList;
+import org.aspectj.apache.bcel.generic.InstructionSelect;
import org.aspectj.apache.bcel.generic.InstructionTargeter;
import org.aspectj.apache.bcel.generic.InvokeInstruction;
import org.aspectj.apache.bcel.generic.LineNumberTag;
-import org.aspectj.apache.bcel.generic.LocalVariableInstruction;
import org.aspectj.apache.bcel.generic.LocalVariableTag;
-import org.aspectj.apache.bcel.generic.MONITORENTER;
-import org.aspectj.apache.bcel.generic.MONITOREXIT;
import org.aspectj.apache.bcel.generic.MULTIANEWARRAY;
import org.aspectj.apache.bcel.generic.MethodGen;
-import org.aspectj.apache.bcel.generic.NEW;
-import org.aspectj.apache.bcel.generic.NEWARRAY;
import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.PUTFIELD;
-import org.aspectj.apache.bcel.generic.PUTSTATIC;
import org.aspectj.apache.bcel.generic.RET;
-import org.aspectj.apache.bcel.generic.ReturnInstruction;
-import org.aspectj.apache.bcel.generic.Select;
import org.aspectj.apache.bcel.generic.Tag;
import org.aspectj.apache.bcel.generic.Type;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.Message;
import org.aspectj.util.PartialOrder;
import org.aspectj.weaver.AjAttribute;
import org.aspectj.weaver.AjcMemberMaker;
+import org.aspectj.weaver.AnnotationX;
import org.aspectj.weaver.AsmRelationshipProvider;
import org.aspectj.weaver.BCException;
import org.aspectj.weaver.ConcreteTypeMunger;
import org.aspectj.weaver.tools.Trace;
import org.aspectj.weaver.tools.TraceFactory;
+import com.sun.org.apache.bcel.internal.generic.BranchInstruction;
+import com.sun.org.apache.bcel.internal.generic.GOTO;
+import com.sun.org.apache.bcel.internal.generic.GOTO_W;
+
class BcelClassWeaver implements IClassWeaver {
private static Trace trace = TraceFactory.getTraceFactory().getTrace(BcelClassWeaver.class);
private final BcelObjectType ty; // alias of clazz.getType()
private final BcelWorld world; // alias of ty.getWorld()
- private final ConstantPoolGen cpg; // alias of clazz.getConstantPoolGen()
+ private final ConstantPool cpg; // alias of clazz.getConstantPoolGen()
private final InstructionFactory fact; // alias of clazz.getFactory();
this.typeMungers = typeMungers;
this.lateTypeMungers = lateTypeMungers;
this.ty = clazz.getBcelObjectType();
- this.cpg = clazz.getConstantPoolGen();
+ this.cpg = clazz.getConstantPool();
this.fact = clazz.getFactory();
fastMatchShadowMungers(shadowMungers);
}
if (annotationsToAdd==null) annotationsToAdd = new ArrayList();
- Annotation a = decaM.getAnnotationX().getBcelAnnotation();
- AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPoolGen(),true);
+ AnnotationGen a = decaM.getAnnotationX().getBcelAnnotation();
+ AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPool(),true);
annotationsToAdd.add(ag);
mg.addAnnotation(decaM.getAnnotationX());
}
if (annotationsToAdd==null) annotationsToAdd = new ArrayList();
- Annotation a = decaM.getAnnotationX().getBcelAnnotation();
- AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPoolGen(),true);
+ AnnotationGen a = decaM.getAnnotationX().getBcelAnnotation();
+ AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPool(),true);
annotationsToAdd.add(ag);
mg.addAnnotation(decaM.getAnnotationX());
}
if (annotationsToAdd!=null) {
Method oldMethod = mg.getMethod();
- MethodGen myGen = new MethodGen(oldMethod,clazz.getClassName(),clazz.getConstantPoolGen(),false);// dont use tags, they won't get repaired like for woven methods.
+ MethodGen myGen = new MethodGen(oldMethod,clazz.getClassName(),clazz.getConstantPool(),false);// dont use tags, they won't get repaired like for woven methods.
for (Iterator iter = annotationsToAdd.iterator(); iter.hasNext();) {
AnnotationGen a = (AnnotationGen) iter.next();
myGen.addAnnotation(a);
return isChanged;
}
- private boolean dontAddTwice(DeclareAnnotation decaF, Annotation [] dontAddMeTwice){
+ private boolean dontAddTwice(DeclareAnnotation decaF, AnnotationX[] dontAddMeTwice){
for (int i = 0; i < dontAddMeTwice.length; i++){
- Annotation ann = dontAddMeTwice[i];
+ AnnotationX ann = dontAddMeTwice[i];
if (ann != null && decaF.getAnnotationX().getTypeName().equals(ann.getTypeName())){
//dontAddMeTwice[i] = null; // incase it really has been added twice!
return true;
List decaFs = getMatchingSubset(allDecafs,clazz.getType());
if (decaFs.isEmpty()) return false; // nothing more to do
- Field[] fields = clazz.getFieldGens();
+ List fields = clazz.getFieldGens();
if (fields!=null) {
Set unusedDecafs = new HashSet();
unusedDecafs.addAll(decaFs);
- for (int fieldCounter = 0;fieldCounter<fields.length;fieldCounter++) {
- BcelField aBcelField = new BcelField(clazz.getBcelObjectType(),fields[fieldCounter]);
+ for (int fieldCounter = 0;fieldCounter<fields.size();fieldCounter++) {
+ BcelField aBcelField = (BcelField)fields.get(fieldCounter);//new BcelField(clazz.getBcelObjectType(),fields[fieldCounter]);
if (!aBcelField.getName().startsWith(NameMangler.PREFIX)) {
// Single first pass
List worthRetrying = new ArrayList();
boolean modificationOccured = false;
- Annotation [] dontAddMeTwice = fields[fieldCounter].getAnnotations();
+ AnnotationX[] dontAddMeTwice = aBcelField.getAnnotations();
// go through all the declare @field statements
for (Iterator iter = decaFs.iterator(); iter.hasNext();) {
if(decaF.getAnnotationX().isRuntimeVisible()){ // isAnnotationWithRuntimeRetention(clazz.getJavaClass(world))){
//if(decaF.getAnnotationTypeX().isAnnotationWithRuntimeRetention(world)){
// it should be runtime visible, so put it on the Field
- Annotation a = decaF.getAnnotationX().getBcelAnnotation();
- AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPoolGen(),true);
- FieldGen myGen = new FieldGen(fields[fieldCounter],clazz.getConstantPoolGen());
- myGen.addAnnotation(ag);
- Field newField = myGen.getField();
+// Annotation a = decaF.getAnnotationX().getBcelAnnotation();
+// AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPoolGen(),true);
+// FieldGen myGen = new FieldGen(fields[fieldCounter],clazz.getConstantPoolGen());
+// myGen.addAnnotation(ag);
+// Field newField = myGen.getField();
aBcelField.addAnnotation(decaF.getAnnotationX());
- clazz.replaceField(fields[fieldCounter],newField);
- fields[fieldCounter]=newField;
+// clazz.replaceField(fields[fieldCounter],newField);
+// fields[fieldCounter]=newField;
} else{
aBcelField.addAnnotation(decaF.getAnnotationX());
}
}
- AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),clazz.getName(),fields[fieldCounter]);
+ AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),clazz.getName(),aBcelField.getName());
reportFieldAnnotationWeavingMessage(clazz, fields, fieldCounter, decaF);
isChanged = true;
modificationOccured = true;
continue; // skip this one...
}
aBcelField.addAnnotation(decaF.getAnnotationX());
- AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),clazz.getName(),fields[fieldCounter]);
+ AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),clazz.getName(),aBcelField.getName());
isChanged = true;
modificationOccured = true;
forRemoval.add(decaF);
}
// TAG: WeavingMessage
- private void reportFieldAnnotationWeavingMessage(LazyClassGen clazz, Field[] fields, int fieldCounter, DeclareAnnotation decaF) {
+ private void reportFieldAnnotationWeavingMessage(LazyClassGen clazz, List fields, int fieldCounter, DeclareAnnotation decaF) {
if (!getWorld().getMessageHandler().isIgnoring(IMessage.WEAVEINFO)){
- Field theField = fields[fieldCounter];
+ BcelField theField = (BcelField)fields.get(fieldCounter);
world.getMessageHandler().handleMessage(
WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ANNOTATES,
new String[]{
- theField.toString() + "' of type '" + clazz.getName(),
+ theField.getFieldAsIs().toString() + "' of type '" + clazz.getName(),
clazz.getFileName(),
decaF.getAnnotationString(),
"field",
}
private boolean isThisCall(InstructionHandle ih) {
- INVOKESPECIAL inst = (INVOKESPECIAL) ih.getInstruction();
+ InvokeInstruction inst = (InvokeInstruction) ih.getInstruction();
return inst.getClassName(cpg).equals(clazz.getName());
}
InstructionHandle walker = body.getStart();
List rets = new ArrayList();
while (walker!=null) {
- if (walker.getInstruction() instanceof ReturnInstruction) {
+ if (walker.getInstruction().isReturnInstruction()) {
rets.add(walker);
}
walker = walker.getNext();
// ignore
} else if (targeter instanceof LineNumberTag) {
// ignore
- } else if (targeter instanceof GOTO || targeter instanceof GOTO_W) {
+ } else if (targeter instanceof InstructionBranch && ((InstructionBranch)targeter).isGoto()) {
// move it...
targeter.updateTarget(element, monitorExitBlockStart);
} else if (targeter instanceof BranchInstruction) {
parttwo.append(InstructionFactory.MONITORENTER);
String fieldname = synchronizedMethod.getEnclosingClass().allocateField("class$");
- Field f = new FieldGen(Modifier.STATIC | Modifier.PRIVATE,
- Type.getType(Class.class),fieldname,synchronizedMethod.getEnclosingClass().getConstantPoolGen()).getField();
+ FieldGen f = new FieldGen(Modifier.STATIC | Modifier.PRIVATE,
+ Type.getType(Class.class),fieldname,synchronizedMethod.getEnclosingClass().getConstantPool());
synchronizedMethod.getEnclosingClass().addField(f, null);
// 10: invokestatic #44; //Method java/lang/Class.forName:(Ljava/lang/String;)Ljava/lang/Class;
InstructionHandle walker = body.getStart();
List rets = new ArrayList();
while (walker!=null) { //!walker.equals(body.getEnd())) {
- if (walker.getInstruction() instanceof ReturnInstruction) {
+ if (walker.getInstruction().isReturnInstruction()) {
rets.add(walker);
}
walker = walker.getNext();
InstructionHandle walker = body.getStart();
List rets = new ArrayList();
while (walker!=null) { //!walker.equals(body.getEnd())) {
- if (walker.getInstruction() instanceof ReturnInstruction) {
+ if (walker.getInstruction().isReturnInstruction()) {
rets.add(walker);
}
walker = walker.getNext();
// ignore
} else if (targeter instanceof LineNumberTag) {
// ignore
- } else if (targeter instanceof GOTO || targeter instanceof GOTO_W) {
+ } else if (targeter instanceof InstructionBranch && ((InstructionBranch)targeter).isGoto()) {
// move it...
targeter.updateTarget(element, monitorExitBlockStart);
- } else if (targeter instanceof BranchInstruction) {
+ } else if (targeter instanceof InstructionBranch) {
// move it
targeter.updateTarget(element, monitorExitBlockStart);
} else {
InstructionList sourceList = donor.getBody();
Map srcToDest = new HashMap();
- ConstantPoolGen donorCpg = donor.getEnclosingClass().getConstantPoolGen();
- ConstantPoolGen recipientCpg = recipient.getEnclosingClass().getConstantPoolGen();
+ ConstantPool donorCpg = donor.getEnclosingClass().getConstantPool();
+ ConstantPool recipientCpg = recipient.getEnclosingClass().getConstantPool();
boolean isAcrossClass = donorCpg != recipientCpg;
{
Instruction fresh = Utility.copyInstruction(src.getInstruction());
InstructionHandle dest;
- if (fresh instanceof CPInstruction) {
+ if (fresh.isConstantPoolInstruction()) {
// need to reset index to go to new constant pool. This is totally
// a computation leak... we're testing this LOTS of times. Sigh.
if (isAcrossClass) {
- CPInstruction cpi = (CPInstruction) fresh;
+ InstructionCP cpi = (InstructionCP) fresh;
cpi.setIndex(
recipientCpg.addConstant(
donorCpg.getConstant(cpi.getIndex()),
}
if (src.getInstruction() == Range.RANGEINSTRUCTION) {
dest = ret.append(Range.RANGEINSTRUCTION);
- } else if (fresh instanceof ReturnInstruction) {
+ } else if (fresh.isReturnInstruction()) {
if (keepReturns) {
dest = ret.append(fresh);
} else {
dest =
ret.append(InstructionFactory.createBranchInstruction(Constants.GOTO, end));
}
- } else if (fresh instanceof BranchInstruction) {
- dest = ret.append((BranchInstruction) fresh);
+ } else if (fresh instanceof InstructionBranch) {
+ dest = ret.append((InstructionBranch) fresh);
} else if (
- fresh instanceof LocalVariableInstruction || fresh instanceof RET) {
- IndexedInstruction indexed = (IndexedInstruction) fresh;
- int oldIndex = indexed.getIndex();
+ fresh.isLocalVariableInstruction() || fresh instanceof RET) {
+
+// IndexedInstruction indexed = (IndexedInstruction) fresh;
+ int oldIndex = fresh.getIndex();
int freshIndex;
if (!frameEnv.hasKey(oldIndex)) {
freshIndex = recipient.allocateLocal(2);
} else {
freshIndex = frameEnv.get(oldIndex);
}
- indexed.setIndex(freshIndex);
+ fresh.setIndex(freshIndex);
dest = ret.append(fresh);
} else {
dest = ret.append(fresh);
Instruction inst = dest.getInstruction();
// retarget branches
- if (inst instanceof BranchInstruction) {
- BranchInstruction branch = (BranchInstruction) inst;
+ if (inst instanceof InstructionBranch) {
+ InstructionBranch branch = (InstructionBranch) inst;
InstructionHandle oldTarget = branch.getTarget();
InstructionHandle newTarget =
(InstructionHandle) srcToDest.get(oldTarget);
// this was a return instruction we previously replaced
} else {
branch.setTarget(newTarget);
- if (branch instanceof Select) {
- Select select = (Select) branch;
+ if (branch instanceof InstructionSelect) {
+ InstructionSelect select = (InstructionSelect) branch;
InstructionHandle[] oldTargets = select.getTargets();
for (int k = oldTargets.length - 1; k >= 0; k--) {
select.setTarget(
InstructionHandle dest;
if (src.getInstruction() == Range.RANGEINSTRUCTION) {
dest = newList.append(Range.RANGEINSTRUCTION);
- } else if (fresh instanceof ReturnInstruction) {
+ } else if (fresh.isReturnInstruction()) {
if (keepReturns) {
newList.append(InstructionFactory.createLoad(monitorVarType,monitorVarSlot));
newList.append(InstructionConstants.MONITOREXIT);
dest =
newList.append(InstructionFactory.createBranchInstruction(Constants.GOTO, end));
}
- } else if (fresh instanceof BranchInstruction) {
- dest = newList.append((BranchInstruction) fresh);
+ } else if (fresh instanceof InstructionBranch) {
+ dest = newList.append((InstructionBranch) fresh);
} else if (
- fresh instanceof LocalVariableInstruction || fresh instanceof RET) {
- IndexedInstruction indexed = (IndexedInstruction) fresh;
- int oldIndex = indexed.getIndex();
+ fresh.isLocalVariableInstruction() || fresh instanceof RET) {
+ //IndexedInstruction indexed = (IndexedInstruction) fresh;
+ int oldIndex = fresh.getIndex();
int freshIndex;
// if (!frameEnv.hasKey(oldIndex)) {
// freshIndex = recipient.allocateLocal(2);
// } else {
freshIndex = oldIndex;//frameEnv.get(oldIndex);
// }
- indexed.setIndex(freshIndex);
+ fresh.setIndex(freshIndex);
dest = newList.append(fresh);
} else {
dest = newList.append(fresh);
Instruction inst = dest.getInstruction();
// retarget branches
- if (inst instanceof BranchInstruction) {
- BranchInstruction branch = (BranchInstruction) inst;
+ if (inst instanceof InstructionBranch) {
+ InstructionBranch branch = (InstructionBranch) inst;
InstructionHandle oldTarget = branch.getTarget();
InstructionHandle newTarget =
(InstructionHandle) srcToDest.get(oldTarget);
// this was a return instruction we previously replaced
} else {
branch.setTarget(newTarget);
- if (branch instanceof Select) {
- Select select = (Select) branch;
+ if (branch instanceof InstructionSelect) {
+ InstructionSelect select = (InstructionSelect) branch;
InstructionHandle[] oldTargets = select.getTargets();
for (int k = oldTargets.length - 1; k >= 0; k--) {
select.setTarget(
if (start == null) return null;
Instruction inst = start.getInstruction();
- if (inst instanceof INVOKESPECIAL
- && ((INVOKESPECIAL) inst).getName(cpg).equals("<init>")) {
+ if (inst.opcode==Constants.INVOKESPECIAL
+ && ((InvokeInstruction) inst).getName(cpg).equals("<init>")) {
depth--;
if (depth == 0) return start;
- } else if (inst instanceof NEW) {
+ } else if (inst.opcode==Constants.NEW) {
depth++;
}
start = start.getNext();
) {
FieldInstruction fi = (FieldInstruction) i;
- if (fi instanceof PUTFIELD || fi instanceof PUTSTATIC) {
+ if (fi.opcode==Constants.PUTFIELD || fi.opcode==Constants.PUTSTATIC) {
// check for sets of constant fields. We first check the previous
// instruction. If the previous instruction is a LD_WHATEVER (push
// constant on the stack) then we must resolve the field to determine
}
} else if (i instanceof InvokeInstruction) {
InvokeInstruction ii = (InvokeInstruction) i;
- if (ii.getMethodName(clazz.getConstantPoolGen()).equals("<init>")) {
+ if (ii.getMethodName(clazz.getConstantPool()).equals("<init>")) {
if (canMatch(Shadow.ConstructorCall))
match(
BcelShadow.makeConstructorCall(world, mg, ih, enclosingShadow),
shadowAccumulator);
- } else if (ii instanceof INVOKESPECIAL) {
+ } else if (ii.opcode==Constants.INVOKESPECIAL) {
String onTypeName = ii.getClassName(cpg);
if (onTypeName.equals(mg.getEnclosingClass().getName())) {
// we are private
} else {
matchInvokeInstruction(mg, ih, ii, enclosingShadow, shadowAccumulator);
}
- } else if (world.isJoinpointArrayConstructionEnabled() &&
- (i instanceof NEWARRAY || i instanceof ANEWARRAY || i instanceof MULTIANEWARRAY)) {
+ } else if (world.isJoinpointArrayConstructionEnabled() && i.isArrayCreationInstruction()) {
if (canMatch(Shadow.ConstructorCall)) {
boolean debug = false;
if (debug) System.err.println("Found new array instruction: "+i);
- if (i instanceof ANEWARRAY) {
- ANEWARRAY arrayInstruction = (ANEWARRAY)i;
- ObjectType arrayType = arrayInstruction.getLoadClassType(clazz.getConstantPoolGen());
+ if (i.opcode==Constants.ANEWARRAY) {
+// ANEWARRAY arrayInstruction = (ANEWARRAY)i;
+ ObjectType arrayType = i.getLoadClassType(clazz.getConstantPool());
if (debug) System.err.println("Array type is "+arrayType);
BcelShadow ctorCallShadow = BcelShadow.makeArrayConstructorCall(world,mg,ih,enclosingShadow);
match(ctorCallShadow,shadowAccumulator);
- } else if (i instanceof NEWARRAY) {
- NEWARRAY arrayInstruction = (NEWARRAY)i;
- Type arrayType = arrayInstruction.getType();
+ } else if (i.opcode==Constants.NEWARRAY) {
+// NEWARRAY arrayInstruction = (NEWARRAY)i;
+ Type arrayType = i.getType();
if (debug) System.err.println("Array type is "+arrayType);
BcelShadow ctorCallShadow = BcelShadow.makeArrayConstructorCall(world,mg,ih,enclosingShadow);
match(ctorCallShadow,shadowAccumulator);
} else if (i instanceof MULTIANEWARRAY) {
MULTIANEWARRAY arrayInstruction = (MULTIANEWARRAY)i;
- ObjectType arrayType = arrayInstruction.getLoadClassType(clazz.getConstantPoolGen());
+ ObjectType arrayType = arrayInstruction.getLoadClassType(clazz.getConstantPool());
if (debug) System.err.println("Array type is "+arrayType);
BcelShadow ctorCallShadow = BcelShadow.makeArrayConstructorCall(world,mg,ih,enclosingShadow);
match(ctorCallShadow,shadowAccumulator);
// } else if (i instanceof AASTORE) {
// // ... magic required
} else if ( world.isJoinpointSynchronizationEnabled() &&
- ((i instanceof MONITORENTER) || (i instanceof MONITOREXIT))) {
+ ((i.getOpcode()==Constants.MONITORENTER) || (i.getOpcode()==Constants.MONITOREXIT))) {
// if (canMatch(Shadow.Monitoring)) {
- if (i instanceof MONITORENTER) {
+ if (i.getOpcode()==Constants.MONITORENTER) {
BcelShadow monitorEntryShadow = BcelShadow.makeMonitorEnter(world,mg,ih,enclosingShadow);
match(monitorEntryShadow,shadowAccumulator);
} else {
// 'putstatic ajc$initFailureCause'. If it is then we are
// in the handler we created in AspectClinit.generatePostSyntheticCode()
InstructionHandle twoInstructionsAway = ih.getNext().getNext();
- if (twoInstructionsAway.getInstruction() instanceof PUTSTATIC) {
- String name = ((PUTSTATIC)twoInstructionsAway.getInstruction()).getFieldName(cpg);
+ if (twoInstructionsAway.getInstruction().opcode==Constants.PUTSTATIC) {
+ String name = ((FieldInstruction)twoInstructionsAway.getInstruction()).getFieldName(cpg);
if (name.equals(NameMangler.INITFAILURECAUSE_FIELD_NAME)) return true;
}
return false;
import org.aspectj.apache.bcel.classfile.Attribute;
import org.aspectj.apache.bcel.classfile.Field;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
import org.aspectj.apache.bcel.classfile.GenericSignatureParser;
import org.aspectj.apache.bcel.classfile.Signature;
import org.aspectj.apache.bcel.classfile.Synthetic;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.generic.FieldGen;
import org.aspectj.weaver.AjAttribute;
import org.aspectj.weaver.AnnotationX;
import org.aspectj.weaver.BCException;
import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.UnresolvedType;
import org.aspectj.weaver.World;
+import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
import org.aspectj.weaver.bcel.BcelGenericSignatureToTypeXConverter.GenericSignatureFormatException;
+
final class BcelField extends ResolvedMemberImpl {
private static int AccSynthetic = 0x1000;
private BcelObjectType bcelObjectType;
private UnresolvedType genericFieldType = null;
private boolean unpackedGenericSignature = false;
+ private boolean annotationsAdded = false;
+
BcelField(BcelObjectType declaringType, Field field) {
super(
unpackAttributes(world);
checkedExceptions = UnresolvedType.NONE;
}
+
+ /**
+ * Constructs an instance that wrappers a Field object, but where we do not (yet) have
+ * a BcelObjectType - usually because the containing type (and this field) are being
+ * constructed at runtime (so there is no .class file to retrieve).
+ */
+ BcelField(String declaringTypeName, Field field,World world) {
+ super(FIELD,UnresolvedType.forName(declaringTypeName),field.getAccessFlags(),field.getName(),field.getSignature());
+ this.field = field;
+ this.world = world;
+ this.bcelObjectType = null;
+ unpackAttributes(world);
+ checkedExceptions = UnresolvedType.NONE;
+ }
// ----
private void unpackAttributes(World world) {
Attribute[] attrs = field.getAttributes();
- List as = BcelAttributes.readAjAttributes(getDeclaringType().getClassName(),attrs, getSourceContext(world),world,bcelObjectType.getWeaverVersionAttribute());
- as.addAll(AtAjAttributes.readAj5FieldAttributes(field, this, world.resolve(getDeclaringType()), getSourceContext(world), world.getMessageHandler()));
-
- for (Iterator iter = as.iterator(); iter.hasNext();) {
- AjAttribute a = (AjAttribute) iter.next();
- if (a instanceof AjAttribute.AjSynthetic) {
- isAjSynthetic = true;
- } else {
- throw new BCException("weird field attribute " + a);
+ if (attrs!=null && attrs.length>0) {
+ List as = BcelAttributes.readAjAttributes(
+ getDeclaringType().getClassName(),
+ attrs,
+ getSourceContext(world),
+ world,
+ (bcelObjectType!=null?bcelObjectType.getWeaverVersionAttribute():WeaverVersionInfo.CURRENT));
+ as.addAll(AtAjAttributes.readAj5FieldAttributes(field, this, world.resolve(getDeclaringType()), getSourceContext(world), world.getMessageHandler()));
+
+ for (Iterator iter = as.iterator(); iter.hasNext();) {
+ AjAttribute a = (AjAttribute) iter.next();
+ if (a instanceof AjAttribute.AjSynthetic) {
+ isAjSynthetic = true;
+ } else {
+ throw new BCException("weird field attribute " + a);
+ }
}
}
isAjSynthetic = false;
private void ensureAnnotationTypesRetrieved() {
if (annotationTypes == null) {
- Annotation annos[] = field.getAnnotations();
+ AnnotationGen annos[] = field.getAnnotations();
if (annos==null || annos.length==0) {
annotationTypes = Collections.EMPTY_SET;
annotations = AnnotationX.NONE;
annotationTypes = new HashSet();
annotations = new AnnotationX[annos.length];
for (int i = 0; i < annos.length; i++) {
- Annotation annotation = annos[i];
+ AnnotationGen annotation = annos[i];
annotationTypes.add(world.resolve(UnresolvedType.forSignature(annotation.getTypeSignature())));
annotations[i] = new AnnotationX(annotation,world);
}
}
// Add it to the set of annotation types
annotationTypes.add(UnresolvedType.forName(annotation.getTypeName()).resolve(world));
+ annotationsAdded=true;
// FIXME asc this call here suggests we are managing the annotations at
// too many levels, here in BcelField we keep a set and in the lower 'field'
// object we keep a set - we should think about reducing this to one
// level??
- field.addAnnotation(annotation.getBcelAnnotation());
+ //field.addAnnotation(annotation.getBcelAnnotation());
+ // FIXME CUSTARD
}
/**
return genericFieldType;
}
+ public Field getFieldAsIs() { return field; }
+
+ // FIXME asc badly performing code ftw !
+ public Field getField(ConstantPool cpg) {
+ if (!annotationsAdded) return field;
+ FieldGen fg = new FieldGen(field,cpg);
+ AnnotationGen[] alreadyHas = fg.getAnnotations();
+ if (annotations!=null) {
+ for (int i = 0; i < annotations.length; i++) {
+ AnnotationX array_element = annotations[i];
+ boolean alreadyHasIt = false;
+ for (int j = 0; j < alreadyHas.length; j++) {
+ AnnotationGen gen = alreadyHas[j];
+ if (gen.getTypeName().equals(array_element.getTypeName())) alreadyHasIt = true;
+ }
+ if (!alreadyHasIt) fg.addAnnotation(new AnnotationGen(array_element.getBcelAnnotation(),cpg,true));
+ }
+ }
+ field = fg.getField();
+ annotationsAdded = false; // we are now correct again
+ return field;
+ }
+
private void unpackGenericSignature() {
if (unpackedGenericSignature) { return; }
if (!world.isInJava5Mode()) {
import org.aspectj.apache.bcel.classfile.Method;
import org.aspectj.apache.bcel.classfile.Signature;
import org.aspectj.apache.bcel.classfile.Signature.TypeVariableSignature;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.SourceLocation;
import org.aspectj.weaver.AjAttribute;
import org.aspectj.weaver.AnnotationX;
import org.aspectj.weaver.BCException;
import org.aspectj.weaver.ISourceContext;
+import org.aspectj.weaver.Member;
import org.aspectj.weaver.ResolvedMemberImpl;
import org.aspectj.weaver.ResolvedPointcutDefinition;
import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.UnresolvedType;
import org.aspectj.weaver.World;
import org.aspectj.weaver.bcel.BcelGenericSignatureToTypeXConverter.GenericSignatureFormatException;
+import java.util.*;
public final class BcelMethod extends ResolvedMemberImpl {
private Method method;
- private boolean isAjSynthetic;
- private boolean isSynthetic;
- private boolean knowIfSynthetic = false;
- private ShadowMunger associatedShadowMunger;
- private ResolvedPointcutDefinition preResolvedPointcut; // used when ajc has pre-resolved the pointcut of some @Advice
-
-// private ResolvedType[] annotationTypes = null;
- private AnnotationX[] annotations = null;
-
- private AjAttribute.EffectiveSignatureAttribute effectiveSignature;
- private AjAttribute.MethodDeclarationLineNumberAttribute declarationLineNumber;
- private World world;
+// private AjAttribute.MethodDeclarationLineNumberAttribute declarationLineNumber;
+// private World world;
private BcelObjectType bcelObjectType;
+
+ public Member slimline() {
+ if (!bcelObjectType.getWorld().isXnoInline()) return this;
+ ResolvedMemberImpl mi = new ResolvedMemberImpl(kind,declaringType,modifiers,returnType,name,parameterTypes);
+ mi.setParameterNames(getParameterNames());
+ return mi;
+ }
+
+// private AnnotationX[] annotations = null;
+// private UnresolvedType genericReturnType = null;
+// private UnresolvedType[] genericParameterTypes = null;
- private boolean parameterNamesInitialized = false;
+ private Map metaData = null;
+ // keys into the meta data
+ private static final String MAPKEY_EFFECTIVE_SIGNATURE ="effectiveSignature";
+ private static final String MAPKEY_PRERESOLVED_POINTCUT ="preresolvedPointcut";
+ private static final String MAPKEY_ASSOCIATED_SHADOWMUNGER ="associatedShadowmunger";
+ private static final String MAPKEY_GENERIC_RETURN_TYPE ="genericReturnType";
+ private static final String MAPKEY_GENERIC_PARAM_TYPES ="genericParameterTypes";
+ private static final String MAPKEY_ANNOTATIONS ="annotations";
+ private static final String MAPKEY_MD_LINE_NUMBER_ATTRIBUTE="mdLineNumberAttribute";
- private boolean canBeParameterized = false;
- // genericized version of return and parameter types
- private boolean unpackedGenericSignature = false;
- private UnresolvedType genericReturnType = null;
- private UnresolvedType[] genericParameterTypes = null;
+// private AjAttribute.EffectiveSignatureAttribute effectiveSignature;
+// private ShadowMunger associatedShadowMunger;
+// private ResolvedPointcutDefinition preResolvedPointcut; // used when ajc has pre-resolved the pointcut of some @Advice
+
+ private int bitflags;
+ private static final int KNOW_IF_SYNTHETIC = 0x0001;
+ private static final int PARAMETER_NAMES_INITIALIZED = 0x0002;
+ private static final int CAN_BE_PARAMETERIZED = 0x0004;
+ private static final int UNPACKED_GENERIC_SIGNATURE = 0x0008;
+ private static final int HAS_EFFECTIVE_SIGNATURE = 0x0010;
+ private static final int HAS_PRERESOLVED_POINTCUT = 0x0020;
+ private static final int IS_AJ_SYNTHETIC = 0x0040;
+ private static final int IS_SYNTHETIC = 0x0080;
+ private static final int IS_SYNTHETIC_INVERSE = 0x7f7f; // all bits but IS_SYNTHETIC (and topmost bit)
+ private static final int HAS_ASSOCIATED_SHADOWMUNGER = 0x0100;
+ private static final int HAS_GENERIC_RETPARAM_TYPES = 0x0200;
+ private static final int HAS_ANNOTATIONS = 0x0400;
+ private static final int HAVE_DETERMINED_ANNOTATIONS = 0x0800;
+ private static final int HAS_MD_LINE_NUMBER_ATTRIBUTE= 0x1000;
+
+// private boolean isAjSynthetic;
+// private boolean isSynthetic;
+// private boolean knowIfSynthetic = false;
+// private boolean parameterNamesInitialized = false;
+// private boolean canBeParameterized = false;
+// private boolean unpackedGenericSignature = false;
BcelMethod(BcelObjectType declaringType, Method method) {
super(
method.getSignature());
this.method = method;
this.sourceContext = declaringType.getResolvedTypeX().getSourceContext();
- this.world = declaringType.getResolvedTypeX().getWorld();
+ //this.world = declaringType.getResolvedTypeX().getWorld();
this.bcelObjectType = declaringType;
unpackJavaAttributes();
- unpackAjAttributes(world);
+ unpackAjAttributes(bcelObjectType.getWorld());
}
// ----
}
public void determineParameterNames() {
- if (parameterNamesInitialized) return;
- parameterNamesInitialized=true;
+ if ((bitflags&PARAMETER_NAMES_INITIALIZED)!=0) return;
+ bitflags|=PARAMETER_NAMES_INITIALIZED;
+// if (parameterNamesInitialized) return;
+// parameterNamesInitialized=true;
LocalVariableTable varTable = method.getLocalVariableTable();
int len = getArity();
if (varTable == null) {
}
private void unpackAjAttributes(World world) {
- associatedShadowMunger = null;
+// associatedShadowMunger = null;
List as = BcelAttributes.readAjAttributes(getDeclaringType().getClassName(),method.getAttributes(), getSourceContext(world),world,bcelObjectType.getWeaverVersionAttribute());
processAttributes(world, as);
- as = AtAjAttributes.readAj5MethodAttributes(method, this, world.resolve(getDeclaringType()), preResolvedPointcut,getSourceContext(world), world.getMessageHandler());
+ as = AtAjAttributes.readAj5MethodAttributes(method, this, world.resolve(getDeclaringType()), getPreResolvedPointcutDefinition(),getSourceContext(world), world.getMessageHandler());
processAttributes(world,as);
}
for (Iterator iter = as.iterator(); iter.hasNext();) {
AjAttribute a = (AjAttribute) iter.next();
if (a instanceof AjAttribute.MethodDeclarationLineNumberAttribute) {
- declarationLineNumber = (AjAttribute.MethodDeclarationLineNumberAttribute)a;
+ addMetaData(MAPKEY_MD_LINE_NUMBER_ATTRIBUTE,a);
+ bitflags|=HAS_MD_LINE_NUMBER_ATTRIBUTE;
+// declarationLineNumber = (AjAttribute.MethodDeclarationLineNumberAttribute)a;
} else if (a instanceof AjAttribute.AdviceAttribute) {
- associatedShadowMunger = ((AjAttribute.AdviceAttribute)a).reify(this, world);
+ bitflags|=HAS_ASSOCIATED_SHADOWMUNGER;
+ addMetaData(MAPKEY_ASSOCIATED_SHADOWMUNGER,((AjAttribute.AdviceAttribute)a).reify(this, world));
+// associatedShadowMunger = ((AjAttribute.AdviceAttribute)a).reify(this, world);
// return;
} else if (a instanceof AjAttribute.AjSynthetic) {
- isAjSynthetic = true;
+ bitflags|=IS_AJ_SYNTHETIC;
+// isAjSynthetic = true;
} else if (a instanceof AjAttribute.EffectiveSignatureAttribute) {
- //System.out.println("found effective: " + this);
- effectiveSignature = (AjAttribute.EffectiveSignatureAttribute)a;
+ // System.out.println("found effective: " + this);
+ bitflags|=HAS_EFFECTIVE_SIGNATURE;
+ addMetaData(MAPKEY_EFFECTIVE_SIGNATURE,a);
+// effectiveSignature = (AjAttribute.EffectiveSignatureAttribute)a;
} else if (a instanceof AjAttribute.PointcutDeclarationAttribute) {
// this is an @AspectJ annotated advice method, with pointcut pre-resolved by ajc
- preResolvedPointcut = ((AjAttribute.PointcutDeclarationAttribute)a).reify();
+ bitflags|=HAS_PRERESOLVED_POINTCUT;
+ addMetaData(MAPKEY_PRERESOLVED_POINTCUT,((AjAttribute.PointcutDeclarationAttribute)a).reify());
+// preResolvedPointcut = ((AjAttribute.PointcutDeclarationAttribute)a).reify();
} else {
throw new BCException("weird method attribute " + a);
}
}
}
+ private void addMetaData(String k,Object v) {
+ if (metaData==null) { metaData = new HashMap();}
+ metaData.put(k,v);
+ }
+
// for testing - if we have this attribute, return it - will return null if it doesnt know anything
public AjAttribute[] getAttributes(String name) {
List results = new ArrayList();
- List l = BcelAttributes.readAjAttributes(getDeclaringType().getClassName(),method.getAttributes(), getSourceContext(world),world,bcelObjectType.getWeaverVersionAttribute());
+ List l = BcelAttributes.readAjAttributes(getDeclaringType().getClassName(),method.getAttributes(), getSourceContext(bcelObjectType.getWorld()),bcelObjectType.getWorld(),bcelObjectType.getWeaverVersionAttribute());
for (Iterator iter = l.iterator(); iter.hasNext();) {
AjAttribute element = (AjAttribute) iter.next();
if (element.getNameString().equals(name)) results.add(element);
}
public boolean isAjSynthetic() {
- return isAjSynthetic; // || getName().startsWith(NameMangler.PREFIX);
+ return (bitflags&IS_AJ_SYNTHETIC)!=0;//isAjSynthetic; // || getName().startsWith(NameMangler.PREFIX);
}
//FIXME ??? needs an isSynthetic method
public ShadowMunger getAssociatedShadowMunger() {
- return associatedShadowMunger;
+ if ((bitflags&HAS_ASSOCIATED_SHADOWMUNGER)==0) return null;
+ return (ShadowMunger)metaData.get(MAPKEY_ASSOCIATED_SHADOWMUNGER);
+// return associatedShadowMunger;
}
public AjAttribute.EffectiveSignatureAttribute getEffectiveSignature() {
- return effectiveSignature;
+ if ((bitflags&HAS_EFFECTIVE_SIGNATURE)==0) return null;
+ return (AjAttribute.EffectiveSignatureAttribute)metaData.get(MAPKEY_EFFECTIVE_SIGNATURE);//effectiveSignature;
+ }
+
+ public ResolvedPointcutDefinition getPreResolvedPointcutDefinition() {
+ if ((bitflags&HAS_PRERESOLVED_POINTCUT)==0) return null;
+ return (ResolvedPointcutDefinition)metaData.get(MAPKEY_PRERESOLVED_POINTCUT);//effectiveSignature;
}
public boolean hasDeclarationLineNumberInfo() {
- return declarationLineNumber != null;
+ return ((bitflags&HAS_MD_LINE_NUMBER_ATTRIBUTE)!=0);
+// return declarationLineNumber != null;
}
public int getDeclarationLineNumber() {
- if (declarationLineNumber != null) {
- return declarationLineNumber.getLineNumber();
- } else {
- return -1;
+ if ((bitflags&HAS_MD_LINE_NUMBER_ATTRIBUTE)!=0) {
+ AjAttribute.MethodDeclarationLineNumberAttribute mdlna = (AjAttribute.MethodDeclarationLineNumberAttribute)metaData.get(MAPKEY_MD_LINE_NUMBER_ATTRIBUTE);
+ return mdlna.getLineNumber();
}
+ return -1;
+// if (declarationLineNumber != null) {
+// return declarationLineNumber.getLineNumber();
+// } else {
+// return -1;
+// }
}
public int getDeclarationOffset() {
- if (declarationLineNumber != null) {
- return declarationLineNumber.getOffset();
- } else {
- return -1;
- }
+ if ((bitflags&HAS_MD_LINE_NUMBER_ATTRIBUTE)!=0) {
+ AjAttribute.MethodDeclarationLineNumberAttribute mdlna = (AjAttribute.MethodDeclarationLineNumberAttribute)metaData.get(MAPKEY_MD_LINE_NUMBER_ATTRIBUTE);
+ return mdlna.getOffset();
+ }
+ return -1;
+// if (declarationLineNumber != null) {
+// return declarationLineNumber.getOffset();
+// } else {
+// return -1;
+// }
}
public ISourceLocation getSourceLocation() {
}
public Kind getKind() {
- if (associatedShadowMunger != null) {
+ if ((bitflags&HAS_ASSOCIATED_SHADOWMUNGER)!=0) {
return ADVICE;
} else {
return super.getKind();
public AnnotationX[] getAnnotations() {
ensureAnnotationTypesRetrieved();
- return annotations;
+ if ((bitflags&HAS_ANNOTATIONS)!=0) {
+ return (AnnotationX[])metaData.get(MAPKEY_ANNOTATIONS);
+ } else {
+ return AnnotationX.NONE;
+ }
+// return annotations;
}
public ResolvedType[] getAnnotationTypes() {
public void addAnnotation(AnnotationX annotation) {
ensureAnnotationTypesRetrieved();
- // Add it to the set of annotations
- int len = annotations.length;
- AnnotationX[] ret = new AnnotationX[len+1];
- System.arraycopy(annotations, 0, ret, 0, len);
- ret[len] = annotation;
- annotations = ret;
+ if ((bitflags&HAS_ANNOTATIONS)==0) {
+ AnnotationX[] ret = new AnnotationX[1];
+ ret[0]=annotation;
+ addMetaData(MAPKEY_ANNOTATIONS,ret);
+ } else {
+ // Add it to the set of annotations
+ AnnotationX[] annotations = (AnnotationX[])metaData.get(MAPKEY_ANNOTATIONS);
+ int len = annotations.length;
+ AnnotationX[] ret = new AnnotationX[len+1];
+ System.arraycopy(annotations, 0, ret, 0, len);
+ ret[len] = annotation;
+ addMetaData(MAPKEY_ANNOTATIONS,ret);
+// annotations = ret;
+ }
+ bitflags|=HAS_ANNOTATIONS;
// Add it to the set of annotation types
- annotationTypes.add(UnresolvedType.forName(annotation.getTypeName()).resolve(world));
+ if (annotationTypes==Collections.EMPTY_SET) annotationTypes = new HashSet();
+ annotationTypes.add(UnresolvedType.forName(annotation.getTypeName()).resolve(bcelObjectType.getWorld()));
// FIXME asc looks like we are managing two 'bunches' of annotations, one
// here and one in the real 'method' - should we reduce it to one layer?
- method.addAnnotation(annotation.getBcelAnnotation());
+// method.addAnnotation(annotation.getBcelAnnotation());
+ // FIXME CUSTARD
}
private void ensureAnnotationTypesRetrieved() {
if (method == null) return; // must be ok, we have evicted it
- if (annotationTypes == null || method.getAnnotations().length!=annotations.length) { // sometimes the list changes underneath us!
- Annotation annos[] = method.getAnnotations();
- annotationTypes = new HashSet();
- annotations = new AnnotationX[annos.length];
- for (int i = 0; i < annos.length; i++) {
- Annotation annotation = annos[i];
- annotationTypes.add(world.resolve(UnresolvedType.forSignature(annotation.getTypeSignature())));
- annotations[i] = new AnnotationX(annotation,world);
- }
+ if ((bitflags&HAVE_DETERMINED_ANNOTATIONS)!=0) return;
+ bitflags|=HAVE_DETERMINED_ANNOTATIONS;
+// if (annotationTypes == null) {// || method.getAnnotations().length!=annotations.length) { // sometimes the list changes underneath us!
+ AnnotationGen annos[] = method.getAnnotations();
+ if (annos.length!=0) {
+ annotationTypes = new HashSet();
+ AnnotationX[] annotations = new AnnotationX[annos.length];
+ for (int i = 0; i < annos.length; i++) {
+ AnnotationGen annotation = annos[i];
+ annotationTypes.add(bcelObjectType.getWorld().resolve(UnresolvedType.forSignature(annotation.getTypeSignature())));
+ annotations[i] = new AnnotationX(annotation,bcelObjectType.getWorld());
+ }
+ addMetaData(MAPKEY_ANNOTATIONS,annotations);
+ bitflags|=HAS_ANNOTATIONS;
+ } else {
+ annotationTypes=Collections.EMPTY_SET;
}
+// }
}
*/
public boolean canBeParameterized() {
unpackGenericSignature();
- return canBeParameterized;
+ return (bitflags&CAN_BE_PARAMETERIZED)!=0;//canBeParameterized;
}
public UnresolvedType[] getGenericParameterTypes() {
unpackGenericSignature();
- return genericParameterTypes;
+ if ((bitflags&HAS_GENERIC_RETPARAM_TYPES)==0) return getParameterTypes();
+ return (UnresolvedType[])metaData.get(MAPKEY_GENERIC_PARAM_TYPES);
+// return genericParameterTypes;
}
public UnresolvedType getGenericReturnType() {
unpackGenericSignature();
- return genericReturnType;
+ if ((bitflags&HAS_GENERIC_RETPARAM_TYPES)==0) return getReturnType();
+ return (UnresolvedType)metaData.get(MAPKEY_GENERIC_RETURN_TYPE);
+// return genericReturnType;
}
/** For testing only */
public Method getMethod() { return method; }
private void unpackGenericSignature() {
- if (unpackedGenericSignature) return;
- unpackedGenericSignature = true;
- if (!world.isInJava5Mode()) {
- this.genericReturnType = getReturnType();
- this.genericParameterTypes = getParameterTypes();
+ if ((bitflags&UNPACKED_GENERIC_SIGNATURE)!=0) return;
+ bitflags|=UNPACKED_GENERIC_SIGNATURE;
+// if (unpackedGenericSignature) return;
+// unpackedGenericSignature = true;
+ if (!bcelObjectType.getWorld().isInJava5Mode()) {
+
+// this.genericReturnType = getReturnType();
+// this.genericParameterTypes = getParameterTypes();
return;
}
String gSig = method.getGenericSignature();
Signature.MethodTypeSignature mSig = new GenericSignatureParser().parseAsMethodSignature(gSig);//method.getGenericSignature());
if (mSig.formalTypeParameters.length > 0) {
// generic method declaration
- canBeParameterized = true;
+ bitflags|=CAN_BE_PARAMETERIZED;
+// canBeParameterized = true;
}
typeVariables = new TypeVariable[mSig.formalTypeParameters.length];
typeVariables[i] = BcelGenericSignatureToTypeXConverter.formalTypeParameter2TypeVariable(
methodFtp,
mSig.formalTypeParameters,
- world);
+ bcelObjectType.getWorld());
} catch (GenericSignatureFormatException e) {
// this is a development bug, so fail fast with good info
throw new IllegalStateException(
System.arraycopy(mSig.formalTypeParameters,0,formals,0,mSig.formalTypeParameters.length);
System.arraycopy(parentFormals,0,formals,mSig.formalTypeParameters.length,parentFormals.length);
Signature.TypeSignature returnTypeSignature = mSig.returnType;
+ bitflags|=HAS_GENERIC_RETPARAM_TYPES;
+ UnresolvedType genericReturnType = null;
+ UnresolvedType[] genericParameterTypes = null;
try {
genericReturnType = BcelGenericSignatureToTypeXConverter.typeSignature2TypeX(
returnTypeSignature, formals,
- world);
+ bcelObjectType.getWorld());
} catch (GenericSignatureFormatException e) {
// development bug, fail fast with good info
throw new IllegalStateException(
try {
genericParameterTypes[i] =
BcelGenericSignatureToTypeXConverter.typeSignature2TypeX(
- paramTypeSigs[i],formals,world);
+ paramTypeSigs[i],formals,bcelObjectType.getWorld());
} catch (GenericSignatureFormatException e) {
// development bug, fail fast with good info
throw new IllegalStateException(
+ e.getMessage());
}
if (paramTypeSigs[i] instanceof TypeVariableSignature) {
- canBeParameterized = true;
+ bitflags|=CAN_BE_PARAMETERIZED;
+// canBeParameterized = true;
}
}
- } else {
- genericReturnType = getReturnType();
- genericParameterTypes = getParameterTypes();
- }
+ addMetaData(MAPKEY_GENERIC_PARAM_TYPES, genericParameterTypes);
+ addMetaData(MAPKEY_GENERIC_RETURN_TYPE, genericReturnType);
+ bitflags|=HAS_GENERIC_RETPARAM_TYPES;
+ }
+// else {
+// genericReturnType = getReturnType();
+// genericParameterTypes = getParameterTypes();
+// }
}
public void evictWeavingState() {
}
public boolean isSynthetic() {
- if (!knowIfSynthetic) workOutIfSynthetic();
- return isSynthetic;
+ if ((bitflags&KNOW_IF_SYNTHETIC)==0) {
+ workOutIfSynthetic();
+ }
+ return (bitflags&IS_SYNTHETIC)!=0;//isSynthetic;
}
// Pre Java5 synthetic is an attribute 'Synthetic', post Java5 it is a modifier (4096 or 0x1000)
private void workOutIfSynthetic() {
- knowIfSynthetic=true;
+ if ((bitflags&KNOW_IF_SYNTHETIC)!=0) return;
+ bitflags|=KNOW_IF_SYNTHETIC;
+// knowIfSynthetic=true;
JavaClass jc = bcelObjectType.getJavaClass();
- isSynthetic=false;
+ bitflags&=IS_SYNTHETIC_INVERSE; // unset the bit
+// isSynthetic=false;
if (jc==null) return; // what the hell has gone wrong?
if (jc.getMajor()<49/*Java5*/) {
// synthetic is an attribute
String[] synthetics = getAttributeNames(false);
if (synthetics!=null) {
for (int i = 0; i < synthetics.length; i++) {
- if (synthetics[i].equals("Synthetic")) {isSynthetic=true;break;}
+ if (synthetics[i].equals("Synthetic")) {
+ bitflags|=IS_SYNTHETIC;
+// isSynthetic=true;
+ break;}
}
}
} else {
// synthetic is a modifier (4096)
- isSynthetic = (modifiers&4096)!=0;
+ if ((modifiers&4096)!=0) {
+ bitflags|=IS_SYNTHETIC;
+ }
+// isSynthetic = (modifiers&4096)!=0;
}
}
import java.util.List;
import org.aspectj.apache.bcel.classfile.Attribute;
+import org.aspectj.apache.bcel.classfile.AttributeUtils;
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.annotation.Annotation;
-import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
-import org.aspectj.apache.bcel.classfile.annotation.ElementValue;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen;
import org.aspectj.bridge.IMessageHandler;
import org.aspectj.weaver.AbstractReferenceTypeDelegate;
import org.aspectj.weaver.AjAttribute;
import org.aspectj.weaver.AnnotationTargetKind;
import org.aspectj.weaver.AnnotationX;
import org.aspectj.weaver.BCException;
+import org.aspectj.weaver.ISourceContext;
import org.aspectj.weaver.ReferenceType;
import org.aspectj.weaver.ResolvedMember;
import org.aspectj.weaver.ResolvedPointcutDefinition;
// @AJ pc refs annotation in class hierarchy
resolvedTypeX.setDelegate(this);
- if (resolvedTypeX.getSourceContext()==SourceContextImpl.UNKNOWN_SOURCE_CONTEXT) {
- setSourceContext(new SourceContextImpl(this));
+ ISourceContext sourceContext = resolvedTypeX.getSourceContext();
+ if (sourceContext==SourceContextImpl.UNKNOWN_SOURCE_CONTEXT) {
+ sourceContext = new SourceContextImpl(this);
+ setSourceContext(sourceContext);
}
// this should only ever be java.lang.Object which is
// the only class in Java-1.4 with no superclasses
isObject = (javaClass.getSuperclassNameIndex() == 0);
ensureAspectJAttributesUnpacked();
+// if (sourceContext instanceof SourceContextImpl) {
+// ((SourceContextImpl)sourceContext).setSourceFileName(javaClass.getSourceFileName());
+// }
setSourcefilename(javaClass.getSourceFileName());
+
}
// repeat initialization
public void setJavaClass(JavaClass newclass) {
+// if (this.getResolvedTypeX().isAspect())
+// new RuntimeException("bcot: "+this.hashCode()+" Set javaclass for aspect").printStackTrace();
this.javaClass = newclass;
resetState();
initializeFromJavaclass();
ResolvedType res = getResolvedTypeX().getWorld().resolve(UnresolvedType.forSignature(superclassSignature));
return res;
}
+
+ public World getWorld() {
+ return getResolvedTypeX().getWorld();
+ }
/**
* Retrieves the declared interfaces - this allows for the generic signature on a type. If specified
if (getResolvedTypeX().getSourceContext() instanceof SourceContextImpl) {
AjAttribute.SourceContextAttribute sca = (AjAttribute.SourceContextAttribute)a;
((SourceContextImpl)getResolvedTypeX().getSourceContext()).configureFromAttribute(sca.getSourceFileName(),sca.getLineBreaks());
+
+ setSourcefilename(sca.getSourceFileName());
}
} else if (a instanceof AjAttribute.WeaverVersionInfo) {
wvInfo = (AjAttribute.WeaverVersionInfo)a; // Set the weaver version used to build this type
public LazyClassGen getLazyClassGen() {
LazyClassGen ret = lazyClassGen;
if (ret == null) {
- //System.err.println("creating lazy class gen for: " + this);
+// System.err.println("creating lazy class gen for: " + this);
ret = new LazyClassGen(this);
//ret.print(System.err);
//System.err.println("made LCG from : " + this.getJavaClass().getSuperclassName );
if (ax.getTypeName().equals(UnresolvedType.AT_RETENTION.getName())) {
List values = ax.getBcelAnnotation().getValues();
for (Iterator it = values.iterator(); it.hasNext();) {
- ElementNameValuePair element = (ElementNameValuePair) it.next();
- ElementValue v = element.getValue();
+ ElementNameValuePairGen element = (ElementNameValuePairGen) it.next();
+ ElementValueGen v = element.getValue();
retentionPolicy = v.stringifyValue();
return retentionPolicy;
}
annotationTargetKinds = null; // null means we have no idea or the @Target annotation hasn't been used
List targetKinds = new ArrayList();
if (isAnnotation()) {
- Annotation[] annotationsOnThisType = javaClass.getAnnotations();
+ AnnotationGen[] annotationsOnThisType = javaClass.getAnnotations();
for (int i = 0; i < annotationsOnThisType.length; i++) {
- Annotation a = annotationsOnThisType[i];
+ AnnotationGen a = annotationsOnThisType[i];
if (a.getTypeName().equals(UnresolvedType.AT_TARGET.getName())) {
- ArrayElementValue arrayValue = (ArrayElementValue)((ElementNameValuePair)a.getValues().get(0)).getValue();
- ElementValue[] evs = arrayValue.getElementValuesArray();
+ ArrayElementValueGen arrayValue = (ArrayElementValueGen)((ElementNameValuePairGen)a.getValues().get(0)).getValue();
+ ElementValueGen[] evs = arrayValue.getElementValuesArray();
if (evs!=null) {
for (int j = 0; j < evs.length; j++) {
String targetKind = evs[j].stringifyValue();
private void ensureAnnotationsUnpacked() {
if (annotationTypes == null) {
- Annotation annos[] = javaClass.getAnnotations();
+ AnnotationGen annos[] = javaClass.getAnnotations();
if (annos==null || annos.length==0) {
annotationTypes = ResolvedType.NONE;
annotations = AnnotationX.NONE;
annotationTypes = new ResolvedType[annos.length];
annotations = new AnnotationX[annos.length];
for (int i = 0; i < annos.length; i++) {
- Annotation annotation = annos[i];
+ AnnotationGen annotation = annos[i];
annotationTypes[i] = w.resolve(UnresolvedType.forSignature(annotation.getTypeSignature()));
annotations[i] = new AnnotationX(annotation,w);
}
private void ensureGenericInfoProcessed() {
if ((bitflag & DISCOVERED_DECLARED_SIGNATURE)!=0) return;
bitflag |= DISCOVERED_DECLARED_SIGNATURE;
- Attribute[] as = javaClass.getAttributes();
- for (int i = 0; i < as.length && declaredSignature==null; i++) {
- Attribute attribute = as[i];
- if (attribute instanceof Signature) declaredSignature = ((Signature)attribute).getSignature();
- }
+ Signature sigAttr = AttributeUtils.getSignatureAttribute(javaClass.getAttributes());
+ declaredSignature = (sigAttr==null?null:sigAttr.getSignature());
if (declaredSignature!=null) isGenericType= (declaredSignature.charAt(0)=='<');
}
public void evictWeavingState() {
// Can't chuck all this away
+// if (getResolvedTypeX().isAspect()) System.err.println("Eviction of "+getResolvedTypeX().getName());
if (getResolvedTypeX().getWorld().couldIncrementalCompileFollow()) return;
if (javaClass != null) {
weaverState.setReweavable(false);
weaverState.setUnwovenClassFileData(null);
}
- for (int i = methods.length - 1; i >= 0; i--) methods[i].evictWeavingState();
+
+ for (int i = methods.length - 1; i >= 0; i--) { methods[i].evictWeavingState();}
for (int i = fields.length - 1; i >= 0; i--) fields[i].evictWeavingState();
+// if (getResolvedTypeX().isAspect()) System.err.println("nulling jc for "+getResolvedTypeX().getName());
javaClass = null;
// setSourceContext(SourceContextImpl.UNKNOWN_SOURCE_CONTEXT); // bit naughty
// interfaces=null; // force reinit - may get us the right instances!
// superClass=null;
+ // if this is a class, make sure aspects are re-evicted if necessary
+// if (!getResolvedTypeX().isAspect()) getWorld().ensureAspectsEvicted();
}
}
package org.aspectj.weaver.bcel;
import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.generic.ATHROW;
-import org.aspectj.apache.bcel.generic.BranchInstruction;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
import org.aspectj.apache.bcel.generic.InstructionConstants;
import org.aspectj.apache.bcel.generic.InstructionFactory;
import org.aspectj.apache.bcel.generic.InstructionHandle;
import org.aspectj.apache.bcel.generic.InstructionList;
-import org.aspectj.apache.bcel.generic.NOP;
import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.POP;
-import org.aspectj.apache.bcel.generic.PUSH;
import org.aspectj.apache.bcel.generic.ReferenceType;
import org.aspectj.apache.bcel.generic.Type;
import org.aspectj.weaver.AjAttribute;
//FIXME Alex percflowX is not using this one but AJ code style does generate it so..
ResolvedMember failureFieldInfo = AjcMemberMaker.initFailureCauseField(aspectType);
- classGen.addField(makeFieldGen(classGen, failureFieldInfo).getField(), null);
+ classGen.addField(makeFieldGen(classGen, failureFieldInfo), null);
if (kind == PerClause.SINGLETON) {
ResolvedMember perSingletonFieldInfo = AjcMemberMaker.perSingletonField(aspectType);
- classGen.addField(makeFieldGen(classGen, perSingletonFieldInfo).getField(), null);
+ classGen.addField(makeFieldGen(classGen, perSingletonFieldInfo), null);
// pr144602 - don't need to do this, PerObjectInterface munger will do it
// } else if (kind == PerClause.PEROBJECT) {
// ResolvedMember perObjectFieldInfo = AjcMemberMaker.perObjectField(aspectType, aspectType);
// // it should be done here.
} else if (kind == PerClause.PERCFLOW) {
ResolvedMember perCflowFieldInfo = AjcMemberMaker.perCflowField(aspectType);
- classGen.addField(makeFieldGen(classGen, perCflowFieldInfo).getField(), null);
+ classGen.addField(makeFieldGen(classGen, perCflowFieldInfo), null);
} else if (kind == PerClause.PERTYPEWITHIN) {
ResolvedMember perTypeWithinForField = AjcMemberMaker.perTypeWithinWithinTypeField(aspectType, aspectType);
- classGen.addField(makeFieldGen(classGen, perTypeWithinForField).getField(), null);
+ classGen.addField(makeFieldGen(classGen, perTypeWithinForField), null);
// } else {
// throw new Error("Should not happen - no such kind " + kind.toString());
}
InstructionList il = method.getBody();
il.append(Utility.createGet(factory, AjcMemberMaker.perSingletonField(aspectType)));
- BranchInstruction ifNotNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
+ InstructionBranch ifNotNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
il.append(ifNotNull);
il.append(factory.createNew(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName()));
il.append(InstructionConstants.DUP);
- il.append(new PUSH(classGen.getConstantPoolGen(), aspectType.getName()));
+ il.append(InstructionFactory.PUSH(classGen.getConstantPool(), aspectType.getName()));
il.append(Utility.createGet(factory, AjcMemberMaker.initFailureCauseField(aspectType)));
il.append(factory.createInvoke(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName(), "<init>", Type.VOID, new Type[] { Type.STRING, new ObjectType("java.lang.Throwable") }, Constants.INVOKESPECIAL));
il.append(InstructionConstants.ATHROW);
InstructionList il = method.getBody();
il.append(Utility.createGet(factory, AjcMemberMaker.perSingletonField(aspectType)));
- BranchInstruction ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
+ InstructionBranch ifNull = (InstructionBranch)InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
il.append(ifNull);
- il.append(new PUSH(classGen.getConstantPoolGen(), true));
+ il.append(InstructionFactory.PUSH(classGen.getConstantPool(), true));
il.append(InstructionFactory.createReturn(Type.INT));
- InstructionHandle ifElse = il.append(new PUSH(classGen.getConstantPoolGen(), false));
+ InstructionHandle ifElse = il.append(InstructionFactory.PUSH(classGen.getConstantPool(), false));
il.append(InstructionFactory.createReturn(Type.INT));
ifNull.setTarget(ifElse);
}
LazyMethodGen clinit = classGen.getStaticInitializer();
il = new InstructionList();
InstructionHandle tryStart = il.append(factory.createInvoke(aspectType.getName(), NameMangler.AJC_POST_CLINIT_NAME, Type.VOID, Type.NO_ARGS, Constants.INVOKESTATIC));
- BranchInstruction tryEnd = InstructionFactory.createBranchInstruction(Constants.GOTO, null);
+ InstructionBranch tryEnd = InstructionFactory.createBranchInstruction(Constants.GOTO, null);
il.append(tryEnd);
InstructionHandle handler = il.append(InstructionConstants.ASTORE_0);
il.append(InstructionConstants.ALOAD_0);
// replace the original "return" with a "nop"
//TODO AV - a bit odd, looks like Bcel alters bytecode and has a IMPDEP1 in its representation
- if (clinit.getBody().getEnd().getInstruction().getOpcode() == Constants.IMPDEP1) {
- clinit.getBody().getEnd().getPrev().setInstruction(new NOP());
+ if (clinit.getBody().getEnd().getInstruction().opcode == Constants.IMPDEP1) {
+ clinit.getBody().getEnd().getPrev().setInstruction(InstructionConstants.NOP);
}
- clinit.getBody().getEnd().setInstruction(new NOP());
+ clinit.getBody().getEnd().setInstruction(InstructionConstants.NOP);
clinit.getBody().append(il);
clinit.addExceptionHandler(
InstructionList il = method.getBody();
il.append(InstructionConstants.ALOAD_0);
il.append(factory.createInstanceOf(interfaceType));
- BranchInstruction ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
+ InstructionBranch ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
il.append(ifEq);
il.append(InstructionConstants.ALOAD_0);
il.append(factory.createCheckCast(interfaceType));
il.append(Utility.createInvoke(factory, Constants.INVOKEINTERFACE, AjcMemberMaker.perObjectInterfaceGet(aspectType)));
il.append(InstructionConstants.DUP);
- BranchInstruction ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
+ InstructionBranch ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
il.append(ifNull);
il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(aspectType)));
- InstructionHandle ifNullElse = il.append(new POP());
+ InstructionHandle ifNullElse = il.append(InstructionConstants.POP);
ifNull.setTarget(ifNullElse);
InstructionHandle ifEqElse = il.append(factory.createNew(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName()));
ifEq.setTarget(ifEqElse);
il.append(InstructionConstants.DUP);
il.append(factory.createInvoke(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName(), "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
- il.append(new ATHROW());
+ il.append(InstructionConstants.ATHROW);
}
private void generatePerObjectHasAspectMethod(LazyClassGen classGen) {
InstructionList il = method.getBody();
il.append(InstructionConstants.ALOAD_0);
il.append(factory.createInstanceOf(interfaceType));
- BranchInstruction ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
+ InstructionBranch ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
il.append(ifEq);
il.append(InstructionConstants.ALOAD_0);
il.append(factory.createCheckCast(interfaceType));
il.append(Utility.createInvoke(factory, Constants.INVOKEINTERFACE, AjcMemberMaker.perObjectInterfaceGet(aspectType)));
- BranchInstruction ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
+ InstructionBranch ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
il.append(ifNull);
il.append(InstructionConstants.ICONST_1);
il.append(InstructionFactory.createReturn(Type.INT));
InstructionList il = method.getBody();
il.append(InstructionConstants.ALOAD_0);
il.append(factory.createInstanceOf(interfaceType));
- BranchInstruction ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
+ InstructionBranch ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
il.append(ifEq);
il.append(InstructionConstants.ALOAD_0);
il.append(factory.createCheckCast(interfaceType));
il.append(Utility.createInvoke(factory, Constants.INVOKEINTERFACE, AjcMemberMaker.perObjectInterfaceGet(aspectType)));
- BranchInstruction ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
+ InstructionBranch ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
il.append(ifNonNull);
il.append(InstructionConstants.ALOAD_0);
il.append(factory.createCheckCast(interfaceType));
));
il.append(InstructionConstants.ASTORE_1);
il.append(InstructionConstants.ALOAD_1);
- BranchInstruction ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
+ InstructionBranch ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
il.append(ifNonNull);
il.append(factory.createNew(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName()));
il.append(InstructionConstants.DUP);
- il.append(new PUSH(classGen.getConstantPoolGen(), aspectType.getName()));
+ il.append(InstructionFactory.PUSH(classGen.getConstantPool(), aspectType.getName()));
il.append(InstructionConstants.ACONST_NULL);
il.append(factory.createInvoke(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName(), "<init>", Type.VOID, new Type[] { Type.STRING, new ObjectType("java.lang.Throwable") }, Constants.INVOKESPECIAL));
il.append(InstructionConstants.ATHROW);
Constants.INVOKESTATIC,
AjcMemberMaker.perTypeWithinGetInstance(aspectType)
));
- BranchInstruction ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
+ InstructionBranch ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
il.append(ifNull);
il.append(InstructionConstants.ICONST_1);
il.append(InstructionConstants.IRETURN);
InstructionList il = method.getBody();
InstructionHandle tryStart = il.append(InstructionConstants.ALOAD_0);
- il.append(new PUSH(factory.getConstantPool(), NameMangler.perTypeWithinLocalAspectOf(aspectType)));
+ il.append(InstructionFactory.PUSH(factory.getConstantPool(), NameMangler.perTypeWithinLocalAspectOf(aspectType)));
il.append(InstructionConstants.ACONST_NULL);//Class[] for "getDeclaredMethod"
il.append(factory.createInvoke(
"java/lang/Class",
methodGen.addAttribute(
BcelAttributes.bcelAttribute(
new AjAttribute.AjSynthetic(),
- methodGen.getEnclosingClass().getConstantPoolGen()
+ methodGen.getEnclosingClass().getConstantPool()
)
);
}
import org.aspectj.apache.bcel.Constants;
import org.aspectj.apache.bcel.classfile.Field;
-import org.aspectj.apache.bcel.generic.ACONST_NULL;
-import org.aspectj.apache.bcel.generic.ALOAD;
-import org.aspectj.apache.bcel.generic.ANEWARRAY;
import org.aspectj.apache.bcel.generic.ArrayType;
-import org.aspectj.apache.bcel.generic.BranchInstruction;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
-import org.aspectj.apache.bcel.generic.DUP;
-import org.aspectj.apache.bcel.generic.DUP_X1;
-import org.aspectj.apache.bcel.generic.DUP_X2;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
import org.aspectj.apache.bcel.generic.FieldInstruction;
import org.aspectj.apache.bcel.generic.INVOKEINTERFACE;
-import org.aspectj.apache.bcel.generic.INVOKESPECIAL;
-import org.aspectj.apache.bcel.generic.INVOKESTATIC;
import org.aspectj.apache.bcel.generic.Instruction;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
import org.aspectj.apache.bcel.generic.InstructionConstants;
import org.aspectj.apache.bcel.generic.InstructionFactory;
import org.aspectj.apache.bcel.generic.InstructionHandle;
+import org.aspectj.apache.bcel.generic.InstructionLV;
import org.aspectj.apache.bcel.generic.InstructionList;
import org.aspectj.apache.bcel.generic.InstructionTargeter;
import org.aspectj.apache.bcel.generic.InvokeInstruction;
import org.aspectj.apache.bcel.generic.LineNumberTag;
-import org.aspectj.apache.bcel.generic.LoadInstruction;
import org.aspectj.apache.bcel.generic.LocalVariableTag;
import org.aspectj.apache.bcel.generic.MULTIANEWARRAY;
-import org.aspectj.apache.bcel.generic.NEW;
import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.PUSH;
-import org.aspectj.apache.bcel.generic.RETURN;
-import org.aspectj.apache.bcel.generic.ReturnInstruction;
-import org.aspectj.apache.bcel.generic.SWAP;
-import org.aspectj.apache.bcel.generic.StoreInstruction;
import org.aspectj.apache.bcel.generic.TargetLostException;
import org.aspectj.apache.bcel.generic.Type;
import org.aspectj.bridge.ISourceLocation;
private void deleteNewAndDup() {
- final ConstantPoolGen cpg = getEnclosingClass().getConstantPoolGen();
+ final ConstantPool cpg = getEnclosingClass().getConstantPool();
int depth = 1;
InstructionHandle ih = range.getStart();
- // Go back from where we are looking for 'NEW' that takes us to a stack depth of 0. INVOKESPECIAL <init>
while (true) {
Instruction inst = ih.getInstruction();
- if (inst instanceof INVOKESPECIAL
- && ((INVOKESPECIAL) inst).getName(cpg).equals("<init>")) {
+ if (inst.opcode==Constants.INVOKESPECIAL
+ && ((InvokeInstruction) inst).getName(cpg).equals("<init>")) {
depth++;
- } else if (inst instanceof NEW) {
+ } else if (inst.opcode==Constants.NEW) {
depth--;
if (depth == 0) break;
- } else if (inst instanceof DUP_X2) {
+ } else if (inst.opcode==Constants.DUP_X2) {
// This code seen in the wild (by Brad):
// 40: new #12; //class java/lang/StringBuffer
// STACK: STRINGBUFFER
// bytecode sequence has only been seen once in the wild.
ih.setInstruction(InstructionConstants.DUP);
}
-
ih = ih.getPrev();
}
// now IH points to the NEW. We're followed by the DUP, and that is followed
InstructionHandle newHandle = ih;
InstructionHandle endHandle = newHandle.getNext();
InstructionHandle nextHandle;
- //
-
- if (endHandle.getInstruction() instanceof DUP) {
+ if (endHandle.getInstruction().opcode==Constants.DUP) {
nextHandle = endHandle.getNext();
retargetFrom(newHandle, nextHandle);
retargetFrom(endHandle, nextHandle);
- } else if (endHandle.getInstruction() instanceof DUP_X1) {
+ } else if (endHandle.getInstruction().opcode==Constants.DUP_X1) {
InstructionHandle dupHandle = endHandle;
endHandle = endHandle.getNext();
nextHandle = endHandle.getNext();
- if (endHandle.getInstruction() instanceof SWAP) {}
+ if (endHandle.getInstruction().opcode==Constants.SWAP) {}
else {
// XXX see next XXX comment
throw new RuntimeException("Unhandled kind of new " + endHandle);
if (clinitStart.getInstruction() instanceof InvokeInstruction) {
InvokeInstruction ii = (InvokeInstruction)clinitStart.getInstruction();
if (ii
- .getName(enclosingMethod.getEnclosingClass().getConstantPoolGen())
+ .getName(enclosingMethod.getEnclosingClass().getConstantPool())
.equals(NameMangler.AJC_PRE_CLINIT_NAME)) {
clinitStart = clinitStart.getNext();
}
//XXX should move the end before the postClinit, but the return is then tricky...
// if (clinitEnd.getInstruction() instanceof InvokeInstruction) {
// InvokeInstruction ii = (InvokeInstruction)clinitEnd.getInstruction();
-// if (ii.getName(enclosingMethod.getEnclosingClass().getConstantPoolGen()).equals(NameMangler.AJC_POST_CLINIT_NAME)) {
+// if (ii.getName(enclosingMethod.getEnclosingClass().getConstantPool()).equals(NameMangler.AJC_POST_CLINIT_NAME)) {
// clinitEnd = clinitEnd.getPrev();
// }
// }
}
private static String findHandlerParamName(InstructionHandle startOfHandler) {
- if (startOfHandler.getInstruction() instanceof StoreInstruction &&
+ if (startOfHandler.getInstruction().isStoreInstruction() &&
startOfHandler.getNext() != null)
{
- int slot = ((StoreInstruction)startOfHandler.getInstruction()).getIndex();
+ int slot = startOfHandler.getInstruction().getIndex();
//System.out.println("got store: " + startOfHandler.getInstruction() + ", " + index);
InstructionTargeter[] targeters = startOfHandler.getNext().getTargeters();
if (targeters!=null) {
if (sources != null) {
for (int i = sources.length - 1; i >= 0; i--) {
InstructionTargeter source = sources[i];
- if (source instanceof BranchInstruction) {
+ if (source instanceof InstructionBranch) {
source.updateTarget(from, to);
}
}
if (hasThis()) {
((BcelVar)getThisVar()).appendLoad(il, fact);
} else {
- il.append(new ACONST_NULL());
+ il.append(InstructionConstants.ACONST_NULL);
}
if (hasTarget()) {
((BcelVar)getTargetVar()).appendLoad(il, fact);
} else {
- il.append(new ACONST_NULL());
+ il.append(InstructionConstants.ACONST_NULL);
}
switch(getArgCount()) {
// Lets go back through the code from the start of the shadow
InstructionHandle searchPtr = range.getStart().getPrev();
while (Range.isRangeHandle(searchPtr) ||
- searchPtr.getInstruction() instanceof StoreInstruction) { // ignore this instruction - it doesnt give us the info we want
+ searchPtr.getInstruction().isStoreInstruction()) { // ignore this instruction - it doesnt give us the info we want
searchPtr = searchPtr.getPrev();
}
// A load instruction may tell us the real type of what the clone() call is on
- if (searchPtr.getInstruction() instanceof LoadInstruction) {
- LoadInstruction li = (LoadInstruction)searchPtr.getInstruction();
- li.getIndex();
- LocalVariableTag lvt = LazyMethodGen.getLocalVariableTag(searchPtr,li.getIndex());
+ if (searchPtr.getInstruction().isLoadInstruction()) {
+ LocalVariableTag lvt = LazyMethodGen.getLocalVariableTag(searchPtr,searchPtr.getInstruction().getIndex());
if (lvt!=null) return UnresolvedType.forSignature(lvt.getType());
}
// A field access instruction may tell us the real type of what the clone() call is on
if (searchPtr.getInstruction() instanceof FieldInstruction) {
FieldInstruction si = (FieldInstruction)searchPtr.getInstruction();
- Type t = si.getFieldType(getEnclosingClass().getConstantPoolGen());
+ Type t = si.getFieldType(getEnclosingClass().getConstantPool());
return BcelWorld.fromBcel(t);
}
// A new array instruction obviously tells us it is an array type !
- if (searchPtr.getInstruction() instanceof ANEWARRAY) {
+ if (searchPtr.getInstruction().opcode==Constants.ANEWARRAY) {
//ANEWARRAY ana = (ANEWARRAY)searchPoint.getInstruction();
- //Type t = ana.getType(getEnclosingClass().getConstantPoolGen());
+// Type t = ana.getType(getEnclosingClass().getConstantPool());
// Just use a standard java.lang.object array - that will work fine
return BcelWorld.fromBcel(new ArrayType(Type.OBJECT,1));
}
// A multi new array instruction obviously tells us it is an array type !
if (searchPtr.getInstruction() instanceof MULTIANEWARRAY) {
MULTIANEWARRAY ana = (MULTIANEWARRAY)searchPtr.getInstruction();
- // Type t = ana.getType(getEnclosingClass().getConstantPoolGen());
+ // Type t = ana.getType(getEnclosingClass().getConstantPool());
// t = new ArrayType(t,ana.getDimensions());
// Just use a standard java.lang.object array - that will work fine
return BcelWorld.fromBcel(new ArrayType(Type.OBJECT,ana.getDimensions()));
private List findReturnInstructions() {
List returns = new ArrayList();
for (InstructionHandle ih = range.getStart(); ih != range.getEnd(); ih = ih.getNext()) {
- if (ih.getInstruction() instanceof ReturnInstruction) {
+ if (ih.getInstruction().isReturnInstruction()) {
returns.add(ih);
}
}
int i=returns.size()-1;
while (newReturnInstruction == null && i>=0) {
InstructionHandle ih = (InstructionHandle)returns.get(i);
- if (!(ih.getInstruction() instanceof RETURN)) {
+ if (ih.getInstruction().opcode!=Constants.RETURN) {
newReturnInstruction = Utility.copyInstruction(ih.getInstruction());
}
i--;
InstructionList ih = new InstructionList(InstructionConstants.NOP);
handler.append(exceptionVar.createLoad(fact));
handler.append(fact.createInstanceOf(eiieBcelType));
- BranchInstruction bi =
+ InstructionBranch bi =
InstructionFactory.createBranchInstruction(Constants.IFEQ,ih.getStart());
handler.append(bi);
handler.append(exceptionVar.createLoad(fact));
String aspectname = munger.getConcreteAspect().getName();
String ptwField = NameMangler.perTypeWithinFieldForTarget(munger.getConcreteAspect());
- entrySuccessInstructions.append(new PUSH(fact.getConstantPool(),t.getName()));
+ entrySuccessInstructions.append(InstructionFactory.PUSH(fact.getConstantPool(),t.getName()));
entrySuccessInstructions.append(fact.createInvoke(aspectname,"ajc$createAspectInstance",new ObjectType(aspectname),
new Type[]{new ObjectType("java.lang.String")},Constants.INVOKESTATIC));
boolean canSeeProceedPassedToOther = false;
InstructionHandle curr = adviceMethod.getBody().getStart();
InstructionHandle end = adviceMethod.getBody().getEnd();
- ConstantPoolGen cpg = adviceMethod.getEnclosingClass().getConstantPoolGen();
+ ConstantPool cpg = adviceMethod.getEnclosingClass().getConstantPool();
while (curr != end) {
InstructionHandle next = curr.getNext();
Instruction inst = curr.getInstruction();
InstructionHandle curr = localAdviceMethod.getBody().getStart();
InstructionHandle end = localAdviceMethod.getBody().getEnd();
- ConstantPoolGen cpg = localAdviceMethod.getEnclosingClass().getConstantPoolGen();
+ ConstantPool cpg = localAdviceMethod.getEnclosingClass().getConstantPool();
while (curr != end) {
InstructionHandle next = curr.getNext();
Instruction inst = curr.getInstruction();
- if ((inst instanceof INVOKESTATIC)
- && proceedName.equals(((INVOKESTATIC) inst).getMethodName(cpg))) {
+ if ((inst.opcode==Constants.INVOKESTATIC)
+ && proceedName.equals(((InvokeInstruction) inst).getMethodName(cpg))) {
localAdviceMethod.getBody().append(
curr,
// [TODO document @AJ code rule: don't manipulate 2 jps proceed at the same time.. in an advice body]
InstructionHandle curr = localAdviceMethod.getBody().getStart();
InstructionHandle end = localAdviceMethod.getBody().getEnd();
- ConstantPoolGen cpg = localAdviceMethod.getEnclosingClass().getConstantPoolGen();
+ ConstantPool cpg = localAdviceMethod.getEnclosingClass().getConstantPool();
while (curr != end) {
InstructionHandle next = curr.getNext();
Instruction inst = curr.getInstruction();
indexIntoObjectArrayForArguments=1;
} else {
// use local variable 0 (which is 'this' for a non-static method)
- ret.append(new ALOAD(0));
+ ret.append(InstructionFactory.createALOAD(0));
indexIntoCallbackMethodForArguments++;
}
}
Type stateType = callbackMethod.getArgumentTypes()[i];
BcelWorld.fromBcel(stateType).resolve(world);
if ("Lorg/aspectj/lang/JoinPoint;".equals(stateType.getSignature())) {
- ret.append(new ALOAD(localJp));// from localAdvice signature
+ ret.append(new InstructionLV(Constants.ALOAD,localJp));// from localAdvice signature
} else {
ret.append(InstructionFactory.createLoad(objectArrayType, localProceedArgArray));
ret.append(Utility.createConstant(fact, i-indexIntoCallbackMethodForArguments +indexIntoObjectArrayForArguments));
/*ResolvedType stateTypeX =*/
BcelWorld.fromBcel(stateType).resolve(world);
if ("Lorg/aspectj/lang/JoinPoint;".equals(stateType.getSignature())) {
- ret.append(new ALOAD(localJp));// from localAdvice signature
+ ret.append(InstructionFactory.createALOAD(localJp));// from localAdvice signature
// } else if ("Lorg/aspectj/lang/ProceedingJoinPoint;".equals(stateType.getSignature())) {
// //FIXME ALEX?
// ret.append(new ALOAD(localJp));// from localAdvice signature
stateIndex++;
}
il.append(fact.createNew(new ObjectType(constructor.getDeclaringType().getName())));
- il.append(new DUP());
+ il.append(InstructionConstants.DUP);
arrayVar.appendLoad(il, fact);
il.append(Utility.createInvoke(fact, world, constructor));
if (getKind() == PreInitialization) {
Modifier.PUBLIC,
new String[] {},
getWorld());
- InstructionFactory fact = new InstructionFactory(closureClass.getConstantPoolGen());
+ InstructionFactory fact = new InstructionFactory(closureClass.getConstantPool());
// constructor
LazyMethodGen constructor = new LazyMethodGen(Modifier.PUBLIC,
InvokeInstruction superCallInstruction =
(InvokeInstruction) superCallHandle.getInstruction();
return superCallInstruction.getArgumentTypes(
- getEnclosingClass().getConstantPoolGen());
+ getEnclosingClass().getConstantPool());
}
import java.util.Set;
import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.generic.BranchInstruction;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
import org.aspectj.apache.bcel.generic.FieldGen;
-import org.aspectj.apache.bcel.generic.INVOKESPECIAL;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
import org.aspectj.apache.bcel.generic.InstructionConstants;
import org.aspectj.apache.bcel.generic.InstructionFactory;
import org.aspectj.apache.bcel.generic.InstructionHandle;
import org.aspectj.apache.bcel.generic.InstructionList;
+import org.aspectj.apache.bcel.generic.InvokeInstruction;
import org.aspectj.apache.bcel.generic.Type;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
import org.aspectj.asm.AsmManager;
import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.weaver.patterns.DeclareAnnotation;
import org.aspectj.weaver.patterns.Pointcut;
+
//XXX addLazyMethodGen is probably bad everywhere
public class BcelTypeMunger extends ConcreteTypeMunger {
InstructionList insList = aMethod.getBody();
InstructionHandle handle = insList.getStart();
while (handle!= null) {
- if (handle.getInstruction() instanceof INVOKESPECIAL) {
- ConstantPoolGen cpg = newParentTarget.getConstantPoolGen();
- INVOKESPECIAL invokeSpecial = (INVOKESPECIAL)handle.getInstruction();
+ if (handle.getInstruction().opcode==Constants.INVOKESPECIAL) {
+ ConstantPool cpg = newParentTarget.getConstantPool();
+ InvokeInstruction invokeSpecial = (InvokeInstruction)handle.getInstruction();
if (invokeSpecial.getClassName(cpg).equals(currentParent) && invokeSpecial.getMethodName(cpg).equals("<init>")) {
// System.err.println("Transforming super call '<init>"+sp.getSignature(cpg)+"'");
/**
* Creates a nice signature for the ctor, something like "(int,Integer,String)"
*/
- private String createReadableCtorSig(ResolvedType newParent, ConstantPoolGen cpg, INVOKESPECIAL invokeSpecial) {
+ private String createReadableCtorSig(ResolvedType newParent, ConstantPool cpg, InvokeInstruction invokeSpecial) {
StringBuffer sb = new StringBuffer();
Type[] ctorArgs = invokeSpecial.getArgumentTypes(cpg);
sb.append(newParent.getClassName());
member.getModifiers(),
BcelWorld.makeBcelType(member.getReturnType()),
member.getName(),
- gen.getConstantPoolGen());
+ gen.getConstantPool());
}
FieldGen fg = makeFieldGen(gen,
AjcMemberMaker.perObjectField(gen.getType(), aspectType));
- gen.addField(fg.getField(),getSourceLocation());
+ gen.addField(fg,getSourceLocation());
Type fieldType = BcelWorld.makeBcelType(aspectType);
// Add (to the target type) the field that will hold the aspect instance
// e.g ajc$com_blah_SecurityAspect$ptwAspectInstance
FieldGen fg = makeFieldGen(gen, AjcMemberMaker.perTypeWithinField(gen.getType(), aspectType));
- gen.addField(fg.getField(),getSourceLocation());
+ gen.addField(fg,getSourceLocation());
// Add an accessor for this new field, the ajc$<aspectname>$localAspectOf() method
// e.g. "public com_blah_SecurityAspect ajc$com_blah_SecurityAspect$localAspectOf()"
if (annotationsOnRealMember!=null) {
for (int i = 0; i < annotationsOnRealMember.length; i++) {
AnnotationX annotationX = annotationsOnRealMember[i];
- Annotation a = annotationX.getBcelAnnotation();
- AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true);
- newMethod.addAnnotation(new AnnotationX(ag.getAnnotation(),weaver.getWorld()));
+ AnnotationGen a = annotationX.getBcelAnnotation();
+ AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPool(),true);
+ newMethod.addAnnotation(new AnnotationX(ag,weaver.getWorld()));
}
}
// the below loop fixes the very special (and very stupid)
if (annotationsOnRealMember!=null) {
for (int i = 0; i < annotationsOnRealMember.length; i++) {
AnnotationX annotationX = annotationsOnRealMember[i];
- Annotation a = annotationX.getBcelAnnotation();
- AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true);
- mg.addAnnotation(new AnnotationX(ag.getAnnotation(),weaver.getWorld()));
+ AnnotationGen a = annotationX.getBcelAnnotation();
+ AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPool(),true);
+ mg.addAnnotation(new AnnotationX(ag,weaver.getWorld()));
}
}
}
if (annotationsOnRealMember!=null) {
for (int i = 0; i < annotationsOnRealMember.length; i++) {
AnnotationX annotationX = annotationsOnRealMember[i];
- Annotation a = annotationX.getBcelAnnotation();
- AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true);
- mg.addAnnotation(new AnnotationX(ag.getAnnotation(),weaver.getWorld()));
+ AnnotationGen a = annotationX.getBcelAnnotation();
+ AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPool(),true);
+ mg.addAnnotation(new AnnotationX(ag,weaver.getWorld()));
}
}
}
// getfield
body.append(InstructionConstants.ALOAD_0);
body.append(Utility.createGet(fact, munger.getDelegate(weaver.getLazyClassGen().getType())));
- BranchInstruction ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
+ InstructionBranch ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
body.append(ifNonNull);
// Create and store a new instance
aspectType);
weaver.getLazyClassGen().addField(makeFieldGen(
weaver.getLazyClassGen(),
- host).getField(), null);
+ host), null);
return true;
}
if (annotationsOnRealMember!=null) {
for (int i = 0; i < annotationsOnRealMember.length; i++) {
AnnotationX annotationX = annotationsOnRealMember[i];
- Annotation a = annotationX.getBcelAnnotation();
- AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true);
- mg.addAnnotation(new AnnotationX(ag.getAnnotation(),weaver.getWorld()));
+ AnnotationGen a = annotationX.getBcelAnnotation();
+ AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPool(),true);
+ mg.addAnnotation(new AnnotationX(ag,weaver.getWorld()));
}
}
// the below loop fixes the very special (and very stupid)
if (annotationsOnRealMember!=null) {
for (int i = 0; i < annotationsOnRealMember.length; i++) {
AnnotationX annotationX = annotationsOnRealMember[i];
- Annotation a = annotationX.getBcelAnnotation();
- AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true);
+ AnnotationGen a = annotationX.getBcelAnnotation();
+ AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPool(),true);
fg.addAnnotation(ag);
}
}
- gen.addField(fg.getField(),getSourceLocation());
+ gen.addField(fg,getSourceLocation());
}
return true;
if (annotationsOnRealMember!=null) {
for (int i = 0; i < annotationsOnRealMember.length; i++) {
AnnotationX annotationX = annotationsOnRealMember[i];
- Annotation a = annotationX.getBcelAnnotation();
- AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true);
+ AnnotationGen a = annotationX.getBcelAnnotation();
+ AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPool(),true);
fg.addAnnotation(ag);
}
}
- gen.addField(fg.getField(),getSourceLocation());
+ gen.addField(fg,getSourceLocation());
//this uses a shadow munger to add init method to constructors
//weaver.getShadowMungers().add(makeInitCallShadowMunger(initMethod));
wsi.getUnwovenClassFileData(wovenJavaClass.getBytes()));
world.storeClass(unwovenJavaClass);
classType.setJavaClass(unwovenJavaClass);
+ if (world.isRunMinimalMemory() && world.isXnoInline())
+ classType.evictWeavingState(); // CUSTARD
// classType.setJavaClass(Utility.makeJavaClass(classType.getJavaClass().getFileName(), wsi.getUnwovenClassFileData(classType.getJavaClass().getBytes())));
}
import java.util.Properties;
import java.util.StringTokenizer;
+import org.aspectj.apache.bcel.Constants;
import org.aspectj.apache.bcel.classfile.Attribute;
import org.aspectj.apache.bcel.classfile.ClassParser;
import org.aspectj.apache.bcel.classfile.JavaClass;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
import org.aspectj.apache.bcel.classfile.Method;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.generic.ANEWARRAY;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
import org.aspectj.apache.bcel.generic.FieldInstruction;
-import org.aspectj.apache.bcel.generic.GETSTATIC;
import org.aspectj.apache.bcel.generic.INVOKEINTERFACE;
-import org.aspectj.apache.bcel.generic.INVOKESPECIAL;
-import org.aspectj.apache.bcel.generic.INVOKESTATIC;
import org.aspectj.apache.bcel.generic.Instruction;
import org.aspectj.apache.bcel.generic.InstructionHandle;
import org.aspectj.apache.bcel.generic.InvokeInstruction;
-import org.aspectj.apache.bcel.generic.MONITORENTER;
-import org.aspectj.apache.bcel.generic.MONITOREXIT;
import org.aspectj.apache.bcel.generic.MULTIANEWARRAY;
-import org.aspectj.apache.bcel.generic.NEWARRAY;
import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.PUTSTATIC;
import org.aspectj.apache.bcel.generic.Type;
import org.aspectj.apache.bcel.util.ClassLoaderRepository;
import org.aspectj.apache.bcel.util.ClassPath;
}
-
-
+
private static List getPathEntries(String s) {
List ret = new ArrayList();
StringTokenizer tok = new StringTokenizer(s, File.pathSeparator);
// TODO Alex do we need to call org.aspectj.apache.bcel.Repository.setRepository(delegate);
// if so, how can that be safe in J2EE ?? (static stuff in Bcel)
}
-
+
/**
* Build a World from a ClassLoader, for LTW support
*
}
public static Member makeFieldJoinPointSignature(LazyClassGen cg, FieldInstruction fi) {
- ConstantPoolGen cpg = cg.getConstantPoolGen();
+ ConstantPool cpg = cg.getConstantPool();
return
MemberImpl.field(
fi.getClassName(cpg),
- (fi instanceof GETSTATIC || fi instanceof PUTSTATIC)
+ (fi.opcode==Constants.GETSTATIC || fi.opcode==Constants.PUTSTATIC)
? Modifier.STATIC: 0,
fi.getName(cpg),
fi.getSignature(cpg));
}
public Member makeJoinPointSignatureForMonitorEnter(LazyClassGen cg,InstructionHandle h) {
- MONITORENTER i = (MONITORENTER)h.getInstruction();
+ Instruction i = h.getInstruction();
return MemberImpl.monitorEnter();
}
public Member makeJoinPointSignatureForMonitorExit(LazyClassGen cg,InstructionHandle h) {
- MONITOREXIT i = (MONITOREXIT)h.getInstruction();
+ Instruction i = h.getInstruction();
return MemberImpl.monitorExit();
}
public Member makeJoinPointSignatureForArrayConstruction(LazyClassGen cg, InstructionHandle handle) {
Instruction i = handle.getInstruction();
- ConstantPoolGen cpg = cg.getConstantPoolGen();
+ ConstantPool cpg = cg.getConstantPool();
Member retval = null;
- if (i instanceof ANEWARRAY) {
- ANEWARRAY arrayInstruction = (ANEWARRAY)i;
- Type ot = arrayInstruction.getType(cpg);
+ if (i.opcode==Constants.ANEWARRAY) {
+// ANEWARRAY arrayInstruction = (ANEWARRAY)i;
+ Type ot = i.getType(cpg);
UnresolvedType ut = fromBcel(ot);
ut = UnresolvedType.makeArray(ut,1);
retval = MemberImpl.method(ut, Modifier.PUBLIC, ResolvedType.VOID, "<init>", new ResolvedType[]{ResolvedType.INT});
for (int ii=0;ii<dimensions;ii++) parms[ii] = ResolvedType.INT;
retval = MemberImpl.method(ut, Modifier.PUBLIC, ResolvedType.VOID, "<init>", parms);
- } else if (i instanceof NEWARRAY) {
- NEWARRAY arrayInstruction = (NEWARRAY)i;
- Type ot = arrayInstruction.getType();
+ } else if (i.opcode==Constants.NEWARRAY) {
+// NEWARRAY arrayInstruction = (NEWARRAY)i;
+ Type ot = i.getType();
UnresolvedType ut = fromBcel(ot);
retval = MemberImpl.method(ut, Modifier.PUBLIC, ResolvedType.VOID, "<init>", new ResolvedType[]{ResolvedType.INT});
} else {
}
public Member makeJoinPointSignatureForMethodInvocation(LazyClassGen cg, InvokeInstruction ii) {
- ConstantPoolGen cpg = cg.getConstantPoolGen();
+ ConstantPool cpg = cg.getConstantPool();
String name = ii.getName(cpg);
String declaring = ii.getClassName(cpg);
UnresolvedType declaringType = null;
int modifier =
(ii instanceof INVOKEINTERFACE)
? Modifier.INTERFACE
- : (ii instanceof INVOKESTATIC)
+ : (ii.opcode==Constants.INVOKESTATIC)
? Modifier.STATIC
- : (ii instanceof INVOKESPECIAL && ! name.equals("<init>"))
+ : (ii.opcode==Constants.INVOKESPECIAL && ! name.equals("<init>"))
? Modifier.PRIVATE
: 0;
// in Java 1.4 and after, static method call of super class within subclass method appears
// as declared by the subclass in the bytecode - but they are not
// see #104212
- if (ii instanceof INVOKESTATIC) {
+ if (ii.opcode==Constants.INVOKESTATIC) {
ResolvedType appearsDeclaredBy = resolve(declaring);
// look for the method there
for (Iterator iterator = appearsDeclaredBy.getMethods(); iterator.hasNext();) {
}
public void clear() {
- throw new RuntimeException("Not implemented");
+ delegate.clear();
+// throw new RuntimeException("Not implemented");
}
// @Override
if (!jc.isClass()) {
return false;
}
- Annotation anns[] = jc.getAnnotations();
+ AnnotationGen anns[] = jc.getAnnotations();
if (anns.length == 0) {
return false;
}
boolean couldBeAtAspectJStyle = false;
for (int i = 0; i < anns.length; i++) {
- Annotation ann = anns[i];
+ AnnotationGen ann = anns[i];
if ("Lorg/aspectj/lang/annotation/Aspect;".equals(ann.getTypeSignature())) {
couldBeAtAspectJStyle = true;
}
import org.aspectj.apache.bcel.classfile.Signature;
import org.aspectj.apache.bcel.classfile.Synthetic;
import org.aspectj.apache.bcel.classfile.Unknown;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
import org.aspectj.apache.bcel.generic.BasicType;
import org.aspectj.apache.bcel.generic.ClassGen;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
import org.aspectj.apache.bcel.generic.FieldGen;
import org.aspectj.apache.bcel.generic.InstructionConstants;
import org.aspectj.apache.bcel.generic.InstructionFactory;
import org.aspectj.apache.bcel.generic.InstructionHandle;
import org.aspectj.apache.bcel.generic.InstructionList;
import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.PUSH;
-import org.aspectj.apache.bcel.generic.RETURN;
import org.aspectj.apache.bcel.generic.Type;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.SourceLocation;
import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
+
/**
* Lazy lazy lazy.
* We don't unpack the underlying class unless necessary. Things
private BcelObjectType myType; // XXX is not set for types we create
private ClassGen myGen;
- private ConstantPoolGen constantPoolGen;
+ private ConstantPool constantPoolGen;
private World world;
private String packageName = null;
+ private List /*BcelField*/ fields = new ArrayList();
private List /*LazyMethodGen*/ methodGens = new ArrayList();
private List /*LazyClassGen*/ classGens = new ArrayList();
private List /*AnnotationGen*/ annotations = new ArrayList();
byte[] bytes = Utility.stringToUTF(data);
int length = bytes.length;
- return new Unknown(nameIndex, length, bytes, constantPoolGen.getConstantPool());
+ return new Unknown(nameIndex, length, bytes, constantPoolGen);
}
// private LazyClassGen() {}
// Do we need to calculate an SUID and add it?
if (!hasSerialVersionUIDField && world.isAddSerialVerUID()) {
calculatedSerialVersionUID = myGen.getSUID();
- Field fg = new FieldGen(
+ FieldGen fg = new FieldGen(
Constants.ACC_PRIVATE|Constants.ACC_FINAL|Constants.ACC_STATIC,
- BasicType.LONG,"serialVersionUID",getConstantPoolGen()).getField();
+ BasicType.LONG,"serialVersionUID",getConstantPool());
addField(fg);
hasSerialVersionUIDField=true;
serialVersionUIDRequiresInitialization=true;
}
}
- Method[] methods = myGen.getMethods();
- for (int i = 0; i < methods.length; i++) {
- addMethodGen(new LazyMethodGen(methods[i], this));
- }
-
+ ResolvedMember[] methods = myType.getDeclaredMethods();
+ for (int i=0; i<methods.length; i++) {
+ addMethodGen(new LazyMethodGen((BcelMethod)methods[i],this));
+ }
+
+ ResolvedMember[] fields = myType.getDeclaredFields();
+ for (int i=0; i<fields.length; i++) {
+ this.fields.add((BcelField)fields[i]);
+ }
}
public static boolean hasSerialVersionUIDField (ResolvedType type) {
// ----
public String getInternalClassName() {
- return getConstantPoolGen().getConstantPool().getConstantString(
- myGen.getClassNameIndex(),
- Constants.CONSTANT_Class);
+ return getConstantPool().getConstantString_CONSTANTClass(myGen.getClassNameIndex());
+ //getConstantPool().getConstantString(
+ // myGen.getClassNameIndex(),
+ // Constants.CONSTANT_Class);
}
methodGens.add(gen);
if (highestLineNumber < gen.highestLineNumber) highestLineNumber = gen.highestLineNumber;
}
-
+
public void addMethodGen(LazyMethodGen gen, ISourceLocation sourceLocation) {
addMethodGen(gen);
if (!gen.getMethod().isPrivate()) {
}
- public void errorOnAddedField (Field field, ISourceLocation sourceLocation) {
+ public void errorOnAddedField (FieldGen field, ISourceLocation sourceLocation) {
if (isSerializable && !hasSerialVersionUIDField) {
getWorld().getLint().serialVersionUIDBroken.signal(
new String[] {
return methodGens; //???Collections.unmodifiableList(methodGens);
}
- // FIXME asc Should be collection returned here
- public Field[] getFieldGens() {
- return myGen.getFields();
+ public List/*BcelField*/ getFieldGens() {
+ return fields;
+ // return myGen.getFields();
}
- public Field getField(String name) {
- Field[] allFields = myGen.getFields();
- if (allFields==null) return null;
- for (int i = 0; i < allFields.length; i++) {
- Field field = allFields[i];
- if (field.getName().equals(name)) return field;
- }
- return null;
- }
+// public Field getField(String name) {
+// Field[] allFields = myGen.getFields();
+// if (allFields==null) return null;
+// for (int i = 0; i < allFields.length; i++) {
+// Field field = allFields[i];
+// if (field.getName().equals(name)) return field;
+// }
+// return null;
+// }
// FIXME asc How do the ones on the underlying class surface if this just returns new ones added?
// FIXME asc ...although no one calls this right now !
}
private void writeBack(BcelWorld world) {
- if (getConstantPoolGen().getSize() > Short.MAX_VALUE) {
+ if (getConstantPool().getSize() > Short.MAX_VALUE) {
reportClassTooBigProblem();
return;
}
AnnotationGen element = (AnnotationGen) iter.next();
myGen.addAnnotation(element);
}
-// Attribute[] annAttributes = org.aspectj.apache.bcel.classfile.Utility.getAnnotationAttributes(getConstantPoolGen(),annotations);
+// Attribute[] annAttributes = org.aspectj.apache.bcel.classfile.Utility.getAnnotationAttributes(getConstantPool(),annotations);
// for (int i = 0; i < annAttributes.length; i++) {
// Attribute attribute = annAttributes[i];
// System.err.println("Adding attribute for "+attribute);
if (attribute.getName().equals("org.aspectj.weaver.WeaverVersion")) hasVersionAttribute=true;
}
if (!hasVersionAttribute)
- myGen.addAttribute(BcelAttributes.bcelAttribute(new AjAttribute.WeaverVersionInfo(),getConstantPoolGen()));
+ myGen.addAttribute(BcelAttributes.bcelAttribute(new AjAttribute.WeaverVersionInfo(),getConstantPool()));
if (myType != null && myType.getWeaverState() != null) {
myGen.addAttribute(BcelAttributes.bcelAttribute(
new AjAttribute.WeaverState(myType.getWeaverState()),
- getConstantPoolGen()));
+ getConstantPool()));
}
//FIXME ATAJ needed only for slow Aspects.aspectOf() - keep or remove
// }
addAjcInitializers();
-
- int len = methodGens.size();
- myGen.setMethods(new Method[0]);
-
+
calculateSourceDebugExtensionOffsets();
+
+ int len = methodGens.size();
+ myGen.setMethods(Method.NoMethods);
for (int i = 0; i < len; i++) {
LazyMethodGen gen = (LazyMethodGen) methodGens.get(i);
// we skip empty clinits
if (isEmptyClinit(gen)) continue;
myGen.addMethod(gen.getMethod());
}
+ len = fields.size();
+ myGen.setFields(Field.NoFields);
+ for (int i = 0; i < len; i++) {
+ BcelField gen = (BcelField) fields.get(i);
+ myGen.addField(gen.getField(this.constantPoolGen));
+ }
+
if (inlinedFiles.size() != 0) {
if (hasSourceDebugExtensionAttribute(myGen)) {
world.showMessage(
private Signature createSignatureAttribute(String signature) {
int nameIndex = constantPoolGen.addUtf8("Signature");
int sigIndex = constantPoolGen.addUtf8(signature);
- return new Signature(nameIndex,2,sigIndex,constantPoolGen.getConstantPool());
+ return new Signature(nameIndex,2,sigIndex,constantPoolGen);
}
/**
}
private static boolean hasSourceDebugExtensionAttribute(ClassGen gen) {
- ConstantPoolGen pool = gen.getConstantPool();
+ ConstantPool pool = gen.getConstantPool();
Attribute[] attrs = gen.getAttributes();
for (int i = 0; i < attrs.length; i++) {
if ("SourceDebugExtension"
//System.err.println("checking clinig: " + gen);
InstructionHandle start = gen.getBody().getStart();
while (start != null) {
- if (Range.isRangeHandle(start) || (start.getInstruction() instanceof RETURN)) {
+ if (Range.isRangeHandle(start) || (start.getInstruction().opcode==Constants.RETURN)) {
start = start.getNext();
} else {
return false;
return true;
}
- public ConstantPoolGen getConstantPoolGen() {
+ public ConstantPool getConstantPool() {
return constantPoolGen;
}
} else {
jpType = isEnclosingJp?enclosingStaticTjpType:staticTjpType;
}
- ret = new FieldGen(modifiers,jpType,"ajc$tjp_" + tjpFields.size(),getConstantPoolGen()).getField();
- addField(ret);
+ FieldGen fGen = new FieldGen(modifiers,jpType,"ajc$tjp_" + tjpFields.size(),getConstantPool());
+ addField(fGen);
+ ret = fGen.getField();
tjpFields.put(shadow, ret);
return ret;
}
// Modifier.PRIVATE | Modifier.FINAL | Modifier.STATIC,
// classType,
// "aj$class",
-// getConstantPoolGen()).getField();
+// getConstantPool()).getField();
// addField(ajClassField);
//
// InstructionList il = new InstructionList();
-// il.append(new PUSH(getConstantPoolGen(), getClassName()));
+// il.append(new PUSH(getConstantPool(), getClassName()));
// il.append(fact.createInvoke("java.lang.Class", "forName", classType,
// new Type[] {Type.STRING}, Constants.INVOKESTATIC));
// il.append(fact.createFieldAccess(getClassName(), ajClassField.getName(),
if (il==null) {
il= new InstructionList();
}
- il.append(new PUSH(getConstantPoolGen(),calculatedSerialVersionUID));
+ il.append(InstructionFactory.PUSH(getConstantPool(),calculatedSerialVersionUID));
il.append(getFactory().createFieldAccess(getClassName(), "serialVersionUID", BasicType.LONG, Constants.PUTSTATIC));
}
list.append(fact.createNew(factoryType));
list.append(InstructionFactory.createDup(1));
- list.append(new PUSH(getConstantPoolGen(), getFileName()));
+ list.append(InstructionFactory.PUSH(getConstantPool(), getFileName()));
// load the current Class object
//XXX check that this works correctly for inners/anonymous
- list.append(new PUSH(getConstantPoolGen(), getClassName()));
+ list.append(InstructionFactory.PUSH(getConstantPool(), getClassName()));
//XXX do we need to worry about the fact the theorectically this could throw
//a ClassNotFoundException
list.append(fact.createInvoke("java.lang.Class", "forName", classType,
list.append(InstructionFactory.createLoad(factoryType, 0));
// load the kind
- list.append(new PUSH(getConstantPoolGen(), shadow.getKind().getName()));
+ list.append(InstructionFactory.PUSH(getConstantPool(), shadow.getKind().getName()));
// create the signature
list.append(InstructionFactory.createLoad(factoryType, 0));
if (world.isTargettingAspectJRuntime12()) { // TAG:SUPPORTING12: We didn't have optimized factory methods in 1.2
- list.append(new PUSH(getConstantPoolGen(), sig.getSignatureString(shadow.getWorld())));
+ list.append(InstructionFactory.PUSH(getConstantPool(), sig.getSignatureString(shadow.getWorld())));
list.append(fact.createInvoke(factoryType.getClassName(),
sig.getSignatureMakerName(),
new ObjectType(sig.getSignatureType()),
} else if (sig.getKind().equals(Member.METHOD)) {
BcelWorld w = shadow.getWorld();
// For methods, push the parts of the signature on.
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getModifiers(w))));
- list.append(new PUSH(getConstantPoolGen(),sig.getName()));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterTypes())));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterNames(w))));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getExceptions(w))));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getReturnType())));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getModifiers(w))));
+ list.append(InstructionFactory.PUSH(getConstantPool(),sig.getName()));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterTypes())));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterNames(w))));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getExceptions(w))));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getReturnType())));
// And generate a call to the variant of makeMethodSig() that takes 7 strings
list.append(fact.createInvoke(factoryType.getClassName(),
sig.getSignatureMakerName(),
new Type[] { Type.STRING,Type.STRING,Type.STRING,Type.STRING,Type.STRING,Type.STRING,Type.STRING },
Constants.INVOKEVIRTUAL));
} else if (sig.getKind().equals(Member.MONITORENTER)) {
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
list.append(fact.createInvoke(factoryType.getClassName(),
sig.getSignatureMakerName(),
new ObjectType(sig.getSignatureType()),
new Type[] { Type.STRING},
Constants.INVOKEVIRTUAL));
} else if (sig.getKind().equals(Member.MONITOREXIT)) {
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
list.append(fact.createInvoke(factoryType.getClassName(),
sig.getSignatureMakerName(),
new ObjectType(sig.getSignatureType()),
Constants.INVOKEVIRTUAL));
} else if (sig.getKind().equals(Member.HANDLER)) {
BcelWorld w = shadow.getWorld();
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterTypes())));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterNames(w))));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterTypes())));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterNames(w))));
list.append(fact.createInvoke(factoryType.getClassName(),
sig.getSignatureMakerName(),
new ObjectType(sig.getSignatureType()),
BcelWorld w = shadow.getWorld();
if (w.isJoinpointArrayConstructionEnabled() && sig.getDeclaringType().isArray()) {
// its the magical new jp
- list.append(new PUSH(getConstantPoolGen(),makeString(Modifier.PUBLIC)));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterTypes())));
- list.append(new PUSH(getConstantPoolGen(),""));//makeString("")));//sig.getParameterNames(w))));
- list.append(new PUSH(getConstantPoolGen(),""));//makeString("")));//sig.getExceptions(w))));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(Modifier.PUBLIC)));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterTypes())));
+ list.append(InstructionFactory.PUSH(getConstantPool(),""));//makeString("")));//sig.getParameterNames(w))));
+ list.append(InstructionFactory.PUSH(getConstantPool(),""));//makeString("")));//sig.getExceptions(w))));
list.append(fact.createInvoke(factoryType.getClassName(),
sig.getSignatureMakerName(),
new ObjectType(sig.getSignatureType()),
new Type[] { Type.STRING, Type.STRING, Type.STRING, Type.STRING, Type.STRING },
Constants.INVOKEVIRTUAL));
} else {
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getModifiers(w))));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterTypes())));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterNames(w))));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getExceptions(w))));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getModifiers(w))));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterTypes())));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterNames(w))));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getExceptions(w))));
list.append(fact.createInvoke(factoryType.getClassName(),
sig.getSignatureMakerName(),
new ObjectType(sig.getSignatureType()),
}
} else if(sig.getKind().equals(Member.FIELD)) {
BcelWorld w = shadow.getWorld();
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getModifiers(w))));
- list.append(new PUSH(getConstantPoolGen(),sig.getName()));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getReturnType())));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getModifiers(w))));
+ list.append(InstructionFactory.PUSH(getConstantPool(),sig.getName()));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getReturnType())));
list.append(fact.createInvoke(factoryType.getClassName(),
sig.getSignatureMakerName(),
new ObjectType(sig.getSignatureType()),
Constants.INVOKEVIRTUAL));
} else if(sig.getKind().equals(Member.ADVICE)) {
BcelWorld w = shadow.getWorld();
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getModifiers(w))));
- list.append(new PUSH(getConstantPoolGen(),sig.getName()));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterTypes())));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getParameterNames(w))));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getExceptions(w))));
- list.append(new PUSH(getConstantPoolGen(),makeString((sig.getReturnType()))));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getModifiers(w))));
+ list.append(InstructionFactory.PUSH(getConstantPool(),sig.getName()));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterTypes())));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getParameterNames(w))));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getExceptions(w))));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString((sig.getReturnType()))));
list.append(fact.createInvoke(factoryType.getClassName(),
sig.getSignatureMakerName(),
new ObjectType(sig.getSignatureType()),
Constants.INVOKEVIRTUAL));
} else if(sig.getKind().equals(Member.STATIC_INITIALIZATION)) {
BcelWorld w = shadow.getWorld();
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getModifiers(w))));
- list.append(new PUSH(getConstantPoolGen(),makeString(sig.getDeclaringType())));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getModifiers(w))));
+ list.append(InstructionFactory.PUSH(getConstantPool(),makeString(sig.getDeclaringType())));
list.append(fact.createInvoke(factoryType.getClassName(),
sig.getSignatureMakerName(),
new ObjectType(sig.getSignatureType()),
new Type[] { Type.STRING, Type.STRING },
Constants.INVOKEVIRTUAL));
} else {
- list.append(new PUSH(getConstantPoolGen(), sig.getSignatureString(shadow.getWorld())));
+ list.append(InstructionFactory.PUSH(getConstantPool(), sig.getSignatureString(shadow.getWorld())));
list.append(fact.createInvoke(factoryType.getClassName(),
sig.getSignatureMakerName(),
new ObjectType(sig.getSignatureType()),
return myGen.getFileName();
}
- private void addField(Field field) {
- myGen.addField(field);
+ // for *new* fields
+ private void addField(FieldGen field) {
makeSyntheticAndTransientIfNeeded(field);
+ BcelField bcelField = null;
+ if (getBcelObjectType() != null) {
+ bcelField = new BcelField(getBcelObjectType(),field.getField());
+ } else {
+ bcelField = new BcelField(getName(),field.getField(),world);
+ }
+ fields.add(bcelField);
+// myGen.addField(field.getField());
}
- private void makeSyntheticAndTransientIfNeeded(Field field) {
+ private void makeSyntheticAndTransientIfNeeded(FieldGen field) {
if (field.getName().startsWith(NameMangler.PREFIX) &&
!field.getName().startsWith("ajc$interField$")) {
// it's an aj added field
}
if (!hasSyntheticAttribute(field.getAttributes())) {
// belt and braces, do the attribute even on Java 5 in addition to the modifier flag
- Attribute[] oldAttrs = field.getAttributes();
- Attribute[] newAttrs = new Attribute[oldAttrs.length + 1];
- System.arraycopy(oldAttrs, 0, newAttrs, 0, oldAttrs.length);
- ConstantPoolGen cpg = myGen.getConstantPool();
+// Attribute[] oldAttrs = field.getAttributes();
+// Attribute[] newAttrs = new Attribute[oldAttrs.length + 1];
+// System.arraycopy(oldAttrs, 0, newAttrs, 0, oldAttrs.length);
+ ConstantPool cpg = myGen.getConstantPool();
int index = cpg.addUtf8("Synthetic");
- Attribute synthetic = new Synthetic(index, 0, new byte[0], cpg.getConstantPool());
- newAttrs[newAttrs.length - 1] = synthetic;
- field.setAttributes(newAttrs);
+ Attribute synthetic = new Synthetic(index, 0, new byte[0], cpg);
+ field.addAttribute(synthetic);
+// newAttrs[newAttrs.length - 1] = synthetic;
+// field.setAttributes(newAttrs);
}
}
}
- private boolean hasSyntheticAttribute(Attribute[] attributes) {
+ private boolean hasSyntheticAttribute(Attribute[] attributes) {
for (int i = 0; i < attributes.length; i++) {
if (attributes[i].getName().equals("Synthetic")) {
return true;
}
return false;
}
-
- public void replaceField(Field oldF, Field newF){
- myGen.removeField(oldF);
- myGen.addField(newF);
- }
- public void addField(Field field, ISourceLocation sourceLocation) {
+ public void addField(FieldGen field, ISourceLocation sourceLocation) {
addField(field);
if (!(field.isPrivate()
&& (field.isStatic() || field.isTransient()))) {
return false;
}
- public void addAnnotation(Annotation a) {
+ public void addAnnotation(AnnotationGen a) {
if (!hasAnnotation(UnresolvedType.forSignature(a.getTypeSignature()))) {
- annotations.add(new AnnotationGen(a,getConstantPoolGen(),true));
+ annotations.add(new AnnotationGen(a,getConstantPool(),true));
}
}
*/
public String allocateField(String prefix) {
int highestAllocated = -1;
- Field[] fs = getFieldGens();
- for (int i = 0; i < fs.length; i++) {
- Field field = fs[i];
+ List/*BcelField*/ fs = getFieldGens();
+ for (int i = 0; i < fs.size(); i++) {
+ BcelField field = (BcelField)fs.get(i);
if (field.getName().startsWith(prefix)) {
try {
int num = Integer.parseInt(field.getName().substring(prefix.length()));
import org.aspectj.apache.bcel.classfile.ConstantPool;
import org.aspectj.apache.bcel.classfile.Method;
import org.aspectj.apache.bcel.classfile.Synthetic;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
import org.aspectj.apache.bcel.generic.BranchHandle;
-import org.aspectj.apache.bcel.generic.BranchInstruction;
-import org.aspectj.apache.bcel.generic.CPInstruction;
import org.aspectj.apache.bcel.generic.ClassGenException;
import org.aspectj.apache.bcel.generic.CodeExceptionGen;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
import org.aspectj.apache.bcel.generic.Instruction;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
import org.aspectj.apache.bcel.generic.InstructionHandle;
import org.aspectj.apache.bcel.generic.InstructionList;
+import org.aspectj.apache.bcel.generic.InstructionSelect;
import org.aspectj.apache.bcel.generic.InstructionTargeter;
import org.aspectj.apache.bcel.generic.LineNumberGen;
import org.aspectj.apache.bcel.generic.LineNumberTag;
import org.aspectj.apache.bcel.generic.LocalVariableGen;
-import org.aspectj.apache.bcel.generic.LocalVariableInstruction;
import org.aspectj.apache.bcel.generic.LocalVariableTag;
import org.aspectj.apache.bcel.generic.MethodGen;
import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.Select;
import org.aspectj.apache.bcel.generic.Tag;
import org.aspectj.apache.bcel.generic.Type;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.MessageUtil;
}
}
}
+ public LazyMethodGen(BcelMethod m,LazyClassGen enclosingClass) {
+ savedMethod = m.getMethod();
+ this.enclosingClass = enclosingClass;
+ if (!(m.isAbstract() || m.isNative()) && savedMethod.getCode() == null) {
+ throw new RuntimeException("bad non-abstract method with no code: " + m + " on " + enclosingClass);
+ }
+ if ((m.isAbstract() || m.isNative()) && savedMethod.getCode() != null) {
+ throw new RuntimeException("bad abstract method with code: " + m + " on " + enclosingClass);
+ }
+ //this.memberView = new BcelMethod(enclosingClass.getBcelObjectType(), m);
+ this.memberView = m;
+ this.accessFlags = savedMethod.getAccessFlags();
+ this.name = m.getName();
+
+ // @AJ advice are not inlined by default since requires further analysis
+ // and weaving ordering control
+ // TODO AV - improve - note: no room for improvement as long as aspects are reweavable
+ // since the inlined version with wrappers and an to be done annotation to keep
+ // inline state will be garbaged due to reweavable impl
+ if (memberView != null && isAdviceMethod()) {
+ if (enclosingClass.getType().isAnnotationStyleAspect()) {
+ //TODO we could check for @Around advice as well
+ this.canInline = false;
+ }
+ }
+
+ }
public boolean hasDeclaredLineNumberInfo() {
return (memberView != null && memberView.hasDeclarationLineNumberInfo());
//System.err.println("initializing: " + getName() + ", " + enclosingClass.getName() + ", " + returnType + ", " + savedMethod);
- MethodGen gen = new MethodGen(savedMethod, enclosingClass.getName(), enclosingClass.getConstantPoolGen(),avoidUseOfBcelGenObjects);
+ MethodGen gen = new MethodGen(savedMethod, enclosingClass.getName(), enclosingClass.getConstantPool(),avoidUseOfBcelGenObjects);
this.returnType = gen.getReturnType();
this.argumentTypes = gen.getArgumentTypes();
List ranges;
BodyPrinter(PrintStream out) {
- this.pool = enclosingClass.getConstantPoolGen().getConstantPool();
+ this.pool = enclosingClass.getConstantPool();
this.body = getBody();
this.out = out;
}
if (r.getStart() == ih) {
insertHandler(r, exnTable);
}
- } else if (t instanceof BranchInstruction) {
+ } else if (t instanceof InstructionBranch) {
if (pendingLabel == null) {
pendingLabel = "L" + lcounter++;
}
printLabel((String) labelMap.get(h), depth);
Instruction inst = h.getInstruction();
- if (inst instanceof CPInstruction) {
- CPInstruction cpinst = (CPInstruction) inst;
- out.print(Constants.OPCODE_NAMES[cpinst.getOpcode()].toUpperCase());
+ if (inst.isConstantPoolInstruction()) {
+ out.print(Constants.OPCODE_NAMES[inst.opcode].toUpperCase());
out.print(" ");
- out.print(pool.constantToString(pool.getConstant(cpinst.getIndex())));
- } else if (inst instanceof Select) {
- Select sinst = (Select) inst;
- out.println(Constants.OPCODE_NAMES[sinst.getOpcode()].toUpperCase());
+ out.print(pool.constantToString(pool.getConstant(inst.getIndex())));
+ } else if (inst instanceof InstructionSelect) {
+ InstructionSelect sinst = (InstructionSelect) inst;
+ out.println(Constants.OPCODE_NAMES[sinst.opcode].toUpperCase());
int[] matches = sinst.getMatchs();
InstructionHandle[] targets = sinst.getTargets();
InstructionHandle defaultTarget = sinst.getTarget();
out.print(" ");
out.print("default: \t");
out.print(labelMap.get(defaultTarget));
- } else if (inst instanceof BranchInstruction) {
- BranchInstruction brinst = (BranchInstruction) inst;
+ } else if (inst instanceof InstructionBranch) {
+ InstructionBranch brinst = (InstructionBranch) inst;
out.print(Constants.OPCODE_NAMES[brinst.getOpcode()].toUpperCase());
out.print(" ");
out.print(labelMap.get(brinst.getTarget()));
- } else if (inst instanceof LocalVariableInstruction) {
- LocalVariableInstruction lvinst = (LocalVariableInstruction) inst;
+ } else if (inst.isLocalVariableInstruction()) {
+ //LocalVariableInstruction lvinst = (LocalVariableInstruction) inst;
out.print(inst.toString(false).toUpperCase());
- int index = lvinst.getIndex();
+ int index = inst.getIndex();
LocalVariableTag tag = getLocalVariableTag(h, index);
if (tag != null) {
out.print(" // ");
getName(),
getEnclosingClass().getName(),
new InstructionList(),
- getEnclosingClass().getConstantPoolGen());
+ getEnclosingClass().getConstantPool());
for (int i = 0, len = declaredExceptions.length; i < len; i++) {
gen.addException(declaredExceptions[i]);
}
if (memberView!=null && memberView.getAnnotations()!=null && memberView.getAnnotations().length!=0) {
AnnotationX[] ans = memberView.getAnnotations();
for (int i = 0, len = ans.length; i < len; i++) {
- Annotation a= ans[i].getBcelAnnotation();
+ AnnotationGen a= ans[i].getBcelAnnotation();
gen.addAnnotation(new AnnotationGen(a,gen.getConstantPool(),true));
}
}
gen.setModifiers(gen.getModifiers() | ACC_SYNTHETIC);
}
// belt and braces, do the attribute even on Java 5 in addition to the modifier flag
- ConstantPoolGen cpg = gen.getConstantPool();
+ ConstantPool cpg = gen.getConstantPool();
int index = cpg.addUtf8("Synthetic");
- gen.addAttribute(new Synthetic(index, 0, new byte[0], cpg.getConstantPool()));
+ gen.addAttribute(new Synthetic(index, 0, new byte[0], cpg));
}
if (hasBody()) {
Instruction oldInstruction = oldInstructionHandle.getInstruction();
Instruction newInstruction = newInstructionHandle.getInstruction();
- if (oldInstruction instanceof BranchInstruction) {
+ if (oldInstruction instanceof InstructionBranch) {
handleBranchInstruction(map, oldInstruction, newInstruction);
}
}
private void handleBranchInstruction(Map map, Instruction oldInstruction, Instruction newInstruction) {
- BranchInstruction oldBranchInstruction = (BranchInstruction) oldInstruction;
- BranchInstruction newBranchInstruction = (BranchInstruction) newInstruction;
+ InstructionBranch oldBranchInstruction = (InstructionBranch) oldInstruction;
+ InstructionBranch newBranchInstruction = (InstructionBranch) newInstruction;
InstructionHandle oldTarget = oldBranchInstruction.getTarget(); // old target
// try {
// throw e;
// }
- if (oldBranchInstruction instanceof Select) {
+ if (oldBranchInstruction instanceof InstructionSelect) {
// Either LOOKUPSWITCH or TABLESWITCH
- InstructionHandle[] oldTargets = ((Select) oldBranchInstruction).getTargets();
- InstructionHandle[] newTargets = ((Select) newBranchInstruction).getTargets();
+ InstructionHandle[] oldTargets = ((InstructionSelect) oldBranchInstruction).getTargets();
+ InstructionHandle[] newTargets = ((InstructionSelect) newBranchInstruction).getTargets();
for (int k = oldTargets.length - 1; k >= 0; k--) {
// Update all targets
Instruction i = ih.getInstruction();
Instruction c = Utility.copyInstruction(i);
- if (c instanceof BranchInstruction)
- map.put(ih, intoList.append((BranchInstruction) c));
+ if (c instanceof InstructionBranch)
+ map.put(ih, intoList.append((InstructionBranch) c));
else
map.put(ih, intoList.append(c));
}
Stack ranges = new Stack();
for (InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) {
body.add(ih);
- if (ih.getInstruction() instanceof BranchInstruction) {
+ if (ih.getInstruction() instanceof InstructionBranch) {
body.add(ih.getInstruction());
}
}
private static void assertGoodHandle(InstructionHandle ih, Set body, Stack ranges, String from) {
Instruction inst = ih.getInstruction();
- if ((inst instanceof BranchInstruction) ^ (ih instanceof BranchHandle)) {
+ if ((inst instanceof InstructionBranch) ^ (ih instanceof BranchHandle)) {
throw new BCException("bad instruction/handle pair in " + from);
}
if (Range.isRangeHandle(ih)) {
assertGoodRangeHandle(ih, body, ranges, from);
- } else if (inst instanceof BranchInstruction) {
- assertGoodBranchInstruction((BranchHandle) ih, (BranchInstruction) inst, body, ranges, from);
+ } else if (inst instanceof InstructionBranch) {
+ assertGoodBranchInstruction((BranchHandle) ih, (InstructionBranch) inst, body, ranges, from);
}
}
private static void assertGoodBranchInstruction(
BranchHandle ih,
- BranchInstruction inst,
+ InstructionBranch inst,
Set body,
Stack ranges,
String from)
InstructionHandle target = ih.getTarget();
assertInBody(target, body, from);
assertTargetedBy(target, inst, from);
- if (inst instanceof Select) {
- Select sel = (Select) inst;
+ if (inst instanceof InstructionSelect) {
+ InstructionSelect sel = (InstructionSelect) inst;
InstructionHandle[] itargets = sel.getTargets();
for (int k = itargets.length - 1; k >= 0; k--) {
assertInBody(itargets[k], body, from);
if (r instanceof ExceptionRange) {
if (((ExceptionRange)r).getHandler() == target) return;
}
- } else if (targeter instanceof BranchInstruction) {
- BranchInstruction bi = (BranchInstruction) targeter;
+ } else if (targeter instanceof InstructionBranch) {
+ InstructionBranch bi = (InstructionBranch) targeter;
if (bi.getTarget() == target) return;
- if (targeter instanceof Select) {
- Select sel = (Select) targeter;
+ if (targeter instanceof InstructionSelect) {
+ InstructionSelect sel = (InstructionSelect) targeter;
InstructionHandle[] itargets = sel.getTargets();
for (int k = itargets.length - 1; k >= 0; k--) {
if (itargets[k] == target) return;
assertTargets(t, ih, from);
if (t instanceof Range) {
assertGoodRange((Range) t, body, from);
- } else if (t instanceof BranchInstruction) {
+ } else if (t instanceof InstructionBranch) {
assertInBody(t, body, from);
}
}
import java.util.Map;
-import org.aspectj.apache.bcel.generic.IMPDEP1;
import org.aspectj.apache.bcel.generic.Instruction;
+import org.aspectj.apache.bcel.generic.InstructionConstants;
import org.aspectj.apache.bcel.generic.InstructionHandle;
import org.aspectj.apache.bcel.generic.InstructionList;
import org.aspectj.apache.bcel.generic.InstructionTargeter;
// note that this is STUPIDLY copied by Instruction.copy(), so don't do that.
- public static final Instruction RANGEINSTRUCTION = new IMPDEP1();
+ public static final Instruction RANGEINSTRUCTION = InstructionConstants.IMPDEP1;
// ----
package org.aspectj.weaver.bcel;
-import org.aspectj.apache.bcel.generic.BranchInstruction;
-import org.aspectj.apache.bcel.generic.IndexedInstruction;
import org.aspectj.apache.bcel.generic.Instruction;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
import org.aspectj.apache.bcel.generic.InstructionFactory;
import org.aspectj.apache.bcel.generic.InstructionHandle;
import org.aspectj.apache.bcel.generic.InstructionList;
+import org.aspectj.apache.bcel.generic.InstructionSelect;
import org.aspectj.apache.bcel.generic.InstructionTargeter;
-import org.aspectj.apache.bcel.generic.LocalVariableInstruction;
import org.aspectj.apache.bcel.generic.LocalVariableTag;
import org.aspectj.apache.bcel.generic.RET;
-import org.aspectj.apache.bcel.generic.Select;
import org.aspectj.apache.bcel.generic.TargetLostException;
import org.aspectj.weaver.BCException;
import org.aspectj.weaver.IntMap;
// Now we add it to the new instruction list.
InstructionHandle freshIh;
- if (freshI instanceof BranchInstruction) {
+ if (freshI instanceof InstructionBranch) {
//If it's a targeting instruction,
// update the target(s) to point to the new copy instead of the old copy.
- BranchInstruction oldBranch = (BranchInstruction) oldI;
- BranchInstruction freshBranch = (BranchInstruction) freshI;
+ InstructionBranch oldBranch = (InstructionBranch) oldI;
+ InstructionBranch freshBranch = (InstructionBranch) freshI;
InstructionHandle oldTarget = oldBranch.getTarget();
oldTarget.removeTargeter(oldBranch);
oldTarget.addTargeter(freshBranch);
- if (freshBranch instanceof Select) {
- Select oldSelect = (Select) oldI;
- Select freshSelect = (Select) freshI;
+ if (freshBranch instanceof InstructionSelect) {
+ InstructionSelect oldSelect = (InstructionSelect) oldI;
+ InstructionSelect freshSelect = (InstructionSelect) freshI;
InstructionHandle[] oldTargets = freshSelect.getTargets();
for (int k = oldTargets.length - 1; k >= 0; k--) {
oldTargets[k].removeTargeter(oldSelect);
// do compaction/expansion: allocate a new local variable, and modify the remap
// to handle it. XXX We're doing the safe thing and allocating ALL these local variables
// as double-wides, in case the location is found to hold a double-wide later.
- if (freshI instanceof LocalVariableInstruction || freshI instanceof RET) {
- IndexedInstruction indexedI = (IndexedInstruction) freshI;
- int oldIndex = indexedI.getIndex();
+ if (freshI.isLocalVariableInstruction() || freshI instanceof RET) {
+// IndexedInstruction indexedI = (IndexedInstruction) freshI;
+ int oldIndex = freshI.getIndex();
int freshIndex;
if (! remap.hasKey(oldIndex)) {
freshIndex = freshMethod.allocateLocal(2);
} else {
freshIndex = remap.get(oldIndex);
}
- indexedI.setIndex(freshIndex);
+ freshI.setIndex(freshIndex);
}
// System.err.println("JUST COPIED: " + oldIh.getInstruction().toString(freshMethod.getEnclosingClass().getConstantPoolGen().getConstantPool())
// + " INTO " + freshIh.getInstruction().toString(freshMethod.getEnclosingClass().getConstantPoolGen().getConstantPool()));
import org.aspectj.apache.bcel.classfile.ClassParser;
import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.Method;
-import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
-import org.aspectj.apache.bcel.classfile.annotation.ElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValue;
+import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValueGen;
import org.aspectj.apache.bcel.generic.ArrayType;
-import org.aspectj.apache.bcel.generic.BIPUSH;
import org.aspectj.apache.bcel.generic.BasicType;
-import org.aspectj.apache.bcel.generic.BranchInstruction;
-import org.aspectj.apache.bcel.generic.ConstantPushInstruction;
-import org.aspectj.apache.bcel.generic.INSTANCEOF;
import org.aspectj.apache.bcel.generic.Instruction;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
+import org.aspectj.apache.bcel.generic.InstructionByte;
+import org.aspectj.apache.bcel.generic.InstructionCP;
import org.aspectj.apache.bcel.generic.InstructionConstants;
import org.aspectj.apache.bcel.generic.InstructionFactory;
import org.aspectj.apache.bcel.generic.InstructionHandle;
import org.aspectj.apache.bcel.generic.InstructionList;
+import org.aspectj.apache.bcel.generic.InstructionSelect;
+import org.aspectj.apache.bcel.generic.InstructionShort;
import org.aspectj.apache.bcel.generic.InstructionTargeter;
import org.aspectj.apache.bcel.generic.InvokeInstruction;
-import org.aspectj.apache.bcel.generic.LDC;
import org.aspectj.apache.bcel.generic.LineNumberTag;
import org.aspectj.apache.bcel.generic.ObjectType;
import org.aspectj.apache.bcel.generic.ReferenceType;
-import org.aspectj.apache.bcel.generic.SIPUSH;
-import org.aspectj.apache.bcel.generic.SWITCH;
-import org.aspectj.apache.bcel.generic.Select;
+import org.aspectj.apache.bcel.generic.SwitchBuilder;
import org.aspectj.apache.bcel.generic.TargetLostException;
import org.aspectj.apache.bcel.generic.Type;
import org.aspectj.bridge.ISourceLocation;
(t instanceof ArrayType)
? fact.getConstantPool().addArrayClass((ArrayType)t)
: fact.getConstantPool().addClass((ObjectType)t);
- return new INSTANCEOF(cpoolEntry);
+ return new InstructionCP(Constants.INSTANCEOF,cpoolEntry);
}
public static Instruction createInvoke(
Type from = BcelWorld.makeBcelType(fromType);
Type to = BcelWorld.makeBcelType(toType);
try {
- il.append(fact.createCast(from, to));
+ Instruction i = fact.createCast(from, to);
+ if (i!=null) {
+ il.append(i);
+ } else {
+ il.append(fact.createCast(from, Type.INT));
+ il.append(fact.createCast(Type.INT, to));
+ }
} catch (RuntimeException e) {
+ e.printStackTrace();
il.append(fact.createCast(from, Type.INT));
il.append(fact.createCast(Type.INT, to));
}
case 5: inst = InstructionConstants.ICONST_5; break;
}
if (i <= Byte.MAX_VALUE && i >= Byte.MIN_VALUE) {
- inst = new BIPUSH((byte)i);
+ inst = new InstructionByte(Constants.BIPUSH,(byte)i);
} else if (i <= Short.MAX_VALUE && i >= Short.MIN_VALUE) {
- inst = new SIPUSH((short)i);
+ inst = new InstructionShort(Constants.SIPUSH,(short)i);
} else {
- inst = new LDC(fact.getClassGen().getConstantPool().addInteger(i));
+ int ii = fact.getClassGen().getConstantPool().addInteger(i);
+ inst = new InstructionCP(i<=Constants.MAX_BYTE?Constants.LDC:Constants.LDC_W,ii);
}
return inst;
}
*/
public static void replaceInstruction(
InstructionHandle ih,
- BranchInstruction branchInstruction,
+ InstructionBranch branchInstruction,
LazyMethodGen enclosingMethod)
{
* </pre>
*/
public static Instruction copyInstruction(Instruction i) {
- if (i instanceof Select) {
- Select freshSelect = (Select)i;
+ if (i instanceof InstructionSelect) {
+ InstructionSelect freshSelect = (InstructionSelect)i;
// Create a new targets array that looks just like the existing one
InstructionHandle[] targets = new InstructionHandle[freshSelect.getTargets().length];
}
// Create a new select statement with the new targets array
- SWITCH switchStatement =
- new SWITCH(freshSelect.getMatchs(), targets, freshSelect.getTarget());
- return (Select)switchStatement.getInstruction();
+
+ return new SwitchBuilder(freshSelect.getMatchs(), targets, freshSelect.getTarget()).getInstruction();
} else {
return i.copy(); // Use clone for shallow copy...
}
}
public static boolean isConstantPushInstruction(Instruction i) {
- return (i instanceof ConstantPushInstruction) || (i instanceof LDC);
+ long ii= Constants.instFlags[i.opcode];
+ return ((ii&Constants.PUSH_INST)!=0 && (ii&Constants.CONSTANT_INST)!=0);
}
/**
suppressed = true;
} else { // (2)
// We know the value is an array value
- ArrayElementValue array = (ArrayElementValue)((ElementNameValuePair)vals.get(0)).getValue();
- ElementValue[] values = array.getElementValuesArray();
+ ArrayElementValueGen array = (ArrayElementValueGen)((ElementNameValuePairGen)vals.get(0)).getValue();
+ ElementValueGen[] values = array.getElementValuesArray();
for (int j = 0; j < values.length; j++) {
// We know values in the array are strings
- SimpleElementValue value = (SimpleElementValue)values[j];
+ SimpleElementValueGen value = (SimpleElementValueGen)values[j];
if (value.getValueString().equals(lintkey)) {
suppressed = true;
}
suppressedWarnings.addAll(lint.allKinds());
} else { // (2)
// We know the value is an array value
- ArrayElementValue array = (ArrayElementValue)((ElementNameValuePair)vals.get(0)).getValue();
- ElementValue[] values = array.getElementValuesArray();
+ ArrayElementValueGen array = (ArrayElementValueGen)((ElementNameValuePairGen)vals.get(0)).getValue();
+ ElementValueGen[] values = array.getElementValuesArray();
for (int j = 0; j < values.length; j++) {
// We know values in the array are strings
- SimpleElementValue value = (SimpleElementValue)values[j];
+ SimpleElementValueGen value = (SimpleElementValueGen)values[j];
Lint.Kind lintKind = lint.getLintKind(value.getValueString());
if (lintKind != null) suppressedWarnings.add(lintKind);
}
InstructionHandle InstrHandle = instrucs.getStart();
while (InstrHandle != null) {
Instruction Instr = InstrHandle.getInstruction();
- int opCode = Instr.getOpcode();
+ int opCode = Instr.opcode;
// if current instruction is a branch instruction, see if it's a backward branch.
// if it is return immediately (can't be trivial)
- if (Instr instanceof BranchInstruction) {
- BranchInstruction BI = (BranchInstruction) Instr;
- if (BI.getIndex() < 0) return false;
+ if (Instr instanceof InstructionBranch) {
+ // InstructionBranch BI = (InstructionBranch) Instr;
+ if (Instr.getIndex() < 0) return false;
} else if (Instr instanceof InvokeInstruction) {
// if current instruction is an invocation, indicate that it can't be trivial
return false;