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.

DeclarationFactory.java 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*******************************************************************************
  2. * Copyright (c) 2002,2003 Palo Alto Research Center, Incorporated (PARC).
  3. * Copyright (c) 2004 IBM Corporation and others.
  4. * All rights reserved. This program and the accompanying materials
  5. * are made available 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. * IBM Corporation
  12. *******************************************************************************/
  13. package org.aspectj.ajdt.internal.compiler.parser;
  14. import org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration;
  15. import org.aspectj.ajdt.internal.compiler.ast.AjConstructorDeclaration;
  16. import org.aspectj.ajdt.internal.compiler.ast.AjMethodDeclaration;
  17. import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration;
  18. import org.aspectj.ajdt.internal.compiler.ast.DeclareAnnotationDeclaration;
  19. import org.aspectj.ajdt.internal.compiler.ast.DeclareDeclaration;
  20. import org.aspectj.ajdt.internal.compiler.ast.IfPseudoToken;
  21. import org.aspectj.ajdt.internal.compiler.ast.InterTypeConstructorDeclaration;
  22. import org.aspectj.ajdt.internal.compiler.ast.InterTypeDeclaration;
  23. import org.aspectj.ajdt.internal.compiler.ast.InterTypeFieldDeclaration;
  24. import org.aspectj.ajdt.internal.compiler.ast.InterTypeMethodDeclaration;
  25. import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration;
  26. import org.aspectj.ajdt.internal.compiler.ast.PointcutDesignator;
  27. import org.aspectj.ajdt.internal.compiler.ast.Proceed;
  28. import org.aspectj.ajdt.internal.compiler.ast.PseudoToken;
  29. import org.aspectj.ajdt.internal.compiler.ast.PseudoTokens;
  30. import org.aspectj.ajdt.internal.core.builder.EclipseSourceContext;
  31. import org.aspectj.weaver.AdviceKind;
  32. import org.aspectj.weaver.patterns.Declare;
  33. import org.aspectj.weaver.patterns.DeclareAnnotation;
  34. import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
  35. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode;
  36. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation;
  37. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument;
  38. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
  39. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression;
  40. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MessageSend;
  41. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
  42. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
  43. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference;
  44. import org.aspectj.org.eclipse.jdt.internal.compiler.parser.Parser;
  45. import org.aspectj.org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory;
  46. /**
  47. * @author colyer
  48. *
  49. * To change the template for this generated type comment go to
  50. * Window>Preferences>Java>Code Generation>Code and Comments
  51. */
  52. public class DeclarationFactory implements IDeclarationFactory {
  53. /* (non-Javadoc)
  54. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createMethodDeclaration(org.eclipse.jdt.internal.compiler.CompilationResult)
  55. */
  56. public MethodDeclaration createMethodDeclaration(CompilationResult result) {
  57. return new AjMethodDeclaration(result);
  58. }
  59. /* (non-Javadoc)
  60. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createConstructorDeclaration(org.eclipse.jdt.internal.compiler.CompilationResult)
  61. */
  62. public ConstructorDeclaration createConstructorDeclaration(CompilationResult result) {
  63. return new AjConstructorDeclaration(result);
  64. }
  65. /* (non-Javadoc)
  66. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createProceed(org.eclipse.jdt.internal.compiler.ast.MessageSend)
  67. */
  68. public MessageSend createProceed(MessageSend m) {
  69. return new Proceed(m);
  70. }
  71. /* (non-Javadoc)
  72. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createAspect(org.eclipse.jdt.internal.compiler.CompilationResult)
  73. */
  74. public TypeDeclaration createAspect(CompilationResult result) {
  75. return new AspectDeclaration(result);
  76. }
  77. /* (non-Javadoc)
  78. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#setPrivileged(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration, boolean)
  79. */
  80. public void setPrivileged(TypeDeclaration aspectDecl, boolean isPrivileged) {
  81. ((AspectDeclaration)aspectDecl).isPrivileged = isPrivileged;
  82. }
  83. /* (non-Javadoc)
  84. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#setPerClauseFrom(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration, org.eclipse.jdt.internal.compiler.ast.ASTNode)
  85. */
  86. public void setPerClauseFrom(TypeDeclaration aspectDecl, ASTNode pseudoTokens, Parser parser) {
  87. AspectDeclaration aspect = (AspectDeclaration) aspectDecl;
  88. PseudoTokens tok = (PseudoTokens) pseudoTokens;
  89. aspect.perClause = tok.parsePerClause(parser);
  90. }
  91. /* (non-Javadoc)
  92. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#setDominatesPatternFrom(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration, org.eclipse.jdt.internal.compiler.ast.ASTNode)
  93. */
  94. public void setDominatesPatternFrom(TypeDeclaration aspectDecl, ASTNode pseudoTokens, Parser parser) {
  95. AspectDeclaration aspect = (AspectDeclaration) aspectDecl;
  96. PseudoTokens tok = (PseudoTokens) pseudoTokens;
  97. aspect.dominatesPattern = tok.maybeParseDominatesPattern(parser);
  98. }
  99. /* (non-Javadoc)
  100. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createPseudoTokensFrom(org.eclipse.jdt.internal.compiler.ast.ASTNode[], org.eclipse.jdt.internal.compiler.CompilationResult)
  101. */
  102. public ASTNode createPseudoTokensFrom(ASTNode[] tokens, CompilationResult result) {
  103. PseudoToken[] psts = new PseudoToken[tokens.length];
  104. for (int i = 0; i < psts.length; i++) {
  105. psts[i] = (PseudoToken)tokens[i];
  106. }
  107. return new PseudoTokens(psts,new EclipseSourceContext(result));
  108. }
  109. /* (non-Javadoc)
  110. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createPointcutDeclaration(org.eclipse.jdt.internal.compiler.CompilationResult)
  111. */
  112. public MethodDeclaration createPointcutDeclaration(CompilationResult result) {
  113. return new PointcutDeclaration(result);
  114. }
  115. /* (non-Javadoc)
  116. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createAroundAdviceDeclaration(org.eclipse.jdt.internal.compiler.CompilationResult)
  117. */
  118. public MethodDeclaration createAroundAdviceDeclaration(CompilationResult result) {
  119. return new AdviceDeclaration(result,AdviceKind.Around);
  120. }
  121. /* (non-Javadoc)
  122. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createAfterAdviceDeclaration(org.eclipse.jdt.internal.compiler.CompilationResult)
  123. */
  124. public MethodDeclaration createAfterAdviceDeclaration(CompilationResult result) {
  125. return new AdviceDeclaration(result,AdviceKind.After);
  126. }
  127. /* (non-Javadoc)
  128. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createBeforeAdviceDeclaration(org.eclipse.jdt.internal.compiler.CompilationResult)
  129. */
  130. public MethodDeclaration createBeforeAdviceDeclaration(CompilationResult result) {
  131. return new AdviceDeclaration(result,AdviceKind.Before);
  132. }
  133. /* (non-Javadoc)
  134. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createPointcutDesignator(org.eclipse.jdt.internal.compiler.parser.Parser, org.eclipse.jdt.internal.compiler.ast.ASTNode)
  135. */
  136. public ASTNode createPointcutDesignator(Parser parser, ASTNode pseudoTokens) {
  137. return new PointcutDesignator(parser,(PseudoTokens)pseudoTokens);
  138. }
  139. /* (non-Javadoc)
  140. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#setPointcutDesignator(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration, org.eclipse.jdt.internal.compiler.ast.ASTNode)
  141. */
  142. public void setPointcutDesignatorOnAdvice(MethodDeclaration adviceDecl, ASTNode des) {
  143. ((AdviceDeclaration)adviceDecl).pointcutDesignator = (PointcutDesignator)des;
  144. }
  145. /* (non-Javadoc)
  146. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#setPointcutDesignator(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration, org.eclipse.jdt.internal.compiler.ast.ASTNode)
  147. */
  148. public void setPointcutDesignatorOnPointcut(MethodDeclaration pcutDecl, ASTNode des) {
  149. ((PointcutDeclaration)pcutDecl).pointcutDesignator = (PointcutDesignator)des;
  150. }
  151. /* (non-Javadoc)
  152. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#setExtraArgument(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration, org.eclipse.jdt.internal.compiler.ast.Argument)
  153. */
  154. public void setExtraArgument(MethodDeclaration adviceDeclaration, Argument arg) {
  155. ((AdviceDeclaration)adviceDeclaration).extraArgument = arg;
  156. }
  157. /* (non-Javadoc)
  158. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#isAfterAdvice(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration)
  159. */
  160. public boolean isAfterAdvice(MethodDeclaration adviceDecl) {
  161. return ((AdviceDeclaration)adviceDecl).kind != AdviceKind.After;
  162. }
  163. /* (non-Javadoc)
  164. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#setAfterThrowingAdviceKind(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration)
  165. */
  166. public void setAfterThrowingAdviceKind(MethodDeclaration adviceDecl) {
  167. ((AdviceDeclaration)adviceDecl).kind = AdviceKind.AfterThrowing;
  168. }
  169. /* (non-Javadoc)
  170. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#setAfterReturningAdviceKind(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration)
  171. */
  172. public void setAfterReturningAdviceKind(MethodDeclaration adviceDecl) {
  173. ((AdviceDeclaration)adviceDecl).kind = AdviceKind.AfterReturning;
  174. }
  175. /* (non-Javadoc)
  176. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createDeclareDeclaration(org.eclipse.jdt.internal.compiler.CompilationResult, org.eclipse.jdt.internal.compiler.ast.ASTNode)
  177. */
  178. public MethodDeclaration createDeclareDeclaration(CompilationResult result, ASTNode pseudoTokens, Parser parser) {
  179. Declare declare = ((PseudoTokens)pseudoTokens).parseDeclare(parser);
  180. return new DeclareDeclaration(result,declare);
  181. }
  182. /* (non-Javadoc)
  183. * @see org.aspectj.org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createDeclareAnnotationDeclaration(org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult, org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode, org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation, org.aspectj.org.eclipse.jdt.internal.compiler.parser.Parser)
  184. */
  185. public MethodDeclaration createDeclareAnnotationDeclaration(
  186. CompilationResult result, ASTNode pseudoTokens,
  187. Annotation annotation, Parser parser) {
  188. DeclareAnnotation declare = (DeclareAnnotation) ((PseudoTokens)pseudoTokens).parseAnnotationDeclare(parser);
  189. DeclareAnnotationDeclaration decl = new DeclareAnnotationDeclaration(result,declare,annotation);
  190. return decl;
  191. }
  192. /* (non-Javadoc)
  193. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createInterTypeFieldDeclaration(org.eclipse.jdt.internal.compiler.CompilationResult, org.eclipse.jdt.internal.compiler.ast.TypeReference)
  194. */
  195. public MethodDeclaration createInterTypeFieldDeclaration(CompilationResult result, TypeReference onType) {
  196. return new InterTypeFieldDeclaration(result,onType);
  197. }
  198. /* (non-Javadoc)
  199. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createInterTypeMethodDeclaration(org.eclipse.jdt.internal.compiler.CompilationResult)
  200. */
  201. public MethodDeclaration createInterTypeMethodDeclaration(CompilationResult result) {
  202. return new InterTypeMethodDeclaration(result,null);
  203. }
  204. /* (non-Javadoc)
  205. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createInterTypeConstructorDeclaration(org.eclipse.jdt.internal.compiler.CompilationResult)
  206. */
  207. public MethodDeclaration createInterTypeConstructorDeclaration(CompilationResult result) {
  208. return new InterTypeConstructorDeclaration(result,null);
  209. }
  210. /* (non-Javadoc)
  211. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#setSelector(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration, char[])
  212. */
  213. public void setSelector(MethodDeclaration interTypeDecl, char[] selector) {
  214. ((InterTypeDeclaration)interTypeDecl).setSelector(selector);
  215. }
  216. /* (non-Javadoc)
  217. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#setDeclaredModifiers(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration, int)
  218. */
  219. public void setDeclaredModifiers(MethodDeclaration interTypeDecl, int modifiers) {
  220. ((InterTypeDeclaration)interTypeDecl).setDeclaredModifiers(modifiers); }
  221. /* (non-Javadoc)
  222. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#setInitialization(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration, org.eclipse.jdt.internal.compiler.ast.Expression)
  223. */
  224. public void setInitialization(MethodDeclaration itdFieldDecl, Expression initialization) {
  225. ((InterTypeFieldDeclaration)itdFieldDecl).setInitialization(initialization);
  226. }
  227. /* (non-Javadoc)
  228. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#setOnType(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration, org.eclipse.jdt.internal.compiler.ast.TypeReference)
  229. */
  230. public void setOnType(MethodDeclaration interTypeDecl, TypeReference onType) {
  231. ((InterTypeDeclaration)interTypeDecl).onType = onType;
  232. }
  233. /* (non-Javadoc)
  234. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createPseudoToken(org.eclipse.jdt.internal.compiler.parser.Parser, java.lang.String, boolean)
  235. */
  236. public ASTNode createPseudoToken(Parser parser, String value, boolean isIdentifier) {
  237. return new PseudoToken(parser,value,isIdentifier);
  238. }
  239. /* (non-Javadoc)
  240. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createIfPseudoToken(org.eclipse.jdt.internal.compiler.parser.Parser, org.eclipse.jdt.internal.compiler.ast.Expression)
  241. */
  242. public ASTNode createIfPseudoToken(Parser parser, Expression expr) {
  243. return new IfPseudoToken(parser,expr);
  244. }
  245. /* (non-Javadoc)
  246. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#setLiteralKind(org.eclipse.jdt.internal.compiler.ast.ASTNode, java.lang.String)
  247. */
  248. public void setLiteralKind(ASTNode pseudoToken, String string) {
  249. ((PseudoToken)pseudoToken).literalKind = string;
  250. }
  251. /* (non-Javadoc)
  252. * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#shouldTryToRecover(org.eclipse.jdt.internal.compiler.ast.ASTNode)
  253. */
  254. public boolean shouldTryToRecover(ASTNode node) {
  255. return !(node instanceof AspectDeclaration ||
  256. node instanceof PointcutDeclaration ||
  257. node instanceof AdviceDeclaration) ;
  258. }
  259. }