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.

NameMangler.java 12KB

21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
18 years ago
18 years ago
18 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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.weaver;
  13. import java.lang.reflect.Modifier;
  14. import org.aspectj.weaver.bcel.LazyClassGen;
  15. public class NameMangler {
  16. private NameMangler() {
  17. throw new RuntimeException("static");
  18. }
  19. public static final String PREFIX = "ajc$";
  20. public static final String ITD_PREFIX = PREFIX + "interType$";
  21. public static final String CFLOW_STACK_TYPE = "org.aspectj.runtime.internal.CFlowStack";
  22. public static final String CFLOW_COUNTER_TYPE="org.aspectj.runtime.internal.CFlowCounter";
  23. public static final String SOFT_EXCEPTION_TYPE = "org.aspectj.lang.SoftException";
  24. public static final String PERSINGLETON_FIELD_NAME = PREFIX + "perSingletonInstance";
  25. public static final String PERCFLOW_FIELD_NAME = PREFIX + "perCflowStack";
  26. //public static final String PERTHIS_FIELD_NAME = PREFIX + "perSingletonInstance";
  27. // -----
  28. public static final String PERCFLOW_PUSH_METHOD = PREFIX + "perCflowPush";
  29. public static final String PEROBJECT_BIND_METHOD = PREFIX + "perObjectBind";
  30. // PTWIMPL Method and field names
  31. public static final String PERTYPEWITHIN_GETINSTANCE_METHOD = PREFIX + "getInstance";
  32. public static final String PERTYPEWITHIN_CREATEASPECTINSTANCE_METHOD = PREFIX + "createAspectInstance";
  33. public static final String PERTYPEWITHIN_WITHINTYPEFIELD = PREFIX + "withinType";
  34. public static final String AJC_PRE_CLINIT_NAME = PREFIX + "preClinit";
  35. public static final String AJC_POST_CLINIT_NAME = PREFIX + "postClinit";
  36. public static final String INITFAILURECAUSE_FIELD_NAME = PREFIX + "initFailureCause";
  37. public static String perObjectInterfaceGet(UnresolvedType aspectType) {
  38. return makeName(aspectType.getNameAsIdentifier(), "perObjectGet");
  39. }
  40. public static String perObjectInterfaceSet(UnresolvedType aspectType) {
  41. return makeName(aspectType.getNameAsIdentifier(), "perObjectSet");
  42. }
  43. public static String perObjectInterfaceField(UnresolvedType aspectType) {
  44. return makeName(aspectType.getNameAsIdentifier(), "perObjectField");
  45. }
  46. // PTWIMPL method names that must include aspect type
  47. public static String perTypeWithinFieldForTarget(UnresolvedType aspectType) {
  48. return makeName(aspectType.getNameAsIdentifier(), "ptwAspectInstance");
  49. }
  50. public static String perTypeWithinLocalAspectOf(UnresolvedType aspectType) {
  51. return makeName(aspectType.getNameAsIdentifier(), "localAspectOf");
  52. }
  53. public static String itdAtDeclareParentsField(UnresolvedType aspectType, UnresolvedType itdType) {
  54. return makeName(aspectType.getNameAsIdentifier(), itdType.getNameAsIdentifier());
  55. }
  56. public static String privilegedAccessMethodForMethod(String name, UnresolvedType objectType, UnresolvedType aspectType) {
  57. return makeName("privMethod", aspectType.getNameAsIdentifier(),
  58. objectType.getNameAsIdentifier(), name);
  59. }
  60. public static String privilegedAccessMethodForFieldGet(String name, UnresolvedType objectType, UnresolvedType aspectType) {
  61. return makeName("privFieldGet", aspectType.getNameAsIdentifier(),
  62. objectType.getNameAsIdentifier(), name);
  63. }
  64. public static String privilegedAccessMethodForFieldSet(String name, UnresolvedType objectType, UnresolvedType aspectType) {
  65. return makeName("privFieldSet", aspectType.getNameAsIdentifier(),
  66. objectType.getNameAsIdentifier(), name);
  67. }
  68. public static String inlineAccessMethodForMethod(String name, UnresolvedType objectType, UnresolvedType aspectType) {
  69. return makeName("inlineAccessMethod", aspectType.getNameAsIdentifier(),
  70. objectType.getNameAsIdentifier(), name);
  71. }
  72. public static String inlineAccessMethodForFieldGet(String name, UnresolvedType objectType, UnresolvedType aspectType) {
  73. return makeName("inlineAccessFieldGet", aspectType.getNameAsIdentifier(),
  74. objectType.getNameAsIdentifier(), name);
  75. }
  76. public static String inlineAccessMethodForFieldSet(String name, UnresolvedType objectType, UnresolvedType aspectType) {
  77. return makeName("inlineAccessFieldSet", aspectType.getNameAsIdentifier(),
  78. objectType.getNameAsIdentifier(), name);
  79. }
  80. /**
  81. * The name of methods corresponding to advice declarations
  82. * Of the form: "ajc$[AdviceKind]$[AspectName]$[NumberOfAdviceInAspect]$[PointcutHash]"
  83. */
  84. public static String adviceName(String nameAsIdentifier, AdviceKind kind, int adviceSeqNumber,int pcdHash) {
  85. String newname = makeName(
  86. kind.getName(),
  87. nameAsIdentifier,
  88. Integer.toString(adviceSeqNumber),
  89. Integer.toHexString(pcdHash));
  90. return newname;
  91. }
  92. /**
  93. * This field goes on top-most implementers of the interface the field
  94. * is declared onto
  95. */
  96. public static String interFieldInterfaceField(UnresolvedType aspectType, UnresolvedType interfaceType, String name) {
  97. return makeName("interField", aspectType.getNameAsIdentifier(),
  98. interfaceType.getNameAsIdentifier(), name);
  99. }
  100. /**
  101. * This instance method goes on the interface the field is declared onto
  102. * as well as its top-most implementors
  103. */
  104. public static String interFieldInterfaceSetter(UnresolvedType aspectType, UnresolvedType interfaceType, String name) {
  105. return makeName("interFieldSet", aspectType.getNameAsIdentifier(),
  106. interfaceType.getNameAsIdentifier(), name);
  107. }
  108. /**
  109. * This instance method goes on the interface the field is declared onto
  110. * as well as its top-most implementors
  111. */
  112. public static String interFieldInterfaceGetter(UnresolvedType aspectType, UnresolvedType interfaceType, String name) {
  113. return makeName("interFieldGet", aspectType.getNameAsIdentifier(),
  114. interfaceType.getNameAsIdentifier(), name);
  115. }
  116. /**
  117. * This static method goes on the aspect that declares the inter-type field
  118. */
  119. public static String interFieldSetDispatcher(UnresolvedType aspectType, UnresolvedType onType, String name) {
  120. return makeName("interFieldSetDispatch", aspectType.getNameAsIdentifier(),
  121. onType.getNameAsIdentifier(), name);
  122. }
  123. /**
  124. * This static method goes on the aspect that declares the inter-type field
  125. */
  126. public static String interFieldGetDispatcher(UnresolvedType aspectType, UnresolvedType onType, String name) {
  127. return makeName("interFieldGetDispatch", aspectType.getNameAsIdentifier(),
  128. onType.getNameAsIdentifier(), name);
  129. }
  130. /**
  131. * This field goes on the class the field
  132. * is declared onto
  133. */
  134. public static String interFieldClassField(int modifiers, UnresolvedType aspectType, UnresolvedType classType, String name) {
  135. if (Modifier.isPublic(modifiers)) return name;
  136. //??? might want to handle case where aspect and class are in same package similar to public
  137. return makeName("interField", makeVisibilityName(modifiers, aspectType), name);
  138. }
  139. // /**
  140. // * This static method goes on the aspect that declares the inter-type field
  141. // */
  142. // public static String classFieldSetDispatcher(UnresolvedType aspectType, UnresolvedType classType, String name) {
  143. // return makeName("interFieldSetDispatch", aspectType.getNameAsIdentifier(),
  144. // classType.getNameAsIdentifier(), name);
  145. // }
  146. //
  147. // /**
  148. // * This static method goes on the aspect that declares the inter-type field
  149. // */
  150. // public static String classFieldGetDispatcher(UnresolvedType aspectType, UnresolvedType classType, String name)
  151. // {
  152. // return makeName(
  153. // "interFieldGetDispatch",
  154. // aspectType.getNameAsIdentifier(),
  155. // classType.getNameAsIdentifier(),
  156. // name);
  157. // }
  158. /**
  159. * This static void method goes on the aspect that declares the inter-type field and is called
  160. * from the appropriate place (target's initializer, or clinit, or topmost implementer's inits),
  161. * to initialize the field;
  162. */
  163. public static String interFieldInitializer(UnresolvedType aspectType, UnresolvedType classType, String name)
  164. {
  165. return makeName(
  166. "interFieldInit",
  167. aspectType.getNameAsIdentifier(),
  168. classType.getNameAsIdentifier(),
  169. name);
  170. }
  171. // ----
  172. /**
  173. * This method goes on the target type of the inter-type method. (and possibly the topmost-implemeters,
  174. * if the target type is an interface)
  175. */
  176. public static String interMethod(int modifiers, UnresolvedType aspectType, UnresolvedType classType, String name)
  177. {
  178. if (Modifier.isPublic(modifiers)) return name;
  179. //??? might want to handle case where aspect and class are in same package similar to public
  180. return makeName("interMethodDispatch2", makeVisibilityName(modifiers, aspectType), name);
  181. }
  182. /**
  183. * This static method goes on the declaring aspect of the inter-type method.
  184. */
  185. public static String interMethodDispatcher(UnresolvedType aspectType, UnresolvedType classType, String name)
  186. {
  187. return makeName("interMethodDispatch1", aspectType.getNameAsIdentifier(),
  188. classType.getNameAsIdentifier(), name);
  189. }
  190. /**
  191. * This static method goes on the declaring aspect of the inter-type method.
  192. */
  193. public static String interMethodBody(UnresolvedType aspectType, UnresolvedType classType, String name)
  194. {
  195. return makeName("interMethod", aspectType.getNameAsIdentifier(),
  196. classType.getNameAsIdentifier(), name);
  197. }
  198. // ----
  199. /**
  200. * This static method goes on the declaring aspect of the inter-type constructor.
  201. */
  202. public static String preIntroducedConstructor(
  203. UnresolvedType aspectType,
  204. UnresolvedType targetType)
  205. {
  206. return makeName("preInterConstructor", aspectType.getNameAsIdentifier(),
  207. targetType.getNameAsIdentifier());
  208. }
  209. /**
  210. * This static method goes on the declaring aspect of the inter-type constructor.
  211. */
  212. public static String postIntroducedConstructor(
  213. UnresolvedType aspectType,
  214. UnresolvedType targetType)
  215. {
  216. return makeName("postInterConstructor", aspectType.getNameAsIdentifier(),
  217. targetType.getNameAsIdentifier());
  218. }
  219. // ----
  220. /**
  221. * This static method goes on the target class of the inter-type method.
  222. */
  223. public static String superDispatchMethod(UnresolvedType classType, String name)
  224. {
  225. return makeName("superDispatch",
  226. classType.getNameAsIdentifier(), name);
  227. }
  228. /**
  229. * This static method goes on the target class of the inter-type method.
  230. */
  231. public static String protectedDispatchMethod(UnresolvedType classType, String name)
  232. {
  233. return makeName("protectedDispatch",
  234. classType.getNameAsIdentifier(), name);
  235. }
  236. // ----
  237. private static String makeVisibilityName(int modifiers, UnresolvedType aspectType) {
  238. if (Modifier.isPrivate(modifiers)) {
  239. return aspectType.getOutermostType().getNameAsIdentifier();
  240. } else if (Modifier.isProtected(modifiers)) {
  241. throw new RuntimeException("protected inter-types not allowed");
  242. } else if (Modifier.isPublic(modifiers)) {
  243. return "";
  244. } else {
  245. return aspectType.getPackageNameAsIdentifier();
  246. }
  247. }
  248. private static String makeName(String s1, String s2) {
  249. return "ajc$" + s1 + "$" + s2;
  250. }
  251. public static String makeName(String s1, String s2, String s3) {
  252. return "ajc$" + s1 + "$" + s2 + "$" + s3;
  253. }
  254. public static String makeName(String s1, String s2, String s3, String s4) {
  255. return "ajc$" + s1 + "$" + s2 + "$" + s3 + "$" + s4;
  256. }
  257. public static String cflowStack(CrosscuttingMembers xcut) {
  258. return makeName("cflowStack", Integer.toHexString(xcut.getCflowEntries().size()));
  259. }
  260. public static String cflowCounter(CrosscuttingMembers xcut) {
  261. return makeName("cflowCounter",Integer.toHexString(xcut.getCflowEntries().size()));
  262. }
  263. public static String makeClosureClassName(
  264. UnresolvedType enclosingType,
  265. int index)
  266. {
  267. return enclosingType.getName() + "$AjcClosure" + index;
  268. }
  269. public static String aroundCallbackMethodName(
  270. Member shadowSig,
  271. LazyClassGen enclosingType)
  272. {
  273. String ret =
  274. shadowSig.getExtractableName()
  275. + "_aroundBody"
  276. + enclosingType.getNewGeneratedNameTag();
  277. return ret;
  278. }
  279. public static String proceedMethodName(String adviceMethodName) {
  280. return adviceMethodName + "proceed";
  281. }
  282. }