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.

InterTypeFieldBinding.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.ajdt.internal.compiler.lookup;
  13. import org.aspectj.weaver.AjcMemberMaker;
  14. import org.aspectj.weaver.ResolvedMember;
  15. import org.aspectj.weaver.TypeX;
  16. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
  17. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
  18. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.InvocationSite;
  19. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
  20. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Scope;
  21. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
  22. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SyntheticMethodBinding;
  23. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
  24. public class InterTypeFieldBinding extends FieldBinding {
  25. public ReferenceBinding targetType;
  26. public SyntheticMethodBinding reader;
  27. public SyntheticMethodBinding writer;
  28. public AbstractMethodDeclaration sourceMethod;
  29. public InterTypeFieldBinding(EclipseFactory world, ResolvedMember signature, TypeX withinType,
  30. AbstractMethodDeclaration sourceMethod)
  31. {
  32. super(world.makeFieldBinding(signature), null);
  33. this.sourceMethod = sourceMethod;
  34. targetType = (ReferenceBinding)world.makeTypeBinding(signature.getDeclaringType());
  35. this.declaringClass = (ReferenceBinding)world.makeTypeBinding(withinType);
  36. reader = new SimpleSyntheticAccessMethodBinding(
  37. world.makeMethodBinding(
  38. AjcMemberMaker.interFieldGetDispatcher(signature, withinType)
  39. ));
  40. writer = new SimpleSyntheticAccessMethodBinding(world.makeMethodBinding(
  41. AjcMemberMaker.interFieldSetDispatcher(signature, withinType)
  42. ));
  43. }
  44. public boolean canBeSeenBy(TypeBinding receiverType, InvocationSite invocationSite, Scope scope) {
  45. scope.compilationUnitScope().recordTypeReference(declaringClass);
  46. //System.err.println("canBeSeenBy: " + this + ", " + isPublic());
  47. if (isPublic()) return true;
  48. SourceTypeBinding invocationType = scope.invocationType();
  49. //System.out.println("receiver: " + receiverType + ", " + invocationType);
  50. if (invocationType == declaringClass) return true;
  51. // if (invocationType.isPrivileged) {
  52. // System.out.println("privileged access to: " + this);
  53. // return true;
  54. // }
  55. if (isProtected()) {
  56. throw new RuntimeException("unimplemented");
  57. }
  58. //XXX make sure this walks correctly
  59. if (isPrivate()) {
  60. // answer true if the receiverType is the declaringClass
  61. // AND the invocationType and the declaringClass have a common enclosingType
  62. if (receiverType != declaringClass) return false;
  63. if (invocationType != declaringClass) {
  64. ReferenceBinding outerInvocationType = invocationType;
  65. ReferenceBinding temp = outerInvocationType.enclosingType();
  66. while (temp != null) {
  67. outerInvocationType = temp;
  68. temp = temp.enclosingType();
  69. }
  70. ReferenceBinding outerDeclaringClass = declaringClass;
  71. temp = outerDeclaringClass.enclosingType();
  72. while (temp != null) {
  73. outerDeclaringClass = temp;
  74. temp = temp.enclosingType();
  75. }
  76. if (outerInvocationType != outerDeclaringClass) return false;
  77. }
  78. return true;
  79. }
  80. // isDefault()
  81. if (invocationType.fPackage == declaringClass.fPackage) return true;
  82. return false;
  83. }
  84. public SyntheticMethodBinding getAccessMethod(boolean isReadAccess) {
  85. if (isReadAccess) return reader;
  86. else return writer;
  87. }
  88. public boolean alwaysNeedsAccessMethod(boolean isReadAccess) { return true; }
  89. public ReferenceBinding getTargetType() {
  90. return targetType;
  91. }
  92. }