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.

PrivilegedAccessMunger.java 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver;
  13. import java.io.IOException;
  14. /**
  15. * A privileged access munger is for handling privileged access to a member. It determines the names of the getter/setter that will
  16. * be used to access a private field in some type, or the special method that provides access to a private method.
  17. *
  18. * There are two syntax styles for field access, the older style was in use up to AspectJ 1.6.9 and involves long named getters and
  19. * setters which include the requesting aspect and the target type. The short style syntax is use from AspectJ 1.6.9 onwards is
  20. * simply 'ajc$get$<fieldname>' and 'ajc$set$<fieldname>' - as the requesting aspect isn't included in the name they can be shared
  21. * across aspects.
  22. */
  23. public class PrivilegedAccessMunger extends ResolvedTypeMunger {
  24. public boolean shortSyntax = false;
  25. public PrivilegedAccessMunger(ResolvedMember member, boolean shortSyntax) {
  26. super(PrivilegedAccess, member);
  27. this.shortSyntax = shortSyntax;
  28. }
  29. @Override
  30. public void write(CompressingDataOutputStream s) throws IOException {
  31. throw new RuntimeException("should not be serialized");
  32. }
  33. public ResolvedMember getMember() {
  34. return getSignature();
  35. }
  36. @Override
  37. public ResolvedMember getMatchingSyntheticMember(Member member, ResolvedType aspectType) {
  38. ResolvedMember ret;
  39. // assert if shortSyntax then aspectType.getCompilerVersion()>=169
  40. if (getSignature().getKind() == Member.FIELD) {
  41. ret = AjcMemberMaker.privilegedAccessMethodForFieldGet(aspectType, getSignature(), shortSyntax);
  42. if (ResolvedType.matches(ret, member)) {
  43. return getSignature();
  44. }
  45. ret = AjcMemberMaker.privilegedAccessMethodForFieldSet(aspectType, getSignature(), shortSyntax);
  46. if (ResolvedType.matches(ret, member)) {
  47. return getSignature();
  48. }
  49. } else {
  50. // System.err.println("sig: " + getSignature());
  51. ret = AjcMemberMaker.privilegedAccessMethodForMethod(aspectType, getSignature());
  52. if (ResolvedType.matches(ret, member)) {
  53. return getSignature();
  54. }
  55. }
  56. return null;
  57. }
  58. @Override
  59. public boolean equals(Object other) {
  60. if (!(other instanceof PrivilegedAccessMunger)) {
  61. return false;
  62. }
  63. PrivilegedAccessMunger o = (PrivilegedAccessMunger) other;
  64. return kind.equals(o.kind)
  65. && ((o.signature == null) ? (signature == null) : signature.equals(o.signature))
  66. && ((o.declaredSignature == null) ? (declaredSignature == null) : declaredSignature.equals(o.declaredSignature))
  67. && ((o.typeVariableAliases == null) ? (typeVariableAliases == null) : typeVariableAliases
  68. .equals(o.typeVariableAliases));
  69. }
  70. @Override
  71. public int hashCode() {
  72. int result = 17;
  73. result = 37 * result + kind.hashCode();
  74. result = 37 * result + ((signature == null) ? 0 : signature.hashCode());
  75. result = 37 * result + ((declaredSignature == null) ? 0 : declaredSignature.hashCode());
  76. result = 37 * result + ((typeVariableAliases == null) ? 0 : typeVariableAliases.hashCode());
  77. return result;
  78. }
  79. @Override
  80. public boolean existsToSupportShadowMunging() {
  81. return true;
  82. }
  83. }