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.

ResolvedPointcutDefinition.java 5.1KB

hace 15 años
hace 15 años
hace 15 años
hace 15 años
hace 15 años
hace 14 años
hace 15 años
hace 15 años
hace 15 años
hace 14 años
hace 15 años
hace 15 años
hace 15 años
hace 14 años
hace 14 años
hace 15 años
hace 15 años
hace 15 años
hace 14 años
hace 15 años
hace 15 años
hace 14 años
hace 15 años
hace 15 años
hace 15 años
hace 15 años
hace 15 años
hace 15 años
hace 15 años
hace 15 años
hace 15 años
hace 15 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. * ******************************************************************/
  12. package org.aspectj.weaver;
  13. import java.io.IOException;
  14. import java.util.HashMap;
  15. import java.util.Map;
  16. import org.aspectj.weaver.patterns.Pointcut;
  17. public class ResolvedPointcutDefinition extends ResolvedMemberImpl {
  18. private Pointcut pointcut;
  19. public ResolvedPointcutDefinition(UnresolvedType declaringType, int modifiers, String name, UnresolvedType[] parameterTypes,
  20. Pointcut pointcut) {
  21. this(declaringType, modifiers, name, parameterTypes, UnresolvedType.VOID, pointcut);
  22. }
  23. /**
  24. * An instance which can be given a specific returnType, used f.e. in if() pointcut for @AJ
  25. *
  26. * @param declaringType
  27. * @param modifiers
  28. * @param name
  29. * @param parameterTypes
  30. * @param returnType
  31. * @param pointcut
  32. */
  33. public ResolvedPointcutDefinition(UnresolvedType declaringType, int modifiers, String name, UnresolvedType[] parameterTypes,
  34. UnresolvedType returnType, Pointcut pointcut) {
  35. super(POINTCUT, declaringType, modifiers, returnType, name, parameterTypes);
  36. this.pointcut = pointcut;
  37. // XXXpointcut.assertState(Pointcut.RESOLVED);
  38. checkedExceptions = UnresolvedType.NONE;
  39. }
  40. // ----
  41. @Override
  42. public void write(CompressingDataOutputStream s) throws IOException {
  43. getDeclaringType().write(s);
  44. s.writeInt(getModifiers());
  45. s.writeUTF(getName());
  46. UnresolvedType.writeArray(getParameterTypes(), s);
  47. pointcut.write(s);
  48. }
  49. public static ResolvedPointcutDefinition read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  50. ResolvedPointcutDefinition rpd = new ResolvedPointcutDefinition(UnresolvedType.read(s), s.readInt(), s.readUTF(),
  51. UnresolvedType.readArray(s), Pointcut.read(s, context));
  52. rpd.setSourceContext(context); // whilst we have a source context, let's remember it
  53. return rpd;
  54. }
  55. @Override
  56. public String toString() {
  57. StringBuilder buf = new StringBuilder();
  58. buf.append("pointcut ");
  59. buf.append((getDeclaringType() == null ? "<nullDeclaringType>" : getDeclaringType().getName()));
  60. buf.append(".");
  61. buf.append(getName());
  62. buf.append("(");
  63. for (int i = 0; i < getParameterTypes().length; i++) {
  64. if (i > 0) {
  65. buf.append(", ");
  66. }
  67. buf.append(getParameterTypes()[i].toString());
  68. }
  69. buf.append(")");
  70. // buf.append(pointcut);
  71. return buf.toString();
  72. }
  73. public Pointcut getPointcut() {
  74. return pointcut;
  75. }
  76. @Override
  77. public boolean isAjSynthetic() {
  78. return true;
  79. }
  80. /**
  81. * Called when asking a parameterized super-aspect for its pointcuts.
  82. */
  83. @Override
  84. public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters, ResolvedType newDeclaringType,
  85. boolean isParameterized) {
  86. TypeVariable[] typeVariables = getDeclaringType().resolve(newDeclaringType.getWorld()).getTypeVariables();
  87. if (isParameterized && (typeVariables.length != typeParameters.length)) {
  88. throw new IllegalStateException("Wrong number of type parameters supplied");
  89. }
  90. Map<String, UnresolvedType> typeMap = new HashMap<>();
  91. boolean typeParametersSupplied = typeParameters != null && typeParameters.length > 0;
  92. if (typeVariables != null) {
  93. // If no 'replacements' were supplied in the typeParameters array then collapse
  94. // type variables to their first bound.
  95. for (int i = 0; i < typeVariables.length; i++) {
  96. UnresolvedType ut = (!typeParametersSupplied ? typeVariables[i].getFirstBound() : typeParameters[i]);
  97. typeMap.put(typeVariables[i].getName(), ut);
  98. }
  99. }
  100. UnresolvedType parameterizedReturnType = parameterize(getGenericReturnType(), typeMap, isParameterized,
  101. newDeclaringType.getWorld());
  102. UnresolvedType[] parameterizedParameterTypes = new UnresolvedType[getGenericParameterTypes().length];
  103. for (int i = 0; i < parameterizedParameterTypes.length; i++) {
  104. parameterizedParameterTypes[i] = parameterize(getGenericParameterTypes()[i], typeMap, isParameterized,
  105. newDeclaringType.getWorld());
  106. }
  107. ResolvedPointcutDefinition ret = new ResolvedPointcutDefinition(newDeclaringType, getModifiers(), getName(),
  108. parameterizedParameterTypes, parameterizedReturnType, pointcut.parameterizeWith(typeMap,
  109. newDeclaringType.getWorld()));
  110. ret.setTypeVariables(getTypeVariables());
  111. ret.setSourceContext(getSourceContext());
  112. ret.setPosition(getStart(), getEnd());
  113. ret.setParameterNames(getParameterNames());
  114. return ret;
  115. // return this;
  116. }
  117. // for testing
  118. public static final ResolvedPointcutDefinition DUMMY = new ResolvedPointcutDefinition(UnresolvedType.OBJECT, 0, "missing",
  119. UnresolvedType.NONE, Pointcut.makeMatchesNothing(Pointcut.RESOLVED));
  120. public static final ResolvedPointcutDefinition[] NO_POINTCUTS = new ResolvedPointcutDefinition[] {};
  121. public void setPointcut(Pointcut pointcut) {
  122. this.pointcut = pointcut;
  123. }
  124. }