Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006
  1. /********************************************************************
  2. * Copyright (c) 2006, 2010 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 - initial version
  10. *******************************************************************/
  11. package org.aspectj.tools.ajc;
  12. import java.util.ArrayList;
  13. import java.util.Collections;
  14. import java.util.Iterator;
  15. import java.util.List;
  16. import org.aspectj.org.eclipse.jdt.core.dom.AST;
  17. import org.aspectj.org.eclipse.jdt.core.dom.ASTNode;
  18. import org.aspectj.org.eclipse.jdt.core.dom.ASTParser;
  19. import org.aspectj.org.eclipse.jdt.core.dom.AbstractBooleanTypePattern;
  20. import org.aspectj.org.eclipse.jdt.core.dom.AfterAdviceDeclaration;
  21. import org.aspectj.org.eclipse.jdt.core.dom.AfterReturningAdviceDeclaration;
  22. import org.aspectj.org.eclipse.jdt.core.dom.AfterThrowingAdviceDeclaration;
  23. import org.aspectj.org.eclipse.jdt.core.dom.AjAST;
  24. import org.aspectj.org.eclipse.jdt.core.dom.AjASTVisitor;
  25. import org.aspectj.org.eclipse.jdt.core.dom.AjTypeDeclaration;
  26. import org.aspectj.org.eclipse.jdt.core.dom.AndPointcut;
  27. import org.aspectj.org.eclipse.jdt.core.dom.AnyTypePattern;
  28. import org.aspectj.org.eclipse.jdt.core.dom.AnyWithAnnotationTypePattern;
  29. import org.aspectj.org.eclipse.jdt.core.dom.AroundAdviceDeclaration;
  30. import org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration;
  31. import org.aspectj.org.eclipse.jdt.core.dom.BeforeAdviceDeclaration;
  32. import org.aspectj.org.eclipse.jdt.core.dom.Block;
  33. import org.aspectj.org.eclipse.jdt.core.dom.CflowPointcut;
  34. import org.aspectj.org.eclipse.jdt.core.dom.ChildListPropertyDescriptor;
  35. import org.aspectj.org.eclipse.jdt.core.dom.ChildPropertyDescriptor;
  36. import org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit;
  37. import org.aspectj.org.eclipse.jdt.core.dom.DeclareAtConstructorDeclaration;
  38. import org.aspectj.org.eclipse.jdt.core.dom.DeclareAtFieldDeclaration;
  39. import org.aspectj.org.eclipse.jdt.core.dom.DeclareAtMethodDeclaration;
  40. import org.aspectj.org.eclipse.jdt.core.dom.DeclareAtTypeDeclaration;
  41. import org.aspectj.org.eclipse.jdt.core.dom.DeclareErrorDeclaration;
  42. import org.aspectj.org.eclipse.jdt.core.dom.DeclareParentsDeclaration;
  43. import org.aspectj.org.eclipse.jdt.core.dom.DeclarePrecedenceDeclaration;
  44. import org.aspectj.org.eclipse.jdt.core.dom.DeclareSoftDeclaration;
  45. import org.aspectj.org.eclipse.jdt.core.dom.DeclareWarningDeclaration;
  46. import org.aspectj.org.eclipse.jdt.core.dom.DefaultPointcut;
  47. import org.aspectj.org.eclipse.jdt.core.dom.DefaultTypePattern;
  48. import org.aspectj.org.eclipse.jdt.core.dom.EllipsisTypePattern;
  49. import org.aspectj.org.eclipse.jdt.core.dom.HasMemberTypePattern;
  50. import org.aspectj.org.eclipse.jdt.core.dom.IExtendedModifier;
  51. import org.aspectj.org.eclipse.jdt.core.dom.IdentifierTypePattern;
  52. import org.aspectj.org.eclipse.jdt.core.dom.InterTypeFieldDeclaration;
  53. import org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration;
  54. import org.aspectj.org.eclipse.jdt.core.dom.Javadoc;
  55. import org.aspectj.org.eclipse.jdt.core.dom.NoTypePattern;
  56. import org.aspectj.org.eclipse.jdt.core.dom.NotPointcut;
  57. import org.aspectj.org.eclipse.jdt.core.dom.NotTypePattern;
  58. import org.aspectj.org.eclipse.jdt.core.dom.OrPointcut;
  59. import org.aspectj.org.eclipse.jdt.core.dom.PerCflow;
  60. import org.aspectj.org.eclipse.jdt.core.dom.PerObject;
  61. import org.aspectj.org.eclipse.jdt.core.dom.PerTypeWithin;
  62. import org.aspectj.org.eclipse.jdt.core.dom.PointcutDeclaration;
  63. import org.aspectj.org.eclipse.jdt.core.dom.PrimitiveType;
  64. import org.aspectj.org.eclipse.jdt.core.dom.ReferencePointcut;
  65. import org.aspectj.org.eclipse.jdt.core.dom.SignaturePattern;
  66. import org.aspectj.org.eclipse.jdt.core.dom.SimpleName;
  67. import org.aspectj.org.eclipse.jdt.core.dom.SimplePropertyDescriptor;
  68. import org.aspectj.org.eclipse.jdt.core.dom.SimpleType;
  69. import org.aspectj.org.eclipse.jdt.core.dom.SingleVariableDeclaration;
  70. import org.aspectj.org.eclipse.jdt.core.dom.StringLiteral;
  71. import org.aspectj.org.eclipse.jdt.core.dom.Type;
  72. import org.aspectj.org.eclipse.jdt.core.dom.TypeCategoryTypePattern;
  73. import org.aspectj.org.eclipse.jdt.core.dom.TypeDeclaration;
  74. import org.aspectj.org.eclipse.jdt.core.dom.TypePattern;
  75. import org.aspectj.org.eclipse.jdt.core.SourceRange;
  76. /**
  77. * For each AspectJ ASTNode there is a test for:
  78. *
  79. * - that a new instance can be created via ajast.newXXX() - that the property descriptors have been set correctly - that the
  80. * get/set methods for the different properties work as expected - that the clone0 method sets the correct properties - that the
  81. * internalStructuralPropertiesForType(int) and internalGetSetXXXProperty(..) methods have been implemented correctly
  82. *
  83. * These are all that is required for an ASTNode, except an implementation of the accept0() method which is tested in
  84. * ASTVisitorTest.
  85. */
  86. public class AjASTTest extends AjASTTestCase {
  87. // -------------- DefaultPointcut tests ---------------
  88. public void testNewDefaultPointcut() {
  89. AjAST ajast = createAjAST();
  90. DefaultPointcut p = ajast.newDefaultPointcut();
  91. assertNotNull("a new DefaultPointcut should have been created", p);
  92. }
  93. public void testGetAndSetDetail() {
  94. AjAST ajast = createAjAST();
  95. DefaultPointcut p = ajast.newDefaultPointcut();
  96. assertEquals("The default detail should be the empty string", "", p.getDetail());
  97. p.setDetail("some detail");
  98. assertEquals("The detail should now be 'some detail'", "some detail", p.getDetail());
  99. }
  100. // -------------- ReferencePointcut tests ---------------
  101. public void testNewReferencePointcut() {
  102. AjAST ajast = createAjAST();
  103. ReferencePointcut p = ajast.newReferencePointcut();
  104. assertNotNull("a new ReferencePointcut should have been created", p);
  105. }
  106. /**
  107. * ReferencePointcut's have a name property - tests the getting and setting of this property
  108. */
  109. public void testGetAndSetRefPointcutName() {
  110. AjAST ajast = createAjAST();
  111. ReferencePointcut p = ajast.newReferencePointcut();
  112. assertEquals("the default reference pointcut name should be MISSING", "MISSING", p.getName().getFullyQualifiedName());
  113. p.setName(ajast.newSimpleName("refPointcutName"));
  114. assertEquals("the pointcut name should now be set to 'refPointcutName'", "refPointcutName", p.getName()
  115. .getFullyQualifiedName());
  116. }
  117. public void testNewAndPointcut() {
  118. AjAST ajast = createAjAST();
  119. AndPointcut p = ajast.newAndPointcut();
  120. assertNotNull("a new AndPointcut should have been created", p);
  121. }
  122. // -------------- AndPointcut tests ---------------
  123. /**
  124. * AndPointcut's have a left property - test the getting and setting of this property
  125. */
  126. public void testGetAndSetLeftOfAndPointcut() {
  127. AjAST ajast = createAjAST();
  128. AndPointcut ap = ajast.newAndPointcut();
  129. assertNull("by default the left side of an AndPointcut should be null", ap.getLeft());
  130. ReferencePointcut p = ajast.newReferencePointcut();
  131. ap.setLeft(p);
  132. assertEquals("the left side of the AndPointcut should now be the" + " ReferencePointcut", p, ap.getLeft());
  133. }
  134. /**
  135. * AndPointcut's have a right property - test the getting and setting of this property
  136. */
  137. public void testGetAndSetRightOfAndPointcut() {
  138. AjAST ajast = createAjAST();
  139. AndPointcut ap = ajast.newAndPointcut();
  140. assertNull("by default the right side of an AndPointcut should be null", ap.getRight());
  141. ReferencePointcut p = ajast.newReferencePointcut();
  142. ap.setRight(p);
  143. assertEquals("the right side of the AndPointcut should now be the" + " ReferencePointcut", p, ap.getRight());
  144. }
  145. // -------------- CflowPointcut tests ---------------
  146. public void testNewCflowPointcut() {
  147. AjAST ajast = createAjAST();
  148. CflowPointcut p = ajast.newCflowPointcut();
  149. assertNotNull("a new CflowPointcut should have been created", p);
  150. }
  151. /**
  152. * CflowPointcut's have a body property - test the getting and setting of this property
  153. */
  154. public void testGetAndSetBodyOfCflowPointcut() {
  155. AjAST ajast = createAjAST();
  156. CflowPointcut p = ajast.newCflowPointcut();
  157. assertNull("by default a CflowPointcut should have a null body", p.getBody());
  158. ReferencePointcut rp = ajast.newReferencePointcut();
  159. p.setBody(rp);
  160. assertEquals("the body of the CflowPointcut should now be a " + "ReferencePointcut", rp, p.getBody());
  161. }
  162. // -------------- NotPointcut tests ---------------
  163. public void testNewNotPointcut() {
  164. AjAST ajast = createAjAST();
  165. NotPointcut p = ajast.newNotPointcut();
  166. assertNotNull("a new NotPointcut should have been created", p);
  167. }
  168. /**
  169. * NotPointcut's have a body property - test the getting and setting of this property
  170. */
  171. public void testGetAndSetBodyOfNotPointcut() {
  172. AjAST ajast = createAjAST();
  173. NotPointcut p = ajast.newNotPointcut();
  174. assertNull("by default a NotPointcut should have a null body", p.getBody());
  175. ReferencePointcut rp = ajast.newReferencePointcut();
  176. p.setBody(rp);
  177. assertEquals("the body of the NotPointcut should now be a " + "ReferencePointcut", rp, p.getBody());
  178. }
  179. // -------------- OrPointcut tests ---------------
  180. public void testNewOrPointcut() {
  181. AjAST ajast = createAjAST();
  182. OrPointcut p = ajast.newOrPointcut();
  183. assertNotNull("a new OrPointcut should have been created", p);
  184. }
  185. /**
  186. * OrPointcut's have a left property - test the getting and setting of this property
  187. */
  188. public void testGetAndSetLeftOfOrPointcut() {
  189. AjAST ajast = createAjAST();
  190. OrPointcut op = ajast.newOrPointcut();
  191. assertNull("by default the left side of an OrPointcut should be null", op.getLeft());
  192. ReferencePointcut p = ajast.newReferencePointcut();
  193. op.setLeft(p);
  194. assertEquals("the left side of the OrPointcut should now be the" + " ReferencePointcut", p, op.getLeft());
  195. }
  196. /**
  197. * OrPointcut's have a right property - test the getting and setting of this property
  198. */
  199. public void testGetAndSetRightOfOrPointcut() {
  200. AjAST ajast = createAjAST();
  201. OrPointcut op = ajast.newOrPointcut();
  202. assertNull("by default the right side of an OrPointcut should be null", op.getRight());
  203. ReferencePointcut p = ajast.newReferencePointcut();
  204. op.setRight(p);
  205. assertEquals("the right side of the OrPointcut should now be the" + " ReferencePointcut", p, op.getRight());
  206. }
  207. // -------------- PerCflow tests ---------------
  208. public void testNewPerCflow() {
  209. AjAST ajast = createAjAST();
  210. PerCflow p = ajast.newPerCflow();
  211. assertNotNull("a new PerCflow should have been created", p);
  212. }
  213. /**
  214. * PerCflow's have a body property - test the getting and setting of this property
  215. */
  216. public void testGetAndSetBodyOfPerCflow() {
  217. AjAST ajast = createAjAST();
  218. PerCflow p = ajast.newPerCflow();
  219. assertNull("by default a PerCflow should have a null body", p.getBody());
  220. ReferencePointcut rp = ajast.newReferencePointcut();
  221. p.setBody(rp);
  222. assertEquals("the body of the PerCflow should now be a " + "ReferencePointcut", rp, p.getBody());
  223. }
  224. // -------------- PerObject tests ---------------
  225. public void testNewPerObject() {
  226. AjAST ajast = createAjAST();
  227. PerObject p = ajast.newPerObject();
  228. assertNotNull("a new PerObject should have been created", p);
  229. }
  230. /**
  231. * PerObject's have a body property - test the getting and setting of this property
  232. */
  233. public void testGetAndSetBodyOfPerObject() {
  234. AjAST ajast = createAjAST();
  235. PerObject p = ajast.newPerObject();
  236. assertNull("by default a PerObject should have a null body", p.getBody());
  237. ReferencePointcut rp = ajast.newReferencePointcut();
  238. p.setBody(rp);
  239. assertEquals("the body of the PerObject should now be a " + "ReferencePointcut", rp, p.getBody());
  240. }
  241. // -------------- PerTypeWithin tests ---------------
  242. public void testNewPerTypeWithin() {
  243. AjAST ajast = createAjAST();
  244. PerTypeWithin p = ajast.newPerTypeWithin();
  245. assertNotNull("a new PerTypeWithin should have been created", p);
  246. }
  247. // -------------- DefaultTypePattern tests ---------------
  248. public void testNewDefaultTypePattern() {
  249. AjAST ajast = createAjAST();
  250. DefaultTypePattern p = ajast.newDefaultTypePattern();
  251. assertNotNull("a new DefaultTypePattern should have been created", p);
  252. }
  253. public void testGetAndSetDetailInDefaultTypePattern() {
  254. AjAST ajast = createAjAST();
  255. DefaultTypePattern p = ajast.newDefaultTypePattern();
  256. assertEquals("The default detail should be the empty string", "", p.getDetail());
  257. p.setDetail("some detail");
  258. assertEquals("The detail should now be 'some detail'", "some detail", p.getDetail());
  259. }
  260. public void testPropertyDescriptorsForDefaultTypePattern() {
  261. AjAST ajast = createAjAST();
  262. // DefaultTypePattern d =
  263. ajast.newDefaultTypePattern();
  264. List props = DefaultTypePattern.propertyDescriptors(AST.JLS3);
  265. assertEquals("there should be no properties for the DefaultTypePattern", 0, props.size());
  266. }
  267. public void testCloneDefaultTypePattern() {
  268. AjAST ajast = createAjAST();
  269. DefaultTypePattern d = ajast.newDefaultTypePattern();
  270. d.setDetail("new detail");
  271. DefaultTypePattern copy = (DefaultTypePattern) ASTNode.copySubtree(ajast, d);
  272. assertEquals("the copy should have detail 'new detail'", "new detail", copy.getDetail());
  273. }
  274. // -------------- SignaturePattern tests ---------------
  275. public void testNewSignaturePattern() {
  276. AjAST ajast = createAjAST();
  277. SignaturePattern p = ajast.newSignaturePattern();
  278. assertNotNull("a new SignaturePattern should have been created", p);
  279. }
  280. public void testGetAndSetDetailInSignaturePattern() {
  281. AjAST ajast = createAjAST();
  282. SignaturePattern p = ajast.newSignaturePattern();
  283. assertEquals("The default detail should be the empty string", "", p.getDetail());
  284. p.setDetail("some detail");
  285. assertEquals("The detail should now be 'some detail'", "some detail", p.getDetail());
  286. }
  287. public void testPropertyDescriptorsForSignaturePattern() {
  288. AjAST ajast = createAjAST();
  289. // SignaturePattern p =
  290. ajast.newSignaturePattern();
  291. List props = SignaturePattern.propertyDescriptors(AST.JLS3);
  292. assertEquals("there should be no properties for the DefaultTypePattern", 0, props.size());
  293. }
  294. public void testCloneDefaultSignaturePattern() {
  295. AjAST ajast = createAjAST();
  296. SignaturePattern p = ajast.newSignaturePattern();
  297. p.setDetail("new detail");
  298. SignaturePattern copy = (SignaturePattern) ASTNode.copySubtree(ajast, p);
  299. assertEquals("the copy should have detail 'new detail'", "new detail", copy.getDetail());
  300. }
  301. // -------------- PointcutDeclaration tests ---------------
  302. public void testNewPointcutDeclaration() {
  303. AjAST ajast = createAjAST();
  304. PointcutDeclaration pd = ajast.newPointcutDeclaration();
  305. assertNotNull("a new PointcutDeclaration should have been created", pd);
  306. }
  307. /**
  308. * PointcutDeclarations's have a name property - test the getting and setting of this property
  309. */
  310. public void testGetAndSetPointcutName() {
  311. AjAST ajast = createAjAST();
  312. PointcutDeclaration pd = ajast.newPointcutDeclaration();
  313. assertEquals("the default pointcut name should be MISSING", "MISSING", pd.getName().getFullyQualifiedName());
  314. pd.setName(ajast.newSimpleName("p"));
  315. assertEquals("the pointcut name should now be set to 'p'", "p", pd.getName().getFullyQualifiedName());
  316. }
  317. /**
  318. * PointcutDeclarations's have a designator property - test the getting and setting of this property
  319. */
  320. public void testGetAndSetPointcutDesignator() {
  321. AjAST ajast = createAjAST();
  322. PointcutDeclaration pd = ajast.newPointcutDeclaration();
  323. assertNull("by default the pointcut designator is null", pd.getDesignator());
  324. ReferencePointcut rp = ajast.newReferencePointcut();
  325. pd.setDesignator(rp);
  326. assertEquals("should have set the pointcut designator to be " + "the ReferencePointcut", rp, pd.getDesignator());
  327. }
  328. public void testGetAndSetPointcutArguments() {
  329. AjAST ajast = createAjAST();
  330. PointcutDeclaration pd = ajast.newPointcutDeclaration();
  331. assertEquals("by default the number of arguments is zero", pd.parameters().size(), 0);
  332. List l = pd.parameters();
  333. assertEquals("there shouldn't be any arguments associated with" + "the pointcut yet", 0, l.size());
  334. SingleVariableDeclaration p1 = ajast.newSingleVariableDeclaration();
  335. l.add(p1);
  336. assertEquals("there should be one parameter associated with" + "the pointcut", 1, pd.parameters().size());
  337. assertEquals("there should be a SingleVariableDeclaration associated with" + "the pointcut", p1, pd.parameters().get(0));
  338. }
  339. public void testPropertyDescriptorsForPointcutDeclaration() {
  340. AjAST ajast = createAjAST();
  341. // PointcutDeclaration d =
  342. ajast.newPointcutDeclaration();
  343. List props = PointcutDeclaration.propertyDescriptors(AST.JLS3);
  344. boolean foundJavadoc = false;
  345. boolean foundModifiers = false;
  346. boolean foundName = false;
  347. boolean foundParamList = false;
  348. boolean foundDesignator = false;
  349. for (Iterator iter = props.iterator(); iter.hasNext();) {
  350. Object o = iter.next();
  351. if ((o instanceof ChildPropertyDescriptor)) {
  352. ChildPropertyDescriptor element = (ChildPropertyDescriptor) o;
  353. String id = element.getId();
  354. if (id.equals("javadoc")) {
  355. foundJavadoc = true;
  356. } else if (id.equals("designator")) {
  357. foundDesignator = true;
  358. } else if (id.equals("name")) {
  359. foundName = true;
  360. } else {
  361. fail("unknown PropertyDescriptor associated with PointcutDeclaration: " + element.getId());
  362. }
  363. } else if (o instanceof ChildListPropertyDescriptor) {
  364. ChildListPropertyDescriptor element = (ChildListPropertyDescriptor) o;
  365. if (element.getId().equals("parameters")) {
  366. foundParamList = true;
  367. } else if (element.getId().equals("modifiers")) {
  368. foundModifiers = true;
  369. }
  370. } else {
  371. fail("unknown PropertyDescriptor associated with PointcutDeclaration: " + o);
  372. }
  373. }
  374. assertTrue("PointcutDeclaration should have a javadoc PropertyDescriptor", foundJavadoc);
  375. assertTrue("PointcutDeclaration should have a designator PropertyDescriptor", foundDesignator);
  376. assertTrue("PointcutDeclaration should have an name PropertyDescriptor", foundName);
  377. assertTrue("PointcutDeclaration should have a parameters PropertyDescriptor", foundParamList);
  378. assertTrue("PointcutDeclaration should have a modifiers PropertyDescriptor", foundModifiers);
  379. }
  380. public void testClonePointcutDeclaration() {
  381. AjAST ajast = createAjAST();
  382. PointcutDeclaration d = ajast.newPointcutDeclaration();
  383. d.setName(ajast.newSimpleName("pointcut_name"));
  384. d.parameters().add(ajast.newSingleVariableDeclaration());
  385. PointcutDeclaration copy = (PointcutDeclaration) ASTNode.copySubtree(ajast, d);
  386. assertEquals("there should be one parameter associated with" + "the pointcut copy", 1, copy.parameters().size());
  387. assertEquals("the PointcutDeclaration clone should have the name ", "pointcut_name", copy.getName().toString());
  388. }
  389. public void testInternalPointcutDeclaration() {
  390. AjAST ajast = createAjAST();
  391. PointcutDeclaration d = ajast.newPointcutDeclaration();
  392. List props = PointcutDeclaration.propertyDescriptors(AST.JLS3);
  393. for (Iterator iter = props.iterator(); iter.hasNext();) {
  394. Object o = iter.next();
  395. if (o instanceof ChildPropertyDescriptor) {
  396. ChildPropertyDescriptor element = (ChildPropertyDescriptor) o;
  397. if (element.getId().equals("name")) {
  398. assertNotNull("PointcutDeclaration's " + element.getId() + " property"
  399. + " should not be null since it is lazily created", d.getStructuralProperty(element));
  400. } else {
  401. assertNull("PointcutDeclaration's " + element.getId() + " property"
  402. + " should be null since we haven't set it yet", d.getStructuralProperty(element));
  403. }
  404. } else if (o instanceof ChildListPropertyDescriptor) {
  405. ChildListPropertyDescriptor element = (ChildListPropertyDescriptor) o;
  406. assertNotNull("PointcutDeclaration's " + element.getId() + " property" + "should not be null since it is a list", d
  407. .getStructuralProperty(element));
  408. boolean isIExtendedModifier = element.getElementType().equals(IExtendedModifier.class);
  409. boolean isSingleVariable = element.getElementType().equals(SingleVariableDeclaration.class);
  410. assertTrue("should only be able to put SingleVariableDeclaration's"
  411. + " (which itself has node type IExtendedModifier) into the list", isIExtendedModifier || isSingleVariable);
  412. } else if (o instanceof SimplePropertyDescriptor) {
  413. SimplePropertyDescriptor element = (SimplePropertyDescriptor) o;
  414. assertNotNull(
  415. "PointcutDeclaration's " + element.getId() + " property" + "should not be null since it is a boolean", d
  416. .getStructuralProperty(element));
  417. } else {
  418. fail("unknown PropertyDescriptor associated with PointcutDeclaration: " + o);
  419. }
  420. }
  421. for (Iterator iter = props.iterator(); iter.hasNext();) {
  422. Object o = iter.next();
  423. if (o instanceof ChildPropertyDescriptor) {
  424. ChildPropertyDescriptor element = (ChildPropertyDescriptor) o;
  425. if (element.getId().equals("designator")) {
  426. ReferencePointcut rp = ajast.newReferencePointcut();
  427. d.setStructuralProperty(element, rp);
  428. assertEquals("PointcutDeclaration's designator property should" + " now be a ReferencePointcut", rp, d
  429. .getStructuralProperty(element));
  430. } else if (element.getId().equals("javadoc")) {
  431. // do nothing since makes no sense to have javadoc
  432. } else if (element.getId().equals("name")) {
  433. SimpleName sn = ajast.newSimpleName("p");
  434. d.setStructuralProperty(element, sn);
  435. assertEquals("PointcutDeclaration's name property should" + " now be a SimpleName", sn, d
  436. .getStructuralProperty(element));
  437. }
  438. }
  439. }
  440. }
  441. // -------------- AspectDeclaration tests ---------------
  442. public void testNewAspectDeclaration() {
  443. AjAST ajast = createAjAST();
  444. AspectDeclaration ad = ajast.newAspectDeclaration();
  445. assertNotNull("a new AspectDeclaration should have been created", ad);
  446. }
  447. public void testPropertyDescriptorsForAspectDeclaration() {
  448. AjAST ajast = createAjAST();
  449. // AspectDeclaration d =
  450. ajast.newAspectDeclaration();
  451. List props = AspectDeclaration.propertyDescriptors(AST.JLS3);
  452. boolean foundJavadoc = false;
  453. boolean foundPerClause = false;
  454. boolean foundIsPrivileged = false;
  455. boolean foundIsAspect = false;
  456. for (Iterator iter = props.iterator(); iter.hasNext();) {
  457. Object o = iter.next();
  458. if ((o instanceof ChildPropertyDescriptor)) {
  459. ChildPropertyDescriptor element = (ChildPropertyDescriptor) o;
  460. String id = element.getId();
  461. if (id.equals("javadoc")) {
  462. foundJavadoc = true;
  463. } else if (id.equals("perClause")) {
  464. foundPerClause = true;
  465. }
  466. } else if (o instanceof SimplePropertyDescriptor) {
  467. SimplePropertyDescriptor element = (SimplePropertyDescriptor) o;
  468. String id = element.getId();
  469. if (id.equals("privileged")) {
  470. foundIsPrivileged = true;
  471. } else if (id.equals("aspect")) {
  472. foundIsAspect = true;
  473. }
  474. }
  475. }
  476. assertTrue("AspectDeclaration should have a javadoc PropertyDescriptor", foundJavadoc);
  477. assertTrue("AspectDeclaration should have a perClause PropertyDescriptor", foundPerClause);
  478. assertTrue("AspectDeclaration should have a privileged PropertyDescriptor", foundIsPrivileged);
  479. assertTrue("AspectDeclaration should have inherited an aspect PropertyDescriptor", foundIsAspect);
  480. }
  481. public void testCloneAspectDeclaration() {
  482. AjAST ajast = createAjAST();
  483. AspectDeclaration d = ajast.newAspectDeclaration();
  484. d.setPerClause(ajast.newPerTypeWithin());
  485. d.setPrivileged(true);
  486. AspectDeclaration copy = (AspectDeclaration) ASTNode.copySubtree(ajast, d);
  487. assertNotNull("the AspectDeclaration clone should have a perClause set", copy.getPerClause());
  488. assertTrue("the AspectDeclaration clone should be a 'privileged'", copy.isPrivileged());
  489. }
  490. /**
  491. * AsepctDeclarations's have a perClause property - test the getting and setting of this property
  492. */
  493. public void testSetPerClauseInAspectDeclaration() {
  494. AjAST ajast = createAjAST();
  495. AspectDeclaration ad = ajast.newAspectDeclaration();
  496. assertNull("by default the perClause should be null", ad.getPerClause());
  497. PerCflow pcf = ajast.newPerCflow();
  498. ad.setPerClause(pcf);
  499. assertEquals("should have set the perClause to be a PerCflow", pcf, ad.getPerClause());
  500. }
  501. /**
  502. * AsepctDeclarations's have a isPrivileged property - test the getting and setting of this property
  503. */
  504. public void testSetPrivilegedInAspectDeclaration() {
  505. AjAST ajast = createAjAST();
  506. AspectDeclaration ad = ajast.newAspectDeclaration();
  507. assertFalse("by default the aspect should not be privileged", ad.isPrivileged());
  508. ad.setPrivileged(true);
  509. assertTrue("the aspect should now privileged", ad.isPrivileged());
  510. }
  511. // -------------- AfterAdviceDeclaration tests ---------------
  512. public void testNewAfterAdviceDeclaration() {
  513. AjAST ajast = createAjAST();
  514. AfterAdviceDeclaration ad = ajast.newAfterAdviceDeclaration();
  515. assertNotNull("a new AfterAdviceDeclaration should have been created", ad);
  516. }
  517. // -------------- BeforeAdviceDeclaration tests ---------------
  518. public void testNewBeforeAdviceDeclaration() {
  519. AjAST ajast = createAjAST();
  520. BeforeAdviceDeclaration bd = ajast.newBeforeAdviceDeclaration();
  521. assertNotNull("a new BeforeAdviceDeclaration should have been created", bd);
  522. }
  523. /**
  524. * AdviceDeclarations's have a pointcut property - test the getting and setting of this property
  525. */
  526. public void testGetAndSetPointcutInAdviceDeclaration() {
  527. AjAST ajast = createAjAST();
  528. BeforeAdviceDeclaration bd = ajast.newBeforeAdviceDeclaration();
  529. assertNull("by default there should be no pointcut associated with" + " the advice", bd.getPointcut());
  530. AndPointcut p = ajast.newAndPointcut();
  531. bd.setPointcut(p);
  532. assertEquals("there should now be an AndPointcut associated with" + " the advice", p, bd.getPointcut());
  533. }
  534. /**
  535. * AdviceDeclarations's have a body property - test the getting and setting of this property
  536. */
  537. public void testGetAndSetBodyInAdviceDeclaration() {
  538. AjAST ajast = createAjAST();
  539. BeforeAdviceDeclaration bd = ajast.newBeforeAdviceDeclaration();
  540. assertNull("by default there should be no body associated with" + " the advice", bd.getBody());
  541. Block b = ajast.newBlock();
  542. bd.setBody(b);
  543. assertEquals("there should now be a body associated with" + " the advice", b, bd.getBody());
  544. }
  545. // -------------- AfterReturningAdviceDeclaration tests ---------------
  546. public void testNewAfterReturningAdviceDeclaration() {
  547. AjAST ajast = createAjAST();
  548. AfterReturningAdviceDeclaration d = ajast.newAfterReturningAdviceDeclaration();
  549. assertNotNull("should have created an AfterReturningAdviceDeclaration", d);
  550. }
  551. /**
  552. * AfterReturningAdviceDeclarations's have a returning property - test the getting and setting of this property
  553. */
  554. public void testGetAndSetReturning() {
  555. AjAST ajast = createAjAST();
  556. AfterReturningAdviceDeclaration d = ajast.newAfterReturningAdviceDeclaration();
  557. assertNull("by default there should be no returning property associated with" + " the AfterReturningAdviceDeclaration", d
  558. .getReturning());
  559. SingleVariableDeclaration s = ajast.newSingleVariableDeclaration();
  560. d.setReturning(s);
  561. assertEquals("there should now be a returning property associated with" + " the AfterReturningAdviceDeclaration", s, d
  562. .getReturning());
  563. }
  564. // -------------- AfterThrowingAdviceDeclaration tests ---------------
  565. public void testNewAfterThrowingAdviceDeclaration() {
  566. AjAST ajast = createAjAST();
  567. AfterThrowingAdviceDeclaration d = ajast.newAfterThrowingAdviceDeclaration();
  568. assertNotNull("should have created an AfterThrowingAdviceDeclaration", d);
  569. }
  570. /**
  571. * AfterThrowingAdviceDeclaration's have a throwing property - test the getting and setting of this property
  572. */
  573. public void testGetAndSetThrowing() {
  574. AjAST ajast = createAjAST();
  575. AfterThrowingAdviceDeclaration d = ajast.newAfterThrowingAdviceDeclaration();
  576. assertNull("by default there should be no throwing property associated with" + " the AfterThrowingAdviceDeclaration", d
  577. .getThrowing());
  578. SingleVariableDeclaration s = ajast.newSingleVariableDeclaration();
  579. d.setThrowing(s);
  580. assertEquals("there should now be a throwing property associated with" + " the AfterThrowingAdviceDeclaration", s, d
  581. .getThrowing());
  582. }
  583. // -------------- AroundAdviceDeclaration tests ---------------
  584. public void testNewAroundAdviceDeclaration() {
  585. AjAST ajast = createAjAST();
  586. AroundAdviceDeclaration d = ajast.newAroundAdviceDeclaration();
  587. assertNotNull("should have created an AroundAdviceDeclaration", d);
  588. }
  589. /**
  590. * AroundAdviceDeclaration's have a return type property - test the getting and setting of this property (different
  591. * implementation for JLS2 and JLS3)
  592. */
  593. public void testGetAndSetReturnTypeJLS2() {
  594. AjAST ajast = createAjAST(AST.JLS2);
  595. AroundAdviceDeclaration d = ajast.newAroundAdviceDeclaration();
  596. Type t = d.getReturnType();
  597. assertTrue("by default the return type associated with the" + " AroundAdviceDeclaration should be a PrimitiveType",
  598. t instanceof PrimitiveType);
  599. assertEquals("by default there should be the PrimitiveType.VOID return "
  600. + "type associated with the AroundAdviceDeclaration", PrimitiveType.VOID.toString(), ((PrimitiveType) t).toString());
  601. SimpleType s = ajast.newSimpleType(ajast.newSimpleName("name"));
  602. d.setReturnType(s);
  603. assertEquals("there should now be a SimpleType return type associated with" + " the AroundAdviceDeclaration", s, d
  604. .getReturnType());
  605. }
  606. /**
  607. * AroundAdviceDeclaration's have a return type property - test the getting and setting of this property (different
  608. * implementation for JLS2 and JLS3)
  609. */
  610. public void testGetAndSetReturnTypeJLS3() {
  611. AjAST ajast = createAjAST();
  612. AroundAdviceDeclaration d = ajast.newAroundAdviceDeclaration();
  613. Type t = d.getReturnType2();
  614. assertTrue("by default the return type associated with the" + " AroundAdviceDeclaration should be a PrimitiveType",
  615. t instanceof PrimitiveType);
  616. assertEquals("by default there should be the PrimitiveType.VOID return "
  617. + "type associated with the AroundAdviceDeclaration", PrimitiveType.VOID.toString(), ((PrimitiveType) t).toString());
  618. SimpleType s = ajast.newSimpleType(ajast.newSimpleName("name"));
  619. d.setReturnType2(s);
  620. assertEquals("there should now be a SimpleType return type associated with" + " the AroundAdviceDeclaration", s, d
  621. .getReturnType2());
  622. }
  623. // -------------- InterTypeFieldDeclaration tests ---------------
  624. public void testNewITDFieldDeclaration() {
  625. AjAST ajast = createAjAST();
  626. InterTypeFieldDeclaration d = ajast.newInterTypeFieldDeclaration();
  627. assertNotNull("should have created an InterTypeFieldDeclaration", d);
  628. }
  629. // -------------- InterTypeMethodDeclaration tests ---------------
  630. public void testNewITDMethodDeclaration() {
  631. AjAST ajast = createAjAST();
  632. InterTypeMethodDeclaration d = ajast.newInterTypeMethodDeclaration();
  633. assertNotNull("should have created an InterTypeMethodDeclaration", d);
  634. }
  635. // -------------- AjTypeDeclaration tests ---------------
  636. public void testNewAjTypeDeclaration() {
  637. AjAST ajast = createAjAST();
  638. AjTypeDeclaration d = ajast.newAjTypeDeclaration();
  639. assertNotNull("should have created an AjTypeDeclaration", d);
  640. }
  641. /**
  642. * AjTypeDeclaration's have an isAspect property - test the getting and setting of this property
  643. */
  644. public void testGetAndSetIsAspect() {
  645. AjAST ajast = createAjAST();
  646. AjTypeDeclaration d = ajast.newAjTypeDeclaration();
  647. assertFalse("by default an AjTypeDeclaration should be a class", d.isAspect());
  648. d.setAspect(true);
  649. assertTrue("AjTypeDeclaration should now be an aspect", d.isAspect());
  650. d.setAspect(false);
  651. assertFalse("AjTypeDeclaration should now be a class", d.isAspect());
  652. }
  653. public void testPropertyDescriptorsForAjTypeDeclaration() {
  654. AjAST ajast = createAjAST();
  655. // AjTypeDeclaration d =
  656. ajast.newAjTypeDeclaration();
  657. List props = AjTypeDeclaration.propertyDescriptors(AST.JLS3);
  658. boolean foundAspect = false;
  659. for (Iterator iter = props.iterator(); iter.hasNext();) {
  660. Object o = iter.next();
  661. if (o instanceof SimplePropertyDescriptor) {
  662. SimplePropertyDescriptor element = (SimplePropertyDescriptor) o;
  663. String id = element.getId();
  664. if (id.equals("aspect")) {
  665. foundAspect = true;
  666. }
  667. }
  668. }
  669. assertTrue("AjTypeDeclaration should have an aspect PropertyDescriptor", foundAspect);
  670. }
  671. public void testCloneAjTypeDeclaration() {
  672. AjAST ajast = createAjAST();
  673. AjTypeDeclaration d = ajast.newAjTypeDeclaration();
  674. d.setAspect(true);
  675. AjTypeDeclaration copy = (AjTypeDeclaration) ASTNode.copySubtree(ajast, d);
  676. assertTrue("the AjTypeDeclaration clone should be an aspect", copy.isAspect());
  677. }
  678. // test for bug 125809 - make sure the property descriptors
  679. // associated with the AspectDeclaration aren't consequently
  680. // associated with the AjTypeDeclaration
  681. public void testPropertyDescriptorsForAjTypeDeclaration2() {
  682. AjAST ajast = createAjAST();
  683. // AspectDeclaration ad =
  684. ajast.newAspectDeclaration();
  685. // List aspectProps = AspectDeclaration.propertyDescriptors(AST.JLS3);
  686. // AjTypeDeclaration d =
  687. ajast.newAjTypeDeclaration();
  688. List props = AjTypeDeclaration.propertyDescriptors(AST.JLS3);
  689. boolean foundPrivileged = false;
  690. boolean foundPerClause = false;
  691. // boolean foundAspect = false;
  692. for (Iterator iter = props.iterator(); iter.hasNext();) {
  693. Object o = iter.next();
  694. if (o instanceof SimplePropertyDescriptor) {
  695. SimplePropertyDescriptor element = (SimplePropertyDescriptor) o;
  696. String id = element.getId();
  697. if (id.equals("privileged")) {
  698. foundPrivileged = true;
  699. }
  700. } else if (o instanceof ChildPropertyDescriptor) {
  701. ChildPropertyDescriptor element = (ChildPropertyDescriptor) o;
  702. if (element.getId().equals("perClause")) {
  703. foundPerClause = true;
  704. }
  705. }
  706. }
  707. assertFalse("AjTypeDeclaration should not have a privileged PropertyDescriptor", foundPrivileged);
  708. assertFalse("AjTypeDeclaration should not have a perClause PropertyDescriptor", foundPerClause);
  709. }
  710. // test for bug 125809 - make sure the property descriptors
  711. // associated with the AjTypeDeclaration aren't consequently
  712. // associated with the TypeDeclaration
  713. public void testPropertyDescriptorsForAjTypeDeclaration3() {
  714. AjAST ajast = createAjAST();
  715. // AjTypeDeclaration d =
  716. ajast.newAjTypeDeclaration();
  717. // List ajProps =
  718. AjTypeDeclaration.propertyDescriptors(AST.JLS3);
  719. // TypeDeclaration td =
  720. ajast.newTypeDeclaration();
  721. List props = TypeDeclaration.propertyDescriptors(AST.JLS3);
  722. boolean foundAspect = false;
  723. for (Iterator iter = props.iterator(); iter.hasNext();) {
  724. Object o = iter.next();
  725. if (o instanceof SimplePropertyDescriptor) {
  726. SimplePropertyDescriptor element = (SimplePropertyDescriptor) o;
  727. String id = element.getId();
  728. if (id.equals("aspect")) {
  729. foundAspect = true;
  730. }
  731. }
  732. }
  733. assertFalse("TypeDeclaration should not have an aspect PropertyDescriptor", foundAspect);
  734. }
  735. // -------------- DeclareAtFieldDeclaration tests ---------------
  736. public void testNewDeclareAtFieldDeclaration() {
  737. AjAST ajast = createAjAST();
  738. DeclareAtFieldDeclaration d = ajast.newDeclareAtFieldDeclaration();
  739. assertNotNull("should have created a DeclareAtFieldDeclaration", d);
  740. }
  741. public void testPropertyDescriptorsForDeclareAtField() {
  742. AjAST ajast = createAjAST();
  743. // DeclareAtFieldDeclaration d =
  744. ajast.newDeclareAtFieldDeclaration();
  745. List props = DeclareAtFieldDeclaration.propertyDescriptors(AST.JLS3);
  746. boolean foundJavadoc = false;
  747. boolean foundPattern = false;
  748. boolean foundAnnotationName = false;
  749. for (Iterator iter = props.iterator(); iter.hasNext();) {
  750. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  751. String id = element.getId();
  752. if (id.equals("javadoc")) {
  753. foundJavadoc = true;
  754. } else if (id.equals("pattern")) {
  755. foundPattern = true;
  756. } else if (id.equals("annotationName")) {
  757. foundAnnotationName = true;
  758. } else {
  759. fail("unknown PropertyDescriptor associated with DeclareAtFieldDeclaration: " + element.getId());
  760. }
  761. }
  762. assertTrue("DeclareAtFieldDeclaration should have a javadoc PropertyDescriptor", foundJavadoc);
  763. assertTrue("DeclareAtFieldDeclaration should have a attern PropertyDescriptor", foundPattern);
  764. assertTrue("DeclareAtFieldDeclaration should have a annotationName PropertyDescriptor", foundAnnotationName);
  765. }
  766. public void testGetAndSetPatternNodeInDeclareAtField() {
  767. AjAST ajast = createAjAST();
  768. DeclareAtFieldDeclaration d = ajast.newDeclareAtFieldDeclaration();
  769. assertNull("by default there should be no typePattern associated with" + " the declare @field annotation", d
  770. .getPatternNode());
  771. SignaturePattern p = ajast.newSignaturePattern();
  772. d.setPatternNode(p);
  773. assertEquals("there should now be a DefaultTypePattern associated with" + " the declare @field annotation", p, d
  774. .getPatternNode());
  775. }
  776. public void testGetAndSetAnnNameInDeclareAtField() {
  777. AjAST ajast = createAjAST();
  778. DeclareAtFieldDeclaration d = ajast.newDeclareAtFieldDeclaration();
  779. assertEquals("the default annotation name should be MISSING", "MISSING", d.getAnnotationName().getFullyQualifiedName());
  780. d.setAnnotationName(ajast.newSimpleName("MyAnnotation"));
  781. assertEquals("the annotation name should now be set to 'MyAnnotation'", "MyAnnotation", d.getAnnotationName()
  782. .getFullyQualifiedName());
  783. }
  784. public void testCloneDeclareAtField() {
  785. AjAST ajast = createAjAST();
  786. DeclareAtFieldDeclaration d = ajast.newDeclareAtFieldDeclaration();
  787. d.setPatternNode(ajast.newSignaturePattern());
  788. d.setAnnotationName(ajast.newSimpleName("MyAnnotation"));
  789. DeclareAtFieldDeclaration copy = (DeclareAtFieldDeclaration) ASTNode.copySubtree(ajast, d);
  790. assertNotNull("the DeclareAtFieldDeclaration clone should have a TypePattern set", copy.getPatternNode());
  791. assertNotNull("the DeclareAtFieldDeclaration clone should have a Annotation name set", copy.getAnnotationName());
  792. }
  793. public void testInternalDeclareAtField() {
  794. AjAST ajast = createAjAST();
  795. DeclareAtFieldDeclaration d = ajast.newDeclareAtFieldDeclaration();
  796. List props = DeclareAtFieldDeclaration.propertyDescriptors(AST.JLS3);
  797. for (Iterator iter = props.iterator(); iter.hasNext();) {
  798. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  799. if (element.getId().equals("annotationName")) {
  800. assertNotNull("DeclareAtFieldDeclaration's " + element.getId() + " property"
  801. + " should not be null since it is lazily created", d.getStructuralProperty(element));
  802. } else {
  803. assertNull("DeclareAtFieldDeclaration's " + element.getId() + " property"
  804. + " should be null since we haven't set it yet", d.getStructuralProperty(element));
  805. }
  806. }
  807. for (Iterator iter = props.iterator(); iter.hasNext();) {
  808. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  809. if (element.getId().equals("pattern")) {
  810. SignaturePattern p = ajast.newSignaturePattern();
  811. d.setStructuralProperty(element, p);
  812. assertEquals("DeclareAtFieldDeclaration's pattern property should" + " now be a SignaturePattern", p, d
  813. .getStructuralProperty(element));
  814. } else if (element.getId().equals("annotationName")) {
  815. SimpleName s = ajast.newSimpleName("MyAnnotation");
  816. d.setStructuralProperty(element, s);
  817. assertEquals("DeclareAtFieldDeclaration's annotationName property should" + " now be a SimpleName", s, d
  818. .getStructuralProperty(element));
  819. } else if (element.getId().equals("javadoc")) {
  820. // do nothing since makes no sense to have javadoc
  821. } else {
  822. fail("unknown property for DeclareAtFieldDeclaration");
  823. }
  824. }
  825. }
  826. // -------------- DeclareAtMethodDeclaration tests ---------------
  827. public void testNewDeclareAtMethodDeclaration() {
  828. AjAST ajast = createAjAST();
  829. DeclareAtMethodDeclaration d = ajast.newDeclareAtMethodDeclaration();
  830. assertNotNull("should have created a DeclareAtMethodDeclaration", d);
  831. }
  832. public void testPropertyDescriptorsForDeclareAtMethod() {
  833. AjAST ajast = createAjAST();
  834. // DeclareAtMethodDeclaration d =
  835. ajast.newDeclareAtMethodDeclaration();
  836. List props = DeclareAtMethodDeclaration.propertyDescriptors(AST.JLS3);
  837. boolean foundJavadoc = false;
  838. boolean foundPattern = false;
  839. boolean foundAnnotationName = false;
  840. for (Iterator iter = props.iterator(); iter.hasNext();) {
  841. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  842. String id = element.getId();
  843. if (id.equals("javadoc")) {
  844. foundJavadoc = true;
  845. } else if (id.equals("pattern")) {
  846. foundPattern = true;
  847. } else if (id.equals("annotationName")) {
  848. foundAnnotationName = true;
  849. } else {
  850. fail("unknown PropertyDescriptor associated with DeclareAtMethodDeclaration: " + element.getId());
  851. }
  852. }
  853. assertTrue("DeclareAtMethodDeclaration should have a javadoc PropertyDescriptor", foundJavadoc);
  854. assertTrue("DeclareAtMethodDeclaration should have a attern PropertyDescriptor", foundPattern);
  855. assertTrue("DeclareAtMethodDeclaration should have a annotationName PropertyDescriptor", foundAnnotationName);
  856. }
  857. public void testGetAndSetPatternNodeInDeclareAtMethod() {
  858. AjAST ajast = createAjAST();
  859. DeclareAtMethodDeclaration d = ajast.newDeclareAtMethodDeclaration();
  860. assertNull("by default there should be no typePattern associated with" + " the declare @method annotation", d
  861. .getPatternNode());
  862. SignaturePattern p = ajast.newSignaturePattern();
  863. d.setPatternNode(p);
  864. assertEquals("there should now be a DefaultTypePattern associated with" + " the declare @method annotation", p, d
  865. .getPatternNode());
  866. }
  867. public void testGetAndSetAnnNameInDeclareAtMethod() {
  868. AjAST ajast = createAjAST();
  869. DeclareAtMethodDeclaration d = ajast.newDeclareAtMethodDeclaration();
  870. assertEquals("the default annotation name should be MISSING", "MISSING", d.getAnnotationName().getFullyQualifiedName());
  871. d.setAnnotationName(ajast.newSimpleName("MyAnnotation"));
  872. assertEquals("the annotation name should now be set to 'MyAnnotation'", "MyAnnotation", d.getAnnotationName()
  873. .getFullyQualifiedName());
  874. }
  875. public void testCloneDeclareAtMethod() {
  876. AjAST ajast = createAjAST();
  877. DeclareAtMethodDeclaration d = ajast.newDeclareAtMethodDeclaration();
  878. d.setPatternNode(ajast.newSignaturePattern());
  879. d.setAnnotationName(ajast.newSimpleName("MyAnnotation"));
  880. DeclareAtMethodDeclaration copy = (DeclareAtMethodDeclaration) ASTNode.copySubtree(ajast, d);
  881. assertNotNull("the DeclareAtMethodDeclaration clone should have a TypePattern set", copy.getPatternNode());
  882. assertNotNull("the DeclareAtMethodDeclaration clone should have a Annotation name set", copy.getAnnotationName());
  883. }
  884. public void testInternalDeclareAtMethod() {
  885. AjAST ajast = createAjAST();
  886. DeclareAtMethodDeclaration d = ajast.newDeclareAtMethodDeclaration();
  887. List props = DeclareAtMethodDeclaration.propertyDescriptors(AST.JLS3);
  888. for (Iterator iter = props.iterator(); iter.hasNext();) {
  889. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  890. if (element.getId().equals("annotationName")) {
  891. assertNotNull("DeclareAtMethodDeclaration's " + element.getId() + " property"
  892. + " should not be null since it is lazily created", d.getStructuralProperty(element));
  893. } else {
  894. assertNull("DeclareAtMethodDeclaration's " + element.getId() + " property"
  895. + " should be null since we haven't set it yet", d.getStructuralProperty(element));
  896. }
  897. }
  898. for (Iterator iter = props.iterator(); iter.hasNext();) {
  899. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  900. if (element.getId().equals("pattern")) {
  901. SignaturePattern p = ajast.newSignaturePattern();
  902. d.setStructuralProperty(element, p);
  903. assertEquals("DeclareAtMethodDeclaration's pattern property should" + " now be a SignaturePattern", p, d
  904. .getStructuralProperty(element));
  905. } else if (element.getId().equals("annotationName")) {
  906. SimpleName s = ajast.newSimpleName("MyAnnotation");
  907. d.setStructuralProperty(element, s);
  908. assertEquals("DeclareAtMethodDeclaration's annotationName property should" + " now be a SimpleName", s, d
  909. .getStructuralProperty(element));
  910. } else if (element.getId().equals("javadoc")) {
  911. // do nothing since makes no sense to have javadoc
  912. } else {
  913. fail("unknown property for DeclareAtMethodDeclaration");
  914. }
  915. }
  916. }
  917. // -------------- DeclareAtConstructorDeclaration tests ---------------
  918. public void testNewDeclareAtConstructorDeclaration() {
  919. AjAST ajast = createAjAST();
  920. DeclareAtConstructorDeclaration d = ajast.newDeclareAtConstructorDeclaration();
  921. assertNotNull("should have created a DeclareAtConstructorDeclaration", d);
  922. }
  923. public void testPropertyDescriptorsForDeclareAtConstructor() {
  924. AjAST ajast = createAjAST();
  925. // DeclareAtConstructorDeclaration d =
  926. ajast.newDeclareAtConstructorDeclaration();
  927. List props = DeclareAtConstructorDeclaration.propertyDescriptors(AST.JLS3);
  928. boolean foundJavadoc = false;
  929. boolean foundPattern = false;
  930. boolean foundAnnotationName = false;
  931. for (Iterator iter = props.iterator(); iter.hasNext();) {
  932. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  933. String id = element.getId();
  934. if (id.equals("javadoc")) {
  935. foundJavadoc = true;
  936. } else if (id.equals("pattern")) {
  937. foundPattern = true;
  938. } else if (id.equals("annotationName")) {
  939. foundAnnotationName = true;
  940. } else {
  941. fail("unknown PropertyDescriptor associated with DeclareAtConstructorDeclaration: " + element.getId());
  942. }
  943. }
  944. assertTrue("DeclareAtConstructorDeclaration should have a javadoc PropertyDescriptor", foundJavadoc);
  945. assertTrue("DeclareAtConstructorDeclaration should have a attern PropertyDescriptor", foundPattern);
  946. assertTrue("DeclareAtConstructorDeclaration should have a annotationName PropertyDescriptor", foundAnnotationName);
  947. }
  948. public void testGetAndSetPatternNodeInDeclareAtConstructor() {
  949. AjAST ajast = createAjAST();
  950. DeclareAtConstructorDeclaration d = ajast.newDeclareAtConstructorDeclaration();
  951. assertNull("by default there should be no typePattern associated with" + " the declare @constructor annotation", d
  952. .getPatternNode());
  953. SignaturePattern p = ajast.newSignaturePattern();
  954. d.setPatternNode(p);
  955. assertEquals("there should now be a DefaultTypePattern associated with" + " the declare @constructor annotation", p, d
  956. .getPatternNode());
  957. }
  958. public void testGetAndSetAnnNameInDeclareAtConstructor() {
  959. AjAST ajast = createAjAST();
  960. DeclareAtConstructorDeclaration d = ajast.newDeclareAtConstructorDeclaration();
  961. assertEquals("the default annotation name should be MISSING", "MISSING", d.getAnnotationName().getFullyQualifiedName());
  962. d.setAnnotationName(ajast.newSimpleName("MyAnnotation"));
  963. assertEquals("the annotation name should now be set to 'MyAnnotation'", "MyAnnotation", d.getAnnotationName()
  964. .getFullyQualifiedName());
  965. }
  966. public void testCloneDeclareAtConstructor() {
  967. AjAST ajast = createAjAST();
  968. DeclareAtConstructorDeclaration d = ajast.newDeclareAtConstructorDeclaration();
  969. d.setPatternNode(ajast.newSignaturePattern());
  970. d.setAnnotationName(ajast.newSimpleName("MyAnnotation"));
  971. DeclareAtConstructorDeclaration copy = (DeclareAtConstructorDeclaration) ASTNode.copySubtree(ajast, d);
  972. assertNotNull("the DeclareAtConstructorDeclaration clone should have a SignaturePattern set", copy.getPatternNode());
  973. assertNotNull("the DeclareAtConstructorDeclaration clone should have a Annotation name set", copy.getAnnotationName());
  974. }
  975. public void testInternalDeclareAtConstructor() {
  976. AjAST ajast = createAjAST();
  977. DeclareAtConstructorDeclaration d = ajast.newDeclareAtConstructorDeclaration();
  978. List props = DeclareAtConstructorDeclaration.propertyDescriptors(AST.JLS3);
  979. for (Iterator iter = props.iterator(); iter.hasNext();) {
  980. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  981. if (element.getId().equals("annotationName")) {
  982. assertNotNull("DeclareAtConstructorDeclaration's " + element.getId() + " property"
  983. + " should not be null since it is lazily created", d.getStructuralProperty(element));
  984. } else {
  985. assertNull("DeclareAtConstructorDeclaration's " + element.getId() + " property"
  986. + " should be null since we haven't set it yet", d.getStructuralProperty(element));
  987. }
  988. }
  989. for (Iterator iter = props.iterator(); iter.hasNext();) {
  990. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  991. if (element.getId().equals("pattern")) {
  992. SignaturePattern p = ajast.newSignaturePattern();
  993. d.setStructuralProperty(element, p);
  994. assertEquals("DeclareAtConstructorDeclaration's pattern property should" + " now be a SignaturePattern", p, d
  995. .getStructuralProperty(element));
  996. } else if (element.getId().equals("annotationName")) {
  997. SimpleName s = ajast.newSimpleName("MyAnnotation");
  998. d.setStructuralProperty(element, s);
  999. assertEquals("DeclareAtConstructorDeclaration's annotationName property should" + " now be a SimpleName", s, d
  1000. .getStructuralProperty(element));
  1001. } else if (element.getId().equals("javadoc")) {
  1002. // do nothing since makes no sense to have javadoc
  1003. } else {
  1004. fail("unknown property for DeclareAtConstructorDeclaration");
  1005. }
  1006. }
  1007. }
  1008. // -------------- DeclareAtTypeDeclaration tests ---------------
  1009. public void testNewDeclareAtTypeDeclaration() {
  1010. AjAST ajast = createAjAST();
  1011. DeclareAtTypeDeclaration d = ajast.newDeclareAtTypeDeclaration();
  1012. assertNotNull("should have created a DeclareAtTypeDeclaration", d);
  1013. }
  1014. public void testPropertyDescriptorsForDeclareAtType() {
  1015. AjAST ajast = createAjAST();
  1016. // DeclareAtTypeDeclaration d =
  1017. ajast.newDeclareAtTypeDeclaration();
  1018. List props = DeclareAtTypeDeclaration.propertyDescriptors(AST.JLS3);
  1019. boolean foundJavadoc = false;
  1020. boolean foundPattern = false;
  1021. boolean foundAnnotationName = false;
  1022. for (Iterator iter = props.iterator(); iter.hasNext();) {
  1023. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  1024. String id = element.getId();
  1025. if (id.equals("javadoc")) {
  1026. foundJavadoc = true;
  1027. } else if (id.equals("pattern")) {
  1028. foundPattern = true;
  1029. } else if (id.equals("annotationName")) {
  1030. foundAnnotationName = true;
  1031. } else {
  1032. fail("unknown PropertyDescriptor associated with DeclareAtTypeDeclaration: " + element.getId());
  1033. }
  1034. }
  1035. assertTrue("DeclareAtTypeDeclaration should have a javadoc PropertyDescriptor", foundJavadoc);
  1036. assertTrue("DeclareAtTypeDeclaration should have a attern PropertyDescriptor", foundPattern);
  1037. assertTrue("DeclareAtTypeDeclaration should have a annotationName PropertyDescriptor", foundAnnotationName);
  1038. }
  1039. public void testGetAndSetPatternNodeInDeclareAtType() {
  1040. AjAST ajast = createAjAST();
  1041. DeclareAtTypeDeclaration d = ajast.newDeclareAtTypeDeclaration();
  1042. assertNull("by default there should be no typePattern associated with" + " the declare @type annotation", d
  1043. .getPatternNode());
  1044. DefaultTypePattern dtp = ajast.newDefaultTypePattern();
  1045. d.setPatternNode(dtp);
  1046. assertEquals("there should now be a DefaultTypePattern associated with" + " the declare @type annotation", dtp, d
  1047. .getPatternNode());
  1048. }
  1049. public void testGetAndSetAnnNameInDeclareAtType() {
  1050. AjAST ajast = createAjAST();
  1051. DeclareAtTypeDeclaration d = ajast.newDeclareAtTypeDeclaration();
  1052. assertEquals("the default annotation name should be MISSING", "MISSING", d.getAnnotationName().getFullyQualifiedName());
  1053. d.setAnnotationName(ajast.newSimpleName("MyAnnotation"));
  1054. assertEquals("the annotation name should now be set to 'MyAnnotation'", "MyAnnotation", d.getAnnotationName()
  1055. .getFullyQualifiedName());
  1056. }
  1057. public void testCloneDeclareAtType() {
  1058. AjAST ajast = createAjAST();
  1059. DeclareAtTypeDeclaration d = ajast.newDeclareAtTypeDeclaration();
  1060. d.setPatternNode(ajast.newDefaultTypePattern());
  1061. d.setAnnotationName(ajast.newSimpleName("MyAnnotation"));
  1062. DeclareAtTypeDeclaration copy = (DeclareAtTypeDeclaration) ASTNode.copySubtree(ajast, d);
  1063. assertNotNull("the DeclareAtTypeDeclaration clone should have a TypePattern set", copy.getPatternNode());
  1064. assertNotNull("the DeclareAtTypeDeclaration clone should have a Annotation name set", copy.getAnnotationName());
  1065. }
  1066. public void testInternalDeclareAtType() {
  1067. AjAST ajast = createAjAST();
  1068. DeclareAtTypeDeclaration d = ajast.newDeclareAtTypeDeclaration();
  1069. List props = DeclareAtTypeDeclaration.propertyDescriptors(AST.JLS3);
  1070. for (Iterator iter = props.iterator(); iter.hasNext();) {
  1071. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  1072. if (element.getId().equals("annotationName")) {
  1073. assertNotNull("DeclareAtTypeDeclaration's " + element.getId() + " property"
  1074. + " should not be null since it is lazily created", d.getStructuralProperty(element));
  1075. } else {
  1076. assertNull("DeclareAtTypeDeclaration's " + element.getId() + " property"
  1077. + " should be null since we haven't set it yet", d.getStructuralProperty(element));
  1078. }
  1079. }
  1080. for (Iterator iter = props.iterator(); iter.hasNext();) {
  1081. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  1082. if (element.getId().equals("pattern")) {
  1083. DefaultTypePattern p = ajast.newDefaultTypePattern();
  1084. d.setStructuralProperty(element, p);
  1085. assertEquals("DeclareAtTypeDeclaration's pattern property should" + " now be a DefaultTypePattern", p, d
  1086. .getStructuralProperty(element));
  1087. } else if (element.getId().equals("annotationName")) {
  1088. SimpleName s = ajast.newSimpleName("MyAnnotation");
  1089. d.setStructuralProperty(element, s);
  1090. assertEquals("DeclareAtTypeDeclaration's annotationName property should" + " now be a SimpleName", s, d
  1091. .getStructuralProperty(element));
  1092. } else if (element.getId().equals("javadoc")) {
  1093. // do nothing since makes no sense to have javadoc
  1094. } else {
  1095. fail("unknown property for DeclareAtTypeDeclaration");
  1096. }
  1097. }
  1098. }
  1099. // -------------- DeclareErrorDeclaration tests ---------------
  1100. public void testNewDeclareErrorDeclaration() {
  1101. AjAST ajast = createAjAST();
  1102. DeclareErrorDeclaration d = ajast.newDeclareErrorDeclaration();
  1103. assertNotNull("should have created a DeclareErrorDeclaration", d);
  1104. }
  1105. public void testPropertyDescriptorsForDeclareErrorDeclaration() {
  1106. AjAST ajast = createAjAST();
  1107. // DeclareErrorDeclaration d =
  1108. ajast.newDeclareErrorDeclaration();
  1109. List props = DeclareErrorDeclaration.propertyDescriptors(AST.JLS3);
  1110. boolean foundJavadoc = false;
  1111. boolean foundPointcut = false;
  1112. boolean foundMessage = false;
  1113. for (Iterator iter = props.iterator(); iter.hasNext();) {
  1114. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  1115. String id = element.getId();
  1116. if (id.equals("javadoc")) {
  1117. foundJavadoc = true;
  1118. } else if (id.equals("pointcut")) {
  1119. foundPointcut = true;
  1120. } else if (id.equals("message")) {
  1121. foundMessage = true;
  1122. } else {
  1123. fail("unknown PropertyDescriptor associated with DeclareErrorDeclaration");
  1124. }
  1125. }
  1126. assertTrue("DeclareErrorDeclaration should have a javadoc PropertyDescriptor", foundJavadoc);
  1127. assertTrue("DeclareErrorDeclaration should have a pointcut PropertyDescriptor", foundPointcut);
  1128. assertTrue("DeclareErrorDeclaration should have a message PropertyDescriptor", foundMessage);
  1129. }
  1130. public void testGetAndSetPointcutInErrorDeclaration() {
  1131. AjAST ajast = createAjAST();
  1132. DeclareErrorDeclaration d = ajast.newDeclareErrorDeclaration();
  1133. assertNull("by default there should be no pointcut associated with" + " the declare error", d.getPointcut());
  1134. AndPointcut p = ajast.newAndPointcut();
  1135. d.setPointcut(p);
  1136. assertEquals("there should now be an AndPointcut associated with" + " the declare error", p, d.getPointcut());
  1137. }
  1138. public void testGetAndSetMessageInErrorDeclaration() {
  1139. AjAST ajast = createAjAST();
  1140. DeclareErrorDeclaration d = ajast.newDeclareErrorDeclaration();
  1141. assertNull("by default there should be no message associated with" + " the declare error", d.getMessage());
  1142. StringLiteral s = ajast.newStringLiteral();
  1143. d.setMessage(s);
  1144. assertEquals("there should now be a StringLiteral message associated with" + " the declare error", s, d.getMessage());
  1145. }
  1146. public void testCloneDeclareErrorDeclaration() {
  1147. AjAST ajast = createAjAST();
  1148. DeclareErrorDeclaration d = ajast.newDeclareErrorDeclaration();
  1149. d.setPointcut(ajast.newAndPointcut());
  1150. d.setMessage(ajast.newStringLiteral());
  1151. DeclareErrorDeclaration copy = (DeclareErrorDeclaration) ASTNode.copySubtree(ajast, d);
  1152. assertNotNull("the DeclareErrorDeclaration clone should have a pointcut set", copy.getPointcut());
  1153. assertNotNull("the DeclareErrorDeclaration clone should have a message set", copy.getMessage());
  1154. }
  1155. public void testInternalDeclareErrorDeclaration() {
  1156. AjAST ajast = createAjAST();
  1157. DeclareErrorDeclaration d = ajast.newDeclareErrorDeclaration();
  1158. List props = DeclareErrorDeclaration.propertyDescriptors(AST.JLS3);
  1159. for (Iterator iter = props.iterator(); iter.hasNext();) {
  1160. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  1161. assertNull("DeclareErrorDeclaration's " + element.getId() + " property" + "should be null since we haven't set it yet",
  1162. d.getStructuralProperty(element));
  1163. }
  1164. for (Iterator iter = props.iterator(); iter.hasNext();) {
  1165. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  1166. if (element.getId().equals("pointcut")) {
  1167. AndPointcut p = ajast.newAndPointcut();
  1168. d.setStructuralProperty(element, p);
  1169. assertEquals("DeclareErrorDeclaration's pointcut property should" + " now be an AndPointcut", p, d
  1170. .getStructuralProperty(element));
  1171. } else if (element.getId().equals("message")) {
  1172. StringLiteral s = ajast.newStringLiteral();
  1173. d.setStructuralProperty(element, s);
  1174. assertEquals("DeclareErrorDeclaration's message property should" + " now be an AndPointcut", s, d
  1175. .getStructuralProperty(element));
  1176. } else if (element.getId().equals("javadoc")) {
  1177. // do nothing since makes no sense to have javadoc
  1178. } else {
  1179. fail("unknown property for DeclareErrorDeclaration");
  1180. }
  1181. }
  1182. }
  1183. // -------------- DeclareParentsDeclaration tests ---------------
  1184. public void testNewDeclareParentsDeclaration() {
  1185. AjAST ajast = createAjAST();
  1186. DeclareParentsDeclaration d = ajast.newDeclareParentsDeclaration();
  1187. assertNotNull("should have created a DeclareParentsDeclaration", d);
  1188. }
  1189. public void testPropertyDescriptorsForDeclareParentsDeclaration() {
  1190. AjAST ajast = createAjAST();
  1191. // DeclareParentsDeclaration d =
  1192. ajast.newDeclareParentsDeclaration();
  1193. List props = DeclareParentsDeclaration.propertyDescriptors(AST.JLS3);
  1194. boolean foundJavadoc = false;
  1195. boolean foundTypePattern = false;
  1196. boolean foundIsExtends = false;
  1197. boolean foundTypePatternList = false;
  1198. for (Iterator iter = props.iterator(); iter.hasNext();) {
  1199. Object o = iter.next();
  1200. if ((o instanceof ChildPropertyDescriptor)) {
  1201. ChildPropertyDescriptor element = (ChildPropertyDescriptor) o;
  1202. String id = element.getId();
  1203. if (id.equals("javadoc")) {
  1204. foundJavadoc = true;
  1205. } else if (id.equals("childTypePattern")) {
  1206. foundTypePattern = true;
  1207. } else {
  1208. fail("unknown PropertyDescriptor associated with DeclareParentsDeclaration: " + element.getId());
  1209. }
  1210. } else if ((o instanceof ChildListPropertyDescriptor)
  1211. && ((ChildListPropertyDescriptor) o).getId().equals("typePatternsList")) {
  1212. foundTypePatternList = true;
  1213. } else if ((o instanceof SimplePropertyDescriptor) && ((SimplePropertyDescriptor) o).getId().equals("isExtends")) {
  1214. foundIsExtends = true;
  1215. } else {
  1216. fail("unknown PropertyDescriptor associated with DeclareErrorDeclaration: " + o);
  1217. }
  1218. }
  1219. assertTrue("DeclareParentsDeclaration should have a javadoc PropertyDescriptor", foundJavadoc);
  1220. assertTrue("DeclareParentsDeclaration should have a typePattern PropertyDescriptor", foundTypePattern);
  1221. assertTrue("DeclareParentsDeclaration should have an isExtends PropertyDescriptor", foundIsExtends);
  1222. assertTrue("DeclareParentsDeclaration should have a typePatternList PropertyDescriptor", foundTypePatternList);
  1223. }
  1224. public void testGetAndSetTypePatternInDeclareParentsDeclaration() {
  1225. AjAST ajast = createAjAST();
  1226. DeclareParentsDeclaration d = ajast.newDeclareParentsDeclaration();
  1227. assertNull("by default there should be no TypePattern associated with" + " the declare parents", d.getChildTypePattern());
  1228. DefaultTypePattern dtp = ajast.newDefaultTypePattern();
  1229. d.setChildTypePattern(dtp);
  1230. assertEquals("there should now be a DefaultTypePattern associated with" + " the declare parents", dtp, d
  1231. .getChildTypePattern());
  1232. }
  1233. public void testGetAndSetIsExtendsInDeclareParentsDeclaration() {
  1234. AjAST ajast = createAjAST();
  1235. DeclareParentsDeclaration d = ajast.newDeclareParentsDeclaration();
  1236. assertFalse("by default the declare parents should not be 'extends'", d.isExtends());
  1237. d.setExtends(true);
  1238. assertTrue("the declare parents should now be 'extends'", d.isExtends());
  1239. }
  1240. public void testTypePatternsInDeclareParents() {
  1241. AjAST ajast = createAjAST();
  1242. DeclareParentsDeclaration d = ajast.newDeclareParentsDeclaration();
  1243. List l = d.parentTypePatterns();
  1244. assertEquals("there shouldn't be any type patterns associated with" + "the declare parents yet", 0, l.size());
  1245. DefaultTypePattern dtp = ajast.newDefaultTypePattern();
  1246. l.add(dtp);
  1247. assertEquals("there should be one type patterns associated with" + "the declare parents", 1, l.size());
  1248. assertEquals("there should be a DefaultTypePattern associated with" + "the declare parents", dtp, l.get(0));
  1249. }
  1250. public void testCloneDeclareParentsDeclaration() {
  1251. AjAST ajast = createAjAST();
  1252. DeclareParentsDeclaration d = ajast.newDeclareParentsDeclaration();
  1253. d.setChildTypePattern(ajast.newDefaultTypePattern());
  1254. d.setExtends(true);
  1255. d.parentTypePatterns().add(ajast.newDefaultTypePattern());
  1256. DeclareParentsDeclaration copy = (DeclareParentsDeclaration) ASTNode.copySubtree(ajast, d);
  1257. assertEquals("there should be one type patterns associated with" + "the declare parents copy", 1, copy.parentTypePatterns()
  1258. .size());
  1259. assertNotNull("the DeclareParentsDeclaration clone should have a typePattern set", copy.getChildTypePattern());
  1260. assertTrue("the DeclareParentsDeclaration clone should be an 'extends'", copy.isExtends());
  1261. }
  1262. // -------------- DeclarePrecedenceDeclaration tests ---------------
  1263. public void testNewDeclarePrecedenceDeclaration() {
  1264. AjAST ajast = createAjAST();
  1265. DeclarePrecedenceDeclaration d = ajast.newDeclarePrecedenceDeclaration();
  1266. assertNotNull("should have created a DeclarePrecedenceDeclaration", d);
  1267. }
  1268. public void testPropertyDescriptorsForDeclarePrecedence() {
  1269. AjAST ajast = createAjAST();
  1270. // DeclarePrecedenceDeclaration d =
  1271. ajast.newDeclarePrecedenceDeclaration();
  1272. List props = DeclarePrecedenceDeclaration.propertyDescriptors(AST.JLS3);
  1273. boolean foundJavadoc = false;
  1274. boolean foundTypePatterns = false;
  1275. for (Iterator iter = props.iterator(); iter.hasNext();) {
  1276. Object o = iter.next();
  1277. if ((o instanceof ChildPropertyDescriptor) && ((ChildPropertyDescriptor) o).getId().equals("javadoc")) {
  1278. foundJavadoc = true;
  1279. } else if ((o instanceof ChildListPropertyDescriptor)
  1280. && ((ChildListPropertyDescriptor) o).getId().equals("parentTypePatterns")) {
  1281. foundTypePatterns = true;
  1282. } else {
  1283. fail("unknown PropertyDescriptor associated with DeclareErrorDeclaration: " + o);
  1284. }
  1285. }
  1286. assertTrue("DeclareErrorDeclaration should have a javadoc PropertyDescriptor", foundJavadoc);
  1287. assertTrue("DeclareErrorDeclaration should have a pointcut PropertyDescriptor", foundTypePatterns);
  1288. }
  1289. public void testTypePatternsInDeclarePrecedence() {
  1290. AjAST ajast = createAjAST();
  1291. DeclarePrecedenceDeclaration d = ajast.newDeclarePrecedenceDeclaration();
  1292. List l = d.typePatterns();
  1293. assertEquals("there shouldn't be any type patterns associated with" + "the declare precedence yet", 0, l.size());
  1294. DefaultTypePattern dtp = ajast.newDefaultTypePattern();
  1295. l.add(dtp);
  1296. assertEquals("there should be one type patterns associated with" + "the declare precedence", 1, l.size());
  1297. assertEquals("there should be a DefaultTypePattern associated with" + "the declare precedence", dtp, l.get(0));
  1298. }
  1299. public void testCloneDeclarePrecedenceDeclaration() {
  1300. AjAST ajast = createAjAST();
  1301. DeclarePrecedenceDeclaration d = ajast.newDeclarePrecedenceDeclaration();
  1302. d.typePatterns().add(ajast.newDefaultTypePattern());
  1303. DeclarePrecedenceDeclaration copy = (DeclarePrecedenceDeclaration) ASTNode.copySubtree(ajast, d);
  1304. assertEquals("there should be one type patterns associated with" + "the declare precedence copy", 1, copy.typePatterns()
  1305. .size());
  1306. }
  1307. public void testInternalDeclarePrecedenceDeclaration() {
  1308. AjAST ajast = createAjAST();
  1309. DeclarePrecedenceDeclaration d = ajast.newDeclarePrecedenceDeclaration();
  1310. List props = DeclarePrecedenceDeclaration.propertyDescriptors(AST.JLS3);
  1311. for (Iterator iter = props.iterator(); iter.hasNext();) {
  1312. Object o = iter.next();
  1313. if (o instanceof ChildPropertyDescriptor) {
  1314. ChildPropertyDescriptor element = (ChildPropertyDescriptor) o;
  1315. assertNull("DeclareErrorDeclaration's " + element.getId() + " property"
  1316. + "should be null since we haven't set it yet", d.getStructuralProperty(element));
  1317. } else if (o instanceof ChildListPropertyDescriptor) {
  1318. ChildListPropertyDescriptor element = (ChildListPropertyDescriptor) o;
  1319. assertNotNull("DeclareErrorDeclaration's " + element.getId() + " property"
  1320. + "should not be null since it is a list", d.getStructuralProperty(element));
  1321. assertEquals("should only be able to put TypePattern's into the list", TypePattern.class, element.getElementType());
  1322. } else {
  1323. fail("unknown PropertyDescriptor associated with DeclareErrorDeclaration: " + o);
  1324. }
  1325. }
  1326. }
  1327. // -------------- DeclareSoftDeclaration tests ---------------
  1328. public void testNewDeclareSoftDeclaration() {
  1329. AjAST ajast = createAjAST();
  1330. DeclareSoftDeclaration d = ajast.newDeclareSoftDeclaration();
  1331. assertNotNull("should have created a DeclareSoftDeclaration", d);
  1332. }
  1333. public void testPropertyDescriptorsForDeclareSoftDeclaration() {
  1334. AjAST ajast = createAjAST();
  1335. // DeclareSoftDeclaration d =
  1336. ajast.newDeclareSoftDeclaration();
  1337. List props = DeclareSoftDeclaration.propertyDescriptors(AST.JLS3);
  1338. boolean foundJavadoc = false;
  1339. boolean foundPointcut = false;
  1340. boolean foundTypePattern = false;
  1341. for (Iterator iter = props.iterator(); iter.hasNext();) {
  1342. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  1343. String id = element.getId();
  1344. if (id.equals("javadoc")) {
  1345. foundJavadoc = true;
  1346. } else if (id.equals("pointcut")) {
  1347. foundPointcut = true;
  1348. } else if (id.equals("typePattern")) {
  1349. foundTypePattern = true;
  1350. } else {
  1351. fail("unknown PropertyDescriptor associated with " + "DeclareSoftDeclaration: " + element.getId());
  1352. }
  1353. }
  1354. assertTrue("DeclareSoftDeclaration should have a javadoc PropertyDescriptor", foundJavadoc);
  1355. assertTrue("DeclareSoftDeclaration should have a pointcut PropertyDescriptor", foundPointcut);
  1356. assertTrue("DeclareSoftDeclaration should have a type PropertyDescriptor", foundTypePattern);
  1357. }
  1358. public void testGetAndSetPointcutInSoftDeclaration() {
  1359. AjAST ajast = createAjAST();
  1360. DeclareSoftDeclaration d = ajast.newDeclareSoftDeclaration();
  1361. assertNull("by default there should be no pointcut associated with" + " the declare soft", d.getPointcut());
  1362. AndPointcut p = ajast.newAndPointcut();
  1363. d.setPointcut(p);
  1364. assertEquals("there should now be an AndPointcut associated with" + " the declare soft", p, d.getPointcut());
  1365. }
  1366. public void testGetAndSetTypePatternInSoftDeclaration() {
  1367. AjAST ajast = createAjAST();
  1368. DeclareSoftDeclaration d = ajast.newDeclareSoftDeclaration();
  1369. assertNull("by default there should be no TypePattern associated with" + " the declare soft", d.getTypePattern());
  1370. DefaultTypePattern dtp = ajast.newDefaultTypePattern();
  1371. d.setTypePattern(dtp);
  1372. assertEquals("there should now be a DefaultTypePattern associated with" + " the declare soft", dtp, d.getTypePattern());
  1373. }
  1374. public void testCloneDeclareSoftDeclaration() {
  1375. AjAST ajast = createAjAST();
  1376. DeclareSoftDeclaration d = ajast.newDeclareSoftDeclaration();
  1377. d.setPointcut(ajast.newAndPointcut());
  1378. d.setTypePattern(ajast.newDefaultTypePattern());
  1379. DeclareSoftDeclaration copy = (DeclareSoftDeclaration) ASTNode.copySubtree(ajast, d);
  1380. assertNotNull("the DeclareSoftDeclaration clone should have a pointcut set", copy.getPointcut());
  1381. assertNotNull("the DeclareSoftDeclaration clone should have a typePattern set", copy.getTypePattern());
  1382. }
  1383. public void testInternalDeclareSoftDeclaration() {
  1384. AjAST ajast = createAjAST();
  1385. DeclareSoftDeclaration d = ajast.newDeclareSoftDeclaration();
  1386. List props = DeclareSoftDeclaration.propertyDescriptors(AST.JLS3);
  1387. for (Iterator iter = props.iterator(); iter.hasNext();) {
  1388. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  1389. assertNull("DeclareSoftDeclaration's " + element.getId() + " property" + "should be null since we haven't set it yet",
  1390. d.getStructuralProperty(element));
  1391. }
  1392. for (Iterator iter = props.iterator(); iter.hasNext();) {
  1393. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  1394. if (element.getId().equals("pointcut")) {
  1395. AndPointcut p = ajast.newAndPointcut();
  1396. d.setStructuralProperty(element, p);
  1397. assertEquals("DeclareSoftDeclaration's pointcut property should" + " now be an AndPointcut", p, d
  1398. .getStructuralProperty(element));
  1399. } else if (element.getId().equals("typePattern")) {
  1400. DefaultTypePattern dtp = ajast.newDefaultTypePattern();
  1401. d.setStructuralProperty(element, dtp);
  1402. assertEquals("DeclareSoftDeclaration's typePattern property should" + " now be an DefaultTypePattern", dtp, d
  1403. .getStructuralProperty(element));
  1404. } else if (element.getId().equals("javadoc")) {
  1405. // do nothing since makes no sense to have javadoc
  1406. } else {
  1407. fail("unknown property for DeclareSoftDeclaration: " + element.getId());
  1408. }
  1409. }
  1410. }
  1411. // -------------- DeclareWarningDeclaration tests ---------------
  1412. public void testNewDeclareWarningDeclaration() {
  1413. AjAST ajast = createAjAST();
  1414. DeclareWarningDeclaration d = ajast.newDeclareWarningDeclaration();
  1415. assertNotNull("should have created a DeclareWarningDeclaration", d);
  1416. }
  1417. public void testPropertyDescriptorsForDeclareWarningDeclaration() {
  1418. AjAST ajast = createAjAST();
  1419. // DeclareWarningDeclaration d =
  1420. ajast.newDeclareWarningDeclaration();
  1421. List props = DeclareWarningDeclaration.propertyDescriptors(AST.JLS3);
  1422. boolean foundJavadoc = false;
  1423. boolean foundPointcut = false;
  1424. boolean foundMessage = false;
  1425. for (Iterator iter = props.iterator(); iter.hasNext();) {
  1426. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  1427. String id = element.getId();
  1428. if (id.equals("javadoc")) {
  1429. foundJavadoc = true;
  1430. } else if (id.equals("pointcut")) {
  1431. foundPointcut = true;
  1432. } else if (id.equals("message")) {
  1433. foundMessage = true;
  1434. } else {
  1435. fail("unknown PropertyDescriptor associated with DeclareWarningDeclaration");
  1436. }
  1437. }
  1438. assertTrue("DeclareWarningDeclaration should have a javadoc PropertyDescriptor", foundJavadoc);
  1439. assertTrue("DeclareWarningDeclaration should have a pointcut PropertyDescriptor", foundPointcut);
  1440. assertTrue("DeclareWarningDeclaration should have a message PropertyDescriptor", foundMessage);
  1441. }
  1442. public void testGetAndSetPointcutInWarningDeclaration() {
  1443. AjAST ajast = createAjAST();
  1444. DeclareWarningDeclaration d = ajast.newDeclareWarningDeclaration();
  1445. assertNull("by default there should be no pointcut associated with" + " the declare warning", d.getPointcut());
  1446. AndPointcut p = ajast.newAndPointcut();
  1447. d.setPointcut(p);
  1448. assertEquals("there should now be an AndPointcut associated with" + " the declare warning", p, d.getPointcut());
  1449. }
  1450. public void testGetAndSetMessageInWarningDeclaration() {
  1451. AjAST ajast = createAjAST();
  1452. DeclareWarningDeclaration d = ajast.newDeclareWarningDeclaration();
  1453. assertNull("by default there should be no message associated with" + " the declare warning", d.getMessage());
  1454. StringLiteral s = ajast.newStringLiteral();
  1455. d.setMessage(s);
  1456. assertEquals("there should now be a StringLiteral message associated with" + " the declare warning", s, d.getMessage());
  1457. }
  1458. public void testCloneDeclareWarningDeclaration() {
  1459. AjAST ajast = createAjAST();
  1460. DeclareWarningDeclaration d = ajast.newDeclareWarningDeclaration();
  1461. d.setPointcut(ajast.newAndPointcut());
  1462. d.setMessage(ajast.newStringLiteral());
  1463. DeclareWarningDeclaration copy = (DeclareWarningDeclaration) ASTNode.copySubtree(ajast, d);
  1464. assertNotNull("the DeclareWarningDeclaration clone should have a pointcut set", copy.getPointcut());
  1465. assertNotNull("the DeclareWarningDeclaration clone should have a message set", copy.getMessage());
  1466. }
  1467. public void testInternalDeclareWarningDeclaration() {
  1468. AjAST ajast = createAjAST();
  1469. DeclareWarningDeclaration d = ajast.newDeclareWarningDeclaration();
  1470. List props = DeclareWarningDeclaration.propertyDescriptors(AST.JLS3);
  1471. for (Iterator iter = props.iterator(); iter.hasNext();) {
  1472. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  1473. assertNull("DeclareWarningDeclaration's " + element.getId() + " property"
  1474. + "should be null since we haven't set it yet", d.getStructuralProperty(element));
  1475. }
  1476. for (Iterator iter = props.iterator(); iter.hasNext();) {
  1477. ChildPropertyDescriptor element = (ChildPropertyDescriptor) iter.next();
  1478. if (element.getId().equals("pointcut")) {
  1479. AndPointcut p = ajast.newAndPointcut();
  1480. d.setStructuralProperty(element, p);
  1481. assertEquals("DeclareWarningDeclaration's pointcut property should" + " now be an AndPointcut", p, d
  1482. .getStructuralProperty(element));
  1483. } else if (element.getId().equals("message")) {
  1484. StringLiteral s = ajast.newStringLiteral();
  1485. d.setStructuralProperty(element, s);
  1486. assertEquals("DeclareWarningDeclaration's message property should" + " now be an AndPointcut", s, d
  1487. .getStructuralProperty(element));
  1488. } else if (element.getId().equals("javadoc")) {
  1489. // do nothing since makes no sense to have javadoc
  1490. } else {
  1491. fail("unknown property for DeclareWarningDeclaration");
  1492. }
  1493. }
  1494. }
  1495. // --------- testing that the source ranges have been set correctly ---------
  1496. public void testDeclareAnnotationType() {
  1497. checkJLS3("@interface MyAnnotation{}class C{}aspect A{declare @type: C : @MyAnnotation;}", 43, 33);
  1498. }
  1499. public void testDeclareAnnotationMethod() {
  1500. checkJLS3("@interface MyAnnotation{}class C{}aspect A{declare @method:public * C.*(..) : @MyAnnotation;}", 43, 49);
  1501. }
  1502. public void testDeclareAnnotationField() {
  1503. checkJLS3("@interface MyAnnotation{}class C{}aspect A{declare @field: * C+.* : @MyAnnotation;}", 43, 39);
  1504. }
  1505. public void testDeclareAnnotationConstructor() {
  1506. checkJLS3("@interface MyAnnotation{}class C{}aspect A{declare @constructor: C+.new(..) : @MyAnnotation;}", 43, 49);
  1507. }
  1508. public void testDeclareParents() {
  1509. checkJLS3("class A{}class B{}aspect C {declare parents : A extends B;}", 28, 29);
  1510. }
  1511. /*
  1512. *
  1513. *
  1514. * START: Test TypePattern nodes introduced in Bugzilla 329268.
  1515. *
  1516. *
  1517. */
  1518. public void testDeclareParentsTypePatternNodeSource() {
  1519. checkTypePatternSourceRangesJLS3("class A{}class B{}aspect C {declare parents : A extends B;}", new int[][] {{46, 1} , {56, 1 }});
  1520. }
  1521. public void testDeclareParentsAnySource() {
  1522. checkTypePatternSourceRangesJLS3("class A{}class B{}aspect C {declare parents : * extends B;}", new int[][] {{46, 1} , {56, 1 }});
  1523. }
  1524. public void testDeclareParentsAndSource() {
  1525. checkTypePatternSourceRangesJLS3(
  1526. "class A{}class B{}class D{}class E{}aspect C {declare parents : A && B && D extends E;}",
  1527. new int[][] { { 64, 11 },// A && B && D,
  1528. { 64, 1 }, // A
  1529. { 69, 6 }, // B && D
  1530. { 69, 1 }, // B
  1531. { 74, 1 }, // D
  1532. { 84, 1 } // E
  1533. });
  1534. }
  1535. public void testDeclareParentsNotSource() {
  1536. checkTypePatternSourceRangesJLS3(
  1537. "class A{}class B{}class D{}class E{}aspect C {declare parents : A && !B extends E;}",
  1538. new int[][] { { 64, 7 },// A && !B
  1539. { 64, 1 }, // A
  1540. { 70, 1 }, // !B: the source location for a negated pattern is the start of the negated pattern excluding "!". Is this a bug?
  1541. { 70, 1 }, // B
  1542. { 80, 1 } // E
  1543. });
  1544. }
  1545. public void testDeclareParentsOrSource() {
  1546. checkTypePatternSourceRangesJLS3(
  1547. "class A{}class B{}class D{}class E{}aspect C {declare parents : A || B || D extends E;}",
  1548. new int[][] { { 64, 11 },// A || B || D,
  1549. { 64, 1 }, // A
  1550. { 69, 6 }, // B || D
  1551. { 69, 1 }, // B
  1552. { 74, 1 }, // D
  1553. { 84, 1 } // E
  1554. });
  1555. }
  1556. public void testDeclareParentsAnyWithAnnotationSource() {
  1557. checkTypePatternSourceRangesJLS3(
  1558. "@interface AnnotationT {}class E{}aspect C {declare parents : (@AnnotationT *) extends E;}",
  1559. new int[][] { { 62, 16 },// (@AnnotationT *)
  1560. { 87, 1 } // E
  1561. });
  1562. }
  1563. public void testDeclareParentsTypeCategorySource() {
  1564. checkTypePatternSourceRangesJLS3(
  1565. "class A{}class E{}aspect C {declare parents : A && is(ClassType) extends E;}",
  1566. new int[][] { { 46, 18 },// A && !is(InnerType)
  1567. { 46, 1 }, // A
  1568. { 51, 13}, // is(InnerType)
  1569. { 73, 1 } // E
  1570. });
  1571. }
  1572. public void testDeclareParentsTypeCategoryNotSource() {
  1573. checkTypePatternSourceRangesJLS3(
  1574. "class A{}class E{}aspect C {declare parents : A && !is(InnerType) extends E;}",
  1575. new int[][] { { 46, 19 },// A && !is(InnerType)
  1576. { 46, 1 }, // A
  1577. { 52, 13}, // !is(InnerType): the source location for a negated pattern is the start of the negated pattern excluding "!". Is this a bug?
  1578. { 52, 13}, // is(InnerType)
  1579. { 74, 1 } // E
  1580. });
  1581. }
  1582. // // TODO: commenting out as there isn't proper support for hasmethod(..)
  1583. // yet. Uncomment and fix when hasmethod is supported
  1584. // public void testDeclareParentsHasMember() {
  1585. // // This is wrong. Call checkTypePatternJLS3 instead to check the source
  1586. // ranges for hasMethod...
  1587. // checkJLS3("class A{}class B{ public void fooB() {}}class D{}aspect C {declare parents : A && hasmethod(void foo*(..)) extends D;}",
  1588. // 37, 34);
  1589. // }
  1590. public void testDeclareParentsTypeCategoryInner() {
  1591. checkCategoryTypePatternJLS3(
  1592. "class A{class B{}}class E{}aspect C {declare parents : B && is(InnerType) extends E;}",
  1593. TypeCategoryTypePattern.INNER, "is(InnerType)");
  1594. }
  1595. public void testDeclareParentsTypeCategoryInterface() {
  1596. checkCategoryTypePatternJLS3(
  1597. "interface B{}interface E{}aspect C {declare parents : B && is(InterfaceType) extends E;}",
  1598. TypeCategoryTypePattern.INTERFACE, "is(InterfaceType)");
  1599. }
  1600. public void testDeclareParentsTypeCategoryClass() {
  1601. checkCategoryTypePatternJLS3(
  1602. "class B{}class E{}aspect C {declare parents : B && is(ClassType) extends E;}",
  1603. TypeCategoryTypePattern.CLASS, "is(ClassType)");
  1604. }
  1605. public void testDeclareParentsTypeCategoryAnnotation() {
  1606. checkCategoryTypePatternJLS3(
  1607. "@interface B{}class E{}aspect C {declare parents : B && is(AnnotationType) extends E;}",
  1608. TypeCategoryTypePattern.ANNOTATION, "is(AnnotationType)");
  1609. }
  1610. public void testDeclareParentsTypeCategoryAnonymous() {
  1611. checkCategoryTypePatternJLS3(
  1612. "class A{B annonymousB = new B() {};}class B{}class E{}aspect C {declare parents : B && is(AnonymousType) extends E;}",
  1613. TypeCategoryTypePattern.ANONYMOUS, "is(AnonymousType)");
  1614. }
  1615. public void testDeclareParentsTypeCategoryEnum() {
  1616. checkCategoryTypePatternJLS3(
  1617. "class B{}class E{}aspect C {declare parents : B && !is(EnumType) extends E;}",
  1618. TypeCategoryTypePattern.ENUM, "is(EnumType)");
  1619. }
  1620. /*
  1621. *
  1622. *
  1623. * END: Test TypePattern nodes introduced in Bugzilla 329268.
  1624. *
  1625. *
  1626. */
  1627. public void testDeclareWarning() {
  1628. checkJLS3("aspect A {pointcut a();declare warning: a(): \"error\";}", 23, 30);
  1629. }
  1630. public void testDeclareError() {
  1631. checkJLS3("aspect A {pointcut a();declare error: a(): \"error\";}", 23, 28);
  1632. }
  1633. public void testDeclareSoft() {
  1634. checkJLS3("aspect A {pointcut a();declare soft: Exception+: a();}", 23, 29);
  1635. }
  1636. public void testDeclarePrecedence() {
  1637. checkJLS3("aspect A{}aspect B{declare precedence: B,A;}", 19, 23);
  1638. }
  1639. // --------- tests for bugs ----------
  1640. public void testJavadocCommentForDeclareExists_pr150467() {
  1641. ASTParser parser = ASTParser.newParser(AST.JLS3);
  1642. parser.setSource("aspect X {/** I have a doc comment */declare parents : Y implements Z;}".toCharArray());
  1643. parser.setCompilerOptions(Collections.EMPTY_MAP);
  1644. parser.setKind(ASTParser.K_COMPILATION_UNIT);
  1645. CompilationUnit cu = (CompilationUnit) parser.createAST(null);
  1646. Javadoc javadoc = ((DeclareParentsDeclaration) ((TypeDeclaration) cu.types().get(0)).bodyDeclarations().get(0))
  1647. .getJavadoc();
  1648. assertNull("expected the doc comment node to be null but it wasn't", javadoc);
  1649. assertEquals("expected there to be one comment but found " + cu.getCommentList().size(), 1, cu.getCommentList().size());
  1650. }
  1651. protected void assertExpression(String expectedExpression, TypePattern node) {
  1652. assertTrue("Expected: " + expectedExpression + ". Actual: " + node.getTypePatternExpression(), node.getTypePatternExpression().equals(expectedExpression));
  1653. }
  1654. protected void assertNodeType(Class<?> expected, TypePattern node) {
  1655. assertTrue("Expected " + expected.toString() + ". Actual: " + node.getClass().toString(), node.getClass().equals(expected));
  1656. }
  1657. }
  1658. class TypeCategoryTypeVisitor extends AjASTVisitor {
  1659. private TypeCategoryTypePattern typeCategory = null;
  1660. public boolean visit(TypeCategoryTypePattern node) {
  1661. typeCategory = node;
  1662. return false;
  1663. }
  1664. public TypeCategoryTypePattern getTypeCategoryNode() {
  1665. return typeCategory;
  1666. }
  1667. }
  1668. class TypePatternSourceRangeVisitor extends AjASTVisitor {
  1669. private List<SourceRange> sourceRanges = new ArrayList<SourceRange>();
  1670. public List<SourceRange> getVisitedSourceRanges() {
  1671. return sourceRanges;
  1672. }
  1673. public boolean visit(AbstractBooleanTypePattern node) {
  1674. sourceRanges.add(new SourceRange(node.getStartPosition(), node
  1675. .getLength()));
  1676. return true;
  1677. }
  1678. public boolean visit(AnyTypePattern node) {
  1679. sourceRanges.add(new SourceRange(node.getStartPosition(), node
  1680. .getLength()));
  1681. return true;
  1682. }
  1683. public boolean visit(AnyWithAnnotationTypePattern node) {
  1684. sourceRanges.add(new SourceRange(node.getStartPosition(), node
  1685. .getLength()));
  1686. return true;
  1687. }
  1688. public boolean visit(EllipsisTypePattern node) {
  1689. sourceRanges.add(new SourceRange(node.getStartPosition(), node
  1690. .getLength()));
  1691. return true;
  1692. }
  1693. public boolean visit(HasMemberTypePattern node) {
  1694. sourceRanges.add(new SourceRange(node.getStartPosition(), node
  1695. .getLength()));
  1696. return true;
  1697. }
  1698. public boolean visit(IdentifierTypePattern node) {
  1699. sourceRanges.add(new SourceRange(node.getStartPosition(), node
  1700. .getLength()));
  1701. return true;
  1702. }
  1703. public boolean visit(NotTypePattern node) {
  1704. sourceRanges.add(new SourceRange(node.getStartPosition(), node
  1705. .getLength()));
  1706. return true;
  1707. }
  1708. public boolean visit(NoTypePattern node) {
  1709. sourceRanges.add(new SourceRange(node.getStartPosition(), node
  1710. .getLength()));
  1711. return true;
  1712. }
  1713. public boolean visit(TypeCategoryTypePattern node) {
  1714. sourceRanges.add(new SourceRange(node.getStartPosition(), node
  1715. .getLength()));
  1716. return true;
  1717. }
  1718. }
  1719. class SourceRangeVisitor extends AjASTVisitor {
  1720. boolean visitTheKids = true;
  1721. boolean visitDocTags;
  1722. int start, length;
  1723. SourceRangeVisitor() {
  1724. this(false);
  1725. }
  1726. SourceRangeVisitor(boolean visitDocTags) {
  1727. super(visitDocTags);
  1728. this.visitDocTags = visitDocTags;
  1729. }
  1730. public boolean isVisitingChildren() {
  1731. return visitTheKids;
  1732. }
  1733. public void setVisitingChildren(boolean visitChildren) {
  1734. visitTheKids = visitChildren;
  1735. }
  1736. public int getStart() {
  1737. return start;
  1738. }
  1739. public int getLength() {
  1740. return length;
  1741. }
  1742. public boolean visit(DeclareAtTypeDeclaration node) {
  1743. start = node.getStartPosition();
  1744. length = node.getLength();
  1745. return isVisitingChildren();
  1746. }
  1747. public boolean visit(DeclareAtMethodDeclaration node) {
  1748. start = node.getStartPosition();
  1749. length = node.getLength();
  1750. return isVisitingChildren();
  1751. }
  1752. public boolean visit(DeclareAtConstructorDeclaration node) {
  1753. start = node.getStartPosition();
  1754. length = node.getLength();
  1755. return isVisitingChildren();
  1756. }
  1757. public boolean visit(DeclareAtFieldDeclaration node) {
  1758. start = node.getStartPosition();
  1759. length = node.getLength();
  1760. return isVisitingChildren();
  1761. }
  1762. public boolean visit(DeclareWarningDeclaration node) {
  1763. start = node.getStartPosition();
  1764. length = node.getLength();
  1765. return isVisitingChildren();
  1766. }
  1767. public boolean visit(DeclareErrorDeclaration node) {
  1768. start = node.getStartPosition();
  1769. length = node.getLength();
  1770. return isVisitingChildren();
  1771. }
  1772. public boolean visit(DeclareParentsDeclaration node) {
  1773. start = node.getStartPosition();
  1774. length = node.getLength();
  1775. return isVisitingChildren();
  1776. }
  1777. public boolean visit(DeclarePrecedenceDeclaration node) {
  1778. start = node.getStartPosition();
  1779. length = node.getLength();
  1780. return isVisitingChildren();
  1781. }
  1782. public boolean visit(DeclareSoftDeclaration node) {
  1783. start = node.getStartPosition();
  1784. length = node.getLength();
  1785. return isVisitingChildren();
  1786. }
  1787. }