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.

IntroducedDocImpl.java 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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.ClassDoc;
  24. import org.aspectj.ajdoc.IntroducedDoc;
  25. import org.aspectj.ajdoc.MemberDoc;
  26. import org.aspectj.compiler.base.ast.ConstructorDec;
  27. import org.aspectj.compiler.base.ast.Dec;
  28. import org.aspectj.compiler.base.ast.FieldDec;
  29. import org.aspectj.compiler.base.ast.MethodDec;
  30. import org.aspectj.compiler.base.ast.TypeDec;
  31. import org.aspectj.compiler.crosscuts.ast.GenTypeName;
  32. import org.aspectj.compiler.crosscuts.ast.IntroducedDec;
  33. import java.util.Iterator;
  34. import java.util.Set;
  35. public class IntroducedDocImpl extends IntroductionDocImpl implements IntroducedDoc {
  36. /** The introduction to which we delegate. */
  37. private final IntroducedDec introducedDec;
  38. /** The member this introduction introduced. */
  39. private final MemberDocImpl member;
  40. public IntroducedDocImpl(com.sun.javadoc.ClassDoc containingClass,
  41. IntroducedDec introducedDec) {
  42. super(containingClass);
  43. this.introducedDec = introducedDec; // used by findMember
  44. (member = findMember()).setIntroduced(this);
  45. createTargets();
  46. }
  47. protected Dec dec() {
  48. return introducedDec;
  49. }
  50. protected void createTargets() {
  51. /*
  52. * HACK:
  53. * Because the compiler doesn't resolve the types
  54. * of introductions, yet, we have to set the introduced
  55. * doc (member) with the appropriate fields, whether it's a
  56. * - field
  57. * - method
  58. * - constructor
  59. */
  60. Set affects = ajc().getCorrespondences().getAffects(introducedDec);
  61. if (affects.size() < 1) return;
  62. nextType:
  63. for (Iterator it = affects.iterator(); it.hasNext();) {
  64. Object o = it.next();
  65. if (o instanceof TypeDec) {
  66. TypeDec owner = (TypeDec)o;
  67. ClassDoc cd = ClassDocImpl.getInstance(owner);
  68. com.sun.javadoc.FieldDoc[] fs = cd.fields();
  69. for (int i = 0; i < fs.length; i++) {
  70. if (member.weakEquals(fs[i])) { // XXX weakEquals is unimplemented
  71. ((FieldDocImpl)fs[i]).setIntroduced(this);
  72. addTarget(cd);
  73. ((FieldDocImpl)member).setType(((FieldDocImpl)fs[i]).
  74. fieldDec().getType());
  75. // why fixup only fields?
  76. continue nextType;
  77. }
  78. }
  79. com.sun.javadoc.MethodDoc[] ms = cd.methods();
  80. for (int i = 0; i < ms.length; i++) {
  81. if (member.weakEquals(ms[i])) {
  82. ((MethodDocImpl)ms[i]).setIntroduced(this);
  83. addTarget(cd);
  84. ((MethodDocImpl)member).setType(((MethodDocImpl)ms[i]).
  85. codeDec().getResultTypeD().
  86. getType());
  87. ((ExecutableMemberDocImpl)member).
  88. makeParameters(((MethodDocImpl)ms[i]).
  89. codeDec().getFormals());
  90. continue nextType;
  91. }
  92. }
  93. com.sun.javadoc.ConstructorDoc[] cs = cd.constructors();
  94. for (int i = 0; i < cs.length; i++) {
  95. if (member.weakEquals(cs[i])) {
  96. ((ConstructorDocImpl)cs[i]).setIntroduced(this);
  97. addTarget(cd);
  98. ((ExecutableMemberDocImpl)member).
  99. makeParameters(((ConstructorDocImpl)cs[i]).
  100. codeDec().getFormals());
  101. continue nextType;
  102. }
  103. }
  104. }
  105. }
  106. }
  107. public MemberDoc member() {
  108. return member;
  109. }
  110. /**
  111. * Returns the name of the member introduction.
  112. *
  113. * @return the name.
  114. */
  115. public String name() { // XXX unused?
  116. Dec indec = introducedDec.getDec();
  117. if (indec != null) {
  118. return "" + indec.getId(); // XXX
  119. } else {
  120. return "";
  121. }
  122. }
  123. private MemberDocImpl findMember() {
  124. Dec dec = introducedDec.getDec();
  125. // fix applied all, though bug was only in methods and constructors
  126. // verified working in all, including fields
  127. dec.setSourceLocation(introducedDec.getSourceLocation()); // PR790, 712
  128. //TODO: a little hacky now
  129. if (dec instanceof FieldDec) {
  130. return new FieldDocImpl(containingClass(),
  131. (FieldDec)dec);
  132. } else if (dec instanceof ConstructorDec) {
  133. return new ConstructorDocImpl(containingClass(),
  134. (ConstructorDec)dec);
  135. } else if (dec instanceof MethodDec) {
  136. return new MethodDocImpl(containingClass(),
  137. (MethodDec)dec);
  138. } else {
  139. return null;
  140. }
  141. // should print type pattern for type of introduced member,
  142. // but it messes up source/target associations
  143. // GenTypeName gtn = introducedDec.getTargets();
  144. // if (null != gtn) {
  145. // name = gtn.toShortString() + name;
  146. // }
  147. }
  148. /**
  149. * Returns the toString() of the member.
  150. *
  151. * @return the toString() of the member.
  152. */
  153. public String toString() {
  154. return member.toString();
  155. }
  156. }