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.

ExecutableMemberDocImpl.java 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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.compiler.base.ast.Formals;
  25. import org.aspectj.compiler.base.ast.NameType;
  26. import org.aspectj.compiler.base.ast.TypeDs;
  27. import com.sun.javadoc.ClassDoc;
  28. import com.sun.javadoc.ExecutableMemberDoc;
  29. import com.sun.javadoc.ParamTag;
  30. import com.sun.javadoc.Parameter;
  31. import com.sun.javadoc.ThrowsTag;
  32. import java.lang.reflect.Modifier;
  33. import java.util.ArrayList;
  34. import java.util.Collection;
  35. import java.util.Collections;
  36. import java.util.List;
  37. public abstract class ExecutableMemberDocImpl
  38. extends MemberDocImpl
  39. implements ExecutableMemberDoc {
  40. /*
  41. * These three fields should be final, but can't because
  42. * they contain calls to abstract methods that aren't
  43. * valid until after the subclasses constructor is run.
  44. * To compensate the accessor methods lazily evaluate
  45. * them, and these methods are final.
  46. */
  47. /** The collection of advice placed on each ExecutableMemberDoc. */
  48. private Collection advice;
  49. /** The List of parameters. */
  50. private Collection parameters;
  51. /** The List of thrown exceptions. */
  52. private Collection thrownExceptions;
  53. /** The full signature. */
  54. private String signature;
  55. /** The flat signature. */
  56. private String flatSignature;
  57. /**
  58. * Constructs a new Doc with the enclosing ClassDoc.
  59. *
  60. * @param containingClass enclosing ClassDoc.
  61. */
  62. public ExecutableMemberDocImpl(ClassDoc containingClass) {
  63. super(containingClass);
  64. }
  65. /**
  66. * Returns a non-null Collection of AdviceDoc
  67. * representing the advice placed on the underlying Dec.
  68. *
  69. * @return a non-null Collection of AdviceDoc
  70. * representing the advice placed on the
  71. * underlying Dec.
  72. */
  73. protected abstract Collection createAdvice();
  74. /**
  75. * Returns the Formals of the underlying Dec.
  76. *
  77. * @return the Formals of the underlying Dec.
  78. */
  79. protected abstract Formals getFormals();
  80. /**
  81. * Returns the TypeDs representing the exceptions
  82. * thrown by the underlying Dec.
  83. *
  84. * @return the TypeDs representing the exceptions
  85. * thrown by the underlying Dec.
  86. */
  87. protected abstract TypeDs getThrows();
  88. /**
  89. * Converts the passed in Formals to a Collection of
  90. * Parameter and sets our parameters to this value.
  91. *
  92. * @param formals the Formals to use.
  93. */
  94. public void makeParameters(Formals formals) {
  95. parameters = createParameters(formals);
  96. }
  97. /**
  98. * Converts the passed in TypeDs to a Collection of
  99. * ClassDoc and sets our thrownExceptions to this value.
  100. *
  101. * @param thrown the TypeDs to use.
  102. */
  103. public void makeThrownExceptions(TypeDs thrown) {
  104. thrownExceptions = createThrownExceptions(thrown);
  105. }
  106. /**
  107. * Returns the advice affecting this member.
  108. *
  109. * @return an array of AdviceDoc representing the advice
  110. * affecting this member.
  111. */
  112. public final AdviceDoc[] advice() {
  113. if (advice == null) advice = createAdvice();
  114. return (AdviceDoc[])advice.toArray(new AdviceDoc[advice.size()]);
  115. }
  116. /**
  117. * Returns the exceptions this code declares to throw.
  118. *
  119. * @return an array of ClassDoc representing the exceptions
  120. * this code declares to throw.
  121. */
  122. public final ClassDoc[] thrownExceptions() {
  123. if (thrownExceptions == null) makeThrownExceptions(getThrows());
  124. return (ClassDoc[])thrownExceptions.toArray
  125. (new ClassDoc[thrownExceptions.size()]);
  126. }
  127. /**
  128. * Returns the parameters taken by this code.
  129. *
  130. * @return an array of Parameter representing the
  131. * parameters this code takes.
  132. */
  133. public final Parameter[] parameters() {
  134. if (parameters == null) makeParameters(getFormals());
  135. return (Parameter[])parameters.toArray
  136. (new Parameter[parameters.size()]);
  137. }
  138. /**
  139. * Returns the flat signature.
  140. *
  141. * @return the flat signature with all types unqualified.
  142. */
  143. public String flatSignature() {
  144. if (flatSignature == null) {
  145. flatSignature = Util.flatSignature(parameters());
  146. }
  147. return flatSignature;
  148. }
  149. /**
  150. * Returns the full signature.
  151. *
  152. * @return the full signature with all types qualified.
  153. */
  154. public String signature() {
  155. if (signature == null) {
  156. signature = Util.signature(parameters());
  157. }
  158. return signature;
  159. }
  160. /**
  161. * Returns <code>true</code> if this code is <code>synchronized</code>.
  162. *
  163. * @return <code>true</code> if this code is <code>synchronized</code>.
  164. */
  165. public boolean isSynchronized() {
  166. //return getModifiers().isSynchronized();
  167. return Modifier.isSynchronized(modifierSpecifier());
  168. }
  169. /**
  170. * Returns <code>true</code>if this code is <code>native</code>.
  171. *
  172. * @return <code>true</code>if this code is <code>native</code>.
  173. */
  174. public boolean isNative() {
  175. //return (modifierSpecifier() & Modifiers.NATIVE) != 0;
  176. return Modifier.isNative(modifierSpecifier());
  177. }
  178. /**
  179. * Returns the throw tags describing exceptions thrown
  180. * declared by this code.
  181. *
  182. * @return an array of ThrowsTag representing the exception
  183. * this code declares to throw.
  184. */
  185. public ThrowsTag[] throwsTags() {
  186. return getComment().throwsTags();
  187. }
  188. /**
  189. * Returns the param tags describing parameters taken
  190. * by this code.
  191. *
  192. * @return an array of ParamTag representing the
  193. * parameters taken by this code.
  194. */
  195. public ParamTag[] paramTags() {
  196. return getComment().paramTags();
  197. }
  198. /**
  199. * Returns the simple name followed the parameters
  200. * enclosed in parens.
  201. *
  202. * @return the simple name followed the parameters
  203. * enclosed in parens.
  204. */
  205. public String toString() {
  206. StringBuffer sb = new StringBuffer(name());
  207. sb.append('(');
  208. Parameter[] params = parameters();
  209. for (int i = 0, N = params.length; i < N; i++) {
  210. if (i > 0) sb.append(",");
  211. sb.append(params[i].type().qualifiedTypeName());
  212. sb.append(params[i].type().dimension());
  213. }
  214. sb.append(')');
  215. return sb.toString();
  216. }
  217. /**
  218. * Returns a Collection of Parameter corresponding to
  219. * the Formals passed in.
  220. *
  221. * @param formals the Formals to use.
  222. * @return a Collection of Parameter corresponding to
  223. * the Formals passed in.
  224. */
  225. private Collection createParameters(Formals formals) {
  226. if (formals == null) return Collections.EMPTY_LIST;
  227. List list = new ArrayList(formals.size());
  228. for (int i = 0, N = formals.size(); i < N; i++) {
  229. list.add(new ParameterImpl(formals.get(i)));
  230. }
  231. return list;
  232. }
  233. /**
  234. * Returns a Collection of ClassDoc corresponding to
  235. * the TypeDs passed in.
  236. *
  237. * @param thrown the TypeDs to use
  238. * @return a Collection of ClassDoc corresponding to
  239. * the TypeDs passed in.
  240. */
  241. private Collection createThrownExceptions(TypeDs typeds) {
  242. if (typeds == null) return Collections.EMPTY_LIST;
  243. List list = new ArrayList(typeds.size());
  244. for (int i = 0, N = typeds.size(); i < N; i++) {
  245. list.add(ClassDocImpl.getInstance
  246. (((NameType)typeds.get(i).getType()).getTypeDec()));
  247. }
  248. return list;
  249. }
  250. /**
  251. * Returns <code>true</code> if the passed in Object is
  252. * an ExecutableMemberDocImpl, its name equals ours, and
  253. * its parameters <code>equals</code> ours.
  254. *
  255. * @return equality based on name and parameters.
  256. */
  257. public boolean weakEquals(Object md) {
  258. if (!(md instanceof ExecutableMemberDocImpl)) {
  259. return false;
  260. }
  261. ExecutableMemberDocImpl emdi = (ExecutableMemberDocImpl)md;
  262. if (!name().equals(emdi.name())) {
  263. return false;
  264. }
  265. Parameter[] ourPds = this.parameters();
  266. Parameter[] edsPds = emdi.parameters();
  267. if (ourPds.length != edsPds.length) {
  268. return false;
  269. }
  270. for (int i = 0, N = ourPds.length; i < N; i++) {
  271. if (!ourPds[i].equals(edsPds[i])) {
  272. return false;
  273. }
  274. }
  275. return true;
  276. }
  277. }