You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TypeAnnotationAccessVar.java 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* *******************************************************************
  2. * Copyright (c) 2005 IBM
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Contributors:
  10. * Andy Clement initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.bcel;
  13. import org.aspectj.apache.bcel.Constants;
  14. import org.aspectj.apache.bcel.generic.Instruction;
  15. import org.aspectj.apache.bcel.generic.InstructionFactory;
  16. import org.aspectj.apache.bcel.generic.InstructionList;
  17. import org.aspectj.apache.bcel.generic.ObjectType;
  18. import org.aspectj.apache.bcel.generic.Type;
  19. import org.aspectj.weaver.ResolvedType;
  20. import org.aspectj.weaver.UnresolvedType;
  21. /**
  22. * Used for @this() @target() @args() - represents accessing an annotated 'thing'. Main use is to create the instructions that
  23. * retrieve the annotation from the 'thing' - see createLoadInstructions()
  24. */
  25. public class TypeAnnotationAccessVar extends BcelVar {
  26. private BcelVar target;
  27. public TypeAnnotationAccessVar(ResolvedType type, BcelVar theAnnotatedTargetIsStoredHere) {
  28. super(type, 0);
  29. target = theAnnotatedTargetIsStoredHere;
  30. }
  31. public String toString() {
  32. return "TypeAnnotationAccessVar(" + getType() + ")";
  33. }
  34. public Instruction createLoad(InstructionFactory fact) {
  35. throw new RuntimeException("unimplemented");
  36. }
  37. public Instruction createStore(InstructionFactory fact) {
  38. throw new RuntimeException("unimplemented");
  39. }
  40. public InstructionList createCopyFrom(InstructionFactory fact, int oldSlot) {
  41. throw new RuntimeException("unimplemented");
  42. }
  43. public void appendLoad(InstructionList il, InstructionFactory fact) {
  44. il.append(createLoadInstructions(getType(), fact));
  45. }
  46. public InstructionList createLoadInstructions(ResolvedType toType, InstructionFactory fact) {
  47. InstructionList il = new InstructionList();
  48. Type jlClass = BcelWorld.makeBcelType(UnresolvedType.JL_CLASS);
  49. Type jlaAnnotation = BcelWorld.makeBcelType(UnresolvedType.ANNOTATION);
  50. il.append(target.createLoad(fact));
  51. il.append(fact.createInvoke("java/lang/Object", "getClass", jlClass, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
  52. il.append(fact.createConstant(new ObjectType(toType.getName())));
  53. il.append(fact.createInvoke("java/lang/Class", "getAnnotation", jlaAnnotation, new Type[] { jlClass },
  54. Constants.INVOKEVIRTUAL));
  55. il.append(Utility.createConversion(fact, jlaAnnotation, BcelWorld.makeBcelType(toType)));
  56. return il;
  57. }
  58. public void appendLoadAndConvert(InstructionList il, InstructionFactory fact, ResolvedType toType) {
  59. il.append(createLoadInstructions(toType, fact));
  60. }
  61. public void insertLoad(InstructionList il, InstructionFactory fact) {
  62. il.insert(createLoadInstructions(getType(), fact));
  63. }
  64. }