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.

TypeVariableReferenceType.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* *******************************************************************
  2. * Copyright (c) 2005 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Adrian Colyer Initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver;
  13. import java.io.DataOutputStream;
  14. import java.io.IOException;
  15. /**
  16. * Represents a type variable in a type or generic method declaration
  17. */
  18. public class TypeVariableReferenceType extends BoundedReferenceType implements TypeVariableReference {
  19. private TypeVariable typeVariable;
  20. private boolean resolvedIfBounds = false;
  21. // If 'fixedUp' then the type variable in here is a reference to the real one that may
  22. // exist either on a member or a type. Not fixedUp means that we unpacked a generic
  23. // signature and weren't able to fix it up during resolution (didn't quite know enough
  24. // at the right time). Wonder if we can fix it up late?
  25. boolean fixedUp = false;
  26. public TypeVariableReferenceType(
  27. TypeVariable aTypeVariable,
  28. World aWorld) {
  29. super(aTypeVariable.getUpperBound().getSignature(),aWorld);
  30. this.typeVariable = aTypeVariable;
  31. this.isExtends = false;
  32. this.isSuper = false;
  33. setDelegate(new ReferenceTypeReferenceTypeDelegate((ReferenceType)aTypeVariable.getUpperBound()));
  34. }
  35. public UnresolvedType getUpperBound() {
  36. if (typeVariable==null) return super.getUpperBound();
  37. return typeVariable.getUpperBound();
  38. }
  39. public UnresolvedType getLowerBound() {
  40. return typeVariable.getLowerBound();
  41. }
  42. private void setAdditionalInterfaceBoundsFromTypeVar() {
  43. if (typeVariable.getAdditionalInterfaceBounds() == null) {
  44. return;
  45. } else {
  46. UnresolvedType [] ifBounds = typeVariable.getAdditionalInterfaceBounds();
  47. additionalInterfaceBounds = new ReferenceType[ifBounds.length];
  48. for (int i = 0; i < ifBounds.length; i++) {
  49. additionalInterfaceBounds[i] = (ReferenceType) ifBounds[i].resolve(getWorld());
  50. }
  51. }
  52. }
  53. public ReferenceType[] getAdditionalBounds() {
  54. if (!resolvedIfBounds) {
  55. setAdditionalInterfaceBoundsFromTypeVar();
  56. resolvedIfBounds = true;
  57. }
  58. return super.getAdditionalBounds();
  59. }
  60. public TypeVariable getTypeVariable() {
  61. // if (!fixedUp) throw new BCException("ARGH"); // SAUSAGES - fix it up now?
  62. return typeVariable;
  63. }
  64. public boolean isTypeVariableReference() {
  65. return true;
  66. }
  67. public boolean isGenericWildcard() {
  68. return false;
  69. }
  70. //public ResolvedType resolve(World world) {
  71. // return super.resolve(world);
  72. //}
  73. public boolean isAnnotation() {
  74. World world = ((ReferenceType)getUpperBound()).getWorld();
  75. ResolvedType annotationType = ResolvedType.ANNOTATION.resolve(world);
  76. if (getUpperBound() != null && ((ReferenceType)getUpperBound()).isAnnotation()) return true;
  77. ReferenceType[] ifBounds = getAdditionalBounds();
  78. for (int i = 0; i < ifBounds.length; i++) {
  79. if (ifBounds[i].isAnnotation()) return true;
  80. if (ifBounds[i] == annotationType) return true; // annotation itself does not have the annotation flag set in Java!
  81. }
  82. return false;
  83. }
  84. /**
  85. * return the signature for a *REFERENCE* to a type variable, which is simply:
  86. * Tname;
  87. * there is no bounds info included, that is in the signature of the type variable itself
  88. */
  89. public String getSignature() {
  90. StringBuffer sb = new StringBuffer();
  91. sb.append("T");
  92. sb.append(typeVariable.getName());
  93. sb.append(";");
  94. return sb.toString();
  95. }
  96. public void write(DataOutputStream s) throws IOException {
  97. super.write(s);
  98. // TypeVariableDeclaringElement tvde = typeVariable.getDeclaringElement();
  99. // if (tvde == null) {
  100. // s.writeInt(TypeVariable.UNKNOWN);
  101. // } else {
  102. // s.writeInt(typeVariable.getDeclaringElementKind());
  103. // if (typeVariable.getDeclaringElementKind() == TypeVariable.TYPE) {
  104. // ((UnresolvedType)tvde).write(s);
  105. // } else if (typeVariable.getDeclaringElementKind() == TypeVariable.METHOD){
  106. // // it's a method
  107. // ((ResolvedMember)tvde).write(s);
  108. // }
  109. // }
  110. }
  111. }