Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

IProgramElement.java 11KB

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