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.

PointcutImpl.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* *******************************************************************
  2. * Copyright (c) 2005 Contributors.
  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. * Adrian Colyer Initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.internal.lang.reflect;
  13. import java.lang.reflect.Method;
  14. import java.util.StringTokenizer;
  15. import org.aspectj.lang.reflect.AjType;
  16. import org.aspectj.lang.reflect.AjTypeSystem;
  17. import org.aspectj.lang.reflect.Pointcut;
  18. import org.aspectj.lang.reflect.PointcutExpression;
  19. /**
  20. * @author colyer
  21. *
  22. */
  23. public class PointcutImpl implements Pointcut {
  24. private final String name;
  25. private final PointcutExpression pc;
  26. private final Method baseMethod;
  27. private final AjType<?> declaringType;
  28. private String[] parameterNames = new String[0];
  29. protected PointcutImpl(String name, String pc, Method method, AjType declaringType, String pNames) {
  30. this.name = name;
  31. this.pc = new PointcutExpressionImpl(pc);
  32. this.baseMethod = method;
  33. this.declaringType = declaringType;
  34. this.parameterNames = splitOnComma(pNames);
  35. }
  36. /* (non-Javadoc)
  37. * @see org.aspectj.lang.reflect.Pointcut#getPointcutExpression()
  38. */
  39. public PointcutExpression getPointcutExpression() {
  40. return pc;
  41. }
  42. public String getName() {
  43. return name;
  44. }
  45. public int getModifiers() {
  46. return baseMethod.getModifiers();
  47. }
  48. public AjType<?>[] getParameterTypes() {
  49. Class<?>[] baseParamTypes = baseMethod.getParameterTypes();
  50. AjType<?>[] ajParamTypes = new AjType<?>[baseParamTypes.length];
  51. for (int i = 0; i < ajParamTypes.length; i++) {
  52. ajParamTypes[i] = AjTypeSystem.getAjType(baseParamTypes[i]);
  53. }
  54. return ajParamTypes;
  55. }
  56. public AjType getDeclaringType() {
  57. return declaringType;
  58. }
  59. public String[] getParameterNames() {
  60. return parameterNames;
  61. }
  62. private String[] splitOnComma(String s) {
  63. StringTokenizer strTok = new StringTokenizer(s,",");
  64. String[] ret = new String[strTok.countTokens()];
  65. for (int i = 0; i < ret.length; i++) {
  66. ret[i] = strTok.nextToken().trim();
  67. }
  68. return ret;
  69. }
  70. public String toString() {
  71. StringBuilder sb = new StringBuilder();
  72. sb.append(getName());
  73. sb.append("(");
  74. AjType<?>[] ptypes = getParameterTypes();
  75. for (int i = 0; i < ptypes.length; i++) {
  76. sb.append(ptypes[i].getName());
  77. if (this.parameterNames != null && this.parameterNames[i] != null) {
  78. sb.append(" ");
  79. sb.append(this.parameterNames[i]);
  80. }
  81. if (i+1 < ptypes.length) sb.append(",");
  82. }
  83. sb.append(") : ");
  84. sb.append(getPointcutExpression().asString());
  85. return sb.toString();
  86. }
  87. }