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.

PointcutDesignator.java 4.3KB

21 yıl önce
21 yıl önce
21 yıl önce
21 yıl önce
15 yıl önce
21 yıl önce
15 yıl önce
21 yıl önce
15 yıl önce
21 yıl önce
15 yıl önce
15 yıl önce
21 yıl önce
21 yıl önce
15 yıl önce
15 yıl önce
15 yıl önce
21 yıl önce
15 yıl önce
15 yıl önce
21 yıl önce
15 yıl önce
15 yıl önce
15 yıl önce
21 yıl önce
15 yıl önce
15 yıl önce
21 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.ajdt.internal.compiler.ast;
  13. import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
  14. import org.aspectj.ajdt.internal.compiler.lookup.EclipseScope;
  15. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode;
  16. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
  17. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument;
  18. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
  19. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
  20. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
  21. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
  22. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
  23. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
  24. import org.aspectj.org.eclipse.jdt.internal.compiler.parser.Parser;
  25. import org.aspectj.weaver.UnresolvedType;
  26. import org.aspectj.weaver.patterns.FormalBinding;
  27. import org.aspectj.weaver.patterns.Pointcut;
  28. public class PointcutDesignator extends ASTNode {
  29. private Pointcut pointcut;
  30. private PseudoTokens tokens;
  31. private boolean isError = false;
  32. public PointcutDesignator(Parser parser, PseudoTokens tokens) {
  33. super();
  34. sourceStart = tokens.sourceStart;
  35. sourceEnd = tokens.sourceEnd;
  36. this.tokens = tokens;
  37. Pointcut pc = tokens.parsePointcut(parser);
  38. if (pc.toString().equals("")) { // ??? is this a good signal
  39. isError = true;
  40. }
  41. pointcut = pc;
  42. }
  43. // called by AtAspectJVisitor
  44. public PointcutDesignator(Pointcut pc) {
  45. this.pointcut = pc;
  46. }
  47. public void postParse(TypeDeclaration typeDec, MethodDeclaration enclosingDec) {
  48. if (tokens != null)
  49. tokens.postParse(typeDec, enclosingDec);
  50. }
  51. public boolean finishResolveTypes(final AbstractMethodDeclaration dec, MethodBinding method, final int baseArgumentCount,
  52. SourceTypeBinding sourceTypeBinding) {
  53. // System.err.println("resolving: " + this);
  54. // Thread.currentThread().dumpStack();
  55. // XXX why do we need this test
  56. // AMC added concrete too. Needed because declare declarations concretize their
  57. // shadow mungers early.
  58. if (pointcut.state == Pointcut.RESOLVED || pointcut.state == Pointcut.CONCRETE)
  59. return true;
  60. EclipseFactory world = EclipseFactory.fromScopeLookupEnvironment(dec.scope);
  61. TypeBinding[] parameters = method.parameters;
  62. Argument[] arguments = dec.arguments;
  63. FormalBinding[] bindings = new FormalBinding[baseArgumentCount];
  64. for (int i = 0, len = baseArgumentCount; i < len; i++) {
  65. Argument arg = arguments[i];
  66. String name = new String(arg.name);
  67. UnresolvedType type = world.fromBinding(parameters[i]);
  68. // pr268710: allow for inner interfaces in a generic aspect
  69. if (parameters[i].isInterface() && parameters[i].isParameterizedType() && parameters[i].isMemberType()) {
  70. TypeVariableBinding[] tvs = parameters[i].typeVariables();
  71. if (tvs == null || tvs.length == 0) {
  72. type = type.getRawType();
  73. }
  74. }
  75. bindings[i] = new FormalBinding(type, name, i, arg.sourceStart, arg.sourceEnd);
  76. }
  77. EclipseScope scope = new EclipseScope(bindings, dec.scope);
  78. pointcut = pointcut.resolve(scope);
  79. return true;
  80. }
  81. public Pointcut getPointcut() {
  82. return pointcut;
  83. }
  84. public String getPointcutDeclarationText() {
  85. StringBuilder sb = new StringBuilder();
  86. PseudoToken[] toks = tokens.tokens;
  87. for (int i = 0; i < (toks.length - 1); i++) {
  88. sb.append(toks[i].getString());
  89. sb.append(" ");
  90. }
  91. return sb.toString();
  92. }
  93. public boolean isError() {
  94. return isError;
  95. }
  96. /*
  97. * (non-Javadoc)
  98. *
  99. * @see org.eclipse.jdt.internal.compiler.ast.ASTNode#print(int, java.lang.StringBuffer)
  100. */
  101. public StringBuffer print(int indent, StringBuffer output) {
  102. if (pointcut == null)
  103. return output.append("<pcd>");
  104. return output.append(pointcut.toString());
  105. }
  106. }