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.

SuperFixerVisitor.java 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.util.*;
  14. import java.util.Arrays;
  15. import org.aspectj.ajdt.internal.compiler.lookup.EclipseWorld;
  16. import org.aspectj.weaver.*;
  17. import org.aspectj.weaver.ShadowMunger;
  18. import org.eclipse.jdt.internal.compiler.AbstractSyntaxTreeVisitorAdapter;
  19. import org.eclipse.jdt.internal.compiler.ast.*;
  20. import org.eclipse.jdt.internal.compiler.lookup.*;
  21. /**
  22. * Takes a method that already has the three extra parameters
  23. * thisJoinPointStaticPart, thisJoinPoint and thisEnclosingJoinPointStaticPart
  24. */
  25. public class SuperFixerVisitor extends AbstractSyntaxTreeVisitorAdapter {
  26. Set superMethodsCalled = new HashSet();
  27. AbstractMethodDeclaration method;
  28. ReferenceBinding targetClass;
  29. SuperFixerVisitor(AbstractMethodDeclaration method, ReferenceBinding targetClass) {
  30. this.method = method;
  31. this.targetClass = targetClass;
  32. }
  33. //XXX does this walk into inners
  34. public void endVisit(MessageSend call, BlockScope scope) {
  35. //System.out.println("endVisit: " + call);
  36. // an error has already occurred
  37. if (call.codegenBinding == null) return;
  38. MethodBinding superBinding = call.codegenBinding;
  39. char[] accessName;
  40. boolean isSuper;
  41. if (call.isSuperAccess() && !call.binding.isStatic()) {
  42. call.receiver = new ThisReference();
  43. accessName =
  44. NameMangler.superDispatchMethod(EclipseWorld.fromBinding(targetClass),
  45. new String(superBinding.selector)).toCharArray();
  46. } else if (call.receiver.isThis() && call.binding.isProtected() && !call.binding.isStatic()) {
  47. //XXX this is a hack that violates some binary compatibility rules
  48. if (superBinding.declaringClass.equals(targetClass)) {
  49. accessName =
  50. NameMangler.protectedDispatchMethod(EclipseWorld.fromBinding(targetClass),
  51. new String(superBinding.selector)).toCharArray();
  52. } else {
  53. accessName =
  54. NameMangler.superDispatchMethod(EclipseWorld.fromBinding(targetClass),
  55. new String(superBinding.selector)).toCharArray();
  56. }
  57. } else {
  58. return;
  59. }
  60. //??? do we want these to be unique
  61. MethodBinding superAccessBinding =
  62. new MethodBinding(AstNode.AccPublic, accessName,
  63. superBinding.returnType, superBinding.parameters, superBinding.thrownExceptions,
  64. targetClass);
  65. call.codegenBinding = superAccessBinding;
  66. ResolvedMember targetMember = EclipseWorld.makeResolvedMember(superBinding);
  67. superMethodsCalled.add(targetMember);
  68. }
  69. }