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.

AjAST.java 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /********************************************************************
  2. * Copyright (c) 2006 Contributors. All rights reserved.
  3. * This program and the accompanying materials are made available
  4. * under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution and is available at
  6. * http://eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: IBM Corporation - initial API and implementation
  9. * Helen Hawkins - iniital version
  10. *******************************************************************/
  11. package org.aspectj.org.eclipse.jdt.core.dom;
  12. import java.util.Map;
  13. import org.eclipse.core.runtime.IProgressMonitor;
  14. import org.aspectj.org.eclipse.jdt.core.dom.AST;
  15. import org.aspectj.org.eclipse.jdt.core.dom.BindingResolver;
  16. import org.aspectj.org.eclipse.jdt.core.dom.DefaultBindingResolver;
  17. public class AjAST extends AST {
  18. /**
  19. * Creates a new AspectJ abstract syntax tree
  20. * (AST) following the specified set of API rules.
  21. *
  22. * @param level the API level; one of the LEVEL constants
  23. * @since 3.0
  24. */
  25. private AjAST(int level) {
  26. super(level);
  27. }
  28. /**
  29. * Creates a new AspectJ abstract syntax tree
  30. * (AST) following the specified set of API rules.
  31. * <p>
  32. * Clients should use this method specifing {@link #JLS3} as the
  33. * AST level in all cases, even when dealing with JDK 1.3 or 1.4..
  34. * </p>
  35. *
  36. * @param level the API level; one of the LEVEL constants
  37. * @return new AST instance following the specified set of API rules.
  38. * @exception IllegalArgumentException if:
  39. * <ul>
  40. * <li>the API level is not one of the LEVEL constants</li>
  41. * </ul>
  42. * @since 3.0
  43. */
  44. public static AjAST newAjAST(int level) {
  45. if ((level != AST.JLS2)
  46. && (level != AST.JLS3)) {
  47. throw new IllegalArgumentException();
  48. }
  49. return new AjAST(level);
  50. }
  51. /**
  52. * Internal method.
  53. * <p>
  54. * This method converts the given internal compiler AST for the given source string
  55. * into a compilation unit. This method is not intended to be called by clients.
  56. * </p>
  57. *
  58. * @param level the API level; one of the LEVEL constants
  59. * @param compilationUnitDeclaration an internal AST node for a compilation unit declaration
  60. * @param source the string of the Java compilation unit
  61. * @param options compiler options
  62. * @param workingCopy the working copy that the AST is created from
  63. * @param monitor the progress monitor used to report progress and request cancelation,
  64. * or <code>null</code> if none
  65. * @param isResolved whether the given compilation unit declaration is resolved
  66. * @return the compilation unit node
  67. */
  68. public static CompilationUnit convertCompilationUnit(
  69. int level,
  70. org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration compilationUnitDeclaration,
  71. char[] source,
  72. Map options,
  73. boolean isResolved,
  74. org.aspectj.org.eclipse.jdt.internal.core.CompilationUnit workingCopy,
  75. IProgressMonitor monitor) {
  76. ASTConverter converter =
  77. // AspectJ extension - use the factory
  78. ASTConverter.getASTConverter(options,isResolved,monitor);
  79. // create a new AjAst - difference between this method in AjAST and AST
  80. AjAST ast = AjAST.newAjAST(level);
  81. int savedDefaultNodeFlag = ast.getDefaultNodeFlag();
  82. ast.setDefaultNodeFlag(ASTNode.ORIGINAL);
  83. BindingResolver resolver = null;
  84. if (isResolved) {
  85. resolver = new DefaultBindingResolver(compilationUnitDeclaration.scope, workingCopy.owner, new DefaultBindingResolver.BindingTables(), false,true);
  86. ast.setFlag(AST.RESOLVED_BINDINGS);
  87. } else {
  88. resolver = new BindingResolver();
  89. }
  90. ast.setBindingResolver(resolver);
  91. converter.setAST(ast);
  92. CompilationUnit unit = converter.convert(compilationUnitDeclaration, source);
  93. unit.setLineEndTable(compilationUnitDeclaration.compilationResult.lineSeparatorPositions);
  94. unit.setTypeRoot(workingCopy);
  95. ast.setDefaultNodeFlag(savedDefaultNodeFlag);
  96. return unit;
  97. }
  98. /**
  99. * Creates an unparented aspect declaration node owned by this AST.
  100. * The name of the aspect is an unspecified, but legal, name;
  101. * no modifiers; no doc comment; no superclass or superinterfaces;
  102. * an empty body; a null perclause; and is not privileged
  103. * <p>
  104. * To set the perclause, use this method and then call
  105. * <code>AspectDeclaration.setPerClause(ASTNode)</code>.
  106. * </p>
  107. * <p>
  108. * To create a privileged aspect, use this method and then call
  109. * <code>AspectDeclaration.setPrivileged(true)</code>.
  110. * </p>
  111. *
  112. * @return a new unparented aspect declaration node
  113. */
  114. public AspectDeclaration newAspectDeclaration() {
  115. AspectDeclaration result = new AspectDeclaration(this);
  116. return result;
  117. }
  118. /**
  119. * Creates an unparented ajtype declaration node owned by this AST.
  120. * The name of the class is an unspecified, but legal, name;
  121. * no modifiers; no doc comment; no superclass or superinterfaces;
  122. * and an empty body.
  123. * <p>
  124. * To create an aspect, use this method and then call
  125. * <code>AjTypeDeclaration.setAspect(true)</code>.
  126. * </p>
  127. *
  128. * @return a new unparented ajtype declaration node
  129. */
  130. public AjTypeDeclaration newAjTypeDeclaration() {
  131. AjTypeDeclaration result = new AjTypeDeclaration(this);
  132. return result;
  133. }
  134. /**
  135. * Creates an unparented after advice declaration node owned by this AST.
  136. * By default, the declaration is for an after advice with no pointcut;
  137. * no doc comment; and no body (as opposed to an empty body).
  138. *
  139. * @return a new unparented after advice declaration node
  140. */
  141. public AfterAdviceDeclaration newAfterAdviceDeclaration() {
  142. AfterAdviceDeclaration result = new AfterAdviceDeclaration(this);
  143. return result;
  144. }
  145. /**
  146. * Creates an unparented after returning advice declaration node owned
  147. * by this AST. By default, the declaration is for an after returning
  148. * advice with no pointcut; no doc comment; no return value and no
  149. * body (as opposed to an empty body).
  150. *
  151. * @return a new unparented after returning advice declaration node
  152. */
  153. public AfterReturningAdviceDeclaration newAfterReturningAdviceDeclaration() {
  154. AfterReturningAdviceDeclaration result = new AfterReturningAdviceDeclaration(this);
  155. return result;
  156. }
  157. /**
  158. * Creates an unparented after throwing advice declaration node owned
  159. * by this AST. By default, the declaration is for an after throwing
  160. * advice with no pointcut; no doc comment; no throwing value and no
  161. * body (as opposed to an empty body).
  162. *
  163. * @return a new unparented after throwing advice declaration node
  164. */
  165. public AfterThrowingAdviceDeclaration newAfterThrowingAdviceDeclaration() {
  166. AfterThrowingAdviceDeclaration result = new AfterThrowingAdviceDeclaration(this);
  167. return result;
  168. }
  169. /**
  170. * Creates an unparented before advice declaration node owned by this AST.
  171. * By default, the declaration is for a before advice with no pointcut;
  172. * no doc comment; and no body (as opposed to an empty body).
  173. *
  174. * @return a new unparented before advice declaration node
  175. */
  176. public BeforeAdviceDeclaration newBeforeAdviceDeclaration() {
  177. BeforeAdviceDeclaration result = new BeforeAdviceDeclaration(this);
  178. return result;
  179. }
  180. /**
  181. * Creates an unparented around advice declaration node owned by this AST.
  182. * By default, the declaration is for an around advice with no pointcut;
  183. * no doc comment; no return type; and no body (as opposed to an empty body).
  184. *
  185. * @return a new unparented around advice declaration node
  186. */
  187. public AroundAdviceDeclaration newAroundAdviceDeclaration() {
  188. AroundAdviceDeclaration result = new AroundAdviceDeclaration(this);
  189. return result;
  190. }
  191. /**
  192. * Creates an unparented declare at constructor declaration node owned by this AST.
  193. * By default, the declaration is for a declare annotation with no doc comment;
  194. * no pattern node; no annotation name; and no declare kind.
  195. *
  196. * @return a new unparented declare at constructor declaration node
  197. * @exception UnsupportedOperationException if this operation is used in
  198. * a JLS2 AST
  199. */
  200. public DeclareAtConstructorDeclaration newDeclareAtConstructorDeclaration() {
  201. DeclareAtConstructorDeclaration result = new DeclareAtConstructorDeclaration(this);
  202. return result;
  203. }
  204. /**
  205. * Creates an unparented declare at field declaration node owned by this AST.
  206. * By default, the declaration is for a declare annotation with no doc comment;
  207. * no pattern node; no annotation name; and no declare kind.
  208. *
  209. * @return a new unparented declare at field declaration node
  210. * @exception UnsupportedOperationException if this operation is used in
  211. * a JLS2 AST
  212. */
  213. public DeclareAtFieldDeclaration newDeclareAtFieldDeclaration() {
  214. DeclareAtFieldDeclaration result = new DeclareAtFieldDeclaration(this);
  215. return result;
  216. }
  217. /**
  218. * Creates an unparented declare at method declaration node owned by this AST.
  219. * By default, the declaration is for a declare annotation with no doc comment;
  220. * no pattern node; no annotation name; and no declare kind.
  221. *
  222. * @return a new unparented declare at method declaration node
  223. * @exception UnsupportedOperationException if this operation is used in
  224. * a JLS2 AST
  225. */
  226. public DeclareAtMethodDeclaration newDeclareAtMethodDeclaration() {
  227. DeclareAtMethodDeclaration result = new DeclareAtMethodDeclaration(this);
  228. return result;
  229. }
  230. /**
  231. * Creates an unparented declare at type declaration node owned by this AST.
  232. * By default, the declaration is for a declare annotation with no doc comment;
  233. * no pattern node; no annotation name; and no declare kind.
  234. *
  235. * @return a new unparented declare at type declaration node
  236. * @exception UnsupportedOperationException if this operation is used in
  237. * a JLS2 AST
  238. */
  239. public DeclareAtTypeDeclaration newDeclareAtTypeDeclaration() {
  240. DeclareAtTypeDeclaration result = new DeclareAtTypeDeclaration(this);
  241. return result;
  242. }
  243. /**
  244. * Creates an unparented declare error declaration node owned by this AST.
  245. * By default, the declaration is for a declare error with no doc comment;
  246. * no pointcut; and no message.
  247. *
  248. * @return a new unparented declare error declaration node
  249. */
  250. public DeclareErrorDeclaration newDeclareErrorDeclaration() {
  251. DeclareErrorDeclaration result = new DeclareErrorDeclaration(this);
  252. return result;
  253. }
  254. /**
  255. * Creates an unparented declare parents declaration node owned by this AST.
  256. * By default, the declaration is for a declare parents which is implements;
  257. * with no doc comment; no child type pattern; and no parent type pattern
  258. * <p>
  259. * To create an extends declare parents, use this method and then call
  260. * <code>DeclareParentsDeclaration.setExtends(true)</code>.
  261. * </p>
  262. *
  263. * @return a new unparented declare parents declaration node
  264. */
  265. public DeclareParentsDeclaration newDeclareParentsDeclaration() {
  266. DeclareParentsDeclaration result = new DeclareParentsDeclaration(this);
  267. return result;
  268. }
  269. /**
  270. * Creates an unparented declare precedence declaration node owned by this AST.
  271. * By default, the declaration is for a declare precedence with no doc comment;
  272. * and no type pattern list.
  273. *
  274. * @return a new unparented declare precedence declaration node
  275. */
  276. public DeclarePrecedenceDeclaration newDeclarePrecedenceDeclaration() {
  277. DeclarePrecedenceDeclaration result = new DeclarePrecedenceDeclaration(this);
  278. return result;
  279. }
  280. /**
  281. * Creates an unparented declare soft declaration node owned by this AST.
  282. * By default, the declaration is for a declare soft with no doc comment;
  283. * no pointcut; and no type pattern.
  284. *
  285. * @return a new unparented declare soft declaration node
  286. */
  287. public DeclareSoftDeclaration newDeclareSoftDeclaration() {
  288. DeclareSoftDeclaration result = new DeclareSoftDeclaration(this);
  289. return result;
  290. }
  291. /**
  292. * Creates an unparented declare warning declaration node owned by this AST.
  293. * By default, the declaration is for a declare warning with no doc comment;
  294. * no pointcut; and no message.
  295. *
  296. * @return a new unparented declare warning declaration node
  297. */
  298. public DeclareWarningDeclaration newDeclareWarningDeclaration() {
  299. DeclareWarningDeclaration result = new DeclareWarningDeclaration(this);
  300. return result;
  301. }
  302. /**
  303. * Creates a new unparented intertype field declaration node owned by this
  304. * AST. By default, there are no modifiers, no doc comment, and the base
  305. * type is unspecified (but legal).
  306. *
  307. * @return a new unparented intertype field declaration node
  308. */
  309. public InterTypeFieldDeclaration newInterTypeFieldDeclaration() {
  310. InterTypeFieldDeclaration result = new InterTypeFieldDeclaration(this);
  311. return result;
  312. }
  313. /**
  314. * Creates an unparented intertype method declaration node owned by
  315. * this AST. By default, the declaration is for a method of an
  316. * unspecified, but legal, name; no modifiers; no doc comment; no
  317. * parameters; return type void; no extra array dimensions; no
  318. * thrown exceptions; and no body (as opposed to an empty body).
  319. *
  320. * @return a new unparented inter type method declaration node
  321. */
  322. public InterTypeMethodDeclaration newInterTypeMethodDeclaration() {
  323. InterTypeMethodDeclaration result = new InterTypeMethodDeclaration(this);
  324. return result;
  325. }
  326. /**
  327. * Creates an unparented pointcut declaration node owned by this AST.
  328. * By default, the declaration is for a pointcut of an unspecified, but
  329. * legal, name; no modifiers; no doc comment; and no pointcut designator
  330. *
  331. * @return a new unparented pointcut declaration node
  332. */
  333. public PointcutDeclaration newPointcutDeclaration() {
  334. PointcutDeclaration result = new PointcutDeclaration(this);
  335. return result;
  336. }
  337. /**
  338. * Creates an unparented AndPointcut node owned by this AST.
  339. * By default, the declaration is for an and pointcut with no left
  340. * or right pointcut designators
  341. *
  342. * @return a new unparented AndPointcut node
  343. */
  344. public AndPointcut newAndPointcut() {
  345. AndPointcut result = new AndPointcut(this);
  346. return result;
  347. }
  348. /**
  349. * Creates an unparented CflowPointcut node owned by this AST.
  350. * By default, the declaration is for a cflow pointcut with no body
  351. * pointcut designator
  352. *
  353. * @return a new unparented CflowPointcut node
  354. */
  355. public CflowPointcut newCflowPointcut() {
  356. CflowPointcut result = new CflowPointcut(this);
  357. return result;
  358. }
  359. /**
  360. * Creates an unparented NotPointcut node owned by this AST.
  361. * By default, the declaration is for a not pointcut with no body
  362. * pointcut designator
  363. *
  364. * @return a new unparented NotPointcut node
  365. */
  366. public NotPointcut newNotPointcut() {
  367. NotPointcut result = new NotPointcut(this);
  368. return result;
  369. }
  370. /**
  371. * Creates an unparented OrPointcut node owned by this AST.
  372. * By default, the declaration is for an or pointcut with no left
  373. * or right pointcut designators
  374. *
  375. * @return a new unparented OrPointcut node
  376. */
  377. public OrPointcut newOrPointcut() {
  378. OrPointcut result = new OrPointcut(this);
  379. return result;
  380. }
  381. /**
  382. * Creates an unparented PerCflow node owned by this AST.
  383. * By default, the declaration is for a percflow with no body
  384. * pointcut designator
  385. *
  386. * @return a new unparented percflow node
  387. */
  388. public PerCflow newPerCflow() {
  389. PerCflow result = new PerCflow(this);
  390. return result;
  391. }
  392. /**
  393. * Creates an unparented perobject node owned by this AST.
  394. * By default, the declaration is for a perobject with no body
  395. * pointcut designator
  396. *
  397. * @return a new unparented perobject node
  398. */
  399. public PerObject newPerObject() {
  400. PerObject result = new PerObject(this);
  401. return result;
  402. }
  403. /**
  404. * Creates an unparented pertypewithin node owned by this AST.
  405. * By default, the declaration is for a pertypewithin
  406. *
  407. * @return a new unparented pertypewithin node
  408. */
  409. public PerTypeWithin newPerTypeWithin() {
  410. PerTypeWithin result = new PerTypeWithin(this);
  411. return result;
  412. }
  413. /**
  414. * Creates an unparented reference pointcut node owned by this AST.
  415. * By default, the declaration is for a reference pointcut with no
  416. * name
  417. *
  418. * @return a new unparented reference pointcut node
  419. */
  420. public ReferencePointcut newReferencePointcut() {
  421. ReferencePointcut result = new ReferencePointcut(this);
  422. return result;
  423. }
  424. /**
  425. * Creates an unparented default pointcut node owned by this AST.
  426. * By default, the declaration is for a default pointcut with an
  427. * empty detail string.
  428. * <p>
  429. * To edit the detail string, use this method and then call
  430. * <code>DefaultPointcut.setDetail("newString")</code>.
  431. * </p>
  432. *
  433. * @return a new unparented default pointcut node
  434. */
  435. public DefaultPointcut newDefaultPointcut() {
  436. DefaultPointcut result = new DefaultPointcut(this,"");
  437. return result;
  438. }
  439. /**
  440. * Creates an unparented default type pattern node owned by this AST.
  441. * By default, the declaration is for a default type pattern with an
  442. * empty detail string.
  443. * <p>
  444. * To edit the detail string, use this method and then call
  445. * <code>DefaultTypePattern.setDetail("newString")</code>.
  446. * </p>
  447. *
  448. * @return a new unparented default type pattern node
  449. */
  450. public DefaultTypePattern newDefaultTypePattern() {
  451. DefaultTypePattern result = new DefaultTypePattern(this,"");
  452. return result;
  453. }
  454. /**
  455. * Creates an unparented default signature pattern node owned by this AST.
  456. * By default, the declaration is for a default signature pattern with an
  457. * empty detail string.
  458. * <p>
  459. * To edit the detail string, use this method and then call
  460. * <code>SignaturePattern.setDetail("newString")</code>.
  461. * </p>
  462. *
  463. * @return a new unparented default signature pattern node
  464. */
  465. public SignaturePattern newSignaturePattern() {
  466. SignaturePattern result = new SignaturePattern(this,"");
  467. return result;
  468. }
  469. }