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.

AspectDeclaration.java 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*******************************************************************************
  2. * Copyright (c) 2000, 2005 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v 2.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors:
  9. * IBM Corporation - initial API and implementation
  10. *******************************************************************************/
  11. package org.aspectj.org.eclipse.jdt.core.dom;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. /**
  15. * AspectDeclaration DOM AST node.
  16. *
  17. * Has everything an AjTypeDeclaration has plus: an ASTNode called 'perClause' a boolean called 'privileged'
  18. *
  19. * @author ajh02
  20. *
  21. */
  22. public class AspectDeclaration extends AjTypeDeclaration {
  23. public static final ChildPropertyDescriptor PERCLAUSE_PROPERTY = new ChildPropertyDescriptor(AspectDeclaration.class,
  24. "perClause", ASTNode.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
  25. public static final SimplePropertyDescriptor PRIVILEGED_PROPERTY = new SimplePropertyDescriptor(AspectDeclaration.class,
  26. "privileged", boolean.class, MANDATORY); //$NON-NLS-1$
  27. protected static List aspectPROPERTY_DESCRIPTORS_2_0;
  28. protected static List aspectPROPERTY_DESCRIPTORS_3_0;
  29. static {
  30. List temporary = new ArrayList();
  31. createPropertyList(AspectDeclaration.class, temporary);
  32. temporary.addAll(ajPROPERTY_DESCRIPTORS_2_0);
  33. addProperty(PERCLAUSE_PROPERTY, temporary);
  34. addProperty(PRIVILEGED_PROPERTY, temporary);
  35. aspectPROPERTY_DESCRIPTORS_2_0 = reapPropertyList(temporary);
  36. temporary.clear();
  37. createPropertyList(AspectDeclaration.class, temporary);
  38. temporary.addAll(ajPROPERTY_DESCRIPTORS_3_0);
  39. addProperty(PERCLAUSE_PROPERTY, temporary);
  40. addProperty(PRIVILEGED_PROPERTY, temporary);
  41. aspectPROPERTY_DESCRIPTORS_3_0 = reapPropertyList(temporary);
  42. }
  43. protected ASTNode perClause = null; // stays null if the aspect is an _implicit_ persingleton()
  44. /**
  45. * <code>true</code> for a privileged aspect, <code>false</code> otherwise. Defaults to not privileged.
  46. */
  47. private boolean isPrivileged = false;
  48. AspectDeclaration(AST ast) {
  49. super(ast);
  50. }
  51. AspectDeclaration(AST ast, ASTNode perClause) {
  52. this(ast);
  53. this.perClause = perClause;
  54. setAspect(true);
  55. }
  56. AspectDeclaration(AST ast, ASTNode perClause, boolean isPrivileged) {
  57. this(ast, perClause);
  58. this.isPrivileged = isPrivileged;
  59. }
  60. /*
  61. * (omit javadoc for this method) Method declared on ASTNode.
  62. */
  63. ASTNode clone0(AST target) {
  64. AspectDeclaration result = new AspectDeclaration(target, perClause);
  65. result.setSourceRange(this.getStartPosition(), this.getLength());
  66. result.setJavadoc((Javadoc) ASTNode.copySubtree(target, getJavadoc()));
  67. if (this.ast.apiLevel == AST.JLS2_INTERNAL) {
  68. result.internalSetModifiers(getModifiers());
  69. result.setSuperclass((Name) ASTNode.copySubtree(target, getSuperclass()));
  70. result.superInterfaces().addAll(ASTNode.copySubtrees(target, superInterfaces()));
  71. }
  72. result.setInterface(isInterface());
  73. result.setAspect(isAspect());
  74. result.setPrivileged(isPrivileged());
  75. result.setName((SimpleName) getName().clone(target));
  76. if (this.ast.apiLevel >= AST.JLS3) {
  77. result.modifiers().addAll(ASTNode.copySubtrees(target, modifiers()));
  78. result.typeParameters().addAll(ASTNode.copySubtrees(target, typeParameters()));
  79. result.setSuperclassType((Type) ASTNode.copySubtree(target, getSuperclassType()));
  80. result.superInterfaceTypes().addAll(ASTNode.copySubtrees(target, superInterfaceTypes()));
  81. }
  82. result.bodyDeclarations().addAll(ASTNode.copySubtrees(target, bodyDeclarations()));
  83. result.setPerClause(getPerClause().clone(target));
  84. return result;
  85. }
  86. /*
  87. * (omit javadoc for this method) Method declared on ASTNode.
  88. */
  89. void accept0(ASTVisitor visitor) {
  90. boolean visitChildren = visitor.visit(this);
  91. if (visitChildren) {
  92. // visit children in normal left to right reading order
  93. if (this.ast.apiLevel == AST.JLS2_INTERNAL) {
  94. acceptChild(visitor, getJavadoc());
  95. acceptChild(visitor, getName());
  96. acceptChild(visitor, getSuperclass());
  97. acceptChildren(visitor, this.superInterfaceNames);
  98. acceptChild(visitor, this.perClause);
  99. acceptChildren(visitor, this.bodyDeclarations);
  100. }
  101. if (this.ast.apiLevel >= AST.JLS3) {
  102. acceptChild(visitor, getJavadoc());
  103. acceptChildren(visitor, this.modifiers);
  104. acceptChild(visitor, getName());
  105. acceptChildren(visitor, this.typeParameters);
  106. acceptChild(visitor, getSuperclassType());
  107. acceptChildren(visitor, this.superInterfaceTypes);
  108. acceptChild(visitor, this.perClause);
  109. acceptChildren(visitor, this.bodyDeclarations);
  110. }
  111. }
  112. visitor.endVisit(this);
  113. }
  114. /*
  115. * (omit javadoc for this method) Method declared on ASTNode and AjTypeDeclaration.
  116. */
  117. final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) {
  118. if (property == PRIVILEGED_PROPERTY) {
  119. if (get) {
  120. return isPrivileged();
  121. } else {
  122. setPrivileged(value);
  123. return false;
  124. }
  125. }
  126. // allow default implementation to flag the error
  127. return super.internalGetSetBooleanProperty(property, get, value);
  128. }
  129. /*
  130. * (omit javadoc for this method) Method declared on ASTNode.
  131. */
  132. final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
  133. if (property == PERCLAUSE_PROPERTY) {
  134. if (get) {
  135. return getPerClause();
  136. } else {
  137. setPerClause(child);
  138. return null;
  139. }
  140. }
  141. return super.internalGetSetChildProperty(property, get, child);
  142. }
  143. /**
  144. * Returns a list of structural property descriptors for this node type. Clients must not modify the result.
  145. *
  146. * @param apiLevel the API level; one of the <code>AST.JLS&ast;</code> constants
  147. *
  148. * @return a list of property descriptors (element type: {@link StructuralPropertyDescriptor})
  149. * @since 3.0
  150. */
  151. public static List propertyDescriptors(int apiLevel) {
  152. if (apiLevel == AST.JLS2_INTERNAL) {
  153. return aspectPROPERTY_DESCRIPTORS_2_0;
  154. } else {
  155. return aspectPROPERTY_DESCRIPTORS_3_0;
  156. }
  157. }
  158. public ASTNode getPerClause() {
  159. return perClause;
  160. }
  161. public void setPerClause(ASTNode perClause) {
  162. if (perClause == null) {
  163. throw new IllegalArgumentException();
  164. }
  165. ASTNode oldChild = this.perClause;
  166. preReplaceChild(oldChild, perClause, PERCLAUSE_PROPERTY);
  167. this.perClause = perClause;
  168. postReplaceChild(oldChild, perClause, PERCLAUSE_PROPERTY);
  169. }
  170. /**
  171. * Returns whether this aspect is a privileged one.
  172. *
  173. * @return <code>true</code> if this is a privileged aspect declaration, and <code>false</code> otherwise.
  174. */
  175. public boolean isPrivileged() {
  176. return this.isPrivileged;
  177. }
  178. /**
  179. * Sets whether this aspect is a privileged one
  180. *
  181. * @param isPrivileged <code>true</code> if this is a privileged aspect declaration, and <code>false</code> otherwise.
  182. */
  183. public void setPrivileged(boolean isPrivileged) {
  184. preValueChange(PRIVILEGED_PROPERTY);
  185. this.isPrivileged = isPrivileged;
  186. postValueChange(PRIVILEGED_PROPERTY);
  187. }
  188. public List getAdvice() {
  189. // ajh02: method added
  190. List bd = bodyDeclarations();
  191. List<AdviceDeclaration> advice = new ArrayList<>();
  192. for (Object decl : bd) {
  193. if (decl instanceof AdviceDeclaration) {
  194. advice.add((AdviceDeclaration)decl);
  195. }
  196. }
  197. return advice;
  198. }
  199. // public PointcutDeclaration[] getPointcuts() {
  200. // // ajh02: method added, currently returning none :-/
  201. // List bd = bodyDeclarations();
  202. // // ajh02: 0 bodyDeclarations :-/
  203. // int pointcutCount = 0;
  204. // for (Iterator it = bd.listIterator(); it.hasNext(); ) {
  205. // if (it.next() instanceof PointcutDeclaration) {
  206. // pointcutCount++;
  207. // }
  208. // }
  209. // PointcutDeclaration[] pointcuts = new PointcutDeclaration[pointcutCount];
  210. // int next = 0;
  211. // for (Iterator it = bd.listIterator(); it.hasNext(); ) {
  212. // Object decl = it.next();
  213. // if (decl instanceof PointcutDeclaration) {
  214. // pointcuts[next++] = (PointcutDeclaration) decl;
  215. // }
  216. // }
  217. // return pointcuts;
  218. // }
  219. }