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.

AdviceDocImpl.java 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  3. * This file is part of the debugger and core tools for the AspectJ(tm)
  4. * programming language; see http://aspectj.org
  5. *
  6. * The contents of this file are subject to the Mozilla Public License
  7. * Version 1.1 (the "License"); you may not use this file except in
  8. * compliance with the License. You may obtain a copy of the License at
  9. * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. *
  16. * The Original Code is AspectJ.
  17. *
  18. * The Initial Developer of the Original Code is Xerox Corporation. Portions
  19. * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
  20. * All Rights Reserved.
  21. */
  22. package org.aspectj.tools.ajdoc;
  23. import org.aspectj.ajdoc.AdviceDoc;
  24. import org.aspectj.ajdoc.AspectDoc;
  25. import org.aspectj.ajdoc.ClassDoc;
  26. import org.aspectj.ajdoc.ExecutableMemberDoc;
  27. import org.aspectj.compiler.base.ast.CodeDec;
  28. import org.aspectj.compiler.base.ast.FormalDec;
  29. import org.aspectj.compiler.base.ast.NameType;
  30. import org.aspectj.compiler.base.ast.TypeDec;
  31. import org.aspectj.compiler.crosscuts.ast.AdviceDec;
  32. import org.aspectj.compiler.crosscuts.ast.AfterReturningAdviceDec;
  33. import org.aspectj.compiler.crosscuts.ast.AfterThrowingAdviceDec;
  34. import org.aspectj.compiler.crosscuts.ast.AroundAdviceDec;
  35. import com.sun.javadoc.Type;
  36. import java.util.ArrayList;
  37. import java.util.Collection;
  38. import java.util.Collections;
  39. import java.util.Iterator;
  40. import java.util.List;
  41. import java.util.Set;
  42. public class AdviceDocImpl extends CodeDocImpl implements AdviceDoc {
  43. /** Crosscuts this advice affects. */
  44. private final Collection crosscuts;
  45. /**
  46. * Constructrs an AdviceDoc with the containing ClassDoc
  47. * and underlying AdviceDec.
  48. *
  49. * @param containingClass containing ClassDoc.
  50. * @param adviceDec underlying AdviceDec.
  51. */
  52. public AdviceDocImpl(ClassDoc containingClass, AdviceDec adviceDec) {
  53. super(containingClass, adviceDec);
  54. crosscuts = createCrosscuts();
  55. }
  56. /**
  57. * Returns the underlying Dec -- an AdviceDec.
  58. *
  59. * @return the underlying Dec -- an AdviceDec.
  60. */
  61. protected AdviceDec adviceDec() {
  62. return (AdviceDec)codeDec();
  63. }
  64. /**
  65. * Return the ExecutableMemberDocs this advice crosscuts.
  66. *
  67. * @return an array of ExecutableMemberDocs representing
  68. * the members this advice crosscuts.
  69. */
  70. public com.sun.javadoc.ExecutableMemberDoc[] crosscuts() {
  71. return (ExecutableMemberDoc[])crosscuts.toArray
  72. (new ExecutableMemberDoc[crosscuts.size()]);
  73. }
  74. /**
  75. * Returns <code>null</code>, because advice can't override
  76. * other advice.
  77. *
  78. * @return <code>null</code>, because advice can't override
  79. * other advice.
  80. */
  81. public AspectDoc overriddenAspect() {
  82. return null;
  83. }
  84. /**
  85. * Returns the return type of the advice -- it may be null.
  86. *
  87. * @return the return type of the advice -- it may be null.
  88. */
  89. public com.sun.javadoc.Type returnType() {
  90. if (adviceDec() instanceof AroundAdviceDec) {
  91. return TypeImpl.getInstance(adviceDec().getReturnType());
  92. } else {
  93. return null;
  94. }
  95. }
  96. /**
  97. * Returns <code>true</code>.
  98. *
  99. * @return <code>true</code>.
  100. */
  101. public boolean isAdvice() {
  102. return true;
  103. }
  104. /**
  105. * Returns <code>true</code> if this advice is <code>abstract</code>.
  106. *
  107. * @return <code>true</code> if this advice is <code>abstract</code>.
  108. */
  109. public boolean isAbstract() {
  110. return adviceDec().isAbstract();
  111. }
  112. /**
  113. * Returns <code>true</code> if this is <code>throwing</code> advice.
  114. *
  115. * @return <code>true</code> if this is <code>throwing</code> advice.
  116. */
  117. public boolean isThrowing() {
  118. return adviceDec() instanceof AfterThrowingAdviceDec;
  119. }
  120. /**
  121. * Returns <code>true</code> if this is <code>returning</code> advice.
  122. *
  123. * @return <code>true</code> if this is <code>returning</code> advice.
  124. */
  125. public boolean isReturning() {
  126. return adviceDec() instanceof AfterReturningAdviceDec;
  127. }
  128. /**
  129. * Returns the extra formal type that's the optional type
  130. * to <code>after returning</code> or <code>after throwing</code>
  131. * advice.
  132. *
  133. * @return an instance of Type that represents the the extra formal type
  134. * that's the optional type to <code>after returning</code> or
  135. * <code>after throwing</code> advice.
  136. */
  137. public Type extraType() {
  138. FormalDec fd = adviceDec().getExtraFormal();
  139. if (fd != null) {
  140. return TypeImpl.getInstance(fd.getType());
  141. }
  142. return null;
  143. }
  144. /**
  145. * Returns a Collection of CodeDocImpl representing the
  146. * crosscuts the underlying TypeDec declares.
  147. *
  148. * @return a Collection of CodeDocImpl representing the
  149. * crosscuts the underlying TypeDec declares.
  150. */
  151. private Collection createCrosscuts() {
  152. Set affects = ajc().getCorrespondences().getAffects(adviceDec());
  153. if (affects.size() < 1) return Collections.EMPTY_LIST;
  154. List list = new ArrayList();
  155. for (Iterator i = affects.iterator(); i.hasNext();) {
  156. Object o = i.next();
  157. if (o instanceof CodeDec) {
  158. CodeDec cdec = (CodeDec)o;
  159. TypeDec owner = ((NameType)cdec.getDeclaringType()).getTypeDec();
  160. ClassDocImpl cd = ClassDocImpl.getInstance(owner);
  161. CodeDocImpl cdoc = cd.docForDec(cdec);
  162. if (cdoc != null) { // todo: silent introduced members
  163. list.add(cdoc);
  164. }
  165. }
  166. }
  167. return list;
  168. }
  169. /**
  170. * Returns the simple name of this advice. Need to override
  171. * this so we don't print afterThrowing or afterReturning.
  172. *
  173. * @return one of after, before, around.
  174. */
  175. public String name() {
  176. if (isThrowing() || isReturning()) return "after";
  177. return super.name();
  178. }
  179. }