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.

AsmRelationshipUtils.java 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /********************************************************************
  2. * Copyright (c) 2006 Contributors. All rights reserved.
  3. * This program and the accompanying materials are made available
  4. * under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution and is available at
  6. * http://eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: IBM Corporation - initial API and implementation
  9. * Helen Hawkins - initial version
  10. *******************************************************************/
  11. package org.aspectj.weaver.model;
  12. import org.aspectj.weaver.patterns.AndPointcut;
  13. import org.aspectj.weaver.patterns.OrPointcut;
  14. import org.aspectj.weaver.patterns.Pointcut;
  15. import org.aspectj.weaver.patterns.ReferencePointcut;
  16. /**
  17. * Provides utility methods for generating details for IProgramElements used when creating the model both from source (via
  18. * AsmElementFormatter.visit(..)) and when filling in the model for binary aspects (via AsmRelationshipProvider bug 145963)
  19. */
  20. public class AsmRelationshipUtils {
  21. // public static final String UNDEFINED="<undefined>";
  22. public static final String DECLARE_PRECEDENCE = "precedence";
  23. public static final String DECLARE_SOFT = "soft";
  24. public static final String DECLARE_PARENTS = "parents";
  25. public static final String DECLARE_WARNING = "warning";
  26. public static final String DECLARE_ERROR = "error";
  27. public static final String DECLARE_UNKNONWN = "<unknown declare>";
  28. public static final String POINTCUT_ABSTRACT = "<abstract pointcut>";
  29. public static final String POINTCUT_ANONYMOUS = "<anonymous pointcut>";
  30. public static final String DOUBLE_DOTS = "..";
  31. public static final int MAX_MESSAGE_LENGTH = 18;
  32. public static final String DEC_LABEL = "declare";
  33. /**
  34. * Generates the declare message used in the details, for example if the declare warning statement has message
  35. * "There should be no printlns" will return 'declare warning: "There should be n.."'
  36. */
  37. public static String genDeclareMessage(String message) {
  38. int length = message.length();
  39. if (length < MAX_MESSAGE_LENGTH) {
  40. return message;
  41. } else {
  42. return message.substring(0, MAX_MESSAGE_LENGTH - 1) + DOUBLE_DOTS;
  43. }
  44. }
  45. /**
  46. * Generates the pointcut details for the given pointcut, for example an anonymous pointcut will return '&lt;anonymous pointcut&gt;'
  47. * and a named pointcut called p() will return 'p()..'
  48. */
  49. public static String genPointcutDetails(Pointcut pcd) {
  50. StringBuffer details = new StringBuffer();
  51. if (pcd instanceof ReferencePointcut) {
  52. ReferencePointcut rp = (ReferencePointcut) pcd;
  53. details.append(rp.name).append(DOUBLE_DOTS);
  54. } else if (pcd instanceof AndPointcut) {
  55. AndPointcut ap = (AndPointcut) pcd;
  56. if (ap.getLeft() instanceof ReferencePointcut) {
  57. details.append(ap.getLeft().toString()).append(DOUBLE_DOTS);
  58. } else {
  59. details.append(POINTCUT_ANONYMOUS).append(DOUBLE_DOTS);
  60. }
  61. } else if (pcd instanceof OrPointcut) {
  62. OrPointcut op = (OrPointcut) pcd;
  63. if (op.getLeft() instanceof ReferencePointcut) {
  64. details.append(op.getLeft().toString()).append(DOUBLE_DOTS);
  65. } else {
  66. details.append(POINTCUT_ANONYMOUS).append(DOUBLE_DOTS);
  67. }
  68. } else {
  69. details.append(POINTCUT_ANONYMOUS);
  70. }
  71. return details.toString();
  72. }
  73. }