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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. import java.util.Map;
  16. /**
  17. * Represents a type variable in a type or generic method declaration
  18. */
  19. public class TypeVariableReferenceType extends BoundedReferenceType implements TypeVariableReference {
  20. private TypeVariable typeVariable;
  21. private boolean resolvedIfBounds = false;
  22. // If 'fixedUp' then the type variable in here is a reference to the real one that may
  23. // exist either on a member or a type. Not fixedUp means that we unpacked a generic
  24. // signature and weren't able to fix it up during resolution (didn't quite know enough
  25. // at the right time). Wonder if we can fix it up late?
  26. boolean fixedUp = false;
  27. public TypeVariableReferenceType(
  28. TypeVariable aTypeVariable,
  29. World aWorld) {
  30. super(
  31. aTypeVariable.getGenericSignature(),
  32. aTypeVariable.getErasureSignature(),
  33. aWorld);
  34. this.typeVariable = aTypeVariable;
  35. this.isExtends = false;
  36. this.isSuper = false;
  37. }
  38. public ReferenceTypeDelegate getDelegate() {
  39. if (delegate==null)
  40. setDelegate(new ReferenceTypeReferenceTypeDelegate((ReferenceType)typeVariable.getFirstBound()));
  41. return delegate;
  42. }
  43. public UnresolvedType getUpperBound() {
  44. if (typeVariable==null) return super.getUpperBound();
  45. return typeVariable.getUpperBound();
  46. }
  47. public UnresolvedType getLowerBound() {
  48. return typeVariable.getLowerBound();
  49. }
  50. private void setAdditionalInterfaceBoundsFromTypeVar() {
  51. if (typeVariable.getAdditionalInterfaceBounds() == null) {
  52. return;
  53. } else {
  54. UnresolvedType [] ifBounds = typeVariable.getAdditionalInterfaceBounds();
  55. additionalInterfaceBounds = new ReferenceType[ifBounds.length];
  56. for (int i = 0; i < ifBounds.length; i++) {
  57. additionalInterfaceBounds[i] = (ReferenceType) ifBounds[i].resolve(getWorld());
  58. }
  59. }
  60. }
  61. public UnresolvedType parameterize(Map typeBindings) {
  62. UnresolvedType ut = (UnresolvedType) typeBindings.get(getName());
  63. if (ut!=null) return world.resolve(ut);
  64. return this;
  65. }
  66. public ReferenceType[] getAdditionalBounds() {
  67. if (!resolvedIfBounds) {
  68. setAdditionalInterfaceBoundsFromTypeVar();
  69. resolvedIfBounds = true;
  70. }
  71. return super.getAdditionalBounds();
  72. }
  73. public TypeVariable getTypeVariable() {
  74. // if (!fixedUp) throw new BCException("ARGH"); // SAUSAGES - fix it up now?
  75. return typeVariable;
  76. }
  77. public boolean isTypeVariableReference() {
  78. return true;
  79. }
  80. public String toString() {
  81. return typeVariable.getName();
  82. }
  83. public boolean isGenericWildcard() {
  84. return false;
  85. }
  86. //public ResolvedType resolve(World world) {
  87. // return super.resolve(world);
  88. //}
  89. public boolean isAnnotation() {
  90. World world = ((ReferenceType)getUpperBound()).getWorld();
  91. ResolvedType annotationType = ResolvedType.ANNOTATION.resolve(world);
  92. if (getUpperBound() != null && ((ReferenceType)getUpperBound()).isAnnotation()) return true;
  93. ReferenceType[] ifBounds = getAdditionalBounds();
  94. for (int i = 0; i < ifBounds.length; i++) {
  95. if (ifBounds[i].isAnnotation()) return true;
  96. if (ifBounds[i] == annotationType) return true; // annotation itself does not have the annotation flag set in Java!
  97. }
  98. return false;
  99. }
  100. /**
  101. * return the signature for a *REFERENCE* to a type variable, which is simply:
  102. * Tname;
  103. * there is no bounds info included, that is in the signature of the type variable itself
  104. */
  105. public String getSignature() {
  106. StringBuffer sb = new StringBuffer();
  107. sb.append("T");
  108. sb.append(typeVariable.getName());
  109. sb.append(";");
  110. return sb.toString();
  111. }
  112. public void write(DataOutputStream s) throws IOException {
  113. super.write(s);
  114. // TypeVariableDeclaringElement tvde = typeVariable.getDeclaringElement();
  115. // if (tvde == null) {
  116. // s.writeInt(TypeVariable.UNKNOWN);
  117. // } else {
  118. // s.writeInt(typeVariable.getDeclaringElementKind());
  119. // if (typeVariable.getDeclaringElementKind() == TypeVariable.TYPE) {
  120. // ((UnresolvedType)tvde).write(s);
  121. // } else if (typeVariable.getDeclaringElementKind() == TypeVariable.METHOD){
  122. // // it's a method
  123. // ((ResolvedMember)tvde).write(s);
  124. // }
  125. // }
  126. }
  127. }