1 22 package org.aspectj.tools.ajdoc; 23 24 25 import org.aspectj.ajdoc.AdviceDoc; 26 import org.aspectj.ajdoc.AspectDoc; 27 import org.aspectj.ajdoc.ClassDoc; 28 import org.aspectj.ajdoc.ExecutableMemberDoc; 29 import org.aspectj.compiler.base.ast.CodeDec; 30 import org.aspectj.compiler.base.ast.FormalDec; 31 import org.aspectj.compiler.base.ast.NameType; 32 import org.aspectj.compiler.base.ast.TypeDec; 33 import org.aspectj.compiler.crosscuts.ast.AdviceDec; 34 import org.aspectj.compiler.crosscuts.ast.AfterReturningAdviceDec; 35 import org.aspectj.compiler.crosscuts.ast.AfterThrowingAdviceDec; 36 import org.aspectj.compiler.crosscuts.ast.AroundAdviceDec; 37 38 import com.sun.javadoc.Type; 39 40 import java.util.ArrayList ; 41 import java.util.Collection ; 42 import java.util.Collections ; 43 import java.util.Iterator ; 44 import java.util.List ; 45 import java.util.Set ; 46 47 public class AdviceDocImpl extends CodeDocImpl implements AdviceDoc { 48 49 50 private final Collection crosscuts; 51 52 59 public AdviceDocImpl(ClassDoc containingClass, AdviceDec adviceDec) { 60 super(containingClass, adviceDec); 61 crosscuts = createCrosscuts(); 62 } 63 64 69 protected AdviceDec adviceDec() { 70 return (AdviceDec)codeDec(); 71 } 72 73 79 public com.sun.javadoc.ExecutableMemberDoc[] crosscuts() { 80 return (ExecutableMemberDoc[])crosscuts.toArray 81 (new ExecutableMemberDoc[crosscuts.size()]); 82 } 83 84 91 public AspectDoc overriddenAspect() { 92 return null; 93 } 94 95 100 public com.sun.javadoc.Type returnType() { 101 if (adviceDec() instanceof AroundAdviceDec) { 102 return TypeImpl.getInstance(adviceDec().getReturnType()); 103 } else { 104 return null; 105 } 106 } 107 108 113 public boolean isAdvice() { 114 return true; 115 } 116 117 122 public boolean isAbstract() { 123 return adviceDec().isAbstract(); 124 } 125 126 127 132 public boolean isThrowing() { 133 return adviceDec() instanceof AfterThrowingAdviceDec; 134 } 135 136 141 public boolean isReturning() { 142 return adviceDec() instanceof AfterReturningAdviceDec; 143 } 144 145 154 public Type extraType() { 155 FormalDec fd = adviceDec().getExtraFormal(); 156 if (fd != null) { 157 return TypeImpl.getInstance(fd.getType()); 158 } 159 return null; 160 } 161 162 163 170 private Collection createCrosscuts() { 171 Set affects = ajc().getCorrespondences().getAffects(adviceDec()); 172 if (affects.size() < 1) return Collections.EMPTY_LIST; 173 List list = new ArrayList (); 174 for (Iterator i = affects.iterator(); i.hasNext();) { 175 Object o = i.next(); 176 if (o instanceof CodeDec) { 177 CodeDec cdec = (CodeDec)o; 178 TypeDec owner = ((NameType)cdec.getDeclaringType()).getTypeDec(); 179 ClassDocImpl cd = ClassDocImpl.getInstance(owner); 180 CodeDocImpl cdoc = cd.docForDec(cdec); 181 if (cdoc != null) { list.add(cdoc); 183 } 184 } 185 } 186 return list; 187 } 188 189 195 public String name() { 196 if (isThrowing() || isReturning()) return "after"; 197 return super.name(); 198 } 199 } 200 | Popular Tags |