private InstructionList createLoadInstructions(ResolvedType toType, InstructionFactory fact) {
InstructionList il = new InstructionList();
Type jlClass = BcelWorld.makeBcelType(UnresolvedType.JL_CLASS);
Type jlString = BcelWorld.makeBcelType(UnresolvedType.JL_STRING);
Type jlClassArray = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_CLASS_ARRAY);
Type jlaAnnotation = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_ANNOTATION);
Instruction pushConstant = fact.createConstant(new ObjectType(toType.getName()));
if (kind == Shadow.MethodCall || kind == Shadow.MethodExecution || kind == Shadow.PreInitialization
|| kind == Shadow.Initialization || kind == Shadow.ConstructorCall || kind == Shadow.ConstructorExecution
|| kind == Shadow.AdviceExecution ||
// annotations for fieldset/fieldget when an ITD is involved are stored against a METHOD
((kind == Shadow.FieldGet || kind == Shadow.FieldSet) && member.getKind() == Member.METHOD)) {
Type jlrMethod = BcelWorld.makeBcelType(UnresolvedType.forSignature("Ljava/lang/reflect/Method;"));
Type jlAnnotation = BcelWorld.makeBcelType(UnresolvedType.forSignature("Ljava/lang/annotation/Annotation;"));
Type[] paramTypes = BcelWorld.makeBcelTypes(member.getParameterTypes());
// il.append(fact.createConstant(BcelWorld.makeBcelType(containingType)));
if (kind == Shadow.MethodCall
|| kind == Shadow.MethodExecution
|| kind == Shadow.AdviceExecution
||
// annotations for fieldset/fieldget when an ITD is involved are stored against a METHOD
((kind == Shadow.FieldGet || kind == Shadow.FieldSet) && member.getKind() == Member.METHOD)
|| ((kind == Shadow.ConstructorCall || kind == Shadow.ConstructorExecution) && member.getKind() == Member.METHOD)) {
// Need to look at the cached annotation before going to fetch it again
Field annotationCachingField = shadow.getEnclosingClass().getAnnotationCachingField(shadow, toType, isWithin);
// Basic idea here is to check if the cached field is null, if it is then initialize it, otherwise use it
il.append(fact.createGetStatic(shadow.getEnclosingClass().getName(), annotationCachingField.getName(), jlAnnotation));
il.append(InstructionConstants.DUP);
InstructionBranch ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
il.append(ifNonNull);
il.append(InstructionConstants.POP);
il.append(fact.createConstant(BcelWorld.makeBcelType(containingType)));
il.append(fact.createConstant(member.getName()));
buildArray(il, fact, jlClass, paramTypes, 1);
// OPTIMIZE cache result of getDeclaredMethod?
il.append(fact.createInvoke("java/lang/Class", "getDeclaredMethod", jlrMethod,
new Type[] { jlString, jlClassArray }, Constants.INVOKEVIRTUAL));
il.append(pushConstant);// fact.createConstant(new ObjectType(toType.getName())));
il.append(fact.createInvoke("java/lang/reflect/Method", "getAnnotation", jlaAnnotation, new Type[] { jlClass },
Constants.INVOKEVIRTUAL));
il.append(InstructionConstants.DUP);
il.append(fact.createPutStatic(shadow.getEnclosingClass().getName(), annotationCachingField.getName(), jlAnnotation));
InstructionHandle ifNullElse = il.append(InstructionConstants.NOP);
ifNonNull.setTarget(ifNullElse);
} else { // init/preinit/ctor-call/ctor-exec
il.append(fact.createConstant(BcelWorld.makeBcelType(containingType)));
buildArray(il, fact, jlClass, paramTypes, 1);
Type jlrCtor = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_REFLECT_CONSTRUCTOR);
// OPTIMIZE cache result of getDeclaredConstructor and getAnnotation? Might be able to use it again if someone else
// needs the same annotations?
il.append(fact.createInvoke("java/lang/Class", "getDeclaredConstructor", jlrCtor, new Type[] { jlClassArray },
Constants.INVOKEVIRTUAL));
il.append(pushConstant);