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.

MissingResolvedTypeWithKnownSignature.java 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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.util.Collections;
  14. import java.util.List;
  15. import org.aspectj.bridge.ISourceLocation;
  16. import org.aspectj.bridge.context.CompilationAndWeavingContext;
  17. /**
  18. * When we try to resolve a type in the world that we require to be present, and then fail to find it, we return an instance of this
  19. * class. This class defers the production of the "can't find type error" until the first time that someone asks a question that
  20. * can't be answered solely from the signature. This enables the weaver to be more tolerant of missing types.
  21. *
  22. */
  23. public class MissingResolvedTypeWithKnownSignature extends ResolvedType {
  24. private static ResolvedMember[] NO_MEMBERS = new ResolvedMember[0];
  25. private static ResolvedType[] NO_TYPES = new ResolvedType[0];
  26. private boolean issuedCantFindTypeError = false;
  27. private boolean issuedJoinPointWarning = false;
  28. private boolean issuedMissingInterfaceWarning = false;
  29. /**
  30. * @param signature
  31. * @param world
  32. */
  33. public MissingResolvedTypeWithKnownSignature(String signature, World world) {
  34. super(signature, world);
  35. }
  36. @Override
  37. public boolean isMissing() {
  38. return true;
  39. }
  40. /**
  41. * @param signature
  42. * @param signatureErasure
  43. * @param world
  44. */
  45. public MissingResolvedTypeWithKnownSignature(String signature, String signatureErasure, World world) {
  46. super(signature, signatureErasure, world);
  47. }
  48. /*
  49. * (non-Javadoc)
  50. *
  51. * @see org.aspectj.weaver.ResolvedType#getDeclaredFields()
  52. */
  53. @Override
  54. public ResolvedMember[] getDeclaredFields() {
  55. raiseCantFindType(WeaverMessages.CANT_FIND_TYPE_FIELDS);
  56. return NO_MEMBERS;
  57. }
  58. /*
  59. * (non-Javadoc)
  60. *
  61. * @see org.aspectj.weaver.ResolvedType#getDeclaredMethods()
  62. */
  63. @Override
  64. public ResolvedMember[] getDeclaredMethods() {
  65. raiseCantFindType(WeaverMessages.CANT_FIND_TYPE_METHODS);
  66. return NO_MEMBERS;
  67. }
  68. @Override
  69. public AnnotationAJ[] getAnnotations() {
  70. raiseCantFindType(WeaverMessages.CANT_FIND_TYPE_ANNOTATION);
  71. return AnnotationAJ.EMPTY_ARRAY;
  72. }
  73. @Override
  74. public ResolvedType[] getDeclaredInterfaces() {
  75. raiseCantFindType(WeaverMessages.CANT_FIND_TYPE_INTERFACES);
  76. return NO_TYPES;
  77. }
  78. @Override
  79. public ResolvedMember[] getDeclaredPointcuts() {
  80. raiseCantFindType(WeaverMessages.CANT_FIND_TYPE_POINTCUTS);
  81. return NO_MEMBERS;
  82. }
  83. @Override
  84. public ResolvedType getSuperclass() {
  85. raiseCantFindType(WeaverMessages.CANT_FIND_TYPE_SUPERCLASS);
  86. return ResolvedType.MISSING;
  87. }
  88. @Override
  89. public int getModifiers() {
  90. raiseCantFindType(WeaverMessages.CANT_FIND_TYPE_MODIFIERS);
  91. return 0;
  92. }
  93. /*
  94. * (non-Javadoc)
  95. *
  96. * @see org.aspectj.weaver.ResolvedType#getSourceContext()
  97. */
  98. @Override
  99. public ISourceContext getSourceContext() {
  100. return new ISourceContext() {
  101. public ISourceLocation makeSourceLocation(IHasPosition position) {
  102. return null;
  103. }
  104. public ISourceLocation makeSourceLocation(int line, int offset) {
  105. return null;
  106. }
  107. public int getOffset() {
  108. return 0;
  109. }
  110. public void tidy() {
  111. }
  112. };
  113. }
  114. /*
  115. * (non-Javadoc)
  116. *
  117. * @see org.aspectj.weaver.ResolvedType#isAssignableFrom(org.aspectj.weaver.ResolvedType)
  118. */
  119. @Override
  120. public boolean isAssignableFrom(ResolvedType other) {
  121. raiseCantFindType(WeaverMessages.CANT_FIND_TYPE_ASSIGNABLE, other.getName());
  122. return false;
  123. }
  124. @Override
  125. public boolean isAssignableFrom(ResolvedType other, boolean allowMissing) {
  126. if (allowMissing) {
  127. return false;
  128. } else {
  129. return isAssignableFrom(other);
  130. }
  131. }
  132. /*
  133. * (non-Javadoc)
  134. *
  135. * @see org.aspectj.weaver.ResolvedType#isCoerceableFrom(org.aspectj.weaver.ResolvedType)
  136. */
  137. @Override
  138. public boolean isCoerceableFrom(ResolvedType other) {
  139. raiseCantFindType(WeaverMessages.CANT_FIND_TYPE_COERCEABLE, other.getName());
  140. return false;
  141. }
  142. /*
  143. * (non-Javadoc)
  144. *
  145. * @see org.aspectj.weaver.AnnotatedElement#hasAnnotation(org.aspectj.weaver.UnresolvedType)
  146. */
  147. public boolean hasAnnotation(UnresolvedType ofType) {
  148. raiseCantFindType(WeaverMessages.CANT_FIND_TYPE_ANNOTATION);
  149. return false;
  150. }
  151. @Override
  152. public List getInterTypeMungers() {
  153. return Collections.EMPTY_LIST;
  154. }
  155. @Override
  156. public List getInterTypeMungersIncludingSupers() {
  157. return Collections.EMPTY_LIST;
  158. }
  159. @Override
  160. public List getInterTypeParentMungers() {
  161. return Collections.EMPTY_LIST;
  162. }
  163. @Override
  164. public List getInterTypeParentMungersIncludingSupers() {
  165. return Collections.EMPTY_LIST;
  166. }
  167. @Override
  168. protected void collectInterTypeMungers(List collector) {
  169. return;
  170. }
  171. public void raiseWarningOnJoinPointSignature(String signature) {
  172. if (issuedJoinPointWarning) {
  173. return;
  174. }
  175. String message = WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_JOINPOINT, getName(), signature);
  176. message += "\n" + CompilationAndWeavingContext.getCurrentContext();
  177. world.getLint().cantFindTypeAffectingJoinPointMatch.signal(message, null);
  178. // MessageUtil.warn(world.getMessageHandler(),message);
  179. issuedJoinPointWarning = true;
  180. }
  181. public void raiseWarningOnMissingInterfaceWhilstFindingMethods() {
  182. if (issuedMissingInterfaceWarning) {
  183. return;
  184. }
  185. String message = WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_INTERFACE_METHODS, getName(), signature);
  186. message += "\n" + CompilationAndWeavingContext.getCurrentContext();
  187. world.getLint().cantFindTypeAffectingJoinPointMatch.signal(message, null);
  188. // MessageUtil.warn(world.getMessageHandler(),message);
  189. issuedMissingInterfaceWarning = true;
  190. }
  191. private void raiseCantFindType(String key) {
  192. if (!world.getLint().cantFindType.isEnabled()) {
  193. return;
  194. }
  195. if (issuedCantFindTypeError) {
  196. return;
  197. }
  198. String message = WeaverMessages.format(key, getName());
  199. message += "\n" + CompilationAndWeavingContext.getCurrentContext();
  200. world.getLint().cantFindType.signal(message, null);
  201. // MessageUtil.error(world.getMessageHandler(),message);
  202. issuedCantFindTypeError = true;
  203. }
  204. private void raiseCantFindType(String key, String insert) {
  205. if (issuedCantFindTypeError) {
  206. return;
  207. }
  208. String message = WeaverMessages.format(key, getName(), insert);
  209. message += "\n" + CompilationAndWeavingContext.getCurrentContext();
  210. world.getLint().cantFindType.signal(message, null);
  211. // MessageUtil.error(world.getMessageHandler(),message);
  212. issuedCantFindTypeError = true;
  213. }
  214. }