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.

AsmElementFormatter.java 20KB

14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
5 years ago
14 years ago
14 years ago
14 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * Alexandre Vasseur support for @AJ style
  12. * ******************************************************************/
  13. package org.aspectj.ajdt.internal.core.builder;
  14. import java.util.ArrayList;
  15. import java.util.Collections;
  16. import java.util.List;
  17. import org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration;
  18. import org.aspectj.ajdt.internal.compiler.ast.DeclareDeclaration;
  19. import org.aspectj.ajdt.internal.compiler.ast.InterTypeConstructorDeclaration;
  20. import org.aspectj.ajdt.internal.compiler.ast.InterTypeDeclaration;
  21. import org.aspectj.ajdt.internal.compiler.ast.InterTypeFieldDeclaration;
  22. import org.aspectj.ajdt.internal.compiler.ast.InterTypeMethodDeclaration;
  23. import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration;
  24. import org.aspectj.ajdt.internal.compiler.lookup.AjLookupEnvironment;
  25. import org.aspectj.asm.IProgramElement;
  26. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
  27. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation;
  28. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument;
  29. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference;
  30. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference;
  31. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
  32. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference;
  33. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference;
  34. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
  35. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
  36. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference;
  37. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Wildcard;
  38. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.MethodScope;
  39. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
  40. import org.aspectj.weaver.AdviceKind;
  41. import org.aspectj.weaver.ResolvedType;
  42. import org.aspectj.weaver.UnresolvedType;
  43. import org.aspectj.weaver.model.AsmRelationshipUtils;
  44. import org.aspectj.weaver.patterns.DeclareAnnotation;
  45. import org.aspectj.weaver.patterns.DeclareErrorOrWarning;
  46. import org.aspectj.weaver.patterns.DeclareParents;
  47. import org.aspectj.weaver.patterns.DeclarePrecedence;
  48. import org.aspectj.weaver.patterns.DeclareSoft;
  49. import org.aspectj.weaver.patterns.TypePattern;
  50. import org.aspectj.weaver.patterns.TypePatternList;
  51. /**
  52. * @author Mik Kersten
  53. */
  54. public class AsmElementFormatter {
  55. private final static String ASPECTJ_ANNOTATION_PACKAGE = "org.aspectj.lang.annotation";
  56. private final static char PACKAGE_INITIAL_CHAR = ASPECTJ_ANNOTATION_PACKAGE.charAt(0);
  57. public void genLabelAndKind(MethodDeclaration methodDeclaration, IProgramElement node) {
  58. if (methodDeclaration instanceof AdviceDeclaration) {
  59. AdviceDeclaration ad = (AdviceDeclaration) methodDeclaration;
  60. node.setKind(IProgramElement.Kind.ADVICE);
  61. if (ad.kind == AdviceKind.Around) {
  62. node.setCorrespondingType(ad.returnType.toString()); // returnTypeToString(0));
  63. }
  64. StringBuilder details = new StringBuilder();
  65. if (ad.pointcutDesignator != null) {
  66. details.append(AsmRelationshipUtils.genPointcutDetails(ad.pointcutDesignator.getPointcut()));
  67. } else {
  68. details.append(AsmRelationshipUtils.POINTCUT_ABSTRACT);
  69. }
  70. node.setName(ad.kind.toString());
  71. // if (details.length()!=0)
  72. node.setDetails(details.toString());
  73. setParameters(methodDeclaration, node);
  74. } else if (methodDeclaration instanceof PointcutDeclaration) {
  75. // PointcutDeclaration pd = (PointcutDeclaration) methodDeclaration;
  76. node.setKind(IProgramElement.Kind.POINTCUT);
  77. node.setName(translatePointcutName(new String(methodDeclaration.selector)));
  78. setParameters(methodDeclaration, node);
  79. } else if (methodDeclaration instanceof DeclareDeclaration) {
  80. DeclareDeclaration declare = (DeclareDeclaration) methodDeclaration;
  81. String name = AsmRelationshipUtils.DEC_LABEL + " ";
  82. if (declare.declareDecl instanceof DeclareErrorOrWarning) {
  83. DeclareErrorOrWarning deow = (DeclareErrorOrWarning) declare.declareDecl;
  84. if (deow.isError()) {
  85. node.setKind(IProgramElement.Kind.DECLARE_ERROR);
  86. name += AsmRelationshipUtils.DECLARE_ERROR;
  87. } else {
  88. node.setKind(IProgramElement.Kind.DECLARE_WARNING);
  89. name += AsmRelationshipUtils.DECLARE_WARNING;
  90. }
  91. node.setName(name);
  92. node.setDetails("\"" + AsmRelationshipUtils.genDeclareMessage(deow.getMessage()) + "\"");
  93. } else if (declare.declareDecl instanceof DeclareParents) {
  94. node.setKind(IProgramElement.Kind.DECLARE_PARENTS);
  95. DeclareParents dp = (DeclareParents) declare.declareDecl;
  96. node.setName(name + AsmRelationshipUtils.DECLARE_PARENTS);
  97. String kindOfDP = null;
  98. StringBuilder details = new StringBuilder("");
  99. TypePattern[] newParents = dp.getParents().getTypePatterns();
  100. for (int i = 0; i < newParents.length; i++) {
  101. TypePattern tp = newParents[i];
  102. UnresolvedType tx = tp.getExactType();
  103. if (kindOfDP == null) {
  104. kindOfDP = "implements ";
  105. try {
  106. ResolvedType rtx = tx.resolve(((AjLookupEnvironment) declare.scope.environment()).factory.getWorld());
  107. if (!rtx.isInterface()) {
  108. kindOfDP = "extends ";
  109. }
  110. } catch (Throwable t) {
  111. // What can go wrong???? who knows!
  112. }
  113. }
  114. String typename = tp.toString();
  115. if (typename.lastIndexOf(".") != -1) {
  116. typename = typename.substring(typename.lastIndexOf(".") + 1);
  117. }
  118. details.append(typename);
  119. if ((i + 1) < newParents.length) {
  120. details.append(",");
  121. }
  122. }
  123. node.setDetails(kindOfDP + details.toString());
  124. } else if (declare.declareDecl instanceof DeclareSoft) {
  125. node.setKind(IProgramElement.Kind.DECLARE_SOFT);
  126. DeclareSoft ds = (DeclareSoft) declare.declareDecl;
  127. node.setName(name + AsmRelationshipUtils.DECLARE_SOFT);
  128. node.setDetails(genTypePatternLabel(ds.getException()));
  129. } else if (declare.declareDecl instanceof DeclarePrecedence) {
  130. node.setKind(IProgramElement.Kind.DECLARE_PRECEDENCE);
  131. DeclarePrecedence ds = (DeclarePrecedence) declare.declareDecl;
  132. node.setName(name + AsmRelationshipUtils.DECLARE_PRECEDENCE);
  133. node.setDetails(genPrecedenceListLabel(ds.getPatterns()));
  134. } else if (declare.declareDecl instanceof DeclareAnnotation) {
  135. DeclareAnnotation deca = (DeclareAnnotation) declare.declareDecl;
  136. String thekind = deca.getKind().toString();
  137. node.setName(name + "@" + thekind.substring(3));
  138. if (deca.getKind() == DeclareAnnotation.AT_CONSTRUCTOR) {
  139. node.setKind(IProgramElement.Kind.DECLARE_ANNOTATION_AT_CONSTRUCTOR);
  140. } else if (deca.getKind() == DeclareAnnotation.AT_FIELD) {
  141. node.setKind(IProgramElement.Kind.DECLARE_ANNOTATION_AT_FIELD);
  142. } else if (deca.getKind() == DeclareAnnotation.AT_METHOD) {
  143. node.setKind(IProgramElement.Kind.DECLARE_ANNOTATION_AT_METHOD);
  144. } else if (deca.getKind() == DeclareAnnotation.AT_TYPE) {
  145. node.setKind(IProgramElement.Kind.DECLARE_ANNOTATION_AT_TYPE);
  146. }
  147. node.setDetails(genDecaLabel(deca));
  148. } else {
  149. node.setKind(IProgramElement.Kind.ERROR);
  150. node.setName(AsmRelationshipUtils.DECLARE_UNKNONWN);
  151. }
  152. } else if (methodDeclaration instanceof InterTypeDeclaration) {
  153. InterTypeDeclaration itd = (InterTypeDeclaration) methodDeclaration;
  154. String fqname = itd.getOnType().toString();
  155. if (fqname.contains(".")) {
  156. // TODO the string handling round here is embarrassing
  157. node.addFullyQualifiedName(fqname + "." + new String(itd.getDeclaredSelector()));
  158. fqname = fqname.substring(fqname.lastIndexOf(".") + 1);
  159. }
  160. String name = fqname + "." + new String(itd.getDeclaredSelector());
  161. if (methodDeclaration instanceof InterTypeFieldDeclaration) {
  162. node.setKind(IProgramElement.Kind.INTER_TYPE_FIELD);
  163. node.setName(name);
  164. } else if (methodDeclaration instanceof InterTypeMethodDeclaration) {
  165. node.setKind(IProgramElement.Kind.INTER_TYPE_METHOD);
  166. node.setName(name);
  167. } else if (methodDeclaration instanceof InterTypeConstructorDeclaration) {
  168. node.setKind(IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR);
  169. // StringBuffer argumentsSignature = new StringBuffer("fubar");
  170. // argumentsSignature.append("(");
  171. // if (methodDeclaration.arguments!=null && methodDeclaration.arguments.length>1) {
  172. //
  173. // for (int i = 1;i<methodDeclaration.arguments.length;i++) {
  174. // argumentsSignature.append(methodDeclaration.arguments[i]);
  175. // if (i+1<methodDeclaration.arguments.length) argumentsSignature.append(",");
  176. // }
  177. // }
  178. // argumentsSignature.append(")");
  179. // InterTypeConstructorDeclaration itcd = (InterTypeConstructorDeclaration)methodDeclaration;
  180. node.setName(itd.getOnType().toString() + "." + itd.getOnType().toString().replace('.', '_'));
  181. } else {
  182. node.setKind(IProgramElement.Kind.ERROR);
  183. node.setName(name);
  184. }
  185. node.setCorrespondingType(new String(itd.returnType.resolvedType.readableName()));
  186. if (node.getKind() != IProgramElement.Kind.INTER_TYPE_FIELD) {
  187. setParameters(methodDeclaration, node);
  188. }
  189. } else {
  190. if (methodDeclaration.isConstructor()) {
  191. node.setKind(IProgramElement.Kind.CONSTRUCTOR);
  192. } else {
  193. node.setKind(IProgramElement.Kind.METHOD);
  194. // TODO AV - could speed up if we could dig only for @Aspect declaring types (or aspect if mixed style allowed)
  195. // ??? how to : node.getParent().getKind().equals(IProgramElement.Kind.ASPECT)) {
  196. if (true && methodDeclaration != null && methodDeclaration.annotations != null && methodDeclaration.scope != null) {
  197. for (int i = 0; i < methodDeclaration.annotations.length; i++) {
  198. // Note: AV: implicit single advice type support here (should be enforced somewhere as well (APT etc))
  199. Annotation annotation = methodDeclaration.annotations[i];
  200. String annotationSig = new String(annotation.type.getTypeBindingPublic(methodDeclaration.scope).signature());
  201. if (annotationSig.charAt(1) == PACKAGE_INITIAL_CHAR) {
  202. if ("Lorg/aspectj/lang/annotation/Pointcut;".equals(annotationSig)) {
  203. node.setKind(IProgramElement.Kind.POINTCUT);
  204. node.setAnnotationStyleDeclaration(true); // pointcuts don't seem to get handled quite right...
  205. break;
  206. } else if ("Lorg/aspectj/lang/annotation/Before;".equals(annotationSig)
  207. || "Lorg/aspectj/lang/annotation/After;".equals(annotationSig)
  208. || "Lorg/aspectj/lang/annotation/AfterReturning;".equals(annotationSig)
  209. || "Lorg/aspectj/lang/annotation/AfterThrowing;".equals(annotationSig)
  210. || "Lorg/aspectj/lang/annotation/Around;".equals(annotationSig)) {
  211. node.setKind(IProgramElement.Kind.ADVICE);
  212. node.setAnnotationStyleDeclaration(true);
  213. // TODO AV - all are considered anonymous - is that ok?
  214. node.setDetails(AsmRelationshipUtils.POINTCUT_ANONYMOUS);
  215. break;
  216. }
  217. }
  218. }
  219. }
  220. }
  221. node.setName(new String(methodDeclaration.selector));
  222. setParameters(methodDeclaration, node);
  223. }
  224. }
  225. private String genDecaLabel(DeclareAnnotation deca) {
  226. StringBuilder sb = new StringBuilder("");
  227. sb.append(deca.getPatternAsString());
  228. sb.append(" : ");
  229. sb.append(deca.getAnnotationString());
  230. return sb.toString();
  231. }
  232. private String genPrecedenceListLabel(TypePatternList list) {
  233. String tpList = "";
  234. for (int i = 0; i < list.size(); i++) {
  235. tpList += genTypePatternLabel(list.get(i));
  236. if (i < list.size() - 1) {
  237. tpList += ", ";
  238. }
  239. }
  240. return tpList;
  241. }
  242. // private String genArguments(MethodDeclaration md) {
  243. // String args = "";
  244. // Argument[] argArray = md.arguments;
  245. // if (argArray == null) return args;
  246. // for (int i = 0; i < argArray.length; i++) {
  247. // String argName = new String(argArray[i].name);
  248. // String argType = argArray[i].type.toString();
  249. // if (acceptArgument(argName, argType)) {
  250. // args += argType + ", ";
  251. // }
  252. // }
  253. // int lastSepIndex = args.lastIndexOf(',');
  254. // if (lastSepIndex != -1 && args.endsWith(", ")) args = args.substring(0, lastSepIndex);
  255. // return args;
  256. // }
  257. private String handleSigForReference(TypeReference ref, TypeBinding tb, MethodScope scope) {
  258. try {
  259. StringBuffer sb = new StringBuffer();
  260. createHandleSigForReference(ref, tb, scope, sb);
  261. return sb.toString();
  262. } catch (Throwable t) {
  263. System.err.println("Problem creating handle sig for this type reference " + ref);
  264. t.printStackTrace(System.err);
  265. return null;
  266. }
  267. }
  268. /**
  269. * Aim of this method is create the signature for a parameter that can be used in a handle such that JDT can interpret the
  270. * handle. Whether a type is qualified or unqualified in its source reference is actually reflected in the handle and this code
  271. * allows for that.
  272. */
  273. private void createHandleSigForReference(TypeReference ref, TypeBinding tb, MethodScope scope, StringBuffer handleSig) {
  274. if (ref instanceof Wildcard) {
  275. Wildcard w = (Wildcard) ref;
  276. if (w.bound == null) {
  277. handleSig.append('*');
  278. } else {
  279. handleSig.append('+');
  280. TypeBinding typeB = w.bound.resolvedType;
  281. if (typeB == null) {
  282. typeB = w.bound.resolveType(scope);
  283. }
  284. createHandleSigForReference(w.bound, typeB, scope, handleSig);
  285. }
  286. } else if (ref instanceof ParameterizedSingleTypeReference) {
  287. ParameterizedSingleTypeReference pstr = (ParameterizedSingleTypeReference) ref;
  288. for (int i = pstr.dimensions(); i > 0; i--) {
  289. handleSig.append("\\[");
  290. }
  291. handleSig.append('Q').append(pstr.token);
  292. TypeReference[] typeRefs = pstr.typeArguments;
  293. if (typeRefs != null && typeRefs.length > 0) {
  294. handleSig.append("\\<");
  295. for (TypeReference typeR : typeRefs) {
  296. TypeBinding typeB = typeR.resolvedType;
  297. if (typeB == null) {
  298. typeB = typeR.resolveType(scope);
  299. }
  300. createHandleSigForReference(typeR, typeB, scope, handleSig);
  301. }
  302. handleSig.append('>');
  303. }
  304. handleSig.append(';');
  305. } else if (ref instanceof ArrayTypeReference) {
  306. ArrayTypeReference atr = (ArrayTypeReference) ref;
  307. for (int i = 0; i < atr.dimensions; i++) {
  308. handleSig.append("\\[");
  309. }
  310. TypeBinding typeB = atr.resolvedType;
  311. if (typeB == null) {
  312. typeB = atr.resolveType(scope);
  313. }
  314. if (typeB.leafComponentType().isBaseType()) {
  315. handleSig.append(tb.leafComponentType().signature());
  316. } else {
  317. handleSig.append('Q').append(atr.token).append(';');
  318. }
  319. } else if (ref instanceof SingleTypeReference) {
  320. SingleTypeReference str = (SingleTypeReference) ref;
  321. if (tb.isBaseType()) {
  322. handleSig.append(tb.signature());
  323. } else {
  324. handleSig.append('Q').append(str.token).append(';');
  325. }
  326. } else if (ref instanceof ParameterizedQualifiedTypeReference) {
  327. ParameterizedQualifiedTypeReference pstr = (ParameterizedQualifiedTypeReference) ref;
  328. char[][] tokens = pstr.tokens;
  329. for (int i = pstr.dimensions(); i > 0; i--) {
  330. handleSig.append("\\[");
  331. }
  332. handleSig.append('Q');
  333. for (int i = 0; i < tokens.length; i++) {
  334. if (i > 0) {
  335. handleSig.append('.');
  336. }
  337. handleSig.append(tokens[i]);
  338. TypeReference[] typeRefs = pstr.typeArguments[i];
  339. if (typeRefs != null && typeRefs.length > 0) {
  340. handleSig.append("\\<");
  341. for (TypeReference typeR : typeRefs) {
  342. TypeBinding typeB = typeR.resolvedType;
  343. if (typeB == null) {
  344. typeB = typeR.resolveType(scope);
  345. }
  346. createHandleSigForReference(typeR, typeB, scope, handleSig);
  347. }
  348. handleSig.append('>');
  349. }
  350. }
  351. handleSig.append(';');
  352. } else if (ref instanceof ArrayQualifiedTypeReference) {
  353. ArrayQualifiedTypeReference atr = (ArrayQualifiedTypeReference) ref;
  354. for (int i = 0; i < atr.dimensions(); i++) {
  355. handleSig.append("\\[");
  356. }
  357. TypeBinding typeB = atr.resolvedType;
  358. if (typeB == null) {
  359. typeB = atr.resolveType(scope);
  360. }
  361. if (typeB.leafComponentType().isBaseType()) {
  362. handleSig.append(tb.leafComponentType().signature());
  363. } else {
  364. char[][] tokens = atr.tokens;
  365. handleSig.append('Q');
  366. for (int i = 0; i < tokens.length; i++) {
  367. if (i > 0) {
  368. handleSig.append('.');
  369. }
  370. handleSig.append(tokens[i]);
  371. }
  372. handleSig.append(';');
  373. }
  374. } else if (ref instanceof QualifiedTypeReference) {
  375. QualifiedTypeReference qtr = (QualifiedTypeReference) ref;
  376. char[][] tokens = qtr.tokens;
  377. handleSig.append('Q');
  378. for (int i = 0; i < tokens.length; i++) {
  379. if (i > 0) {
  380. handleSig.append('.');
  381. }
  382. handleSig.append(tokens[i]);
  383. }
  384. handleSig.append(';');
  385. } else {
  386. throw new RuntimeException("Cant handle " + ref.getClass());
  387. }
  388. }
  389. public void setParameters(AbstractMethodDeclaration md, IProgramElement pe) {
  390. Argument[] argArray = md.arguments;
  391. if (argArray == null) {
  392. pe.setParameterNames(Collections.<String>emptyList());
  393. pe.setParameterSignatures(Collections.<char[]>emptyList(), Collections.<String>emptyList());
  394. } else {
  395. List<String> names = new ArrayList<>();
  396. List<char[]> paramSigs = new ArrayList<>();
  397. List<String> paramSourceRefs = new ArrayList<>();
  398. boolean problemWithSourceRefs = false;
  399. for (Argument argument : argArray) {
  400. String argName = new String(argument.name);
  401. // String argType = "<UnknownType>"; // pr135052
  402. if (acceptArgument(argName, argument.type.toString())) {
  403. TypeReference typeR = argument.type;
  404. if (typeR != null && md.scope != null) {
  405. TypeBinding typeB = typeR.resolvedType;
  406. if (typeB == null) {
  407. typeB = typeR.resolveType(md.scope);
  408. }
  409. // This code will conjure up a 'P' style signature:
  410. // EclipseFactory factory = EclipseFactory.fromScopeLookupEnvironment(md.scope);
  411. // UnresolvedType ut = factory.fromBinding(typeB);
  412. // paramSigs.add(ut.getSignature().toCharArray());
  413. paramSigs.add(typeB.genericTypeSignature());
  414. String hsig = handleSigForReference(typeR, typeB, md.scope);
  415. if (hsig == null) {
  416. problemWithSourceRefs = true;
  417. } else {
  418. paramSourceRefs.add(hsig);
  419. }
  420. }
  421. names.add(argName);
  422. }
  423. }
  424. pe.setParameterNames(names);
  425. if (!paramSigs.isEmpty()) {
  426. pe.setParameterSignatures(paramSigs, (problemWithSourceRefs ? null : paramSourceRefs));
  427. }
  428. }
  429. }
  430. // TODO: fix this way of determing ajc-added arguments, make subtype of Argument with extra info
  431. private boolean acceptArgument(String name, String type) {
  432. if (name.charAt(0) != 'a' && type.charAt(0) != PACKAGE_INITIAL_CHAR) {
  433. return true;
  434. }
  435. return !name.startsWith("ajc$this_") && !type.equals("org.aspectj.lang.JoinPoint.StaticPart")
  436. && !type.equals("org.aspectj.lang.JoinPoint") && !type.equals("org.aspectj.runtime.internal.AroundClosure");
  437. }
  438. public String genTypePatternLabel(TypePattern tp) {
  439. final String TYPE_PATTERN_LITERAL = "<type pattern>";
  440. String label;
  441. UnresolvedType typeX = tp.getExactType();
  442. if (!ResolvedType.isMissing(typeX)) {
  443. label = typeX.getName();
  444. if (tp.isIncludeSubtypes()) {
  445. label += "+";
  446. }
  447. } else {
  448. label = TYPE_PATTERN_LITERAL;
  449. }
  450. return label;
  451. }
  452. // // TODO:
  453. // private String translateAdviceName(String label) {
  454. // if (label.indexOf("before") != -1) return "before";
  455. // if (label.indexOf("returning") != -1) return "after returning";
  456. // if (label.indexOf("after") != -1) return "after";
  457. // if (label.indexOf("around") != -1) return "around";
  458. // else return "<advice>";
  459. // }
  460. // // !!! move or replace
  461. // private String translateDeclareName(String name) {
  462. // int colonIndex = name.indexOf(":");
  463. // if (colonIndex != -1) {
  464. // return name.substring(0, colonIndex);
  465. // } else {
  466. // return name;
  467. // }
  468. // }
  469. // !!! move or replace
  470. // private String translateInterTypeDecName(String name) {
  471. // int index = name.lastIndexOf('$');
  472. // if (index != -1) {
  473. // return name.substring(index+1);
  474. // } else {
  475. // return name;
  476. // }
  477. // }
  478. // !!! move or replace
  479. private String translatePointcutName(String name) {
  480. int index = name.indexOf("$$") + 2;
  481. int endIndex = name.lastIndexOf('$');
  482. if (index != -1 && endIndex != -1) {
  483. return name.substring(index, endIndex);
  484. } else {
  485. return name;
  486. }
  487. }
  488. }