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 13KB

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