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.

IProgramElement.java 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /* *******************************************************************
  2. * Copyright (c) 2003 Contributors.
  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. * Mik Kersten initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.asm;
  13. import java.io.*;
  14. import java.util.*;
  15. import org.aspectj.bridge.*;
  16. /**
  17. * Represents program elements in the AspectJ containment hierarchy.
  18. *
  19. * @author Mik Kersten
  20. */
  21. public interface IProgramElement extends Serializable {
  22. public List/*IProgramElement*/ getChildren();
  23. public void setChildren(List children);
  24. public void addChild(IProgramElement child);
  25. // Extra stuff
  26. // Could be just a string but may prove more useful as an object in the long run ...
  27. public static class ExtraInformation implements Serializable {
  28. private static final long serialVersionUID = -3880735494840820638L;
  29. private String extraInfo;
  30. public ExtraInformation() { extraInfo = "";}
  31. public void setExtraAdviceInformation(String string) {extraInfo = string;}
  32. public String getExtraAdviceInformation() {return extraInfo;}
  33. public String toString() {
  34. return "ExtraInformation: ["+extraInfo+"]";
  35. }
  36. }
  37. public void setExtraInfo(ExtraInformation info);
  38. public ExtraInformation getExtraInfo();
  39. public IProgramElement getParent();
  40. public void setParent(IProgramElement parent);
  41. public String getName();
  42. public void setName(String name);
  43. public String getDetails();
  44. public void setDetails(String details);
  45. public IProgramElement.Kind getKind();
  46. public void setKind(Kind kind);
  47. public List getModifiers();
  48. public void setModifiers(int i);
  49. public Accessibility getAccessibility();
  50. public String getDeclaringType(); // TODO: remove (Emacs uses it)
  51. public String getPackageName();
  52. /**
  53. * @param method return types or field types
  54. */
  55. public void setCorrespondingType(String returnType);
  56. /**
  57. * This correponds to both method return types and field types.
  58. */
  59. public String getCorrespondingType();
  60. public String getCorrespondingType(boolean getFullyQualifiedType);
  61. public String toSignatureString();
  62. public String toSignatureString(boolean getFullyQualifiedArgTypes);
  63. public void setRunnable(boolean value);
  64. public boolean isRunnable();
  65. public boolean isImplementor();
  66. public void setImplementor(boolean value);
  67. public boolean isOverrider();
  68. public void setOverrider(boolean value);
  69. public IMessage getMessage();
  70. public void setMessage(IMessage message);
  71. public ISourceLocation getSourceLocation();
  72. public void setSourceLocation(ISourceLocation sourceLocation);
  73. public String toString();
  74. /**
  75. * @return the javadoc comment for this program element, null if not available
  76. */
  77. public String getFormalComment();
  78. public void setFormalComment(String comment);
  79. /**
  80. * Includes information about the origin of the node.
  81. */
  82. public String toLinkLabelString();
  83. public String toLinkLabelString(boolean getFullyQualifiedArgTypes);
  84. /**
  85. * Includes name, parameter types (if any) and details (if any).
  86. */
  87. public String toLabelString();
  88. public String toLabelString(boolean getFullyQualifiedArgTypes);
  89. public List getParameterNames();
  90. public void setParameterNames(List list);
  91. public List getParameterSignatures();
  92. public void setParameterSignatures(List list);
  93. public List getParameterTypes();
  94. /**
  95. * The format of the string handle is not specified, but is stable across
  96. * compilation sessions.
  97. *
  98. * @return a string representtaion of this element
  99. */
  100. public String getHandleIdentifier();
  101. /**
  102. * @return a string representation of this node and all of its children (recursive)
  103. */
  104. public String toLongString();
  105. public String getBytecodeName();
  106. public String getBytecodeSignature();
  107. public void setBytecodeName(String bytecodeName);
  108. public void setBytecodeSignature(String bytecodeSignature);
  109. /**
  110. * @return the full signature of this element, as it appears in the source
  111. */
  112. public String getSourceSignature();
  113. public void setSourceSignature(String string);
  114. public IProgramElement walk(HierarchyWalker walker);
  115. /**
  116. * Uses "typesafe enum" pattern.
  117. */
  118. public static class Modifiers implements Serializable {
  119. private static final long serialVersionUID = -8279300899976607927L;
  120. public static final Modifiers STATIC = new Modifiers("static");
  121. public static final Modifiers FINAL = new Modifiers("final");
  122. public static final Modifiers ABSTRACT = new Modifiers("abstract");
  123. public static final Modifiers SYNCHRONIZED = new Modifiers("synchronized");
  124. public static final Modifiers VOLATILE = new Modifiers("volatile");
  125. public static final Modifiers STRICTFP = new Modifiers("strictfp");
  126. public static final Modifiers TRANSIENT = new Modifiers("transient");
  127. public static final Modifiers NATIVE = new Modifiers("native");
  128. public static final Modifiers[] ALL = { STATIC, FINAL, ABSTRACT, SYNCHRONIZED, VOLATILE, STRICTFP, TRANSIENT, NATIVE };
  129. private final String name;
  130. private Modifiers(String name) {
  131. this.name = name;
  132. }
  133. public String toString() {
  134. return name;
  135. }
  136. // The 4 declarations below are necessary for serialization
  137. private static int nextOrdinal = 0;
  138. private final int ordinal = nextOrdinal++;
  139. private Object readResolve() throws ObjectStreamException {
  140. return ALL[ordinal];
  141. }
  142. }
  143. /**
  144. * Uses "typesafe enum" pattern.
  145. */
  146. public static class Accessibility implements Serializable {
  147. private static final long serialVersionUID = 5371838588180918519L;
  148. public static final Accessibility PUBLIC = new Accessibility("public");
  149. public static final Accessibility PACKAGE = new Accessibility("package");
  150. public static final Accessibility PROTECTED = new Accessibility("protected");
  151. public static final Accessibility PRIVATE = new Accessibility("private");
  152. public static final Accessibility PRIVILEGED = new Accessibility("privileged");
  153. public static final Accessibility[] ALL = { PUBLIC, PACKAGE, PROTECTED, PRIVATE, PRIVILEGED };
  154. private final String name;
  155. private Accessibility(String name) {
  156. this.name = name;
  157. }
  158. public String toString() {
  159. return name;
  160. }
  161. // The 4 declarations below are necessary for serialization
  162. private static int nextOrdinal = 0;
  163. private final int ordinal = nextOrdinal++;
  164. private Object readResolve() throws ObjectStreamException {
  165. return ALL[ordinal];
  166. }
  167. }
  168. /**
  169. * Uses "typesafe enum" pattern.
  170. */
  171. public static class Kind implements Serializable {
  172. private static final long serialVersionUID = -1963553877479266124L;
  173. public static final Kind PROJECT = new Kind("project");
  174. public static final Kind PACKAGE = new Kind("package");
  175. public static final Kind FILE = new Kind("file");
  176. public static final Kind FILE_JAVA = new Kind("java source file");
  177. public static final Kind FILE_ASPECTJ = new Kind("aspect source file");
  178. public static final Kind FILE_LST = new Kind("build configuration file");
  179. public static final Kind IMPORT_REFERENCE = new Kind("import reference");
  180. public static final Kind CLASS = new Kind("class");
  181. public static final Kind INTERFACE = new Kind("interface");
  182. public static final Kind ASPECT = new Kind("aspect");
  183. public static final Kind ENUM = new Kind("enum");
  184. public static final Kind ENUM_VALUE = new Kind("enumvalue");
  185. public static final Kind ANNOTATION = new Kind("annotation");
  186. public static final Kind INITIALIZER = new Kind("initializer");
  187. public static final Kind INTER_TYPE_FIELD = new Kind("inter-type field");
  188. public static final Kind INTER_TYPE_METHOD = new Kind("inter-type method");
  189. public static final Kind INTER_TYPE_CONSTRUCTOR = new Kind("inter-type constructor");
  190. public static final Kind INTER_TYPE_PARENT = new Kind("inter-type parent");
  191. public static final Kind CONSTRUCTOR = new Kind("constructor");
  192. public static final Kind METHOD = new Kind("method");
  193. public static final Kind FIELD = new Kind("field");
  194. public static final Kind POINTCUT = new Kind("pointcut");
  195. public static final Kind ADVICE = new Kind("advice");
  196. public static final Kind DECLARE_PARENTS = new Kind("declare parents");
  197. public static final Kind DECLARE_WARNING = new Kind("declare warning");
  198. public static final Kind DECLARE_ERROR = new Kind("declare error");
  199. public static final Kind DECLARE_SOFT = new Kind("declare soft");
  200. public static final Kind DECLARE_PRECEDENCE= new Kind("declare precedence");
  201. public static final Kind CODE = new Kind("code");
  202. public static final Kind ERROR = new Kind("error");
  203. public static final Kind DECLARE_ANNOTATION_AT_CONSTRUCTOR = new Kind("declare @constructor");
  204. public static final Kind DECLARE_ANNOTATION_AT_FIELD = new Kind("declare @field");
  205. public static final Kind DECLARE_ANNOTATION_AT_METHOD = new Kind("declare @method");
  206. public static final Kind DECLARE_ANNOTATION_AT_TYPE = new Kind("declare @type");
  207. public static final Kind[] ALL =
  208. {
  209. PROJECT,
  210. PACKAGE,
  211. FILE,
  212. FILE_JAVA,
  213. FILE_ASPECTJ,
  214. FILE_LST,
  215. IMPORT_REFERENCE,
  216. CLASS,
  217. INTERFACE,
  218. ASPECT,
  219. ENUM,
  220. ENUM_VALUE,
  221. ANNOTATION,
  222. INITIALIZER,
  223. INTER_TYPE_FIELD,
  224. INTER_TYPE_METHOD,
  225. INTER_TYPE_CONSTRUCTOR,
  226. INTER_TYPE_PARENT,
  227. CONSTRUCTOR,
  228. METHOD,
  229. FIELD,
  230. POINTCUT,
  231. ADVICE,
  232. DECLARE_PARENTS,
  233. DECLARE_WARNING,
  234. DECLARE_ERROR,
  235. DECLARE_SOFT,
  236. DECLARE_PRECEDENCE,
  237. CODE,
  238. ERROR,
  239. DECLARE_ANNOTATION_AT_CONSTRUCTOR,
  240. DECLARE_ANNOTATION_AT_FIELD,
  241. DECLARE_ANNOTATION_AT_METHOD,
  242. DECLARE_ANNOTATION_AT_TYPE
  243. };
  244. public static Kind getKindForString(String kindString) {
  245. for (int i = 0; i < ALL.length; i++) {
  246. if (ALL[i].toString().equals(kindString)) return ALL[i];
  247. }
  248. return ERROR;
  249. }
  250. private final String name;
  251. private Kind(String name) {
  252. this.name = name;
  253. }
  254. public String toString() {
  255. return name;
  256. }
  257. public static List getNonAJMemberKinds() {
  258. List list = new ArrayList();
  259. list.add(METHOD);
  260. list.add(ENUM_VALUE);
  261. list.add(FIELD);
  262. list.add(CONSTRUCTOR);
  263. return list;
  264. }
  265. public boolean isMember() {
  266. return this == FIELD
  267. || this == METHOD
  268. || this == CONSTRUCTOR
  269. || this == POINTCUT
  270. || this == ADVICE
  271. || this == ENUM_VALUE;
  272. }
  273. public boolean isInterTypeMember() {
  274. return this == INTER_TYPE_CONSTRUCTOR
  275. || this == INTER_TYPE_FIELD
  276. || this == INTER_TYPE_METHOD;
  277. }
  278. public boolean isType() {
  279. return this == CLASS
  280. || this == INTERFACE
  281. || this == ASPECT
  282. || this == ANNOTATION
  283. || this == ENUM;
  284. }
  285. public boolean isSourceFile() {
  286. return this == FILE_ASPECTJ
  287. || this == FILE_JAVA;
  288. }
  289. public boolean isDeclare() {
  290. return name.startsWith("declare");
  291. }
  292. public boolean isDeclareAnnotation() {
  293. return name.startsWith("declare @");
  294. }
  295. // The 4 declarations below are necessary for serialization
  296. private static int nextOrdinal = 0;
  297. private final int ordinal = nextOrdinal++;
  298. private Object readResolve() throws ObjectStreamException {
  299. return ALL[ordinal];
  300. }
  301. }
  302. }