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.

EclipseShadow.java 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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.lookup;
  13. import org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration;
  14. import org.aspectj.ajdt.internal.compiler.ast.InterTypeConstructorDeclaration;
  15. import org.aspectj.ajdt.internal.compiler.ast.InterTypeDeclaration;
  16. import org.aspectj.ajdt.internal.compiler.ast.InterTypeFieldDeclaration;
  17. import org.aspectj.ajdt.internal.compiler.ast.InterTypeMethodDeclaration;
  18. import org.aspectj.bridge.ISourceLocation;
  19. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode;
  20. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
  21. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AllocationExpression;
  22. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Clinit;
  23. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
  24. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall;
  25. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MessageSend;
  26. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
  27. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
  28. import org.aspectj.org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
  29. import org.aspectj.weaver.Member;
  30. import org.aspectj.weaver.MemberImpl;
  31. import org.aspectj.weaver.ResolvedType;
  32. import org.aspectj.weaver.Shadow;
  33. import org.aspectj.weaver.UnresolvedType;
  34. import org.aspectj.weaver.World;
  35. import org.aspectj.weaver.ast.Var;
  36. /**
  37. * This is only used for declare soft right now.
  38. *
  39. * It might be used for other compile-time matching, but in all such cases this and target pcds can't be used. We might not behave
  40. * correctly in such cases.
  41. */
  42. public class EclipseShadow extends Shadow {
  43. EclipseFactory world;
  44. ASTNode astNode;
  45. ReferenceContext context;
  46. // AbstractMethodDeclaration enclosingMethod;
  47. public EclipseShadow(EclipseFactory world, Kind kind, Member signature, ASTNode astNode, ReferenceContext context) {
  48. super(kind, signature, null);
  49. this.world = world;
  50. this.astNode = astNode;
  51. this.context = context;
  52. }
  53. public World getIWorld() {
  54. return world.getWorld();
  55. }
  56. public UnresolvedType getEnclosingType() {
  57. if (context instanceof TypeDeclaration) {
  58. return world.fromBinding(((TypeDeclaration) context).binding);
  59. } else if (context instanceof AbstractMethodDeclaration) {
  60. return world.fromBinding(((AbstractMethodDeclaration) context).binding.declaringClass);
  61. } else {
  62. return ResolvedType.MISSING;
  63. }
  64. }
  65. public ISourceLocation getSourceLocation() {
  66. // XXX need to fill this in ASAP
  67. return null;
  68. }
  69. public Member getEnclosingCodeSignature() {
  70. if (context instanceof TypeDeclaration) {
  71. return new MemberImpl(Member.STATIC_INITIALIZATION, getEnclosingType(), 0, UnresolvedType.VOID, "<clinit>",
  72. UnresolvedType.NONE);
  73. } else if (context instanceof AbstractMethodDeclaration) {
  74. return world.makeResolvedMember(((AbstractMethodDeclaration) context).binding);
  75. } else {
  76. return null;
  77. }
  78. }
  79. // -- all below here are only used for implementing, not in matching
  80. // -- we should probably pull out a super-interface to capture this in type system
  81. public Var getThisVar() {
  82. throw new RuntimeException("unimplemented");
  83. }
  84. public Var getTargetVar() {
  85. throw new RuntimeException("unimplemented");
  86. }
  87. public Var getArgVar(int i) {
  88. throw new RuntimeException("unimplemented");
  89. }
  90. public Var getThisJoinPointVar() {
  91. throw new RuntimeException("unimplemented");
  92. }
  93. public Var getThisJoinPointStaticPartVar() {
  94. throw new RuntimeException("unimplemented");
  95. }
  96. public Var getThisEnclosingJoinPointStaticPartVar() {
  97. throw new RuntimeException("unimplemented");
  98. }
  99. public Var getArgAnnotationVar(int i, UnresolvedType annotationType) {
  100. throw new RuntimeException("unimplemented");
  101. }
  102. public Var getKindedAnnotationVar(UnresolvedType annotationType) {
  103. throw new RuntimeException("unimplemented");
  104. }
  105. public Var getTargetAnnotationVar(UnresolvedType annotationType) {
  106. throw new RuntimeException("unimplemented");
  107. }
  108. public Var getThisAnnotationVar(UnresolvedType annotationType) {
  109. throw new RuntimeException("unimplemented");
  110. }
  111. public Var getThisAspectInstanceVar(ResolvedType aspectType) {
  112. throw new RuntimeException("unimplemented");
  113. }
  114. public Var getWithinAnnotationVar(UnresolvedType annotationType) {
  115. throw new RuntimeException("unimplemented");
  116. }
  117. public Var getWithinCodeAnnotationVar(UnresolvedType annotationType) {
  118. throw new RuntimeException("unimplemented");
  119. }
  120. // --- factory methods
  121. public static EclipseShadow makeShadow(EclipseFactory world, ASTNode astNode, ReferenceContext context) {
  122. // XXX make sure we're getting the correct declaring type at call-site
  123. if (astNode instanceof AllocationExpression) {
  124. AllocationExpression e = (AllocationExpression) astNode;
  125. return new EclipseShadow(world, Shadow.ConstructorCall, world.makeResolvedMember(e.binding), astNode, context);
  126. } else if (astNode instanceof MessageSend) {
  127. MessageSend e = (MessageSend) astNode;
  128. if (e.isSuperAccess())
  129. return null; // super calls don't have shadows
  130. return new EclipseShadow(world, Shadow.MethodCall, world.makeResolvedMember(e.binding), astNode, context);
  131. } else if (astNode instanceof ExplicitConstructorCall) {
  132. // ??? these should be ignored, they don't have shadows
  133. return null;
  134. } else if (astNode instanceof AbstractMethodDeclaration) {
  135. AbstractMethodDeclaration e = (AbstractMethodDeclaration) astNode;
  136. Shadow.Kind kind;
  137. if (e instanceof AdviceDeclaration) {
  138. kind = Shadow.AdviceExecution;
  139. } else if (e instanceof InterTypeMethodDeclaration) {
  140. return new EclipseShadow(world, Shadow.MethodExecution, ((InterTypeDeclaration) e).getSignature(), astNode, context);
  141. } else if (e instanceof InterTypeConstructorDeclaration) {
  142. return new EclipseShadow(world, Shadow.ConstructorExecution, ((InterTypeDeclaration) e).getSignature(), astNode,
  143. context);
  144. } else if (e instanceof InterTypeFieldDeclaration) {
  145. return null;
  146. } else if (e instanceof MethodDeclaration) {
  147. kind = Shadow.MethodExecution;
  148. } else if (e instanceof ConstructorDeclaration) {
  149. kind = Shadow.ConstructorExecution;
  150. } else if (e instanceof Clinit) {
  151. kind = Shadow.StaticInitialization;
  152. } else {
  153. return null;
  154. // throw new RuntimeException("unimplemented: " + e);
  155. }
  156. return new EclipseShadow(world, kind, world.makeResolvedMember(e.binding, kind), astNode, context);
  157. } else if (astNode instanceof TypeDeclaration) {
  158. return new EclipseShadow(world, Shadow.StaticInitialization,
  159. new MemberImpl(Member.STATIC_INITIALIZATION, world.fromBinding(((TypeDeclaration) astNode).binding), 0,
  160. UnresolvedType.VOID, "<clinit>", UnresolvedType.NONE), astNode, context);
  161. } else {
  162. return null;
  163. // throw new RuntimeException("unimplemented: " + astNode);
  164. }
  165. }
  166. }