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.

PointcutDeclaration.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * Xerox/PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.ajdt.internal.compiler.ast;
  13. import java.io.*;
  14. import java.io.IOException;
  15. import org.aspectj.ajdt.internal.compiler.lookup.EclipseWorld;
  16. import org.aspectj.ajdt.internal.core.builder.EclipseSourceContext;
  17. import org.aspectj.weaver.*;
  18. import org.aspectj.weaver.ResolvedPointcutDefinition;
  19. import org.aspectj.weaver.patterns.Pointcut;
  20. import org.eclipse.jdt.internal.compiler.*;
  21. import org.eclipse.jdt.internal.compiler.ast.*;
  22. import org.eclipse.jdt.internal.compiler.lookup.*;
  23. import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
  24. import org.eclipse.jdt.internal.compiler.parser.Parser;
  25. import org.eclipse.jdt.internal.compiler.util.CharOperation;
  26. /**
  27. * pointcut [declaredModifiers] [declaredName]([arguments]): [pointcutDesignator];
  28. *
  29. * <p>No method will actually be generated for this node but an attribute
  30. * will be added to the enclosing class.</p>
  31. *
  32. * @author Jim Hugunin
  33. */
  34. public class PointcutDeclaration extends MethodDeclaration {
  35. public static final char[] mangledPrefix = "ajc$pointcut$".toCharArray();
  36. public PointcutDesignator pointcutDesignator;
  37. private int declaredModifiers;
  38. private String declaredName;
  39. public PointcutDeclaration(CompilationResult compilationResult) {
  40. super(compilationResult);
  41. this.returnType = TypeReference.baseTypeReference(T_void, 0);
  42. }
  43. private Pointcut getPointcut() {
  44. if (pointcutDesignator == null) {
  45. return Pointcut.makeMatchesNothing(Pointcut.RESOLVED);
  46. } else {
  47. return pointcutDesignator.getPointcut();
  48. }
  49. }
  50. public void parseStatements(
  51. Parser parser,
  52. CompilationUnitDeclaration unit) {
  53. // do nothing
  54. }
  55. public void postParse(TypeDeclaration typeDec) {
  56. if (arguments == null) arguments = new Argument[0];
  57. this.declaredModifiers = modifiers;
  58. this.declaredName = new String(selector);
  59. selector = CharOperation.concat(mangledPrefix, '$', selector, '$',
  60. Integer.toHexString(sourceStart).toCharArray());
  61. if (pointcutDesignator == null) return; //XXX
  62. pointcutDesignator.postParse(typeDec, this);
  63. }
  64. public void resolveStatements(ClassScope upperScope) {
  65. if (isAbstract()) this.modifiers |= AccSemicolonBody;
  66. if (binding == null || ignoreFurtherInvestigation) return;
  67. if (pointcutDesignator != null) {
  68. pointcutDesignator.finishResolveTypes(this, this.binding, arguments.length,
  69. upperScope.referenceContext.binding);
  70. }
  71. super.resolveStatements(upperScope);
  72. }
  73. public ResolvedPointcutDefinition makeResolvedPointcutDefinition() {
  74. //System.out.println("pc: " + getPointcut());
  75. ResolvedPointcutDefinition ret = new ResolvedPointcutDefinition(
  76. EclipseWorld.fromBinding(this.binding.declaringClass),
  77. declaredModifiers,
  78. declaredName,
  79. EclipseWorld.fromBindings(this.binding.parameters),
  80. getPointcut());
  81. ret.setPosition(sourceStart, sourceEnd);
  82. ret.setSourceContext(new EclipseSourceContext(compilationResult));
  83. return ret;
  84. }
  85. public AjAttribute makeAttribute() {
  86. return new AjAttribute.PointcutDeclarationAttribute(makeResolvedPointcutDefinition());
  87. }
  88. /**
  89. * A pointcut declaration exists in a classfile only as an attibute on the
  90. * class. Unlike advice and inter-type declarations, it has no corresponding
  91. * method.
  92. */
  93. public void generateCode(ClassScope classScope, ClassFile classFile) {
  94. if (ignoreFurtherInvestigation) return ;
  95. classFile.extraAttributes.add(new EclipseAttributeAdapter(makeAttribute()));
  96. return;
  97. }
  98. public String toString(int tab) {
  99. StringBuffer buf = new StringBuffer();
  100. buf.append(tabString(tab));
  101. if (modifiers != 0) {
  102. buf.append(modifiersString(modifiers));
  103. }
  104. buf.append("pointcut ");
  105. buf.append(new String(selector));
  106. buf.append("(");
  107. if (arguments != null) {
  108. for (int i = 0; i < arguments.length; i++) {
  109. if (i > 0) buf.append(", ");
  110. buf.append(arguments[i].toString(0));
  111. };
  112. };
  113. buf.append("): ");
  114. buf.append(getPointcut());
  115. buf.append(";");
  116. return buf.toString();
  117. }
  118. }