1 22 package org.aspectj.tools.ajdoc; 23 24 import org.aspectj.ajdoc.AdviceDoc; 25 import org.aspectj.compiler.base.ast.Formals; 26 import org.aspectj.compiler.base.ast.NameType; 27 import org.aspectj.compiler.base.ast.TypeDs; 28 29 import com.sun.javadoc.ClassDoc; 30 import com.sun.javadoc.ExecutableMemberDoc; 31 import com.sun.javadoc.ParamTag; 32 import com.sun.javadoc.Parameter; 33 import com.sun.javadoc.ThrowsTag; 34 35 import java.lang.reflect.Modifier ; 36 import java.util.ArrayList ; 37 import java.util.Collection ; 38 import java.util.Collections ; 39 import java.util.List ; 40 41 public abstract class ExecutableMemberDocImpl 42 extends MemberDocImpl 43 implements ExecutableMemberDoc { 44 45 52 53 54 private Collection advice; 55 56 57 private Collection parameters; 58 59 60 private Collection thrownExceptions; 61 62 63 private String signature; 64 65 66 private String flatSignature; 67 68 73 public ExecutableMemberDocImpl(ClassDoc containingClass) { 74 super(containingClass); 75 } 76 77 85 protected abstract Collection createAdvice(); 86 87 92 protected abstract Formals getFormals(); 93 94 101 protected abstract TypeDs getThrows(); 102 103 104 110 public void makeParameters(Formals formals) { 111 parameters = createParameters(formals); 112 } 113 114 120 public void makeThrownExceptions(TypeDs thrown) { 121 thrownExceptions = createThrownExceptions(thrown); 122 } 123 124 130 public final AdviceDoc[] advice() { 131 if (advice == null) advice = createAdvice(); 132 return (AdviceDoc[])advice.toArray(new AdviceDoc[advice.size()]); 133 } 134 135 141 public final ClassDoc[] thrownExceptions() { 142 if (thrownExceptions == null) makeThrownExceptions(getThrows()); 143 return (ClassDoc[])thrownExceptions.toArray 144 (new ClassDoc[thrownExceptions.size()]); 145 } 146 147 153 public final Parameter[] parameters() { 154 if (parameters == null) makeParameters(getFormals()); 155 return (Parameter[])parameters.toArray 156 (new Parameter[parameters.size()]); 157 } 158 159 164 public String flatSignature() { 165 if (flatSignature == null) { 166 flatSignature = Util.flatSignature(parameters()); 167 } 168 return flatSignature; 169 } 170 171 176 public String signature() { 177 if (signature == null) { 178 signature = Util.signature(parameters()); 179 } 180 return signature; 181 } 182 183 188 public boolean isSynchronized() { 189 return Modifier.isSynchronized(modifierSpecifier()); 191 } 192 193 198 public boolean isNative() { 199 return Modifier.isNative(modifierSpecifier()); 201 } 202 203 210 public ThrowsTag[] throwsTags() { 211 return getComment().throwsTags(); 212 } 213 214 221 public ParamTag[] paramTags() { 222 return getComment().paramTags(); 223 } 224 225 232 public String toString() { 233 StringBuffer sb = new StringBuffer (name()); 234 sb.append('('); 235 Parameter[] params = parameters(); 236 for (int i = 0, N = params.length; i < N; i++) { 237 if (i > 0) sb.append(","); 238 sb.append(params[i].type().qualifiedTypeName()); 239 sb.append(params[i].type().dimension()); 240 } 241 sb.append(')'); 242 return sb.toString(); 243 } 244 245 253 private Collection createParameters(Formals formals) { 254 if (formals == null) return Collections.EMPTY_LIST; 255 List list = new ArrayList (formals.size()); 256 for (int i = 0, N = formals.size(); i < N; i++) { 257 list.add(new ParameterImpl(formals.get(i))); 258 } 259 return list; 260 } 261 262 270 private Collection createThrownExceptions(TypeDs typeds) { 271 if (typeds == null) return Collections.EMPTY_LIST; 272 List list = new ArrayList (typeds.size()); 273 for (int i = 0, N = typeds.size(); i < N; i++) { 274 list.add(ClassDocImpl.getInstance 275 (((NameType)typeds.get(i).getType()).getTypeDec())); 276 } 277 return list; 278 } 279 280 287 public boolean weakEquals(Object md) { 288 if (!(md instanceof ExecutableMemberDocImpl)) { 289 return false; 290 } 291 ExecutableMemberDocImpl emdi = (ExecutableMemberDocImpl)md; 292 if (!name().equals(emdi.name())) { 293 return false; 294 } 295 Parameter[] ourPds = this.parameters(); 296 Parameter[] edsPds = emdi.parameters(); 297 if (ourPds.length != edsPds.length) { 298 return false; 299 } 300 for (int i = 0, N = ourPds.length; i < N; i++) { 301 if (!ourPds[i].equals(edsPds[i])) { 302 return false; 303 } 304 } 305 return true; 306 } 307 } 308 | Popular Tags |