You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AjASTConverter.java 214KB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
10 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
10 years ago
18 years ago
18 years ago
10 years ago
18 years ago
18 years ago
18 years ago
10 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
10 years ago
10 years ago
18 years ago
10 years ago
18 years ago
10 years ago
18 years ago
10 years ago
18 years ago
10 years ago
18 years ago
10 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880
  1. /*******************************************************************************
  2. * Copyright (c) 2000, 2010 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v 2.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors:
  9. * IBM Corporation - initial API and implementation
  10. * Nieraj Singh
  11. *******************************************************************************/
  12. package org.aspectj.org.eclipse.jdt.core.dom;
  13. import java.util.HashSet;
  14. import java.util.List;
  15. import java.util.Map;
  16. import org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration;
  17. import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration;
  18. import org.aspectj.ajdt.internal.compiler.ast.DeclareDeclaration;
  19. import org.aspectj.ajdt.internal.compiler.ast.InterTypeConstructorDeclaration;
  20. import org.aspectj.ajdt.internal.compiler.ast.InterTypeDeclaration;
  21. import org.aspectj.ajdt.internal.compiler.ast.InterTypeFieldDeclaration;
  22. import org.aspectj.ajdt.internal.compiler.ast.InterTypeMethodDeclaration;
  23. import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration;
  24. import org.aspectj.org.eclipse.jdt.core.compiler.CategorizedProblem;
  25. import org.aspectj.org.eclipse.jdt.core.compiler.CharOperation;
  26. import org.aspectj.org.eclipse.jdt.core.compiler.IProblem;
  27. import org.aspectj.org.eclipse.jdt.core.compiler.InvalidInputException;
  28. import org.aspectj.org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
  29. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
  30. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument;
  31. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ForeachStatement;
  32. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocArgumentExpression;
  33. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocFieldReference;
  34. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocMessageSend;
  35. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
  36. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference;
  37. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference;
  38. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
  39. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
  40. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteralConcatenation;
  41. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference;
  42. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Wildcard;
  43. import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
  44. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.BlockScope;
  45. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
  46. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
  47. import org.aspectj.org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
  48. import org.aspectj.weaver.AdviceKind;
  49. import org.aspectj.weaver.patterns.Declare;
  50. import org.aspectj.weaver.patterns.DeclareAnnotation;
  51. import org.aspectj.weaver.patterns.DeclareErrorOrWarning;
  52. import org.aspectj.weaver.patterns.DeclareParents;
  53. import org.aspectj.weaver.patterns.DeclarePrecedence;
  54. import org.aspectj.weaver.patterns.DeclareSoft;
  55. import org.aspectj.weaver.patterns.ISignaturePattern;
  56. import org.aspectj.weaver.patterns.PatternNode;
  57. import org.aspectj.weaver.patterns.SignaturePattern;
  58. import org.aspectj.weaver.patterns.TypePattern;
  59. import org.eclipse.core.runtime.IProgressMonitor;
  60. /**
  61. * Internal class for converting internal compiler ASTs into public ASTs.
  62. */
  63. @SuppressWarnings("unchecked")
  64. public class AjASTConverter extends ASTConverter {
  65. public AjASTConverter(Map options, boolean resolveBindings, IProgressMonitor monitor) {
  66. super(options, resolveBindings, monitor);
  67. }
  68. public ASTNode convert(AdviceDeclaration adviceDeclaration) {
  69. // ajh02: method added
  70. org.aspectj.org.eclipse.jdt.core.dom.AdviceDeclaration adviceDecl = null;
  71. if (adviceDeclaration.kind.equals(AdviceKind.Before)) {
  72. adviceDecl = new org.aspectj.org.eclipse.jdt.core.dom.BeforeAdviceDeclaration(this.ast);
  73. } else if (adviceDeclaration.kind.equals(AdviceKind.After)) {
  74. adviceDecl = new org.aspectj.org.eclipse.jdt.core.dom.AfterAdviceDeclaration(this.ast);
  75. } else if (adviceDeclaration.kind.equals(AdviceKind.AfterThrowing)) {
  76. adviceDecl = new AfterThrowingAdviceDeclaration(this.ast);
  77. if (adviceDeclaration.extraArgument != null) {
  78. SingleVariableDeclaration throwing = convert(adviceDeclaration.extraArgument);
  79. ((AfterThrowingAdviceDeclaration) adviceDecl).setThrowing(throwing);
  80. }
  81. } else if (adviceDeclaration.kind.equals(AdviceKind.AfterReturning)) {
  82. adviceDecl = new AfterReturningAdviceDeclaration(this.ast);
  83. if (adviceDeclaration.extraArgument != null) {
  84. SingleVariableDeclaration returning = convert(adviceDeclaration.extraArgument);
  85. ((AfterReturningAdviceDeclaration) adviceDecl).setReturning(returning);
  86. }
  87. } else if (adviceDeclaration.kind.equals(AdviceKind.Around)) {
  88. adviceDecl = new AroundAdviceDeclaration(this.ast);
  89. // set the returnType
  90. org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference typeReference = adviceDeclaration.returnType;
  91. if (typeReference != null) {
  92. Type returnType = convertType(typeReference);
  93. // get the positions of the right parenthesis
  94. setTypeForAroundAdviceDeclaration((AroundAdviceDeclaration) adviceDecl, returnType);
  95. }
  96. org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParameters = adviceDeclaration.typeParameters();
  97. if (typeParameters != null) {
  98. switch (this.ast.apiLevel) {
  99. case AST.JLS2_INTERNAL:
  100. adviceDecl.setFlags(adviceDecl.getFlags() | ASTNode.MALFORMED);
  101. break;
  102. case AST.JLS3:
  103. for (org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeParameter typeParameter : typeParameters) {
  104. ((AroundAdviceDeclaration) adviceDecl).typeParameters().add(convert(typeParameter));
  105. }
  106. }
  107. }
  108. }
  109. // set its javadoc, parameters, throws, pointcut and body
  110. org.aspectj.weaver.patterns.Pointcut pointcut = adviceDeclaration.pointcutDesignator.getPointcut();
  111. adviceDecl.setPointcut(convert(pointcut));
  112. org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference[] thrownExceptions = adviceDeclaration.thrownExceptions;
  113. if (thrownExceptions != null) {
  114. int thrownExceptionsLength = thrownExceptions.length;
  115. for (TypeReference thrownException : thrownExceptions) {
  116. adviceDecl.thrownExceptions().add(convert(thrownException));
  117. }
  118. }
  119. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument[] parameters = adviceDeclaration.arguments;
  120. if (parameters != null) {
  121. int parametersLength = parameters.length;
  122. for (Argument parameter : parameters) {
  123. adviceDecl.parameters().add(convert(parameter));
  124. }
  125. }
  126. int start = adviceDeclaration.sourceStart;
  127. int end = retrieveIdentifierEndPosition(start, adviceDeclaration.sourceEnd);
  128. int declarationSourceStart = adviceDeclaration.declarationSourceStart;
  129. int declarationSourceEnd = adviceDeclaration.bodyEnd;
  130. adviceDecl.setSourceRange(declarationSourceStart, declarationSourceEnd - declarationSourceStart + 1);
  131. int closingPosition = retrieveRightBraceOrSemiColonPosition(adviceDeclaration.bodyEnd + 1,
  132. adviceDeclaration.declarationSourceEnd);
  133. if (closingPosition != -1) {
  134. int startPosition = adviceDecl.getStartPosition();
  135. adviceDecl.setSourceRange(startPosition, closingPosition - startPosition + 1);
  136. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Statement[] statements = adviceDeclaration.statements;
  137. start = retrieveStartBlockPosition(adviceDeclaration.sourceStart, declarationSourceEnd);
  138. end = retrieveEndBlockPosition(adviceDeclaration.sourceStart, adviceDeclaration.declarationSourceEnd);
  139. Block block = null;
  140. if (start != -1 && end != -1) {
  141. /*
  142. * start or end can be equal to -1 if we have an interface's method.
  143. */
  144. block = new Block(this.ast);
  145. block.setSourceRange(start, end - start + 1);
  146. adviceDecl.setBody(block);
  147. }
  148. if (block != null && statements != null) {
  149. int statementsLength = statements.length;
  150. for (int i = 0; i < statementsLength; i++) {
  151. if (statements[i] instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
  152. checkAndAddMultipleLocalDeclaration(statements, i, block.statements());
  153. } else {
  154. block.statements().add(convert(statements[i]));
  155. }
  156. }
  157. }
  158. if (block != null) {
  159. adviceDecl.setFlags(adviceDecl.getFlags() | ASTNode.MALFORMED);
  160. }
  161. } else {
  162. // syntax error in this advice declaration
  163. start = retrieveStartBlockPosition(adviceDeclaration.sourceStart, declarationSourceEnd);
  164. end = adviceDeclaration.bodyEnd;
  165. // try to get the best end position
  166. IProblem[] problems = adviceDeclaration.compilationResult().problems;
  167. if (problems != null) {
  168. for (int i = 0, max = adviceDeclaration.compilationResult().problemCount; i < max; i++) {
  169. IProblem currentProblem = problems[i];
  170. if (currentProblem.getSourceStart() == start && currentProblem.getID() == IProblem.ParsingErrorInsertToComplete) {
  171. end = currentProblem.getSourceEnd();
  172. break;
  173. }
  174. }
  175. }
  176. int startPosition = adviceDecl.getStartPosition();
  177. adviceDecl.setSourceRange(startPosition, end - startPosition + 1);
  178. if (start != -1 && end != -1) {
  179. /*
  180. * start or end can be equal to -1 if we have an interface's method.
  181. */
  182. Block block = new Block(this.ast);
  183. block.setSourceRange(start, end - start + 1);
  184. adviceDecl.setBody(block);
  185. }
  186. }
  187. // The javadoc comment is now got from list store in compilation unit declaration
  188. if (this.resolveBindings) {
  189. recordNodes(adviceDecl, adviceDeclaration);
  190. // if (adviceDecl.resolveBinding() != null) {
  191. // // ajh02: what is resolveBinding()?
  192. // convert(adviceDeclaration.javadoc, adviceDecl);
  193. // }
  194. } else {
  195. convert(adviceDeclaration.javadoc, adviceDecl);
  196. }
  197. return adviceDecl;
  198. }
  199. //public ASTNode convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration methodDeclaration) {
  200. public ASTNode convert(boolean isInterface, org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration methodDeclaration) {
  201. checkCanceled();
  202. if (methodDeclaration instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) {
  203. return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) methodDeclaration);
  204. }
  205. MethodDeclaration methodDecl = new MethodDeclaration(this.ast);
  206. boolean isConstructor = methodDeclaration.isConstructor();
  207. methodDecl.setConstructor(isConstructor);
  208. // //////////////// ajh02: added. ugh, polymorphism! Where are you!
  209. if (methodDeclaration instanceof DeclareDeclaration) {
  210. return convert((DeclareDeclaration) methodDeclaration);
  211. } else if (methodDeclaration instanceof InterTypeFieldDeclaration) {
  212. return convert((InterTypeFieldDeclaration) methodDeclaration);
  213. } else if (methodDeclaration instanceof InterTypeMethodDeclaration) {
  214. methodDecl = new org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration(this.ast);
  215. ((org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration) methodDecl)
  216. .setOnType(((InterTypeMethodDeclaration) methodDeclaration).getOnType().toString());
  217. } else if (methodDeclaration instanceof InterTypeConstructorDeclaration) {
  218. methodDecl = new org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration(this.ast);
  219. ((org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration) methodDecl)
  220. .setOnType(((InterTypeConstructorDeclaration) methodDeclaration).getOnType().toString());
  221. methodDecl.setConstructor(true);
  222. } else if (methodDeclaration instanceof PointcutDeclaration) {
  223. return convert((PointcutDeclaration) methodDeclaration);
  224. } else if (methodDeclaration instanceof AdviceDeclaration) {
  225. return convert((AdviceDeclaration) methodDeclaration);
  226. }
  227. // ///////////////////////
  228. // set modifiers after checking whether we're an itd, otherwise
  229. // the modifiers are not set on the correct object.
  230. setModifiers(methodDecl, methodDeclaration);
  231. final SimpleName methodName = new SimpleName(this.ast);
  232. // AspectJ Extension - for ITD's use the declaredSelector
  233. if (methodDeclaration instanceof InterTypeDeclaration) {
  234. InterTypeDeclaration itd = (InterTypeDeclaration) methodDeclaration;
  235. methodName.internalSetIdentifier(new String(itd.getDeclaredSelector()));
  236. } else {
  237. methodName.internalSetIdentifier(new String(methodDeclaration.selector));
  238. }
  239. // AspectJ Extension end
  240. int start = methodDeclaration.sourceStart;
  241. int end = retrieveIdentifierEndPosition(start, methodDeclaration.sourceEnd);
  242. methodName.setSourceRange(start, end - start + 1);
  243. methodDecl.setName(methodName);
  244. org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference[] thrownExceptions = methodDeclaration.thrownExceptions;
  245. int methodHeaderEnd = methodDeclaration.sourceEnd;
  246. int thrownExceptionsLength = thrownExceptions == null ? 0 : thrownExceptions.length;
  247. if (thrownExceptionsLength > 0) {
  248. Name thrownException;
  249. int i = 0;
  250. do {
  251. thrownException = convert(thrownExceptions[i++]);
  252. methodDecl.thrownExceptions().add(thrownException);
  253. } while (i < thrownExceptionsLength);
  254. methodHeaderEnd = thrownException.getStartPosition() + thrownException.getLength();
  255. }
  256. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument[] parameters = methodDeclaration.arguments;
  257. int parametersLength = parameters == null ? 0 : parameters.length;
  258. if (parametersLength > 0) {
  259. SingleVariableDeclaration parameter;
  260. int i = 0;
  261. do {
  262. parameter = convert(parameters[i++]);
  263. methodDecl.parameters().add(parameter);
  264. } while (i < parametersLength);
  265. if (thrownExceptionsLength == 0) {
  266. methodHeaderEnd = parameter.getStartPosition() + parameter.getLength();
  267. }
  268. }
  269. org.aspectj.org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall explicitConstructorCall = null;
  270. if (isConstructor) {
  271. if (isInterface) {
  272. // interface cannot have a constructor
  273. methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
  274. }
  275. org.aspectj.org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration constructorDeclaration = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration) methodDeclaration;
  276. explicitConstructorCall = constructorDeclaration.constructorCall;
  277. switch(this.ast.apiLevel) {
  278. case AST.JLS2_INTERNAL :
  279. // set the return type to VOID
  280. PrimitiveType returnType = new PrimitiveType(this.ast);
  281. returnType.setPrimitiveTypeCode(PrimitiveType.VOID);
  282. returnType.setSourceRange(methodDeclaration.sourceStart, 0);
  283. methodDecl.internalSetReturnType(returnType);
  284. break;
  285. default :
  286. methodDecl.setReturnType2(null);
  287. }
  288. } else if (methodDeclaration instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) {
  289. org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration method = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) methodDeclaration;
  290. org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference typeReference = method.returnType;
  291. if (typeReference != null) {
  292. Type returnType = convertType(typeReference);
  293. // get the positions of the right parenthesis
  294. int rightParenthesisPosition = retrieveEndOfRightParenthesisPosition(end, method.bodyEnd);
  295. int extraDimensions = retrieveExtraDimension(rightParenthesisPosition, method.bodyEnd);
  296. methodDecl.setExtraDimensions(extraDimensions);
  297. setTypeForMethodDeclaration(methodDecl, returnType, extraDimensions);
  298. } else {
  299. // no return type for a method that is not a constructor
  300. methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
  301. switch(this.ast.apiLevel) {
  302. case AST.JLS2_INTERNAL :
  303. break;
  304. default :
  305. methodDecl.setReturnType2(null);
  306. }
  307. }
  308. }
  309. int declarationSourceStart = methodDeclaration.declarationSourceStart;
  310. int bodyEnd = methodDeclaration.bodyEnd;
  311. methodDecl.setSourceRange(declarationSourceStart, bodyEnd - declarationSourceStart + 1);
  312. int declarationSourceEnd = methodDeclaration.declarationSourceEnd;
  313. int rightBraceOrSemiColonPositionStart = bodyEnd == declarationSourceEnd ? bodyEnd : bodyEnd + 1;
  314. int closingPosition = retrieveRightBraceOrSemiColonPosition(rightBraceOrSemiColonPositionStart, declarationSourceEnd);
  315. if (closingPosition != -1) {
  316. int startPosition = methodDecl.getStartPosition();
  317. methodDecl.setSourceRange(startPosition, closingPosition - startPosition + 1);
  318. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Statement[] statements = methodDeclaration.statements;
  319. start = retrieveStartBlockPosition(methodHeaderEnd, methodDeclaration.bodyStart);
  320. if (start == -1) start = methodDeclaration.bodyStart; // use recovery position for body start
  321. end = retrieveRightBrace(methodDeclaration.bodyEnd, declarationSourceEnd);
  322. Block block = null;
  323. if (start != -1 && end != -1) {
  324. /*
  325. * start or end can be equal to -1 if we have an interface's method.
  326. */
  327. block = new Block(this.ast);
  328. block.setSourceRange(start, closingPosition - start + 1);
  329. methodDecl.setBody(block);
  330. }
  331. if (block != null && (statements != null || explicitConstructorCall != null)) {
  332. if (explicitConstructorCall != null && explicitConstructorCall.accessMode != org.aspectj.org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall.ImplicitSuper) {
  333. block.statements().add(convert(explicitConstructorCall));
  334. }
  335. int statementsLength = statements == null ? 0 : statements.length;
  336. for (int i = 0; i < statementsLength; i++) {
  337. if (statements[i] instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
  338. checkAndAddMultipleLocalDeclaration(statements, i, block.statements());
  339. } else {
  340. final Statement statement = convert(statements[i]);
  341. if (statement != null) {
  342. block.statements().add(statement);
  343. }
  344. }
  345. }
  346. }
  347. if (block != null
  348. && (Modifier.isAbstract(methodDecl.getModifiers())
  349. || Modifier.isNative(methodDecl.getModifiers())
  350. || isInterface)) {
  351. methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
  352. }
  353. } else {
  354. // syntax error in this method declaration
  355. methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
  356. if (!methodDeclaration.isNative() && !methodDeclaration.isAbstract()) {
  357. start = retrieveStartBlockPosition(methodHeaderEnd, bodyEnd);
  358. if (start == -1) start = methodDeclaration.bodyStart; // use recovery position for body start
  359. end = methodDeclaration.bodyEnd;
  360. // try to get the best end position
  361. CategorizedProblem[] problems = methodDeclaration.compilationResult().problems;
  362. if (problems != null) {
  363. for (int i = 0, max = methodDeclaration.compilationResult().problemCount; i < max; i++) {
  364. CategorizedProblem currentProblem = problems[i];
  365. if (currentProblem.getSourceStart() == start && currentProblem.getID() == IProblem.ParsingErrorInsertToComplete) {
  366. end = currentProblem.getSourceEnd();
  367. break;
  368. }
  369. }
  370. }
  371. int startPosition = methodDecl.getStartPosition();
  372. methodDecl.setSourceRange(startPosition, end - startPosition + 1);
  373. if (start != -1 && end != -1) {
  374. /*
  375. * start or end can be equal to -1 if we have an interface's method.
  376. */
  377. Block block = new Block(this.ast);
  378. block.setSourceRange(start, end - start + 1);
  379. methodDecl.setBody(block);
  380. }
  381. }
  382. }
  383. org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParameters = methodDeclaration.typeParameters();
  384. if (typeParameters != null) {
  385. switch(this.ast.apiLevel) {
  386. case AST.JLS2_INTERNAL :
  387. methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
  388. break;
  389. default :
  390. for (org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeParameter typeParameter : typeParameters) {
  391. methodDecl.typeParameters().add(convert(typeParameter));
  392. }
  393. }
  394. }
  395. // The javadoc comment is now got from list store in compilation unit declaration
  396. convert(methodDeclaration.javadoc, methodDecl);
  397. if (this.resolveBindings) {
  398. recordNodes(methodDecl, methodDeclaration);
  399. recordNodes(methodName, methodDeclaration);
  400. methodDecl.resolveBinding();
  401. }
  402. return methodDecl;
  403. }
  404. // checkCanceled();
  405. // if (methodDeclaration instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) {
  406. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) methodDeclaration);
  407. // }
  408. // MethodDeclaration methodDecl = new MethodDeclaration(this.ast);
  409. // boolean isConstructor = methodDeclaration.isConstructor();
  410. // methodDecl.setConstructor(isConstructor);
  411. //
  412. // // //////////////// ajh02: added. ugh, polymorphism! Where are you!
  413. // if (methodDeclaration instanceof DeclareDeclaration) {
  414. // return convert((DeclareDeclaration) methodDeclaration);
  415. // } else if (methodDeclaration instanceof InterTypeFieldDeclaration) {
  416. // return convert((InterTypeFieldDeclaration) methodDeclaration);
  417. // } else if (methodDeclaration instanceof InterTypeMethodDeclaration) {
  418. // methodDecl = new org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration(this.ast);
  419. // ((org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration) methodDecl)
  420. // .setOnType(((InterTypeMethodDeclaration) methodDeclaration).getOnType().toString());
  421. // } else if (methodDeclaration instanceof InterTypeConstructorDeclaration) {
  422. // methodDecl = new org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration(this.ast);
  423. // ((org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration) methodDecl)
  424. // .setOnType(((InterTypeConstructorDeclaration) methodDeclaration).getOnType().toString());
  425. // methodDecl.setConstructor(true);
  426. // } else if (methodDeclaration instanceof PointcutDeclaration) {
  427. // return convert((PointcutDeclaration) methodDeclaration);
  428. // } else if (methodDeclaration instanceof AdviceDeclaration) {
  429. // return convert((AdviceDeclaration) methodDeclaration);
  430. // }
  431. // // ///////////////////////
  432. //
  433. // // set modifiers after checking whether we're an itd, otherwise
  434. // // the modifiers are not set on the correct object.
  435. // setModifiers(methodDecl, methodDeclaration);
  436. //
  437. // // for ITD's use the declaredSelector
  438. // final SimpleName methodName = new SimpleName(this.ast);
  439. // if (methodDeclaration instanceof InterTypeDeclaration) {
  440. // InterTypeDeclaration itd = (InterTypeDeclaration) methodDeclaration;
  441. // methodName.internalSetIdentifier(new String(itd.getDeclaredSelector()));
  442. // } else {
  443. // methodName.internalSetIdentifier(new String(methodDeclaration.selector));
  444. // }
  445. // int start = methodDeclaration.sourceStart;
  446. // int end = retrieveIdentifierEndPosition(start, methodDeclaration.sourceEnd);
  447. // methodName.setSourceRange(start, end - start + 1);
  448. // methodDecl.setName(methodName);
  449. //
  450. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference[] thrownExceptions = methodDeclaration.thrownExceptions;
  451. // if (thrownExceptions != null) {
  452. // int thrownExceptionsLength = thrownExceptions.length;
  453. // for (int i = 0; i < thrownExceptionsLength; i++) {
  454. // methodDecl.thrownExceptions().add(convert(thrownExceptions[i]));
  455. // }
  456. // }
  457. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument[] parameters = methodDeclaration.arguments;
  458. // if (parameters != null) {
  459. // int parametersLength = parameters.length;
  460. // for (int i = 0; i < parametersLength; i++) {
  461. // methodDecl.parameters().add(convert(parameters[i]));
  462. // }
  463. // }
  464. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall explicitConstructorCall = null;
  465. // if (isConstructor) {
  466. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration constructorDeclaration = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration) methodDeclaration;
  467. // explicitConstructorCall = constructorDeclaration.constructorCall;
  468. // switch (this.ast.apiLevel) {
  469. // case AST.JLS2_INTERNAL:
  470. // // set the return type to VOID
  471. // PrimitiveType returnType = new PrimitiveType(this.ast);
  472. // returnType.setPrimitiveTypeCode(PrimitiveType.VOID);
  473. // returnType.setSourceRange(methodDeclaration.sourceStart, 0);
  474. // methodDecl.internalSetReturnType(returnType);
  475. // break;
  476. // case AST.JLS3:
  477. // methodDecl.setReturnType2(null);
  478. // }
  479. // } else if (methodDeclaration instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) {
  480. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration method = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) methodDeclaration;
  481. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference typeReference = method.returnType;
  482. // if (typeReference != null) {
  483. // Type returnType = convertType(typeReference);
  484. // // get the positions of the right parenthesis
  485. // int rightParenthesisPosition = retrieveEndOfRightParenthesisPosition(end, method.bodyEnd);
  486. // int extraDimensions = retrieveExtraDimension(rightParenthesisPosition, method.bodyEnd);
  487. // methodDecl.setExtraDimensions(extraDimensions);
  488. // setTypeForMethodDeclaration(methodDecl, returnType, extraDimensions);
  489. // }
  490. // }
  491. // int declarationSourceStart = methodDeclaration.declarationSourceStart;
  492. // int declarationSourceEnd = methodDeclaration.bodyEnd;
  493. // methodDecl.setSourceRange(declarationSourceStart, declarationSourceEnd - declarationSourceStart + 1);
  494. // int closingPosition = retrieveRightBraceOrSemiColonPosition(methodDeclaration.bodyEnd + 1,
  495. // methodDeclaration.declarationSourceEnd);
  496. // if (closingPosition != -1) {
  497. // int startPosition = methodDecl.getStartPosition();
  498. // methodDecl.setSourceRange(startPosition, closingPosition - startPosition + 1);
  499. //
  500. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.Statement[] statements = methodDeclaration.statements;
  501. //
  502. // start = retrieveStartBlockPosition(methodDeclaration.sourceStart, declarationSourceEnd);
  503. // end = retrieveEndBlockPosition(methodDeclaration.sourceStart, methodDeclaration.declarationSourceEnd);
  504. // Block block = null;
  505. // if (start != -1 && end != -1) {
  506. // /*
  507. // * start or end can be equal to -1 if we have an interface's method.
  508. // */
  509. // block = new Block(this.ast);
  510. // block.setSourceRange(start, end - start + 1);
  511. // methodDecl.setBody(block);
  512. // }
  513. // if (block != null && (statements != null || explicitConstructorCall != null)) {
  514. // if (explicitConstructorCall != null
  515. // && explicitConstructorCall.accessMode != org.aspectj.org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall.ImplicitSuper) {
  516. // block.statements().add(super.convert(explicitConstructorCall));
  517. // }
  518. // int statementsLength = statements == null ? 0 : statements.length;
  519. // for (int i = 0; i < statementsLength; i++) {
  520. // if (statements[i] instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
  521. // checkAndAddMultipleLocalDeclaration(statements, i, block.statements());
  522. // } else {
  523. // block.statements().add(convert(statements[i]));
  524. // }
  525. // }
  526. // }
  527. // if (block != null && (Modifier.isAbstract(methodDecl.getModifiers()) || Modifier.isNative(methodDecl.getModifiers()))) {
  528. // methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
  529. // }
  530. // } else {
  531. // // syntax error in this method declaration
  532. // if (!methodDeclaration.isNative() && !methodDeclaration.isAbstract()) {
  533. // start = retrieveStartBlockPosition(methodDeclaration.sourceStart, declarationSourceEnd);
  534. // end = methodDeclaration.bodyEnd;
  535. // // try to get the best end position
  536. // IProblem[] problems = methodDeclaration.compilationResult().problems;
  537. // if (problems != null) {
  538. // for (int i = 0, max = methodDeclaration.compilationResult().problemCount; i < max; i++) {
  539. // IProblem currentProblem = problems[i];
  540. // if (currentProblem.getSourceStart() == start
  541. // && currentProblem.getID() == IProblem.ParsingErrorInsertToComplete) {
  542. // end = currentProblem.getSourceEnd();
  543. // break;
  544. // }
  545. // }
  546. // }
  547. // int startPosition = methodDecl.getStartPosition();
  548. // methodDecl.setSourceRange(startPosition, end - startPosition + 1);
  549. // if (start != -1 && end != -1) {
  550. // /*
  551. // * start or end can be equal to -1 if we have an interface's method.
  552. // */
  553. // Block block = new Block(this.ast);
  554. // block.setSourceRange(start, end - start + 1);
  555. // methodDecl.setBody(block);
  556. // }
  557. // }
  558. // }
  559. //
  560. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParameters = methodDeclaration.typeParameters();
  561. // if (typeParameters != null) {
  562. // switch (this.ast.apiLevel) {
  563. // case AST.JLS2_INTERNAL:
  564. // methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
  565. // break;
  566. // case AST.JLS3:
  567. // for (int i = 0, max = typeParameters.length; i < max; i++) {
  568. // methodDecl.typeParameters().add(convert(typeParameters[i]));
  569. // }
  570. // }
  571. // }
  572. //
  573. // // The javadoc comment is now got from list store in compilation unit declaration
  574. // if (this.resolveBindings) {
  575. // recordNodes(methodDecl, methodDeclaration);
  576. // recordNodes(methodName, methodDeclaration);
  577. // if (methodDecl.resolveBinding() != null) {
  578. // convert(methodDeclaration.javadoc, methodDecl);
  579. // }
  580. // } else {
  581. // convert(methodDeclaration.javadoc, methodDecl);
  582. // }
  583. // return methodDecl;
  584. // }
  585. public ASTNode convert(DeclareDeclaration declareDecl) {
  586. checkCanceled(); // is this line needed?
  587. org.aspectj.org.eclipse.jdt.core.dom.DeclareDeclaration declareDeclaration = null;
  588. Declare declare = declareDecl.declareDecl;
  589. if (declare instanceof DeclareAnnotation) {
  590. DeclareAnnotation da = (DeclareAnnotation) declare;
  591. if (da.getKind().equals(DeclareAnnotation.AT_TYPE)) {
  592. declareDeclaration = new DeclareAtTypeDeclaration(this.ast);
  593. ((DeclareAtTypeDeclaration) declareDeclaration).setPatternNode(convert(da.getTypePattern()));
  594. SimpleName annotationName = new SimpleName(this.ast);
  595. annotationName.setSourceRange(da.getAnnotationSourceStart(),
  596. da.getAnnotationSourceEnd() - da.getAnnotationSourceStart());
  597. annotationName.internalSetIdentifier(da.getAnnotationString());
  598. ((DeclareAtTypeDeclaration) declareDeclaration).setAnnotationName(annotationName);
  599. } else if (da.getKind().equals(DeclareAnnotation.AT_CONSTRUCTOR)) {
  600. declareDeclaration = new DeclareAtConstructorDeclaration(this.ast);
  601. ((DeclareAtConstructorDeclaration) declareDeclaration).setPatternNode(convertSignature(da.getSignaturePattern()));
  602. SimpleName annotationName = new SimpleName(this.ast);
  603. annotationName.setSourceRange(da.getAnnotationSourceStart(),
  604. da.getAnnotationSourceEnd() - da.getAnnotationSourceStart());
  605. annotationName.internalSetIdentifier(da.getAnnotationString());
  606. ((DeclareAtConstructorDeclaration) declareDeclaration).setAnnotationName(annotationName);
  607. } else if (da.getKind().equals(DeclareAnnotation.AT_FIELD)) {
  608. declareDeclaration = new DeclareAtFieldDeclaration(this.ast);
  609. ((DeclareAtFieldDeclaration) declareDeclaration).setPatternNode(convertSignature(da.getSignaturePattern()));
  610. SimpleName annotationName = new SimpleName(this.ast);
  611. annotationName.setSourceRange(da.getAnnotationSourceStart(),
  612. da.getAnnotationSourceEnd() - da.getAnnotationSourceStart());
  613. annotationName.internalSetIdentifier(da.getAnnotationString());
  614. ((DeclareAtFieldDeclaration) declareDeclaration).setAnnotationName(annotationName);
  615. } else if (da.getKind().equals(DeclareAnnotation.AT_METHOD)) {
  616. declareDeclaration = new DeclareAtMethodDeclaration(this.ast);
  617. ((DeclareAtMethodDeclaration) declareDeclaration).setPatternNode(convertSignature(da.getSignaturePattern()));
  618. SimpleName annotationName = new SimpleName(this.ast);
  619. annotationName.setSourceRange(da.getAnnotationSourceStart(),
  620. da.getAnnotationSourceEnd() - da.getAnnotationSourceStart());
  621. annotationName.internalSetIdentifier(da.getAnnotationString());
  622. ((DeclareAtMethodDeclaration) declareDeclaration).setAnnotationName(annotationName);
  623. }
  624. } else if (declare instanceof DeclareErrorOrWarning) {
  625. DeclareErrorOrWarning deow = (DeclareErrorOrWarning) declare;
  626. if (deow.isError()) {
  627. declareDeclaration = new DeclareErrorDeclaration(this.ast);
  628. ((DeclareErrorDeclaration) declareDeclaration).setPointcut(convert(deow.getPointcut()));
  629. StringLiteral message = new StringLiteral(this.ast);
  630. message.setEscapedValue(updateString(deow.getMessage()));
  631. ((DeclareErrorDeclaration) declareDeclaration).setMessage(message);
  632. } else {
  633. declareDeclaration = new DeclareWarningDeclaration(this.ast);
  634. ((DeclareWarningDeclaration) declareDeclaration).setPointcut(convert(deow.getPointcut()));
  635. StringLiteral message = new StringLiteral(this.ast);
  636. message.setEscapedValue(updateString(deow.getMessage()));
  637. ((DeclareWarningDeclaration) declareDeclaration).setMessage(message);
  638. }
  639. } else if (declare instanceof DeclareParents) {
  640. DeclareParents dp = (DeclareParents) declare;
  641. declareDeclaration = new org.aspectj.org.eclipse.jdt.core.dom.DeclareParentsDeclaration(this.ast, dp.isExtends());
  642. org.aspectj.org.eclipse.jdt.core.dom.PatternNode pNode = convert(dp.getChild());
  643. if (pNode instanceof AbstractTypePattern) {
  644. ((DeclareParentsDeclaration) declareDeclaration)
  645. .setChildTypePattern((AbstractTypePattern) pNode);
  646. }
  647. TypePattern[] weaverTypePatterns = dp.getParents().getTypePatterns();
  648. List typePatterns = ((DeclareParentsDeclaration) declareDeclaration).parentTypePatterns();
  649. for (TypePattern weaverTypePattern : weaverTypePatterns) {
  650. typePatterns.add(convert(weaverTypePattern));
  651. }
  652. } else if (declare instanceof DeclarePrecedence) {
  653. declareDeclaration = new org.aspectj.org.eclipse.jdt.core.dom.DeclarePrecedenceDeclaration(this.ast);
  654. DeclarePrecedence dp = (DeclarePrecedence) declare;
  655. TypePattern[] weaverTypePatterns = dp.getPatterns().getTypePatterns();
  656. List typePatterns = ((DeclarePrecedenceDeclaration) declareDeclaration).typePatterns();
  657. for (TypePattern weaverTypePattern : weaverTypePatterns) {
  658. typePatterns.add(convert(weaverTypePattern));
  659. }
  660. } else if (declare instanceof DeclareSoft) {
  661. declareDeclaration = new DeclareSoftDeclaration(this.ast);
  662. DeclareSoft ds = (DeclareSoft) declare;
  663. ((DeclareSoftDeclaration) declareDeclaration).setPointcut(convert(ds.getPointcut()));
  664. org.aspectj.org.eclipse.jdt.core.dom.PatternNode pNode = convert(ds.getException());
  665. if (pNode instanceof AbstractTypePattern) {
  666. ((DeclareSoftDeclaration) declareDeclaration)
  667. .setTypePattern((AbstractTypePattern) pNode);
  668. }
  669. }
  670. if (declareDeclaration != null) {
  671. declareDeclaration.setSourceRange(declareDecl.declarationSourceStart, declareDecl.declarationSourceEnd
  672. - declareDecl.declarationSourceStart + 1);
  673. }
  674. return declareDeclaration;
  675. }
  676. private String updateString(String message) {
  677. StringBuilder sb = new StringBuilder(message);
  678. int nextQuote = sb.toString().indexOf("\"");
  679. while (nextQuote != -1) {
  680. sb.insert(nextQuote, "\\");
  681. nextQuote = sb.toString().indexOf("\"");
  682. }
  683. int nextNewLine = sb.toString().indexOf("\n");
  684. while (nextNewLine != -1) {
  685. sb.insert(nextNewLine, "\\");
  686. nextNewLine = sb.toString().indexOf("\n");
  687. }
  688. if (!sb.toString().startsWith("\"")) {
  689. sb.insert(0, "\"");
  690. }
  691. if (!sb.toString().endsWith("\"")) {
  692. sb.insert(sb.toString().length(), "\"");
  693. }
  694. return sb.toString();
  695. }
  696. public ASTNode convert(InterTypeFieldDeclaration fieldDecl) {
  697. // ajh02: method added
  698. checkCanceled(); // ajh02: is this line needed?
  699. VariableDeclarationFragment variableDeclarationFragment = convertToVariableDeclarationFragment(fieldDecl);
  700. final org.aspectj.org.eclipse.jdt.core.dom.InterTypeFieldDeclaration fieldDeclaration = new org.aspectj.org.eclipse.jdt.core.dom.InterTypeFieldDeclaration(
  701. this.ast);
  702. fieldDeclaration.fragments().add(variableDeclarationFragment);
  703. IVariableBinding binding = null;
  704. if (this.resolveBindings) {
  705. recordNodes(variableDeclarationFragment, fieldDecl);
  706. binding = variableDeclarationFragment.resolveBinding();
  707. }
  708. fieldDeclaration.setSourceRange(fieldDecl.declarationSourceStart, fieldDecl.declarationSourceEnd
  709. - fieldDecl.declarationSourceStart + 1);
  710. Type type = convertType(fieldDecl.returnType);
  711. setTypeForField(fieldDeclaration, type, variableDeclarationFragment.getExtraDimensions());
  712. setModifiers(fieldDeclaration, fieldDecl);
  713. if (!(this.resolveBindings && binding == null)) {
  714. convert(fieldDecl.javadoc, fieldDeclaration);
  715. }
  716. fieldDeclaration.setOnType(fieldDecl.getOnType().toString());
  717. return fieldDeclaration;
  718. }
  719. public ASTNode convert(PointcutDeclaration pointcutDeclaration) {
  720. // ajh02: method added
  721. checkCanceled();
  722. org.aspectj.org.eclipse.jdt.core.dom.PointcutDeclaration pointcutDecl = new org.aspectj.org.eclipse.jdt.core.dom.PointcutDeclaration(
  723. this.ast);
  724. setModifiers(pointcutDecl, pointcutDeclaration);
  725. final SimpleName pointcutName = new SimpleName(this.ast);
  726. pointcutName.internalSetIdentifier(new String(pointcutDeclaration.selector));
  727. int start = pointcutDeclaration.sourceStart;
  728. int end = retrieveIdentifierEndPosition(start, pointcutDeclaration.sourceEnd);
  729. pointcutName.setSourceRange(start, end - start + 1);
  730. pointcutDecl.setSourceRange(pointcutDeclaration.declarationSourceStart, (pointcutDeclaration.bodyEnd
  731. - pointcutDeclaration.declarationSourceStart + 1));
  732. pointcutDecl.setName(pointcutName);
  733. if (pointcutDeclaration.pointcutDesignator != null) {
  734. pointcutDecl.setDesignator(convert(pointcutDeclaration.pointcutDesignator.getPointcut()));
  735. } else {
  736. pointcutDecl.setDesignator(new org.aspectj.org.eclipse.jdt.core.dom.DefaultPointcut(this.ast, pointcutDeclaration
  737. .toString()));
  738. }
  739. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument[] parameters = pointcutDeclaration.arguments;
  740. if (parameters != null) {
  741. int parametersLength = parameters.length;
  742. for (Argument parameter : parameters) {
  743. pointcutDecl.parameters().add(convert(parameter));
  744. }
  745. }
  746. // The javadoc comment is now got from list store in compilation unit declaration
  747. if (this.resolveBindings) {
  748. recordNodes(pointcutDecl, pointcutDeclaration);
  749. recordNodes(pointcutName, pointcutDeclaration);
  750. } else {
  751. convert(pointcutDeclaration.javadoc, pointcutDecl);
  752. }
  753. return pointcutDecl;
  754. }
  755. public org.aspectj.org.eclipse.jdt.core.dom.PointcutDesignator convert(org.aspectj.weaver.patterns.Pointcut pointcut) {
  756. // ajh02: this could do with being seperate methods
  757. // rather than a huge if.elseif..elseif.. thing
  758. org.aspectj.org.eclipse.jdt.core.dom.PointcutDesignator pointcutDesi = null;
  759. if (pointcut instanceof org.aspectj.weaver.patterns.ReferencePointcut) {
  760. pointcutDesi = new org.aspectj.org.eclipse.jdt.core.dom.ReferencePointcut(this.ast);
  761. final SimpleName pointcutName = new SimpleName(this.ast);
  762. int start = pointcut.getStart();
  763. int end = retrieveIdentifierEndPosition(start, pointcut.getEnd());
  764. pointcutName.setSourceRange(start, end - start + 1);
  765. pointcutName.internalSetIdentifier(((org.aspectj.weaver.patterns.ReferencePointcut) pointcut).name);
  766. ((org.aspectj.org.eclipse.jdt.core.dom.ReferencePointcut) pointcutDesi).setName(pointcutName);
  767. } else if (pointcut instanceof org.aspectj.weaver.patterns.NotPointcut) {
  768. pointcutDesi = new org.aspectj.org.eclipse.jdt.core.dom.NotPointcut(this.ast);
  769. final org.aspectj.org.eclipse.jdt.core.dom.PointcutDesignator body = convert(((org.aspectj.weaver.patterns.NotPointcut) pointcut)
  770. .getNegatedPointcut());
  771. ((org.aspectj.org.eclipse.jdt.core.dom.NotPointcut) pointcutDesi).setBody(body);
  772. } else if (pointcut instanceof org.aspectj.weaver.patterns.PerObject) {
  773. pointcutDesi = new org.aspectj.org.eclipse.jdt.core.dom.PerObject(this.ast);
  774. final org.aspectj.org.eclipse.jdt.core.dom.PointcutDesignator body = convert(((org.aspectj.weaver.patterns.PerObject) pointcut)
  775. .getEntry());
  776. ((org.aspectj.org.eclipse.jdt.core.dom.PerObject) pointcutDesi).setBody(body);
  777. } else if (pointcut instanceof org.aspectj.weaver.patterns.PerCflow) {
  778. pointcutDesi = new org.aspectj.org.eclipse.jdt.core.dom.PerCflow(this.ast);
  779. final org.aspectj.org.eclipse.jdt.core.dom.PointcutDesignator body = convert(((org.aspectj.weaver.patterns.PerCflow) pointcut)
  780. .getEntry());
  781. ((org.aspectj.org.eclipse.jdt.core.dom.PerCflow) pointcutDesi).setBody(body);
  782. } else if (pointcut instanceof org.aspectj.weaver.patterns.PerTypeWithin) {
  783. pointcutDesi = new org.aspectj.org.eclipse.jdt.core.dom.PerTypeWithin(this.ast);
  784. // should set its type pattern here
  785. } else if (pointcut instanceof org.aspectj.weaver.patterns.CflowPointcut) {
  786. pointcutDesi = new org.aspectj.org.eclipse.jdt.core.dom.CflowPointcut(this.ast);
  787. final org.aspectj.org.eclipse.jdt.core.dom.PointcutDesignator body = convert(((org.aspectj.weaver.patterns.CflowPointcut) pointcut)
  788. .getEntry());
  789. ((org.aspectj.org.eclipse.jdt.core.dom.CflowPointcut) pointcutDesi).setBody(body);
  790. ((org.aspectj.org.eclipse.jdt.core.dom.CflowPointcut) pointcutDesi)
  791. .setIsCflowBelow(((org.aspectj.weaver.patterns.CflowPointcut) pointcut).isCflowBelow());
  792. } else if (pointcut instanceof org.aspectj.weaver.patterns.AndPointcut) {
  793. pointcutDesi = new org.aspectj.org.eclipse.jdt.core.dom.AndPointcut(this.ast);
  794. final org.aspectj.org.eclipse.jdt.core.dom.PointcutDesignator left = convert(((org.aspectj.weaver.patterns.AndPointcut) pointcut)
  795. .getLeft());
  796. final org.aspectj.org.eclipse.jdt.core.dom.PointcutDesignator right = convert(((org.aspectj.weaver.patterns.AndPointcut) pointcut)
  797. .getRight());
  798. ((org.aspectj.org.eclipse.jdt.core.dom.AndPointcut) pointcutDesi).setLeft(left);
  799. ((org.aspectj.org.eclipse.jdt.core.dom.AndPointcut) pointcutDesi).setRight(right);
  800. } else if (pointcut instanceof org.aspectj.weaver.patterns.OrPointcut) {
  801. pointcutDesi = new org.aspectj.org.eclipse.jdt.core.dom.OrPointcut(this.ast);
  802. final org.aspectj.org.eclipse.jdt.core.dom.PointcutDesignator left = convert(((org.aspectj.weaver.patterns.OrPointcut) pointcut)
  803. .getLeft());
  804. final org.aspectj.org.eclipse.jdt.core.dom.PointcutDesignator right = convert(((org.aspectj.weaver.patterns.OrPointcut) pointcut)
  805. .getRight());
  806. ((org.aspectj.org.eclipse.jdt.core.dom.OrPointcut) pointcutDesi).setLeft(left);
  807. ((org.aspectj.org.eclipse.jdt.core.dom.OrPointcut) pointcutDesi).setRight(right);
  808. } else {
  809. // ajh02: default stub until I make all the concrete PointcutDesignator types
  810. pointcutDesi = new org.aspectj.org.eclipse.jdt.core.dom.DefaultPointcut(this.ast, pointcut.toString());
  811. }
  812. pointcutDesi.setSourceRange(pointcut.getStart(), (pointcut.getEnd() - pointcut.getStart() + 1));
  813. return pointcutDesi;
  814. }
  815. public org.aspectj.org.eclipse.jdt.core.dom.SignaturePattern convertSignature(ISignaturePattern patternNode) {
  816. org.aspectj.org.eclipse.jdt.core.dom.SignaturePattern pNode = null;
  817. if (patternNode instanceof SignaturePattern) {
  818. SignaturePattern sigPat = (SignaturePattern) patternNode;
  819. pNode = new org.aspectj.org.eclipse.jdt.core.dom.SignaturePattern(this.ast, sigPat.toString());
  820. pNode.setSourceRange(sigPat.getStart(), (sigPat.getEnd() - sigPat.getStart() + 1));
  821. } else {
  822. throw new IllegalStateException("Not yet implemented for " + patternNode.getClass());
  823. }
  824. return pNode;
  825. }
  826. public org.aspectj.org.eclipse.jdt.core.dom.PatternNode convert(
  827. PatternNode patternNode) {
  828. org.aspectj.org.eclipse.jdt.core.dom.PatternNode pNode = null;
  829. if (patternNode instanceof TypePattern) {
  830. TypePattern weaverTypePattern = (TypePattern) patternNode;
  831. return convert(weaverTypePattern);
  832. } else if (patternNode instanceof SignaturePattern) {
  833. SignaturePattern sigPat = (SignaturePattern) patternNode;
  834. pNode = new org.aspectj.org.eclipse.jdt.core.dom.SignaturePattern(this.ast, sigPat.toString());
  835. pNode.setSourceRange(sigPat.getStart(), (sigPat.getEnd() - sigPat.getStart() + 1));
  836. }
  837. return pNode;
  838. }
  839. public AbstractTypePattern convert(
  840. TypePattern weaverNode) {
  841. // First check if the node is a Java type (WildType, ExactType,
  842. // BindingType)
  843. AbstractTypePattern domNode = createIdentifierTypePattern(weaverNode);
  844. if (domNode == null) {
  845. if (weaverNode instanceof org.aspectj.weaver.patterns.EllipsisTypePattern) {
  846. domNode = new org.aspectj.org.eclipse.jdt.core.dom.EllipsisTypePattern(
  847. ast);
  848. } else if (weaverNode instanceof org.aspectj.weaver.patterns.NoTypePattern) {
  849. domNode = new org.aspectj.org.eclipse.jdt.core.dom.NoTypePattern(
  850. ast);
  851. } else if (weaverNode instanceof org.aspectj.weaver.patterns.AnyTypePattern) {
  852. domNode = new org.aspectj.org.eclipse.jdt.core.dom.AnyTypePattern(
  853. ast);
  854. } else if (weaverNode instanceof org.aspectj.weaver.patterns.AnyWithAnnotationTypePattern) {
  855. // For now construct the node with just the annotation
  856. // expression
  857. String annotationExpression = ((org.aspectj.weaver.patterns.AnyWithAnnotationTypePattern) weaverNode)
  858. .toString();
  859. domNode = new org.aspectj.org.eclipse.jdt.core.dom.AnyWithAnnotationTypePattern(
  860. ast, annotationExpression);
  861. } else if (weaverNode instanceof org.aspectj.weaver.patterns.OrTypePattern) {
  862. org.aspectj.weaver.patterns.OrTypePattern compilerOrNode = (org.aspectj.weaver.patterns.OrTypePattern) weaverNode;
  863. domNode = new OrTypePattern(this.ast,
  864. convert(compilerOrNode.getLeft()),
  865. convert(compilerOrNode.getRight()));
  866. } else if (weaverNode instanceof org.aspectj.weaver.patterns.AndTypePattern) {
  867. org.aspectj.weaver.patterns.AndTypePattern compilerAndType = (org.aspectj.weaver.patterns.AndTypePattern) weaverNode;
  868. domNode = new org.aspectj.org.eclipse.jdt.core.dom.AndTypePattern(
  869. this.ast, convert(compilerAndType.getLeft()),
  870. convert(compilerAndType.getRight()));
  871. } else if (weaverNode instanceof org.aspectj.weaver.patterns.NotTypePattern) {
  872. //NOTE: the source range for not type patterns is the source range of the negated type pattern
  873. // EXCLUDING the "!" character. Example: !A. If A starts at 1, the source starting point for the
  874. // nottypepattern is 1, NOT 0.
  875. TypePattern negatedTypePattern = ((org.aspectj.weaver.patterns.NotTypePattern) weaverNode)
  876. .getNegatedPattern();
  877. AbstractTypePattern negatedDomTypePattern = convert(negatedTypePattern);
  878. domNode = new org.aspectj.org.eclipse.jdt.core.dom.NotTypePattern(
  879. ast, negatedDomTypePattern);
  880. } else if (weaverNode instanceof org.aspectj.weaver.patterns.TypeCategoryTypePattern) {
  881. org.aspectj.weaver.patterns.TypeCategoryTypePattern typeCategoryWeaverNode = (org.aspectj.weaver.patterns.TypeCategoryTypePattern) weaverNode;
  882. domNode = new org.aspectj.org.eclipse.jdt.core.dom.TypeCategoryTypePattern(
  883. ast, typeCategoryWeaverNode.getTypeCategory());
  884. } else if (weaverNode instanceof org.aspectj.weaver.patterns.HasMemberTypePattern) {
  885. ISignaturePattern weaverSignature = ((org.aspectj.weaver.patterns.HasMemberTypePattern) weaverNode)
  886. .getSignaturePattern();
  887. org.aspectj.org.eclipse.jdt.core.dom.SignaturePattern signature = convertSignature(weaverSignature);
  888. domNode = new org.aspectj.org.eclipse.jdt.core.dom.HasMemberTypePattern(
  889. ast, signature);
  890. } else {
  891. // Handle any cases that are not yet implemented. Create a
  892. // default node for
  893. // them.
  894. domNode = new DefaultTypePattern(this.ast,
  895. weaverNode.toString());
  896. }
  897. }
  898. if (domNode != null) {
  899. domNode.setSourceRange(weaverNode.getStart(), (weaverNode.getEnd()
  900. - weaverNode.getStart() + 1));
  901. }
  902. return domNode;
  903. }
  904. /**
  905. * Creates an ExactType, WildType, or BindingType, or null if none of the
  906. * three can be created
  907. *
  908. * @param weaverTypePattern
  909. * to convert to a DOM equivalent
  910. * @return DOM node or null if it was not created
  911. */
  912. protected AbstractTypePattern createIdentifierTypePattern(
  913. TypePattern weaverTypePattern) {
  914. String typeExpression = weaverTypePattern.toString();
  915. AbstractTypePattern domTypePattern = null;
  916. if (weaverTypePattern instanceof org.aspectj.weaver.patterns.WildTypePattern) {
  917. // Use the expression for wild type patterns as a Name may not be
  918. // constructed
  919. // for a Type with a unresolved typeExpression
  920. domTypePattern = new org.aspectj.org.eclipse.jdt.core.dom.WildTypePattern(
  921. ast, typeExpression);
  922. } else {
  923. // TODO: At this point, the type pattern should be resolved. Type
  924. // information
  925. // may be able to be obtained from the exact type in the weaver
  926. // pattern, therefore
  927. // replace using the expression to construct the Type and use more
  928. // appropriate
  929. // information obtained from the exact type
  930. if (weaverTypePattern instanceof org.aspectj.weaver.patterns.ExactTypePattern) {
  931. Type type = this.ast.newSimpleType(this.ast
  932. .newSimpleName(typeExpression));
  933. domTypePattern = new ExactTypePattern(ast, type);
  934. } else if (weaverTypePattern instanceof org.aspectj.weaver.patterns.BindingTypePattern) {
  935. Type type = this.ast.newSimpleType(this.ast
  936. .newSimpleName(typeExpression));
  937. String binding = ((org.aspectj.weaver.patterns.BindingTypePattern) weaverTypePattern)
  938. .getBindingName();
  939. FormalBinding formalBinding = new FormalBinding(type, binding,
  940. ast);
  941. domTypePattern = new org.aspectj.org.eclipse.jdt.core.dom.BindingTypePattern(
  942. ast, formalBinding);
  943. }
  944. }
  945. return domTypePattern;
  946. }
  947. public ASTNode convert(
  948. org.aspectj.org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration annotationTypeMemberDeclaration) {
  949. checkCanceled();
  950. if (this.ast.apiLevel == AST.JLS2_INTERNAL) {
  951. return null;
  952. }
  953. AnnotationTypeMemberDeclaration annotationTypeMemberDeclaration2 = new AnnotationTypeMemberDeclaration(this.ast);
  954. setModifiers(annotationTypeMemberDeclaration2, annotationTypeMemberDeclaration);
  955. final SimpleName methodName = new SimpleName(this.ast);
  956. methodName.internalSetIdentifier(new String(annotationTypeMemberDeclaration.selector));
  957. int start = annotationTypeMemberDeclaration.sourceStart;
  958. int end = retrieveIdentifierEndPosition(start, annotationTypeMemberDeclaration.sourceEnd);
  959. methodName.setSourceRange(start, end - start + 1);
  960. annotationTypeMemberDeclaration2.setName(methodName);
  961. org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference typeReference = annotationTypeMemberDeclaration.returnType;
  962. if (typeReference != null) {
  963. Type returnType = convertType(typeReference);
  964. setTypeForMethodDeclaration(annotationTypeMemberDeclaration2, returnType, 0);
  965. }
  966. int declarationSourceStart = annotationTypeMemberDeclaration.declarationSourceStart;
  967. int declarationSourceEnd = annotationTypeMemberDeclaration.bodyEnd;
  968. annotationTypeMemberDeclaration2.setSourceRange(declarationSourceStart, declarationSourceEnd - declarationSourceStart + 1);
  969. // The javadoc comment is now got from list store in compilation unit declaration
  970. convert(annotationTypeMemberDeclaration.javadoc, annotationTypeMemberDeclaration2);
  971. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression memberValue = annotationTypeMemberDeclaration.defaultValue;
  972. if (memberValue != null) {
  973. annotationTypeMemberDeclaration2.setDefault(super.convert(memberValue));
  974. }
  975. if (this.resolveBindings) {
  976. recordNodes(annotationTypeMemberDeclaration2, annotationTypeMemberDeclaration);
  977. recordNodes(methodName, annotationTypeMemberDeclaration);
  978. annotationTypeMemberDeclaration2.resolveBinding();
  979. }
  980. return annotationTypeMemberDeclaration2;
  981. }
  982. public SingleVariableDeclaration convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument argument) {
  983. SingleVariableDeclaration variableDecl = new SingleVariableDeclaration(this.ast);
  984. setModifiers(variableDecl, argument);
  985. final SimpleName name = new SimpleName(this.ast);
  986. name.internalSetIdentifier(new String(argument.name));
  987. int start = argument.sourceStart;
  988. int nameEnd = argument.sourceEnd;
  989. name.setSourceRange(start, nameEnd - start + 1);
  990. variableDecl.setName(name);
  991. final int typeSourceEnd = argument.type.sourceEnd;
  992. final int extraDimensions = retrieveExtraDimension(nameEnd + 1, typeSourceEnd);
  993. variableDecl.setExtraDimensions(extraDimensions);
  994. final boolean isVarArgs = argument.isVarArgs();
  995. if (isVarArgs && extraDimensions == 0) {
  996. // remove the ellipsis from the type source end
  997. argument.type.sourceEnd = retrieveEllipsisStartPosition(argument.type.sourceStart, typeSourceEnd);
  998. }
  999. Type type = convertType(argument.type);
  1000. int typeEnd = type.getStartPosition() + type.getLength() - 1;
  1001. int rightEnd = Math.max(typeEnd, argument.declarationSourceEnd);
  1002. /*
  1003. * There is extra work to do to set the proper type positions See PR http://bugs.eclipse.org/bugs/show_bug.cgi?id=23284
  1004. */
  1005. if (isVarArgs) {
  1006. setTypeForSingleVariableDeclaration(variableDecl, type, extraDimensions + 1);
  1007. if (extraDimensions != 0) {
  1008. variableDecl.setFlags(variableDecl.getFlags() | ASTNode.MALFORMED);
  1009. }
  1010. } else {
  1011. setTypeForSingleVariableDeclaration(variableDecl, type, extraDimensions);
  1012. }
  1013. variableDecl.setSourceRange(argument.declarationSourceStart, rightEnd - argument.declarationSourceStart + 1);
  1014. if (isVarArgs) {
  1015. switch (this.ast.apiLevel) {
  1016. case AST.JLS2_INTERNAL:
  1017. variableDecl.setFlags(variableDecl.getFlags() | ASTNode.MALFORMED);
  1018. break;
  1019. case AST.JLS3:
  1020. variableDecl.setVarargs(true);
  1021. }
  1022. }
  1023. if (this.resolveBindings) {
  1024. recordNodes(name, argument);
  1025. recordNodes(variableDecl, argument);
  1026. variableDecl.resolveBinding();
  1027. }
  1028. return variableDecl;
  1029. }
  1030. // public Annotation convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation annotation) {
  1031. // if (annotation instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation) {
  1032. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation) annotation);
  1033. // } else if (annotation instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation) {
  1034. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation ma =
  1035. // (org.aspectj.org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation) annotation;
  1036. // return convert( ma);//(org.aspectj.org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation) annotation);
  1037. // } else {
  1038. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.NormalAnnotation) annotation);
  1039. // }
  1040. // }
  1041. // public ArrayCreation convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression expression) {
  1042. // ArrayCreation arrayCreation = new ArrayCreation(this.ast);
  1043. // if (this.resolveBindings) {
  1044. // recordNodes(arrayCreation, expression);
  1045. // }
  1046. // arrayCreation.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
  1047. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression[] dimensions = expression.dimensions;
  1048. //
  1049. // int dimensionsLength = dimensions.length;
  1050. // for (int i = 0; i < dimensionsLength; i++) {
  1051. // if (dimensions[i] != null) {
  1052. // Expression dimension = convert(dimensions[i]);
  1053. // if (this.resolveBindings) {
  1054. // recordNodes(dimension, dimensions[i]);
  1055. // }
  1056. // arrayCreation.dimensions().add(dimension);
  1057. // }
  1058. // }
  1059. // Type type = convertType(expression.type);
  1060. // if (this.resolveBindings) {
  1061. // recordNodes(type, expression.type);
  1062. // }
  1063. // ArrayType arrayType = null;
  1064. // if (type.isArrayType()) {
  1065. // arrayType = (ArrayType) type;
  1066. // } else {
  1067. // arrayType = this.ast.newArrayType(type, dimensionsLength);
  1068. // if (this.resolveBindings) {
  1069. // completeRecord(arrayType, expression);
  1070. // }
  1071. // int start = type.getStartPosition();
  1072. // int end = type.getStartPosition() + type.getLength();
  1073. // int previousSearchStart = end;
  1074. // ArrayType componentType = (ArrayType) type.getParent();
  1075. // for (int i = 0; i < dimensionsLength; i++) {
  1076. // previousSearchStart = retrieveRightBracketPosition(previousSearchStart + 1, this.compilationUnitSourceLength);
  1077. // componentType.setSourceRange(start, previousSearchStart - start + 1);
  1078. // componentType = (ArrayType) componentType.getParent();
  1079. // }
  1080. // }
  1081. // arrayCreation.setType(arrayType);
  1082. // if (this.resolveBindings) {
  1083. // recordNodes(arrayType, expression);
  1084. // }
  1085. // if (expression.initializer != null) {
  1086. // arrayCreation.setInitializer(convert(expression.initializer));
  1087. // }
  1088. // return arrayCreation;
  1089. // }
  1090. public ArrayInitializer convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayInitializer expression) {
  1091. ArrayInitializer arrayInitializer = new ArrayInitializer(this.ast);
  1092. if (this.resolveBindings) {
  1093. recordNodes(arrayInitializer, expression);
  1094. }
  1095. arrayInitializer.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
  1096. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression[] expressions = expression.expressions;
  1097. if (expressions != null) {
  1098. int length = expressions.length;
  1099. for (org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression value : expressions) {
  1100. Expression expr = super.convert(value);
  1101. if (this.resolveBindings) {
  1102. recordNodes(expr, value);
  1103. }
  1104. arrayInitializer.expressions().add(expr);
  1105. }
  1106. }
  1107. return arrayInitializer;
  1108. }
  1109. // public ArrayAccess convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayReference reference) {
  1110. // ArrayAccess arrayAccess = new ArrayAccess(this.ast);
  1111. // if (this.resolveBindings) {
  1112. // recordNodes(arrayAccess, reference);
  1113. // }
  1114. // arrayAccess.setSourceRange(reference.sourceStart, reference.sourceEnd - reference.sourceStart + 1);
  1115. // arrayAccess.setArray(convert(reference.receiver));
  1116. // arrayAccess.setIndex(convert(reference.position));
  1117. // return arrayAccess;
  1118. // }
  1119. // public AssertStatement convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.AssertStatement statement) {
  1120. // AssertStatement assertStatement = new AssertStatement(this.ast);
  1121. // int end = statement.assertExpression.sourceEnd + 1;
  1122. // assertStatement.setExpression(convert(statement.assertExpression));
  1123. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression exceptionArgument = statement.exceptionArgument;
  1124. // if (exceptionArgument != null) {
  1125. // end = exceptionArgument.sourceEnd + 1;
  1126. // assertStatement.setMessage(convert(exceptionArgument));
  1127. // }
  1128. // int start = statement.sourceStart;
  1129. // int sourceEnd = retrieveEndingSemiColonPosition(end, this.compilationUnitSourceLength);
  1130. // assertStatement.setSourceRange(start, sourceEnd - start + 1);
  1131. // return assertStatement;
  1132. // }
  1133. // public Assignment convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Assignment expression) {
  1134. // Assignment assignment = new Assignment(this.ast);
  1135. // if (this.resolveBindings) {
  1136. // recordNodes(assignment, expression);
  1137. // }
  1138. // Expression lhs = convert(expression.lhs);
  1139. // assignment.setLeftHandSide(lhs);
  1140. // assignment.setOperator(Assignment.Operator.ASSIGN);
  1141. // assignment.setRightHandSide(convert(expression.expression));
  1142. // int start = lhs.getStartPosition();
  1143. // assignment.setSourceRange(start, expression.sourceEnd - start + 1);
  1144. // return assignment;
  1145. // }
  1146. /*
  1147. * Internal use only Used to convert class body declarations
  1148. */
  1149. // public TypeDeclaration convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode[] nodes) {
  1150. // final TypeDeclaration typeDecl = TypeDeclaration.getTypeDeclaration(this.ast);
  1151. // typeDecl.setInterface(false);
  1152. // int nodesLength = nodes.length;
  1153. // for (int i = 0; i < nodesLength; i++) {
  1154. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode node = nodes[i];
  1155. // if (node instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.Initializer) {
  1156. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.Initializer oldInitializer = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.Initializer) node;
  1157. // Initializer initializer = new Initializer(this.ast);
  1158. // initializer.setBody(convert(oldInitializer.block));
  1159. // setModifiers(initializer, oldInitializer);
  1160. // initializer.setSourceRange(oldInitializer.declarationSourceStart, oldInitializer.sourceEnd
  1161. // - oldInitializer.declarationSourceStart + 1);
  1162. // // setJavaDocComment(initializer);
  1163. // // initializer.setJavadoc(convert(oldInitializer.javadoc));
  1164. // convert(oldInitializer.javadoc, initializer);
  1165. // typeDecl.bodyDeclarations().add(initializer);
  1166. // } else if (node instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) {
  1167. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node;
  1168. // if (i > 0
  1169. // && (nodes[i - 1] instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldDeclaration)
  1170. // && ((org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) nodes[i - 1]).declarationSourceStart == fieldDeclaration.declarationSourceStart) {
  1171. // // we have a multiple field declaration
  1172. // // We retrieve the existing fieldDeclaration to add the new VariableDeclarationFragment
  1173. // FieldDeclaration currentFieldDeclaration = (FieldDeclaration) typeDecl.bodyDeclarations().get(
  1174. // typeDecl.bodyDeclarations().size() - 1);
  1175. // currentFieldDeclaration.fragments().add(convertToVariableDeclarationFragment(fieldDeclaration));
  1176. // } else {
  1177. // // we can create a new FieldDeclaration
  1178. // typeDecl.bodyDeclarations().add(convertToFieldDeclaration(fieldDeclaration));
  1179. // }
  1180. // } else if (node instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration) {
  1181. // AbstractMethodDeclaration nextMethodDeclaration = (AbstractMethodDeclaration) node;
  1182. // if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) {
  1183. // typeDecl.bodyDeclarations().add(convert(nextMethodDeclaration));
  1184. // }
  1185. // } else if (node instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) {
  1186. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration nextMemberDeclaration = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node;
  1187. // ASTNode nextMemberDeclarationNode = convert(nextMemberDeclaration);
  1188. // if (nextMemberDeclarationNode == null) {
  1189. // typeDecl.setFlags(typeDecl.getFlags() | ASTNode.MALFORMED);
  1190. // } else {
  1191. // typeDecl.bodyDeclarations().add(nextMemberDeclarationNode);
  1192. // }
  1193. // }
  1194. // }
  1195. // return typeDecl;
  1196. // }
  1197. // public Expression convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.BinaryExpression expression) {
  1198. // InfixExpression infixExpression = new InfixExpression(this.ast);
  1199. // if (this.resolveBindings) {
  1200. // this.recordNodes(infixExpression, expression);
  1201. // }
  1202. //
  1203. // int expressionOperatorID = (expression.bits & org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode.OperatorMASK) >>
  1204. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode.OperatorSHIFT;
  1205. // switch (expressionOperatorID) {
  1206. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.EQUAL_EQUAL :
  1207. // infixExpression.setOperator(InfixExpression.Operator.EQUALS);
  1208. // break;
  1209. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.LESS_EQUAL :
  1210. // infixExpression.setOperator(InfixExpression.Operator.LESS_EQUALS);
  1211. // break;
  1212. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.GREATER_EQUAL :
  1213. // infixExpression.setOperator(InfixExpression.Operator.GREATER_EQUALS);
  1214. // break;
  1215. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.NOT_EQUAL :
  1216. // infixExpression.setOperator(InfixExpression.Operator.NOT_EQUALS);
  1217. // break;
  1218. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.LEFT_SHIFT :
  1219. // infixExpression.setOperator(InfixExpression.Operator.LEFT_SHIFT);
  1220. // break;
  1221. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.RIGHT_SHIFT :
  1222. // infixExpression.setOperator(InfixExpression.Operator.RIGHT_SHIFT_SIGNED);
  1223. // break;
  1224. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.UNSIGNED_RIGHT_SHIFT :
  1225. // infixExpression.setOperator(InfixExpression.Operator.RIGHT_SHIFT_UNSIGNED);
  1226. // break;
  1227. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.OR_OR :
  1228. // infixExpression.setOperator(InfixExpression.Operator.CONDITIONAL_OR);
  1229. // break;
  1230. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.AND_AND :
  1231. // infixExpression.setOperator(InfixExpression.Operator.CONDITIONAL_AND);
  1232. // break;
  1233. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.PLUS :
  1234. // infixExpression.setOperator(InfixExpression.Operator.PLUS);
  1235. // break;
  1236. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.MINUS :
  1237. // infixExpression.setOperator(InfixExpression.Operator.MINUS);
  1238. // break;
  1239. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.REMAINDER :
  1240. // infixExpression.setOperator(InfixExpression.Operator.REMAINDER);
  1241. // break;
  1242. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.XOR :
  1243. // infixExpression.setOperator(InfixExpression.Operator.XOR);
  1244. // break;
  1245. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.AND :
  1246. // infixExpression.setOperator(InfixExpression.Operator.AND);
  1247. // break;
  1248. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.MULTIPLY :
  1249. // infixExpression.setOperator(InfixExpression.Operator.TIMES);
  1250. // break;
  1251. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.OR :
  1252. // infixExpression.setOperator(InfixExpression.Operator.OR);
  1253. // break;
  1254. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.DIVIDE :
  1255. // infixExpression.setOperator(InfixExpression.Operator.DIVIDE);
  1256. // break;
  1257. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.GREATER :
  1258. // infixExpression.setOperator(InfixExpression.Operator.GREATER);
  1259. // break;
  1260. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.LESS :
  1261. // infixExpression.setOperator(InfixExpression.Operator.LESS);
  1262. // }
  1263. //
  1264. // if (expression.left instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.BinaryExpression
  1265. // && ((expression.left.bits & org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode.ParenthesizedMASK) == 0)) {
  1266. // // create an extended string literal equivalent => use the extended operands list
  1267. // infixExpression.extendedOperands().add(convert(expression.right));
  1268. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression leftOperand = expression.left;
  1269. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression rightOperand = null;
  1270. // do {
  1271. // rightOperand = ((org.aspectj.org.eclipse.jdt.internal.compiler.ast.BinaryExpression) leftOperand).right;
  1272. // if ((((leftOperand.bits & org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode.OperatorMASK) >>
  1273. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode.OperatorSHIFT) != expressionOperatorID
  1274. // && ((leftOperand.bits & org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode.ParenthesizedMASK) == 0))
  1275. // || ((rightOperand instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.BinaryExpression
  1276. // && ((rightOperand.bits & org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode.OperatorMASK) >>
  1277. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode.OperatorSHIFT) != expressionOperatorID)
  1278. // && ((rightOperand.bits & org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode.ParenthesizedMASK) == 0))) {
  1279. // List extendedOperands = infixExpression.extendedOperands();
  1280. // InfixExpression temp = new InfixExpression(this.ast);
  1281. // if (this.resolveBindings) {
  1282. // this.recordNodes(temp, expression);
  1283. // }
  1284. // temp.setOperator(getOperatorFor(expressionOperatorID));
  1285. // Expression leftSide = convert(leftOperand);
  1286. // temp.setLeftOperand(leftSide);
  1287. // temp.setSourceRange(leftSide.getStartPosition(), leftSide.getLength());
  1288. // int size = extendedOperands.size();
  1289. // for (int i = 0; i < size - 1; i++) {
  1290. // Expression expr = temp;
  1291. // temp = new InfixExpression(this.ast);
  1292. //
  1293. // if (this.resolveBindings) {
  1294. // this.recordNodes(temp, expression);
  1295. // }
  1296. // temp.setLeftOperand(expr);
  1297. // temp.setOperator(getOperatorFor(expressionOperatorID));
  1298. // temp.setSourceRange(expr.getStartPosition(), expr.getLength());
  1299. // }
  1300. // infixExpression = temp;
  1301. // for (int i = 0; i < size; i++) {
  1302. // Expression extendedOperand = (Expression) extendedOperands.remove(size - 1 - i);
  1303. // temp.setRightOperand(extendedOperand);
  1304. // int startPosition = temp.getLeftOperand().getStartPosition();
  1305. // temp.setSourceRange(startPosition, extendedOperand.getStartPosition() + extendedOperand.getLength() - startPosition);
  1306. // if (temp.getLeftOperand().getNodeType() == ASTNode.INFIX_EXPRESSION) {
  1307. // temp = (InfixExpression) temp.getLeftOperand();
  1308. // }
  1309. // }
  1310. // int startPosition = infixExpression.getLeftOperand().getStartPosition();
  1311. // infixExpression.setSourceRange(startPosition, expression.sourceEnd - startPosition + 1);
  1312. // if (this.resolveBindings) {
  1313. // this.recordNodes(infixExpression, expression);
  1314. // }
  1315. // return infixExpression;
  1316. // }
  1317. // infixExpression.extendedOperands().add(0, convert(rightOperand));
  1318. // leftOperand = ((org.aspectj.org.eclipse.jdt.internal.compiler.ast.BinaryExpression) leftOperand).left;
  1319. // } while (leftOperand instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.BinaryExpression && ((leftOperand.bits &
  1320. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode.ParenthesizedMASK) == 0));
  1321. // Expression leftExpression = convert(leftOperand);
  1322. // infixExpression.setLeftOperand(leftExpression);
  1323. // infixExpression.setRightOperand((Expression)infixExpression.extendedOperands().remove(0));
  1324. // int startPosition = leftExpression.getStartPosition();
  1325. // infixExpression.setSourceRange(startPosition, expression.sourceEnd - startPosition + 1);
  1326. // return infixExpression;
  1327. // } else if (expression.left instanceof StringLiteralConcatenation
  1328. // && ((expression.left.bits & org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode.ParenthesizedMASK) == 0)) {
  1329. // StringLiteralConcatenation literal = (StringLiteralConcatenation) expression.left;
  1330. // final org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression[] stringLiterals = literal.literals;
  1331. // infixExpression.setLeftOperand(convert(stringLiterals[0]));
  1332. // infixExpression.setRightOperand(convert(stringLiterals[1]));
  1333. // for (int i = 2; i < literal.counter; i++) {
  1334. // infixExpression.extendedOperands().add(convert(stringLiterals[i]));
  1335. // }
  1336. // infixExpression.extendedOperands().add(convert(expression.right));
  1337. // int startPosition = literal.sourceStart;
  1338. // infixExpression.setSourceRange(startPosition, expression.sourceEnd - startPosition + 1);
  1339. // return infixExpression;
  1340. // }
  1341. // Expression leftExpression = convert(expression.left);
  1342. // infixExpression.setLeftOperand(leftExpression);
  1343. // infixExpression.setRightOperand(convert(expression.right));
  1344. // int startPosition = leftExpression.getStartPosition();
  1345. // infixExpression.setSourceRange(startPosition, expression.sourceEnd - startPosition + 1);
  1346. // return infixExpression;
  1347. // }
  1348. public Block convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Block statement) {
  1349. Block block = new Block(this.ast);
  1350. if (statement.sourceEnd > 0) {
  1351. block.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
  1352. }
  1353. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Statement[] statements = statement.statements;
  1354. if (statements != null) {
  1355. int statementsLength = statements.length;
  1356. for (int i = 0; i < statementsLength; i++) {
  1357. if (statements[i] instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
  1358. checkAndAddMultipleLocalDeclaration(statements, i, block.statements());
  1359. } else {
  1360. block.statements().add(convert(statements[i]));
  1361. }
  1362. }
  1363. }
  1364. return block;
  1365. }
  1366. public BreakStatement convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.BreakStatement statement) {
  1367. BreakStatement breakStatement = new BreakStatement(this.ast);
  1368. breakStatement.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
  1369. if (statement.label != null) {
  1370. final SimpleName name = new SimpleName(this.ast);
  1371. name.internalSetIdentifier(new String(statement.label));
  1372. retrieveIdentifierAndSetPositions(statement.sourceStart, statement.sourceEnd, name);
  1373. breakStatement.setLabel(name);
  1374. }
  1375. retrieveSemiColonPosition(breakStatement);
  1376. return breakStatement;
  1377. }
  1378. // public SwitchCase convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.CaseStatement statement) {
  1379. // SwitchCase switchCase = new SwitchCase(this.ast);
  1380. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression constantExpression = statement.constantExpression;
  1381. // if (constantExpression == null) {
  1382. // switchCase.setExpression(null);
  1383. // } else {
  1384. // switchCase.setExpression(convert(constantExpression));
  1385. // }
  1386. // switchCase.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
  1387. // retrieveColonPosition(switchCase);
  1388. // return switchCase;
  1389. // }
  1390. // public CastExpression convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.CastExpression expression) {
  1391. // CastExpression castExpression = new CastExpression(this.ast);
  1392. // castExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
  1393. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression type = expression.type;
  1394. // trimWhiteSpacesAndComments(type);
  1395. // if (type instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference ) {
  1396. // castExpression.setType(convertType((org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference)type));
  1397. // } else if (type instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.NameReference) {
  1398. // castExpression.setType(convertToType((org.aspectj.org.eclipse.jdt.internal.compiler.ast.NameReference)type));
  1399. // }
  1400. // castExpression.setExpression(convert(expression.expression));
  1401. // if (this.resolveBindings) {
  1402. // recordNodes(castExpression, expression);
  1403. // }
  1404. // return castExpression;
  1405. // }
  1406. public CharacterLiteral convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.CharLiteral expression) {
  1407. int length = expression.sourceEnd - expression.sourceStart + 1;
  1408. int sourceStart = expression.sourceStart;
  1409. CharacterLiteral literal = new CharacterLiteral(this.ast);
  1410. if (this.resolveBindings) {
  1411. this.recordNodes(literal, expression);
  1412. }
  1413. literal.internalSetEscapedValue(new String(this.compilationUnitSource, sourceStart, length));
  1414. literal.setSourceRange(sourceStart, length);
  1415. removeLeadingAndTrailingCommentsFromLiteral(literal);
  1416. return literal;
  1417. }
  1418. public Expression convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess expression) {
  1419. TypeLiteral typeLiteral = new TypeLiteral(this.ast);
  1420. if (this.resolveBindings) {
  1421. this.recordNodes(typeLiteral, expression);
  1422. }
  1423. typeLiteral.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
  1424. typeLiteral.setType(convertType(expression.type));
  1425. return typeLiteral;
  1426. }
  1427. public CompilationUnit convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration unit, char[] source) {
  1428. this.compilationUnitSource = source;
  1429. this.compilationUnitSourceLength = source.length;
  1430. this.scanner.setSource(source, unit.compilationResult);
  1431. CompilationUnit compilationUnit = new CompilationUnit(this.ast);
  1432. // Parse comments
  1433. int[][] comments = unit.comments;
  1434. if (comments != null) {
  1435. buildCommentsTable(compilationUnit, comments);
  1436. }
  1437. // handle the package declaration immediately
  1438. // There is no node corresponding to the package declaration
  1439. if (this.resolveBindings) {
  1440. recordNodes(compilationUnit, unit);
  1441. }
  1442. if (unit.currentPackage != null) {
  1443. PackageDeclaration packageDeclaration = convertPackage(unit);
  1444. compilationUnit.setPackage(packageDeclaration);
  1445. }
  1446. org.aspectj.org.eclipse.jdt.internal.compiler.ast.ImportReference[] imports = unit.imports;
  1447. if (imports != null) {
  1448. int importLength = imports.length;
  1449. for (org.aspectj.org.eclipse.jdt.internal.compiler.ast.ImportReference anImport : imports) {
  1450. compilationUnit.imports().add(convertImport(anImport));
  1451. }
  1452. }
  1453. org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = unit.types;
  1454. if (types != null) {
  1455. int typesLength = types.length;
  1456. for (org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration declaration : types) {
  1457. if (CharOperation.equals(declaration.name, TypeConstants.PACKAGE_INFO_NAME)) {
  1458. continue;
  1459. }
  1460. ASTNode type = convert(declaration);
  1461. if (type == null) {
  1462. compilationUnit.setFlags(compilationUnit.getFlags() | ASTNode.MALFORMED);
  1463. } else {
  1464. compilationUnit.types().add(type);
  1465. }
  1466. }
  1467. }
  1468. compilationUnit.setSourceRange(unit.sourceStart, unit.sourceEnd - unit.sourceStart + 1);
  1469. int problemLength = unit.compilationResult.problemCount;
  1470. if (problemLength != 0) {
  1471. CategorizedProblem[] resizedProblems = null;
  1472. final CategorizedProblem[] problems = unit.compilationResult.getProblems();
  1473. final int realProblemLength = problems.length;
  1474. if (realProblemLength == problemLength) {
  1475. resizedProblems = problems;
  1476. } else {
  1477. System.arraycopy(problems, 0, (resizedProblems = new CategorizedProblem[realProblemLength]), 0, realProblemLength);
  1478. }
  1479. ASTSyntaxErrorPropagator syntaxErrorPropagator = new ASTSyntaxErrorPropagator(resizedProblems);
  1480. compilationUnit.accept(syntaxErrorPropagator);
  1481. compilationUnit.setProblems(resizedProblems);
  1482. }
  1483. if (this.resolveBindings) {
  1484. lookupForScopes();
  1485. }
  1486. compilationUnit.initCommentMapper(this.scanner);
  1487. return compilationUnit;
  1488. }
  1489. // public Assignment convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompoundAssignment expression) {
  1490. // Assignment assignment = new Assignment(this.ast);
  1491. // Expression lhs = convert(expression.lhs);
  1492. // assignment.setLeftHandSide(lhs);
  1493. // int start = lhs.getStartPosition();
  1494. // assignment.setSourceRange(start, expression.sourceEnd - start + 1);
  1495. // switch (expression.operator) {
  1496. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.PLUS :
  1497. // assignment.setOperator(Assignment.Operator.PLUS_ASSIGN);
  1498. // break;
  1499. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.MINUS :
  1500. // assignment.setOperator(Assignment.Operator.MINUS_ASSIGN);
  1501. // break;
  1502. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.MULTIPLY :
  1503. // assignment.setOperator(Assignment.Operator.TIMES_ASSIGN);
  1504. // break;
  1505. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.DIVIDE :
  1506. // assignment.setOperator(Assignment.Operator.DIVIDE_ASSIGN);
  1507. // break;
  1508. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.AND :
  1509. // assignment.setOperator(Assignment.Operator.BIT_AND_ASSIGN);
  1510. // break;
  1511. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.OR :
  1512. // assignment.setOperator(Assignment.Operator.BIT_OR_ASSIGN);
  1513. // break;
  1514. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.XOR :
  1515. // assignment.setOperator(Assignment.Operator.BIT_XOR_ASSIGN);
  1516. // break;
  1517. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.REMAINDER :
  1518. // assignment.setOperator(Assignment.Operator.REMAINDER_ASSIGN);
  1519. // break;
  1520. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.LEFT_SHIFT :
  1521. // assignment.setOperator(Assignment.Operator.LEFT_SHIFT_ASSIGN);
  1522. // break;
  1523. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.RIGHT_SHIFT :
  1524. // assignment.setOperator(Assignment.Operator.RIGHT_SHIFT_SIGNED_ASSIGN);
  1525. // break;
  1526. // case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.UNSIGNED_RIGHT_SHIFT :
  1527. // assignment.setOperator(Assignment.Operator.RIGHT_SHIFT_UNSIGNED_ASSIGN);
  1528. // break;
  1529. // }
  1530. // assignment.setRightHandSide(convert(expression.expression));
  1531. // if (this.resolveBindings) {
  1532. // recordNodes(assignment, expression);
  1533. // }
  1534. // return assignment;
  1535. // }
  1536. // public ConditionalExpression convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.ConditionalExpression expression) {
  1537. // ConditionalExpression conditionalExpression = new ConditionalExpression(this.ast);
  1538. // if (this.resolveBindings) {
  1539. // recordNodes(conditionalExpression, expression);
  1540. // }
  1541. // conditionalExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
  1542. // conditionalExpression.setExpression(convert(expression.condition));
  1543. // conditionalExpression.setThenExpression(convert(expression.valueIfTrue));
  1544. // conditionalExpression.setElseExpression(convert(expression.valueIfFalse));
  1545. // return conditionalExpression;
  1546. // }
  1547. // public Statement convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall statement) {
  1548. // Statement newStatement;
  1549. // int sourceStart = statement.sourceStart;
  1550. // if (statement.isSuperAccess() || statement.isSuper()) {
  1551. // SuperConstructorInvocation superConstructorInvocation = new SuperConstructorInvocation(this.ast);
  1552. // if (statement.qualification != null) {
  1553. // superConstructorInvocation.setExpression(convert(statement.qualification));
  1554. // }
  1555. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression[] arguments = statement.arguments;
  1556. // if (arguments != null) {
  1557. // int length = arguments.length;
  1558. // for (int i = 0; i < length; i++) {
  1559. // superConstructorInvocation.arguments().add(convert(arguments[i]));
  1560. // }
  1561. // }
  1562. // if (statement.typeArguments != null) {
  1563. // if (sourceStart > statement.typeArgumentsSourceStart) {
  1564. // sourceStart = statement.typeArgumentsSourceStart;
  1565. // }
  1566. // switch(this.ast.apiLevel) {
  1567. // case AST.JLS2_INTERNAL :
  1568. // superConstructorInvocation.setFlags(superConstructorInvocation.getFlags() | ASTNode.MALFORMED);
  1569. // break;
  1570. // case AST.JLS3 :
  1571. // for (int i = 0, max = statement.typeArguments.length; i < max; i++) {
  1572. // superConstructorInvocation.typeArguments().add(convertType(statement.typeArguments[i]));
  1573. // }
  1574. // break;
  1575. // }
  1576. // }
  1577. // newStatement = superConstructorInvocation;
  1578. // } else {
  1579. // ConstructorInvocation constructorInvocation = new ConstructorInvocation(this.ast);
  1580. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression[] arguments = statement.arguments;
  1581. // if (arguments != null) {
  1582. // int length = arguments.length;
  1583. // for (int i = 0; i < length; i++) {
  1584. // constructorInvocation.arguments().add(convert(arguments[i]));
  1585. // }
  1586. // }
  1587. // if (statement.typeArguments != null) {
  1588. // if (sourceStart > statement.typeArgumentsSourceStart) {
  1589. // sourceStart = statement.typeArgumentsSourceStart;
  1590. // }
  1591. // switch(this.ast.apiLevel) {
  1592. // case AST.JLS2_INTERNAL :
  1593. // constructorInvocation.setFlags(constructorInvocation.getFlags() | ASTNode.MALFORMED);
  1594. // break;
  1595. // case AST.JLS3 :
  1596. // for (int i = 0, max = statement.typeArguments.length; i < max; i++) {
  1597. // constructorInvocation.typeArguments().add(convertType(statement.typeArguments[i]));
  1598. // }
  1599. // break;
  1600. // }
  1601. // }
  1602. // if (statement.qualification != null) {
  1603. // // this is an error
  1604. // constructorInvocation.setFlags(constructorInvocation.getFlags() | ASTNode.MALFORMED);
  1605. // }
  1606. // newStatement = constructorInvocation;
  1607. // }
  1608. // newStatement.setSourceRange(sourceStart, statement.sourceEnd - sourceStart + 1);
  1609. // retrieveSemiColonPosition(newStatement);
  1610. // if (this.resolveBindings) {
  1611. // recordNodes(newStatement, statement);
  1612. // }
  1613. // return newStatement;
  1614. // }
  1615. // public Expression convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression) {
  1616. // if ((expression.bits & org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode.ParenthesizedMASK) != 0) {
  1617. // return convertToParenthesizedExpression(expression);
  1618. // }
  1619. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation) {
  1620. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation) expression);
  1621. // }
  1622. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.CastExpression) {
  1623. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.CastExpression) expression);
  1624. // }
  1625. // // switch between all types of expression
  1626. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression) {
  1627. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression) expression);
  1628. // }
  1629. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression) {
  1630. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression) expression);
  1631. // }
  1632. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.AllocationExpression) {
  1633. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.AllocationExpression) expression);
  1634. // }
  1635. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayInitializer) {
  1636. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayInitializer) expression);
  1637. // }
  1638. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.PrefixExpression) {
  1639. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.PrefixExpression) expression);
  1640. // }
  1641. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.PostfixExpression) {
  1642. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.PostfixExpression) expression);
  1643. // }
  1644. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompoundAssignment) {
  1645. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompoundAssignment) expression);
  1646. // }
  1647. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.Assignment) {
  1648. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.Assignment) expression);
  1649. // }
  1650. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess) {
  1651. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess) expression);
  1652. // }
  1653. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.FalseLiteral) {
  1654. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.FalseLiteral) expression);
  1655. // }
  1656. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.TrueLiteral) {
  1657. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.TrueLiteral) expression);
  1658. // }
  1659. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.NullLiteral) {
  1660. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.NullLiteral) expression);
  1661. // }
  1662. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.CharLiteral) {
  1663. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.CharLiteral) expression);
  1664. // }
  1665. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.DoubleLiteral) {
  1666. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.DoubleLiteral) expression);
  1667. // }
  1668. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.FloatLiteral) {
  1669. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.FloatLiteral) expression);
  1670. // }
  1671. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.IntLiteralMinValue) {
  1672. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.IntLiteralMinValue) expression);
  1673. // }
  1674. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.IntLiteral) {
  1675. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.IntLiteral) expression);
  1676. // }
  1677. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.LongLiteralMinValue) {
  1678. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.LongLiteralMinValue) expression);
  1679. // }
  1680. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.LongLiteral) {
  1681. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.LongLiteral) expression);
  1682. // }
  1683. // if (expression instanceof StringLiteralConcatenation) {
  1684. // return convert((StringLiteralConcatenation) expression);
  1685. // }
  1686. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ExtendedStringLiteral) {
  1687. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.ExtendedStringLiteral) expression);
  1688. // }
  1689. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteral) {
  1690. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteral) expression);
  1691. // }
  1692. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.AND_AND_Expression) {
  1693. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.AND_AND_Expression) expression);
  1694. // }
  1695. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.OR_OR_Expression) {
  1696. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.OR_OR_Expression) expression);
  1697. // }
  1698. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.EqualExpression) {
  1699. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.EqualExpression) expression);
  1700. // }
  1701. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.BinaryExpression) {
  1702. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.BinaryExpression) expression);
  1703. // }
  1704. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.InstanceOfExpression) {
  1705. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.InstanceOfExpression) expression);
  1706. // }
  1707. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.UnaryExpression) {
  1708. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.UnaryExpression) expression);
  1709. // }
  1710. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ConditionalExpression) {
  1711. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.ConditionalExpression) expression);
  1712. // }
  1713. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.MessageSend) {
  1714. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.MessageSend) expression);
  1715. // }
  1716. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.Reference) {
  1717. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.Reference) expression);
  1718. // }
  1719. // if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) {
  1720. // return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) expression);
  1721. // }
  1722. // return null;
  1723. // }
  1724. public StringLiteral convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.ExtendedStringLiteral expression) {
  1725. expression.computeConstant();
  1726. StringLiteral literal = new StringLiteral(this.ast);
  1727. if (this.resolveBindings) {
  1728. this.recordNodes(literal, expression);
  1729. }
  1730. literal.setLiteralValue(expression.constant.stringValue());
  1731. literal.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
  1732. return literal;
  1733. }
  1734. public BooleanLiteral convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.FalseLiteral expression) {
  1735. final BooleanLiteral literal = new BooleanLiteral(this.ast);
  1736. literal.setBooleanValue(false);
  1737. if (this.resolveBindings) {
  1738. this.recordNodes(literal, expression);
  1739. }
  1740. literal.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
  1741. return literal;
  1742. }
  1743. public Expression convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldReference reference) {
  1744. if (reference.receiver.isSuper()) {
  1745. final SuperFieldAccess superFieldAccess = new SuperFieldAccess(this.ast);
  1746. if (this.resolveBindings) {
  1747. recordNodes(superFieldAccess, reference);
  1748. }
  1749. if (reference.receiver instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference) {
  1750. Name qualifier = convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference) reference.receiver);
  1751. superFieldAccess.setQualifier(qualifier);
  1752. if (this.resolveBindings) {
  1753. recordNodes(qualifier, reference.receiver);
  1754. }
  1755. }
  1756. final SimpleName simpleName = new SimpleName(this.ast);
  1757. simpleName.internalSetIdentifier(new String(reference.token));
  1758. int sourceStart = (int) (reference.nameSourcePosition >>> 32);
  1759. int length = (int) (reference.nameSourcePosition & 0xFFFFFFFF) - sourceStart + 1;
  1760. simpleName.setSourceRange(sourceStart, length);
  1761. superFieldAccess.setName(simpleName);
  1762. if (this.resolveBindings) {
  1763. recordNodes(simpleName, reference);
  1764. }
  1765. superFieldAccess.setSourceRange(reference.receiver.sourceStart, reference.sourceEnd - reference.receiver.sourceStart
  1766. + 1);
  1767. return superFieldAccess;
  1768. } else {
  1769. final FieldAccess fieldAccess = new FieldAccess(this.ast);
  1770. if (this.resolveBindings) {
  1771. recordNodes(fieldAccess, reference);
  1772. }
  1773. Expression receiver = super.convert(reference.receiver);
  1774. fieldAccess.setExpression(receiver);
  1775. final SimpleName simpleName = new SimpleName(this.ast);
  1776. simpleName.internalSetIdentifier(new String(reference.token));
  1777. int sourceStart = (int) (reference.nameSourcePosition >>> 32);
  1778. int length = (int) (reference.nameSourcePosition & 0xFFFFFFFF) - sourceStart + 1;
  1779. simpleName.setSourceRange(sourceStart, length);
  1780. fieldAccess.setName(simpleName);
  1781. if (this.resolveBindings) {
  1782. recordNodes(simpleName, reference);
  1783. }
  1784. fieldAccess.setSourceRange(receiver.getStartPosition(), reference.sourceEnd - receiver.getStartPosition() + 1);
  1785. return fieldAccess;
  1786. }
  1787. }
  1788. public NumberLiteral convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.FloatLiteral expression) {
  1789. int length = expression.sourceEnd - expression.sourceStart + 1;
  1790. int sourceStart = expression.sourceStart;
  1791. NumberLiteral literal = new NumberLiteral(this.ast);
  1792. literal.internalSetToken(new String(this.compilationUnitSource, sourceStart, length));
  1793. if (this.resolveBindings) {
  1794. this.recordNodes(literal, expression);
  1795. }
  1796. literal.setSourceRange(sourceStart, length);
  1797. removeLeadingAndTrailingCommentsFromLiteral(literal);
  1798. return literal;
  1799. }
  1800. public Statement convert(ForeachStatement statement) {
  1801. switch (this.ast.apiLevel) {
  1802. case AST.JLS2_INTERNAL:
  1803. return createFakeEmptyStatement(statement);
  1804. case AST.JLS3:
  1805. EnhancedForStatement enhancedForStatement = new EnhancedForStatement(this.ast);
  1806. enhancedForStatement.setParameter(convertToSingleVariableDeclaration(statement.elementVariable));
  1807. enhancedForStatement.setExpression(super.convert(statement.collection));
  1808. enhancedForStatement.setBody(convert(statement.action));
  1809. int start = statement.sourceStart;
  1810. int end = statement.sourceEnd;
  1811. enhancedForStatement.setSourceRange(start, end - start + 1);
  1812. return enhancedForStatement;
  1813. default:
  1814. return createFakeEmptyStatement(statement);
  1815. }
  1816. }
  1817. public ForStatement convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.ForStatement statement) {
  1818. ForStatement forStatement = new ForStatement(this.ast);
  1819. forStatement.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
  1820. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Statement[] initializations = statement.initializations;
  1821. if (initializations != null) {
  1822. // we know that we have at least one initialization
  1823. if (initializations[0] instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
  1824. VariableDeclarationExpression variableDeclarationExpression = convertToVariableDeclarationExpression((org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) initializations[0]);
  1825. int initializationsLength = initializations.length;
  1826. for (int i = 1; i < initializationsLength; i++) {
  1827. variableDeclarationExpression
  1828. .fragments()
  1829. .add(convertToVariableDeclarationFragment((org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) initializations[i]));
  1830. }
  1831. if (initializationsLength != 1) {
  1832. int start = variableDeclarationExpression.getStartPosition();
  1833. int end = ((org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) initializations[initializationsLength - 1]).declarationSourceEnd;
  1834. variableDeclarationExpression.setSourceRange(start, end - start + 1);
  1835. }
  1836. forStatement.initializers().add(variableDeclarationExpression);
  1837. } else {
  1838. int initializationsLength = initializations.length;
  1839. for (org.aspectj.org.eclipse.jdt.internal.compiler.ast.Statement initialization : initializations) {
  1840. Expression initializer = convertToExpression(initialization);
  1841. if (initializer != null) {
  1842. forStatement.initializers().add(initializer);
  1843. } else {
  1844. forStatement.setFlags(forStatement.getFlags() | ASTNode.MALFORMED);
  1845. }
  1846. }
  1847. }
  1848. }
  1849. if (statement.condition != null) {
  1850. forStatement.setExpression(super.convert(statement.condition));
  1851. }
  1852. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Statement[] increments = statement.increments;
  1853. if (increments != null) {
  1854. int incrementsLength = increments.length;
  1855. for (org.aspectj.org.eclipse.jdt.internal.compiler.ast.Statement increment : increments) {
  1856. forStatement.updaters().add(convertToExpression(increment));
  1857. }
  1858. }
  1859. forStatement.setBody(convert(statement.action));
  1860. return forStatement;
  1861. }
  1862. public IfStatement convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.IfStatement statement) {
  1863. IfStatement ifStatement = new IfStatement(this.ast);
  1864. ifStatement.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
  1865. ifStatement.setExpression(super.convert(statement.condition));
  1866. ifStatement.setThenStatement(convert(statement.thenStatement));
  1867. if (statement.elseStatement != null) {
  1868. ifStatement.setElseStatement(convert(statement.elseStatement));
  1869. }
  1870. return ifStatement;
  1871. }
  1872. public InstanceofExpression convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.InstanceOfExpression expression) {
  1873. InstanceofExpression instanceOfExpression = new InstanceofExpression(this.ast);
  1874. if (this.resolveBindings) {
  1875. recordNodes(instanceOfExpression, expression);
  1876. }
  1877. Expression leftExpression = super.convert(expression.expression);
  1878. instanceOfExpression.setLeftOperand(leftExpression);
  1879. instanceOfExpression.setRightOperand(convertType(expression.type));
  1880. int startPosition = leftExpression.getStartPosition();
  1881. instanceOfExpression.setSourceRange(startPosition, expression.sourceEnd - startPosition + 1);
  1882. return instanceOfExpression;
  1883. }
  1884. public NumberLiteral convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.IntLiteral expression) {
  1885. int length = expression.sourceEnd - expression.sourceStart + 1;
  1886. int sourceStart = expression.sourceStart;
  1887. final NumberLiteral literal = new NumberLiteral(this.ast);
  1888. literal.internalSetToken(new String(this.compilationUnitSource, sourceStart, length));
  1889. if (this.resolveBindings) {
  1890. this.recordNodes(literal, expression);
  1891. }
  1892. literal.setSourceRange(sourceStart, length);
  1893. removeLeadingAndTrailingCommentsFromLiteral(literal);
  1894. return literal;
  1895. }
  1896. public NumberLiteral convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.IntLiteralMinValue expression) {
  1897. int length = expression.sourceEnd - expression.sourceStart + 1;
  1898. int sourceStart = expression.sourceStart;
  1899. NumberLiteral literal = new NumberLiteral(this.ast);
  1900. literal.internalSetToken(new String(this.compilationUnitSource, sourceStart, length));
  1901. if (this.resolveBindings) {
  1902. this.recordNodes(literal, expression);
  1903. }
  1904. literal.setSourceRange(sourceStart, length);
  1905. removeLeadingAndTrailingCommentsFromLiteral(literal);
  1906. return literal;
  1907. }
  1908. public void convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Javadoc javadoc, BodyDeclaration bodyDeclaration) {
  1909. if (bodyDeclaration.getJavadoc() == null) {
  1910. if (javadoc != null) {
  1911. if (this.commentMapper == null || !this.commentMapper.hasSameTable(this.commentsTable)) {
  1912. this.commentMapper = new DefaultCommentMapper(this.commentsTable);
  1913. }
  1914. Comment comment = this.commentMapper.getComment(javadoc.sourceStart);
  1915. if (comment != null && comment.isDocComment() && comment.getParent() == null) {
  1916. Javadoc docComment = (Javadoc) comment;
  1917. if (this.resolveBindings) {
  1918. recordNodes(docComment, javadoc);
  1919. // resolve member and method references binding
  1920. for (Object o : docComment.tags()) {
  1921. recordNodes(javadoc, (TagElement) o);
  1922. }
  1923. }
  1924. bodyDeclaration.setJavadoc(docComment);
  1925. }
  1926. }
  1927. }
  1928. }
  1929. public void convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Javadoc javadoc, PackageDeclaration packageDeclaration) {
  1930. if (ast.apiLevel == AST.JLS3 && packageDeclaration.getJavadoc() == null) {
  1931. if (javadoc != null) {
  1932. if (this.commentMapper == null || !this.commentMapper.hasSameTable(this.commentsTable)) {
  1933. this.commentMapper = new DefaultCommentMapper(this.commentsTable);
  1934. }
  1935. Comment comment = this.commentMapper.getComment(javadoc.sourceStart);
  1936. if (comment != null && comment.isDocComment() && comment.getParent() == null) {
  1937. Javadoc docComment = (Javadoc) comment;
  1938. if (this.resolveBindings) {
  1939. recordNodes(docComment, javadoc);
  1940. // resolve member and method references binding
  1941. for (Object o : docComment.tags()) {
  1942. recordNodes(javadoc, (TagElement) o);
  1943. }
  1944. }
  1945. packageDeclaration.setJavadoc(docComment);
  1946. }
  1947. }
  1948. }
  1949. }
  1950. public LabeledStatement convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.LabeledStatement statement) {
  1951. LabeledStatement labeledStatement = new LabeledStatement(this.ast);
  1952. labeledStatement.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
  1953. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Statement body = statement.statement;
  1954. labeledStatement.setBody(convert(body));
  1955. final SimpleName name = new SimpleName(this.ast);
  1956. name.internalSetIdentifier(new String(statement.label));
  1957. retrieveIdentifierAndSetPositions(statement.sourceStart, statement.sourceEnd, name);
  1958. labeledStatement.setLabel(name);
  1959. return labeledStatement;
  1960. }
  1961. public InfixExpression convert(StringLiteralConcatenation expression) {
  1962. expression.computeConstant();
  1963. final InfixExpression infixExpression = new InfixExpression(this.ast);
  1964. infixExpression.setOperator(InfixExpression.Operator.PLUS);
  1965. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression[] stringLiterals = expression.literals;
  1966. infixExpression.setLeftOperand(super.convert(stringLiterals[0]));
  1967. infixExpression.setRightOperand(super.convert(stringLiterals[1]));
  1968. for (int i = 2; i < expression.counter; i++) {
  1969. infixExpression.extendedOperands().add(super.convert(stringLiterals[i]));
  1970. }
  1971. if (this.resolveBindings) {
  1972. this.recordNodes(infixExpression, expression);
  1973. }
  1974. infixExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
  1975. return infixExpression;
  1976. }
  1977. public NormalAnnotation convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.NormalAnnotation annotation) {
  1978. final NormalAnnotation normalAnnotation = new NormalAnnotation(this.ast);
  1979. setTypeNameForAnnotation(annotation, normalAnnotation);
  1980. org.aspectj.org.eclipse.jdt.internal.compiler.ast.MemberValuePair[] memberValuePairs = annotation.memberValuePairs;
  1981. if (memberValuePairs != null) {
  1982. for (org.aspectj.org.eclipse.jdt.internal.compiler.ast.MemberValuePair memberValuePair : memberValuePairs) {
  1983. normalAnnotation.values().add(convert(memberValuePair));
  1984. }
  1985. }
  1986. int start = annotation.sourceStart;
  1987. int end = annotation.declarationSourceEnd;
  1988. normalAnnotation.setSourceRange(start, end - start + 1);
  1989. if (this.resolveBindings) {
  1990. recordNodes(normalAnnotation, annotation);
  1991. }
  1992. return normalAnnotation;
  1993. }
  1994. public NullLiteral convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.NullLiteral expression) {
  1995. final NullLiteral literal = new NullLiteral(this.ast);
  1996. if (this.resolveBindings) {
  1997. this.recordNodes(literal, expression);
  1998. }
  1999. literal.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
  2000. return literal;
  2001. }
  2002. public Expression convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.OR_OR_Expression expression) {
  2003. final InfixExpression infixExpression = new InfixExpression(this.ast);
  2004. if (this.resolveBindings) {
  2005. recordNodes(infixExpression, expression);
  2006. }
  2007. Expression leftExpression = super.convert(expression.left);
  2008. infixExpression.setLeftOperand(leftExpression);
  2009. infixExpression.setRightOperand(super.convert(expression.right));
  2010. infixExpression.setOperator(InfixExpression.Operator.CONDITIONAL_OR);
  2011. int sourceStart = leftExpression.getStartPosition();
  2012. infixExpression.setSourceRange(sourceStart, expression.sourceEnd - sourceStart + 1);
  2013. return infixExpression;
  2014. }
  2015. public PostfixExpression convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.PostfixExpression expression) {
  2016. final PostfixExpression postfixExpression = new PostfixExpression(this.ast);
  2017. if (this.resolveBindings) {
  2018. recordNodes(postfixExpression, expression);
  2019. }
  2020. postfixExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
  2021. postfixExpression.setOperand(super.convert(expression.lhs));
  2022. switch (expression.operator) {
  2023. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.PLUS:
  2024. postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
  2025. break;
  2026. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.MINUS:
  2027. postfixExpression.setOperator(PostfixExpression.Operator.DECREMENT);
  2028. break;
  2029. }
  2030. return postfixExpression;
  2031. }
  2032. public PrefixExpression convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.PrefixExpression expression) {
  2033. final PrefixExpression prefixExpression = new PrefixExpression(this.ast);
  2034. if (this.resolveBindings) {
  2035. recordNodes(prefixExpression, expression);
  2036. }
  2037. prefixExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
  2038. prefixExpression.setOperand(super.convert(expression.lhs));
  2039. switch (expression.operator) {
  2040. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.PLUS:
  2041. prefixExpression.setOperator(PrefixExpression.Operator.INCREMENT);
  2042. break;
  2043. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.MINUS:
  2044. prefixExpression.setOperator(PrefixExpression.Operator.DECREMENT);
  2045. break;
  2046. }
  2047. return prefixExpression;
  2048. }
  2049. public Expression convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression allocation) {
  2050. final ClassInstanceCreation classInstanceCreation = new ClassInstanceCreation(this.ast);
  2051. if (allocation.enclosingInstance != null) {
  2052. classInstanceCreation.setExpression(super.convert(allocation.enclosingInstance));
  2053. }
  2054. switch (this.ast.apiLevel) {
  2055. case AST.JLS2_INTERNAL:
  2056. classInstanceCreation.internalSetName(convert(allocation.type));
  2057. break;
  2058. case AST.JLS3:
  2059. classInstanceCreation.setType(convertType(allocation.type));
  2060. }
  2061. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression[] arguments = allocation.arguments;
  2062. if (arguments != null) {
  2063. int length = arguments.length;
  2064. for (org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression : arguments) {
  2065. Expression argument = super.convert(expression);
  2066. if (this.resolveBindings) {
  2067. recordNodes(argument, expression);
  2068. }
  2069. classInstanceCreation.arguments().add(argument);
  2070. }
  2071. }
  2072. if (allocation.typeArguments != null) {
  2073. switch (this.ast.apiLevel) {
  2074. case AST.JLS2_INTERNAL:
  2075. classInstanceCreation.setFlags(classInstanceCreation.getFlags() | ASTNode.MALFORMED);
  2076. break;
  2077. case AST.JLS3:
  2078. for (int i = 0, max = allocation.typeArguments.length; i < max; i++) {
  2079. classInstanceCreation.typeArguments().add(convertType(allocation.typeArguments[i]));
  2080. }
  2081. }
  2082. }
  2083. if (allocation.anonymousType != null) {
  2084. int declarationSourceStart = allocation.sourceStart;
  2085. classInstanceCreation.setSourceRange(declarationSourceStart, allocation.anonymousType.bodyEnd - declarationSourceStart
  2086. + 1);
  2087. final AnonymousClassDeclaration anonymousClassDeclaration = new AnonymousClassDeclaration(this.ast);
  2088. int start = retrieveStartBlockPosition(allocation.anonymousType.sourceEnd, allocation.anonymousType.bodyEnd);
  2089. anonymousClassDeclaration.setSourceRange(start, allocation.anonymousType.bodyEnd - start + 1);
  2090. classInstanceCreation.setAnonymousClassDeclaration(anonymousClassDeclaration);
  2091. buildBodyDeclarations(allocation.anonymousType, anonymousClassDeclaration);
  2092. if (this.resolveBindings) {
  2093. recordNodes(classInstanceCreation, allocation.anonymousType);
  2094. recordNodes(anonymousClassDeclaration, allocation.anonymousType);
  2095. anonymousClassDeclaration.resolveBinding();
  2096. }
  2097. return classInstanceCreation;
  2098. } else {
  2099. final int start = allocation.sourceStart;
  2100. classInstanceCreation.setSourceRange(start, allocation.sourceEnd - start + 1);
  2101. if (this.resolveBindings) {
  2102. recordNodes(classInstanceCreation, allocation);
  2103. }
  2104. // removeTrailingCommentFromExpressionEndingWithAParen(classInstanceCreation);
  2105. return classInstanceCreation;
  2106. }
  2107. }
  2108. public Name convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference nameReference) {
  2109. return setQualifiedNameNameAndSourceRanges(nameReference.tokens, nameReference.sourcePositions, nameReference);
  2110. }
  2111. public Name convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference reference) {
  2112. return convert(reference.qualification);
  2113. }
  2114. public ThisExpression convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedThisReference reference) {
  2115. final ThisExpression thisExpression = new ThisExpression(this.ast);
  2116. thisExpression.setSourceRange(reference.sourceStart, reference.sourceEnd - reference.sourceStart + 1);
  2117. thisExpression.setQualifier(convert(reference.qualification));
  2118. if (this.resolveBindings) {
  2119. recordNodes(thisExpression, reference);
  2120. recordPendingThisExpressionScopeResolution(thisExpression);
  2121. }
  2122. return thisExpression;
  2123. }
  2124. public Expression convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Reference reference) {
  2125. if (reference instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.NameReference) {
  2126. return super.convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.NameReference) reference);
  2127. }
  2128. if (reference instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ThisReference) {
  2129. return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.ThisReference) reference);
  2130. }
  2131. if (reference instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayReference) {
  2132. return super.convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayReference) reference);
  2133. }
  2134. if (reference instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldReference) {
  2135. return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldReference) reference);
  2136. }
  2137. return null; // cannot be reached
  2138. }
  2139. public ReturnStatement convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.ReturnStatement statement) {
  2140. final ReturnStatement returnStatement = new ReturnStatement(this.ast);
  2141. returnStatement.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
  2142. if (statement.expression != null) {
  2143. returnStatement.setExpression(super.convert(statement.expression));
  2144. }
  2145. retrieveSemiColonPosition(returnStatement);
  2146. return returnStatement;
  2147. }
  2148. public SingleMemberAnnotation convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation annotation) {
  2149. final SingleMemberAnnotation singleMemberAnnotation = new SingleMemberAnnotation(this.ast);
  2150. setTypeNameForAnnotation(annotation, singleMemberAnnotation);
  2151. singleMemberAnnotation.setValue(super.convert(annotation.memberValue));
  2152. int start = annotation.sourceStart;
  2153. int end = annotation.declarationSourceEnd;
  2154. singleMemberAnnotation.setSourceRange(start, end - start + 1);
  2155. if (this.resolveBindings) {
  2156. recordNodes(singleMemberAnnotation, annotation);
  2157. }
  2158. return singleMemberAnnotation;
  2159. }
  2160. public SimpleName convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleNameReference nameReference) {
  2161. final SimpleName name = new SimpleName(this.ast);
  2162. name.internalSetIdentifier(new String(nameReference.token));
  2163. if (this.resolveBindings) {
  2164. recordNodes(name, nameReference);
  2165. }
  2166. name.setSourceRange(nameReference.sourceStart, nameReference.sourceEnd - nameReference.sourceStart + 1);
  2167. return name;
  2168. }
  2169. public Statement convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Statement statement) {
  2170. if (statement instanceof ForeachStatement) {
  2171. return convert((ForeachStatement) statement);
  2172. }
  2173. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
  2174. return convertToVariableDeclarationStatement((org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) statement);
  2175. }
  2176. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.AssertStatement) {
  2177. return super.convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.AssertStatement) statement);
  2178. }
  2179. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.Block) {
  2180. return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.Block) statement);
  2181. }
  2182. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.BreakStatement) {
  2183. return super.convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.BreakStatement) statement);
  2184. }
  2185. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ContinueStatement) {
  2186. return super.convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.ContinueStatement) statement);
  2187. }
  2188. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.CaseStatement) {
  2189. return super.convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.CaseStatement) statement);
  2190. }
  2191. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.DoStatement) {
  2192. return super.convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.DoStatement) statement);
  2193. }
  2194. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.EmptyStatement) {
  2195. return super.convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.EmptyStatement) statement);
  2196. }
  2197. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall) {
  2198. return super.convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall) statement);
  2199. }
  2200. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ForStatement) {
  2201. return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.ForStatement) statement);
  2202. }
  2203. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.IfStatement) {
  2204. return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.IfStatement) statement);
  2205. }
  2206. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.LabeledStatement) {
  2207. return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.LabeledStatement) statement);
  2208. }
  2209. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ReturnStatement) {
  2210. return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.ReturnStatement) statement);
  2211. }
  2212. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.SwitchStatement) {
  2213. return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.SwitchStatement) statement);
  2214. }
  2215. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.SynchronizedStatement) {
  2216. return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.SynchronizedStatement) statement);
  2217. }
  2218. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ThrowStatement) {
  2219. return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.ThrowStatement) statement);
  2220. }
  2221. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.TryStatement) {
  2222. return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.TryStatement) statement);
  2223. }
  2224. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) {
  2225. ASTNode result = convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) statement);
  2226. if (result == null) {
  2227. return createFakeEmptyStatement(statement);
  2228. }
  2229. switch (result.getNodeType()) {
  2230. case ASTNode.ENUM_DECLARATION:
  2231. switch (this.ast.apiLevel) {
  2232. case AST.JLS2_INTERNAL:
  2233. return createFakeEmptyStatement(statement);
  2234. case AST.JLS3:
  2235. final TypeDeclarationStatement typeDeclarationStatement = new TypeDeclarationStatement(this.ast);
  2236. typeDeclarationStatement.setDeclaration((EnumDeclaration) result);
  2237. AbstractTypeDeclaration typeDecl = typeDeclarationStatement.getDeclaration();
  2238. typeDeclarationStatement.setSourceRange(typeDecl.getStartPosition(), typeDecl.getLength());
  2239. return typeDeclarationStatement;
  2240. }
  2241. break;
  2242. case ASTNode.ANNOTATION_TYPE_DECLARATION:
  2243. switch (this.ast.apiLevel) {
  2244. case AST.JLS2_INTERNAL:
  2245. return createFakeEmptyStatement(statement);
  2246. case AST.JLS3:
  2247. TypeDeclarationStatement typeDeclarationStatement = new TypeDeclarationStatement(this.ast);
  2248. typeDeclarationStatement.setDeclaration((AnnotationTypeDeclaration) result);
  2249. AbstractTypeDeclaration typeDecl = typeDeclarationStatement.getDeclaration();
  2250. typeDeclarationStatement.setSourceRange(typeDecl.getStartPosition(), typeDecl.getLength());
  2251. return typeDeclarationStatement;
  2252. }
  2253. break;
  2254. default:
  2255. TypeDeclaration typeDeclaration = (TypeDeclaration) result;
  2256. if (typeDeclaration == null) {
  2257. return createFakeEmptyStatement(statement);
  2258. } else {
  2259. TypeDeclarationStatement typeDeclarationStatement = new TypeDeclarationStatement(this.ast);
  2260. typeDeclarationStatement.setDeclaration(typeDeclaration);
  2261. switch (this.ast.apiLevel) {
  2262. case AST.JLS2_INTERNAL:
  2263. TypeDeclaration typeDecl = typeDeclarationStatement.internalGetTypeDeclaration();
  2264. typeDeclarationStatement.setSourceRange(typeDecl.getStartPosition(), typeDecl.getLength());
  2265. break;
  2266. case AST.JLS3:
  2267. AbstractTypeDeclaration typeDeclAST3 = typeDeclarationStatement.getDeclaration();
  2268. typeDeclarationStatement.setSourceRange(typeDeclAST3.getStartPosition(), typeDeclAST3.getLength());
  2269. break;
  2270. }
  2271. return typeDeclarationStatement;
  2272. }
  2273. }
  2274. }
  2275. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.WhileStatement) {
  2276. return super.convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.WhileStatement) statement);
  2277. }
  2278. if (statement instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression) {
  2279. final Expression expr = super.convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression) statement);
  2280. final ExpressionStatement stmt = new ExpressionStatement(this.ast);
  2281. stmt.setExpression(expr);
  2282. stmt.setSourceRange(expr.getStartPosition(), expr.getLength());
  2283. retrieveSemiColonPosition(stmt);
  2284. return stmt;
  2285. }
  2286. return createFakeEmptyStatement(statement);
  2287. }
  2288. public Expression convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteral expression) {
  2289. if (expression instanceof StringLiteralConcatenation) {
  2290. return convert((StringLiteralConcatenation) expression);
  2291. }
  2292. int length = expression.sourceEnd - expression.sourceStart + 1;
  2293. int sourceStart = expression.sourceStart;
  2294. StringLiteral literal = new StringLiteral(this.ast);
  2295. if (this.resolveBindings) {
  2296. this.recordNodes(literal, expression);
  2297. }
  2298. literal.internalSetEscapedValue(new String(this.compilationUnitSource, sourceStart, length));
  2299. literal.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
  2300. return literal;
  2301. }
  2302. public SwitchStatement convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.SwitchStatement statement) {
  2303. SwitchStatement switchStatement = new SwitchStatement(this.ast);
  2304. switchStatement.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
  2305. switchStatement.setExpression(super.convert(statement.expression));
  2306. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Statement[] statements = statement.statements;
  2307. if (statements != null) {
  2308. int statementsLength = statements.length;
  2309. for (org.aspectj.org.eclipse.jdt.internal.compiler.ast.Statement value : statements) {
  2310. switchStatement.statements().add(convert(value));
  2311. }
  2312. }
  2313. return switchStatement;
  2314. }
  2315. public SynchronizedStatement convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.SynchronizedStatement statement) {
  2316. SynchronizedStatement synchronizedStatement = new SynchronizedStatement(this.ast);
  2317. synchronizedStatement.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
  2318. synchronizedStatement.setBody(convert(statement.block));
  2319. synchronizedStatement.setExpression(super.convert(statement.expression));
  2320. return synchronizedStatement;
  2321. }
  2322. public Expression convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.ThisReference reference) {
  2323. if (reference.isImplicitThis()) {
  2324. // There is no source associated with an implicit this
  2325. return null;
  2326. } else if (reference instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference) {
  2327. return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference) reference);
  2328. } else if (reference instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedThisReference) {
  2329. return convert((org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedThisReference) reference);
  2330. } else {
  2331. ThisExpression thisExpression = new ThisExpression(this.ast);
  2332. thisExpression.setSourceRange(reference.sourceStart, reference.sourceEnd - reference.sourceStart + 1);
  2333. if (this.resolveBindings) {
  2334. recordNodes(thisExpression, reference);
  2335. recordPendingThisExpressionScopeResolution(thisExpression);
  2336. }
  2337. return thisExpression;
  2338. }
  2339. }
  2340. public ThrowStatement convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.ThrowStatement statement) {
  2341. final ThrowStatement throwStatement = new ThrowStatement(this.ast);
  2342. throwStatement.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
  2343. throwStatement.setExpression(super.convert(statement.exception));
  2344. retrieveSemiColonPosition(throwStatement);
  2345. return throwStatement;
  2346. }
  2347. public BooleanLiteral convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.TrueLiteral expression) {
  2348. final BooleanLiteral literal = new BooleanLiteral(this.ast);
  2349. literal.setBooleanValue(true);
  2350. if (this.resolveBindings) {
  2351. this.recordNodes(literal, expression);
  2352. }
  2353. literal.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
  2354. return literal;
  2355. }
  2356. public TryStatement convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.TryStatement statement) {
  2357. final TryStatement tryStatement = new TryStatement(this.ast);
  2358. tryStatement.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
  2359. tryStatement.setBody(convert(statement.tryBlock));
  2360. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument[] catchArguments = statement.catchArguments;
  2361. if (catchArguments != null) {
  2362. int catchArgumentsLength = catchArguments.length;
  2363. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Block[] catchBlocks = statement.catchBlocks;
  2364. int start = statement.tryBlock.sourceEnd;
  2365. for (int i = 0; i < catchArgumentsLength; i++) {
  2366. CatchClause catchClause = new CatchClause(this.ast);
  2367. int catchClauseSourceStart = retrieveStartingCatchPosition(start, catchArguments[i].sourceStart);
  2368. catchClause.setSourceRange(catchClauseSourceStart, catchBlocks[i].sourceEnd - catchClauseSourceStart + 1);
  2369. catchClause.setBody(convert(catchBlocks[i]));
  2370. catchClause.setException(convert(catchArguments[i]));
  2371. tryStatement.catchClauses().add(catchClause);
  2372. start = catchBlocks[i].sourceEnd;
  2373. }
  2374. }
  2375. if (statement.finallyBlock != null) {
  2376. tryStatement.setFinally(convert(statement.finallyBlock));
  2377. }
  2378. return tryStatement;
  2379. }
  2380. public ASTNode convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration) {
  2381. int kind = org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.kind(typeDeclaration.modifiers);
  2382. switch (kind) {
  2383. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.ENUM_DECL :
  2384. if (this.ast.apiLevel == AST.JLS2_INTERNAL) {
  2385. return null;
  2386. } else {
  2387. return convertToEnumDeclaration(typeDeclaration);
  2388. }
  2389. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.ANNOTATION_TYPE_DECL :
  2390. if (this.ast.apiLevel == AST.JLS2_INTERNAL) {
  2391. return null;
  2392. } else {
  2393. return convertToAnnotationDeclaration(typeDeclaration);
  2394. }
  2395. }
  2396. checkCanceled();
  2397. TypeDeclaration typeDecl = TypeDeclaration.getTypeDeclaration(this.ast);
  2398. // ////////////// ajh02: added
  2399. if (typeDeclaration instanceof AspectDeclaration) {
  2400. org.aspectj.weaver.patterns.PerClause perClause = ((AspectDeclaration) typeDeclaration).perClause;
  2401. boolean isPrivileged = ((AspectDeclaration) typeDeclaration).isPrivileged;
  2402. if (perClause == null) {
  2403. typeDecl = new org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration(this.ast, null, isPrivileged);
  2404. } else {
  2405. typeDecl = new org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration(this.ast, convert(perClause), isPrivileged);
  2406. }
  2407. }
  2408. // /////////////////////////////
  2409. if (typeDeclaration.modifiersSourceStart != -1) {
  2410. setModifiers(typeDecl, typeDeclaration);
  2411. }
  2412. boolean isInterface = kind == org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.INTERFACE_DECL;
  2413. typeDecl.setInterface(isInterface);
  2414. final SimpleName typeName = new SimpleName(this.ast);
  2415. typeName.internalSetIdentifier(new String(typeDeclaration.name));
  2416. typeName.setSourceRange(typeDeclaration.sourceStart, typeDeclaration.sourceEnd - typeDeclaration.sourceStart + 1);
  2417. typeDecl.setName(typeName);
  2418. typeDecl.setSourceRange(typeDeclaration.declarationSourceStart, typeDeclaration.bodyEnd - typeDeclaration.declarationSourceStart + 1);
  2419. // need to set the superclass and super interfaces here since we cannot distinguish them at
  2420. // the type references level.
  2421. if (typeDeclaration.superclass != null) {
  2422. switch(this.ast.apiLevel) {
  2423. case AST.JLS2_INTERNAL :
  2424. typeDecl.internalSetSuperclass(convert(typeDeclaration.superclass));
  2425. break;
  2426. default :
  2427. typeDecl.setSuperclassType(convertType(typeDeclaration.superclass));
  2428. break;
  2429. }
  2430. }
  2431. org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference[] superInterfaces = typeDeclaration.superInterfaces;
  2432. if (superInterfaces != null) {
  2433. switch(this.ast.apiLevel) {
  2434. case AST.JLS2_INTERNAL :
  2435. for (TypeReference anInterface : superInterfaces) {
  2436. typeDecl.internalSuperInterfaces().add(convert(anInterface));
  2437. }
  2438. break;
  2439. default :
  2440. for (TypeReference superInterface : superInterfaces) {
  2441. typeDecl.superInterfaceTypes().add(convertType(superInterface));
  2442. }
  2443. }
  2444. }
  2445. org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParameters = typeDeclaration.typeParameters;
  2446. if (typeParameters != null) {
  2447. switch(this.ast.apiLevel) {
  2448. case AST.JLS2_INTERNAL :
  2449. typeDecl.setFlags(typeDecl.getFlags() | ASTNode.MALFORMED);
  2450. break;
  2451. default :
  2452. for (org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeParameter typeParameter : typeParameters) {
  2453. typeDecl.typeParameters().add(convert(typeParameter));
  2454. }
  2455. }
  2456. }
  2457. buildBodyDeclarations(typeDeclaration, typeDecl, isInterface);
  2458. if (this.resolveBindings) {
  2459. recordNodes(typeDecl, typeDeclaration);
  2460. recordNodes(typeName, typeDeclaration);
  2461. typeDecl.resolveBinding();
  2462. }
  2463. return typeDecl;
  2464. }
  2465. public TypeParameter convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeParameter typeParameter) {
  2466. final TypeParameter typeParameter2 = new TypeParameter(this.ast);
  2467. final SimpleName simpleName = new SimpleName(this.ast);
  2468. simpleName.internalSetIdentifier(new String(typeParameter.name));
  2469. int start = typeParameter.sourceStart;
  2470. int end = typeParameter.sourceEnd;
  2471. simpleName.setSourceRange(start, end - start + 1);
  2472. typeParameter2.setName(simpleName);
  2473. final TypeReference superType = typeParameter.type;
  2474. end = typeParameter.declarationSourceEnd;
  2475. if (superType != null) {
  2476. Type type = convertType(superType);
  2477. typeParameter2.typeBounds().add(type);
  2478. end = type.getStartPosition() + type.getLength() - 1;
  2479. }
  2480. TypeReference[] bounds = typeParameter.bounds;
  2481. if (bounds != null) {
  2482. Type type = null;
  2483. for (TypeReference bound : bounds) {
  2484. type = convertType(bound);
  2485. typeParameter2.typeBounds().add(type);
  2486. end = type.getStartPosition() + type.getLength() - 1;
  2487. }
  2488. }
  2489. start = typeParameter.declarationSourceStart;
  2490. end = retrieveClosingAngleBracketPosition(end);
  2491. typeParameter2.setSourceRange(start, end - start + 1);
  2492. if (this.resolveBindings) {
  2493. recordName(simpleName, typeParameter);
  2494. recordNodes(typeParameter2, typeParameter);
  2495. typeParameter2.resolveBinding();
  2496. }
  2497. return typeParameter2;
  2498. }
  2499. public Name convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference typeReference) {
  2500. char[][] typeName = typeReference.getTypeName();
  2501. int length = typeName.length;
  2502. if (length > 1) {
  2503. // QualifiedName
  2504. org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference qualifiedTypeReference = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) typeReference;
  2505. final long[] positions = qualifiedTypeReference.sourcePositions;
  2506. return setQualifiedNameNameAndSourceRanges(typeName, positions, typeReference);
  2507. } else {
  2508. final SimpleName name = new SimpleName(this.ast);
  2509. name.internalSetIdentifier(new String(typeName[0]));
  2510. name.setSourceRange(typeReference.sourceStart, typeReference.sourceEnd - typeReference.sourceStart + 1);
  2511. if (this.resolveBindings) {
  2512. recordNodes(name, typeReference);
  2513. }
  2514. return name;
  2515. }
  2516. }
  2517. protected FieldDeclaration convertToFieldDeclaration(
  2518. org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDecl) {
  2519. VariableDeclarationFragment variableDeclarationFragment = convertToVariableDeclarationFragment(fieldDecl);
  2520. final FieldDeclaration fieldDeclaration = new FieldDeclaration(this.ast);
  2521. fieldDeclaration.fragments().add(variableDeclarationFragment);
  2522. IVariableBinding binding = null;
  2523. if (this.resolveBindings) {
  2524. recordNodes(variableDeclarationFragment, fieldDecl);
  2525. binding = variableDeclarationFragment.resolveBinding();
  2526. }
  2527. fieldDeclaration.setSourceRange(fieldDecl.declarationSourceStart, fieldDecl.declarationEnd
  2528. - fieldDecl.declarationSourceStart + 1);
  2529. Type type = convertType(fieldDecl.type);
  2530. setTypeForField(fieldDeclaration, type, variableDeclarationFragment.getExtraDimensions());
  2531. setModifiers(fieldDeclaration, fieldDecl);
  2532. if (!(this.resolveBindings && binding == null)) {
  2533. convert(fieldDecl.javadoc, fieldDeclaration);
  2534. }
  2535. return fieldDeclaration;
  2536. }
  2537. // public ParenthesizedExpression convertToParenthesizedExpression(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression
  2538. // expression) {
  2539. // final ParenthesizedExpression parenthesizedExpression = new ParenthesizedExpression(this.ast);
  2540. // if (this.resolveBindings) {
  2541. // recordNodes(parenthesizedExpression, expression);
  2542. // }
  2543. // parenthesizedExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
  2544. // adjustSourcePositionsForParent(expression);
  2545. // trimWhiteSpacesAndComments(expression);
  2546. // // decrement the number of parenthesis
  2547. // int numberOfParenthesis = (expression.bits & org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode.ParenthesizedMASK) >>
  2548. // org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode.ParenthesizedSHIFT;
  2549. // expression.bits &= ~org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode.ParenthesizedMASK;
  2550. // expression.bits |= (numberOfParenthesis - 1) << org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode.ParenthesizedSHIFT;
  2551. // parenthesizedExpression.setExpression(convert(expression));
  2552. // return parenthesizedExpression;
  2553. // }
  2554. // public Type convertToType(org.aspectj.org.eclipse.jdt.internal.compiler.ast.NameReference reference) {
  2555. // Name name = convert(reference);
  2556. // final SimpleType type = new SimpleType(this.ast);
  2557. // type.setName(name);
  2558. // type.setSourceRange(name.getStartPosition(), name.getLength());
  2559. // if (this.resolveBindings) {
  2560. // this.recordNodes(type, reference);
  2561. // }
  2562. // return type;
  2563. // }
  2564. protected VariableDeclarationExpression convertToVariableDeclarationExpression(
  2565. org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration localDeclaration) {
  2566. final VariableDeclarationFragment variableDeclarationFragment = convertToVariableDeclarationFragment(localDeclaration);
  2567. final VariableDeclarationExpression variableDeclarationExpression = new VariableDeclarationExpression(this.ast);
  2568. variableDeclarationExpression.fragments().add(variableDeclarationFragment);
  2569. if (this.resolveBindings) {
  2570. recordNodes(variableDeclarationFragment, localDeclaration);
  2571. }
  2572. variableDeclarationExpression.setSourceRange(localDeclaration.declarationSourceStart, localDeclaration.declarationSourceEnd
  2573. - localDeclaration.declarationSourceStart + 1);
  2574. Type type = convertType(localDeclaration.type);
  2575. setTypeForVariableDeclarationExpression(variableDeclarationExpression, type,
  2576. variableDeclarationFragment.getExtraDimensions());
  2577. if (localDeclaration.modifiersSourceStart != -1) {
  2578. setModifiers(variableDeclarationExpression, localDeclaration);
  2579. }
  2580. return variableDeclarationExpression;
  2581. }
  2582. protected SingleVariableDeclaration convertToSingleVariableDeclaration(LocalDeclaration localDeclaration) {
  2583. final SingleVariableDeclaration variableDecl = new SingleVariableDeclaration(this.ast);
  2584. setModifiers(variableDecl, localDeclaration);
  2585. final SimpleName name = new SimpleName(this.ast);
  2586. name.internalSetIdentifier(new String(localDeclaration.name));
  2587. int start = localDeclaration.sourceStart;
  2588. int nameEnd = localDeclaration.sourceEnd;
  2589. name.setSourceRange(start, nameEnd - start + 1);
  2590. variableDecl.setName(name);
  2591. final int extraDimensions = retrieveExtraDimension(nameEnd + 1, localDeclaration.type.sourceEnd);
  2592. variableDecl.setExtraDimensions(extraDimensions);
  2593. Type type = convertType(localDeclaration.type);
  2594. int typeEnd = type.getStartPosition() + type.getLength() - 1;
  2595. int rightEnd = Math.max(typeEnd, localDeclaration.declarationSourceEnd);
  2596. /*
  2597. * There is extra work to do to set the proper type positions See PR http://bugs.eclipse.org/bugs/show_bug.cgi?id=23284
  2598. */
  2599. setTypeForSingleVariableDeclaration(variableDecl, type, extraDimensions);
  2600. variableDecl
  2601. .setSourceRange(localDeclaration.declarationSourceStart, rightEnd - localDeclaration.declarationSourceStart + 1);
  2602. if (this.resolveBindings) {
  2603. recordNodes(name, localDeclaration);
  2604. recordNodes(variableDecl, localDeclaration);
  2605. variableDecl.resolveBinding();
  2606. }
  2607. return variableDecl;
  2608. }
  2609. protected VariableDeclarationFragment convertToVariableDeclarationFragment(InterTypeFieldDeclaration fieldDeclaration) {
  2610. // ajh02: method added
  2611. final VariableDeclarationFragment variableDeclarationFragment = new VariableDeclarationFragment(this.ast);
  2612. final SimpleName name = new SimpleName(this.ast);
  2613. name.internalSetIdentifier(new String(fieldDeclaration.getDeclaredSelector()));
  2614. name.setSourceRange(fieldDeclaration.sourceStart, fieldDeclaration.sourceEnd - fieldDeclaration.sourceStart + 1);
  2615. variableDeclarationFragment.setName(name);
  2616. int start = fieldDeclaration.sourceEnd;
  2617. if (fieldDeclaration.initialization != null) {
  2618. final Expression expression = super.convert(fieldDeclaration.initialization);
  2619. variableDeclarationFragment.setInitializer(expression);
  2620. start = expression.getStartPosition() + expression.getLength();
  2621. }
  2622. int end = retrievePositionBeforeNextCommaOrSemiColon(start, fieldDeclaration.declarationSourceEnd);
  2623. if (end == -1) {
  2624. variableDeclarationFragment.setSourceRange(fieldDeclaration.sourceStart, fieldDeclaration.declarationSourceEnd
  2625. - fieldDeclaration.sourceStart + 1);
  2626. variableDeclarationFragment.setFlags(variableDeclarationFragment.getFlags() | ASTNode.MALFORMED);
  2627. } else {
  2628. variableDeclarationFragment.setSourceRange(fieldDeclaration.sourceStart, end - fieldDeclaration.sourceStart + 1);
  2629. }
  2630. variableDeclarationFragment.setExtraDimensions(retrieveExtraDimension(fieldDeclaration.sourceEnd + 1,
  2631. fieldDeclaration.declarationSourceEnd));
  2632. if (this.resolveBindings) {
  2633. recordNodes(name, fieldDeclaration);
  2634. recordNodes(variableDeclarationFragment, fieldDeclaration);
  2635. variableDeclarationFragment.resolveBinding();
  2636. }
  2637. return variableDeclarationFragment;
  2638. }
  2639. protected VariableDeclarationFragment convertToVariableDeclarationFragment(
  2640. org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration) {
  2641. final VariableDeclarationFragment variableDeclarationFragment = new VariableDeclarationFragment(this.ast);
  2642. final SimpleName name = new SimpleName(this.ast);
  2643. name.internalSetIdentifier(new String(fieldDeclaration.name));
  2644. name.setSourceRange(fieldDeclaration.sourceStart, fieldDeclaration.sourceEnd - fieldDeclaration.sourceStart + 1);
  2645. variableDeclarationFragment.setName(name);
  2646. int start = fieldDeclaration.sourceEnd;
  2647. if (fieldDeclaration.initialization != null) {
  2648. final Expression expression = super.convert(fieldDeclaration.initialization);
  2649. variableDeclarationFragment.setInitializer(expression);
  2650. start = expression.getStartPosition() + expression.getLength();
  2651. }
  2652. int end = retrievePositionBeforeNextCommaOrSemiColon(start, fieldDeclaration.declarationSourceEnd);
  2653. if (end == -1) {
  2654. variableDeclarationFragment.setSourceRange(fieldDeclaration.sourceStart, fieldDeclaration.declarationSourceEnd
  2655. - fieldDeclaration.sourceStart + 1);
  2656. variableDeclarationFragment.setFlags(variableDeclarationFragment.getFlags() | ASTNode.MALFORMED);
  2657. } else {
  2658. variableDeclarationFragment.setSourceRange(fieldDeclaration.sourceStart, end - fieldDeclaration.sourceStart + 1);
  2659. }
  2660. variableDeclarationFragment.setExtraDimensions(retrieveExtraDimension(fieldDeclaration.sourceEnd + 1,
  2661. fieldDeclaration.declarationSourceEnd));
  2662. if (this.resolveBindings) {
  2663. recordNodes(name, fieldDeclaration);
  2664. recordNodes(variableDeclarationFragment, fieldDeclaration);
  2665. variableDeclarationFragment.resolveBinding();
  2666. }
  2667. return variableDeclarationFragment;
  2668. }
  2669. protected VariableDeclarationFragment convertToVariableDeclarationFragment(
  2670. org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration localDeclaration) {
  2671. final VariableDeclarationFragment variableDeclarationFragment = new VariableDeclarationFragment(this.ast);
  2672. final SimpleName name = new SimpleName(this.ast);
  2673. name.internalSetIdentifier(new String(localDeclaration.name));
  2674. name.setSourceRange(localDeclaration.sourceStart, localDeclaration.sourceEnd - localDeclaration.sourceStart + 1);
  2675. variableDeclarationFragment.setName(name);
  2676. int start = localDeclaration.sourceEnd;
  2677. if (localDeclaration.initialization != null) {
  2678. final Expression expression = super.convert(localDeclaration.initialization);
  2679. variableDeclarationFragment.setInitializer(expression);
  2680. start = expression.getStartPosition() + expression.getLength();
  2681. }
  2682. int end = retrievePositionBeforeNextCommaOrSemiColon(start, localDeclaration.declarationSourceEnd);
  2683. if (end == -1) {
  2684. if (localDeclaration.initialization != null) {
  2685. variableDeclarationFragment.setSourceRange(localDeclaration.sourceStart, localDeclaration.initialization.sourceEnd
  2686. - localDeclaration.sourceStart + 1);
  2687. } else {
  2688. variableDeclarationFragment.setSourceRange(localDeclaration.sourceStart, localDeclaration.sourceEnd
  2689. - localDeclaration.sourceStart + 1);
  2690. }
  2691. } else {
  2692. variableDeclarationFragment.setSourceRange(localDeclaration.sourceStart, end - localDeclaration.sourceStart + 1);
  2693. }
  2694. variableDeclarationFragment.setExtraDimensions(retrieveExtraDimension(localDeclaration.sourceEnd + 1,
  2695. this.compilationUnitSourceLength));
  2696. if (this.resolveBindings) {
  2697. recordNodes(variableDeclarationFragment, localDeclaration);
  2698. recordNodes(name, localDeclaration);
  2699. variableDeclarationFragment.resolveBinding();
  2700. }
  2701. return variableDeclarationFragment;
  2702. }
  2703. protected VariableDeclarationStatement convertToVariableDeclarationStatement(
  2704. org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration localDeclaration) {
  2705. final VariableDeclarationFragment variableDeclarationFragment = convertToVariableDeclarationFragment(localDeclaration);
  2706. final VariableDeclarationStatement variableDeclarationStatement = new VariableDeclarationStatement(this.ast);
  2707. variableDeclarationStatement.fragments().add(variableDeclarationFragment);
  2708. if (this.resolveBindings) {
  2709. recordNodes(variableDeclarationFragment, localDeclaration);
  2710. }
  2711. variableDeclarationStatement.setSourceRange(localDeclaration.declarationSourceStart, localDeclaration.declarationSourceEnd
  2712. - localDeclaration.declarationSourceStart + 1);
  2713. Type type = convertType(localDeclaration.type);
  2714. setTypeForVariableDeclarationStatement(variableDeclarationStatement, type, variableDeclarationFragment.getExtraDimensions());
  2715. if (localDeclaration.modifiersSourceStart != -1) {
  2716. setModifiers(variableDeclarationStatement, localDeclaration);
  2717. }
  2718. return variableDeclarationStatement;
  2719. }
  2720. public Type convertType(TypeReference typeReference) {
  2721. if (typeReference instanceof Wildcard) {
  2722. final Wildcard wildcard = (Wildcard) typeReference;
  2723. final WildcardType wildcardType = new WildcardType(this.ast);
  2724. if (wildcard.bound != null) {
  2725. final Type bound = convertType(wildcard.bound);
  2726. wildcardType.setBound(bound, wildcard.kind == Wildcard.EXTENDS);
  2727. int start = wildcard.sourceStart;
  2728. wildcardType.setSourceRange(start, bound.getStartPosition() + bound.getLength() - start);
  2729. } else {
  2730. final int start = wildcard.sourceStart;
  2731. final int end = wildcard.sourceEnd;
  2732. wildcardType.setSourceRange(start, end - start + 1);
  2733. }
  2734. if (this.resolveBindings) {
  2735. recordNodes(wildcardType, typeReference);
  2736. }
  2737. return wildcardType;
  2738. }
  2739. Type type = null;
  2740. int sourceStart = -1;
  2741. int length = 0;
  2742. int dimensions = typeReference.dimensions();
  2743. if (typeReference instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleTypeReference) {
  2744. // this is either an ArrayTypeReference or a SingleTypeReference
  2745. char[] name = ((org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleTypeReference) typeReference).getTypeName()[0];
  2746. sourceStart = typeReference.sourceStart;
  2747. length = typeReference.sourceEnd - typeReference.sourceStart + 1;
  2748. // need to find out if this is an array type of primitive types or not
  2749. if (isPrimitiveType(name)) {
  2750. int end = retrieveEndOfElementTypeNamePosition(sourceStart, sourceStart + length)[1];
  2751. if (end == -1) {
  2752. end = sourceStart + length - 1;
  2753. }
  2754. final PrimitiveType primitiveType = new PrimitiveType(this.ast);
  2755. primitiveType.setPrimitiveTypeCode(getPrimitiveTypeCode(name));
  2756. primitiveType.setSourceRange(sourceStart, end - sourceStart + 1);
  2757. type = primitiveType;
  2758. } else if (typeReference instanceof ParameterizedSingleTypeReference) {
  2759. ParameterizedSingleTypeReference parameterizedSingleTypeReference = (ParameterizedSingleTypeReference) typeReference;
  2760. final SimpleName simpleName = new SimpleName(this.ast);
  2761. simpleName.internalSetIdentifier(new String(name));
  2762. int end = retrieveEndOfElementTypeNamePosition(sourceStart, sourceStart + length)[1];
  2763. if (end == -1) {
  2764. end = sourceStart + length - 1;
  2765. }
  2766. simpleName.setSourceRange(sourceStart, end - sourceStart + 1);
  2767. switch (this.ast.apiLevel) {
  2768. case AST.JLS2_INTERNAL:
  2769. SimpleType simpleType = new SimpleType(this.ast);
  2770. simpleType.setName(simpleName);
  2771. simpleType.setFlags(simpleType.getFlags() | ASTNode.MALFORMED);
  2772. simpleType.setSourceRange(sourceStart, end - sourceStart + 1);
  2773. type = simpleType;
  2774. if (this.resolveBindings) {
  2775. this.recordNodes(simpleName, typeReference);
  2776. }
  2777. break;
  2778. case AST.JLS3:
  2779. simpleType = new SimpleType(this.ast);
  2780. simpleType.setName(simpleName);
  2781. simpleType.setSourceRange(simpleName.getStartPosition(), simpleName.getLength());
  2782. final ParameterizedType parameterizedType = new ParameterizedType(this.ast);
  2783. parameterizedType.setType(simpleType);
  2784. type = parameterizedType;
  2785. TypeReference[] typeArguments = parameterizedSingleTypeReference.typeArguments;
  2786. if (typeArguments != null) {
  2787. Type type2 = null;
  2788. for (TypeReference typeArgument : typeArguments) {
  2789. type2 = convertType(typeArgument);
  2790. ((ParameterizedType) type).typeArguments().add(type2);
  2791. end = type2.getStartPosition() + type2.getLength() - 1;
  2792. }
  2793. end = retrieveClosingAngleBracketPosition(end + 1);
  2794. type.setSourceRange(sourceStart, end - sourceStart + 1);
  2795. } else {
  2796. type.setSourceRange(sourceStart, end - sourceStart + 1);
  2797. }
  2798. if (this.resolveBindings) {
  2799. this.recordNodes(simpleName, typeReference);
  2800. this.recordNodes(simpleType, typeReference);
  2801. }
  2802. }
  2803. } else {
  2804. final SimpleName simpleName = new SimpleName(this.ast);
  2805. simpleName.internalSetIdentifier(new String(name));
  2806. // we need to search for the starting position of the first brace in order to set the proper length
  2807. // PR http://dev.eclipse.org/bugs/show_bug.cgi?id=10759
  2808. int end = retrieveEndOfElementTypeNamePosition(sourceStart, sourceStart + length)[1];
  2809. if (end == -1) {
  2810. end = sourceStart + length - 1;
  2811. }
  2812. simpleName.setSourceRange(sourceStart, end - sourceStart + 1);
  2813. final SimpleType simpleType = new SimpleType(this.ast);
  2814. simpleType.setName(simpleName);
  2815. type = simpleType;
  2816. type.setSourceRange(sourceStart, end - sourceStart + 1);
  2817. type = simpleType;
  2818. if (this.resolveBindings) {
  2819. this.recordNodes(simpleName, typeReference);
  2820. }
  2821. }
  2822. if (dimensions != 0) {
  2823. type = this.ast.newArrayType(type, dimensions);
  2824. type.setSourceRange(sourceStart, length);
  2825. ArrayType subarrayType = (ArrayType) type;
  2826. int index = dimensions - 1;
  2827. while (index > 0) {
  2828. subarrayType = (ArrayType) subarrayType.getComponentType();
  2829. int end = retrieveProperRightBracketPosition(index, sourceStart);
  2830. subarrayType.setSourceRange(sourceStart, end - sourceStart + 1);
  2831. index--;
  2832. }
  2833. if (this.resolveBindings) {
  2834. // store keys for inner types
  2835. completeRecord((ArrayType) type, typeReference);
  2836. }
  2837. }
  2838. } else {
  2839. if (typeReference instanceof ParameterizedQualifiedTypeReference) {
  2840. ParameterizedQualifiedTypeReference parameterizedQualifiedTypeReference = (ParameterizedQualifiedTypeReference) typeReference;
  2841. char[][] tokens = parameterizedQualifiedTypeReference.tokens;
  2842. TypeReference[][] typeArguments = parameterizedQualifiedTypeReference.typeArguments;
  2843. long[] positions = parameterizedQualifiedTypeReference.sourcePositions;
  2844. sourceStart = (int) (positions[0] >>> 32);
  2845. switch (this.ast.apiLevel) {
  2846. case AST.JLS2_INTERNAL: {
  2847. char[][] name = ((org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) typeReference)
  2848. .getTypeName();
  2849. int nameLength = name.length;
  2850. sourceStart = (int) (positions[0] >>> 32);
  2851. length = (int) (positions[nameLength - 1] & 0xFFFFFFFF) - sourceStart + 1;
  2852. Name qualifiedName = this.setQualifiedNameNameAndSourceRanges(name, positions, typeReference);
  2853. final SimpleType simpleType = new SimpleType(this.ast);
  2854. simpleType.setName(qualifiedName);
  2855. simpleType.setSourceRange(sourceStart, length);
  2856. type = simpleType;
  2857. }
  2858. break;
  2859. case AST.JLS3:
  2860. if (typeArguments != null) {
  2861. int numberOfEnclosingType = 0;
  2862. int startingIndex = 0;
  2863. int endingIndex = 0;
  2864. for (TypeReference[] typeArgument : typeArguments) {
  2865. if (typeArgument != null) {
  2866. numberOfEnclosingType++;
  2867. } else if (numberOfEnclosingType == 0) {
  2868. endingIndex++;
  2869. }
  2870. }
  2871. Name name = null;
  2872. if (endingIndex - startingIndex == 0) {
  2873. final SimpleName simpleName = new SimpleName(this.ast);
  2874. simpleName.internalSetIdentifier(new String(tokens[startingIndex]));
  2875. recordPendingNameScopeResolution(simpleName);
  2876. int start = (int) (positions[startingIndex] >>> 32);
  2877. int end = (int) positions[startingIndex];
  2878. simpleName.setSourceRange(start, end - start + 1);
  2879. simpleName.index = 1;
  2880. name = simpleName;
  2881. if (this.resolveBindings) {
  2882. recordNodes(simpleName, typeReference);
  2883. }
  2884. } else {
  2885. name = this.setQualifiedNameNameAndSourceRanges(tokens, positions, endingIndex, typeReference);
  2886. }
  2887. SimpleType simpleType = new SimpleType(this.ast);
  2888. simpleType.setName(name);
  2889. int start = (int) (positions[startingIndex] >>> 32);
  2890. int end = (int) positions[endingIndex];
  2891. simpleType.setSourceRange(start, end - start + 1);
  2892. ParameterizedType parameterizedType = new ParameterizedType(this.ast);
  2893. parameterizedType.setType(simpleType);
  2894. if (this.resolveBindings) {
  2895. recordNodes(simpleType, typeReference);
  2896. recordNodes(parameterizedType, typeReference);
  2897. }
  2898. start = simpleType.getStartPosition();
  2899. end = start + simpleType.getLength() - 1;
  2900. for (int i = 0, max = typeArguments[endingIndex].length; i < max; i++) {
  2901. final Type type2 = convertType(typeArguments[endingIndex][i]);
  2902. parameterizedType.typeArguments().add(type2);
  2903. end = type2.getStartPosition() + type2.getLength() - 1;
  2904. }
  2905. int indexOfEnclosingType = 1;
  2906. parameterizedType.index = indexOfEnclosingType;
  2907. end = retrieveClosingAngleBracketPosition(end + 1);
  2908. length = end + 1;
  2909. parameterizedType.setSourceRange(start, end - start + 1);
  2910. startingIndex = endingIndex + 1;
  2911. Type currentType = parameterizedType;
  2912. while (startingIndex < typeArguments.length) {
  2913. SimpleName simpleName = new SimpleName(this.ast);
  2914. simpleName.internalSetIdentifier(new String(tokens[startingIndex]));
  2915. simpleName.index = startingIndex + 1;
  2916. start = (int) (positions[startingIndex] >>> 32);
  2917. end = (int) positions[startingIndex];
  2918. simpleName.setSourceRange(start, end - start + 1);
  2919. recordPendingNameScopeResolution(simpleName);
  2920. QualifiedType qualifiedType = new QualifiedType(this.ast);
  2921. qualifiedType.setQualifier(currentType);
  2922. qualifiedType.setName(simpleName);
  2923. if (this.resolveBindings) {
  2924. recordNodes(simpleName, typeReference);
  2925. recordNodes(qualifiedType, typeReference);
  2926. }
  2927. start = currentType.getStartPosition();
  2928. end = simpleName.getStartPosition() + simpleName.getLength() - 1;
  2929. qualifiedType.setSourceRange(start, end - start + 1);
  2930. indexOfEnclosingType++;
  2931. if (typeArguments[startingIndex] != null) {
  2932. qualifiedType.index = indexOfEnclosingType;
  2933. ParameterizedType parameterizedType2 = new ParameterizedType(this.ast);
  2934. parameterizedType2.setType(qualifiedType);
  2935. parameterizedType2.index = indexOfEnclosingType;
  2936. if (this.resolveBindings) {
  2937. recordNodes(parameterizedType2, typeReference);
  2938. }
  2939. for (int i = 0, max = typeArguments[startingIndex].length; i < max; i++) {
  2940. final Type type2 = convertType(typeArguments[startingIndex][i]);
  2941. parameterizedType2.typeArguments().add(type2);
  2942. end = type2.getStartPosition() + type2.getLength() - 1;
  2943. }
  2944. end = retrieveClosingAngleBracketPosition(end + 1);
  2945. length = end + 1;
  2946. parameterizedType2.setSourceRange(start, end - start + 1);
  2947. currentType = parameterizedType2;
  2948. } else {
  2949. currentType = qualifiedType;
  2950. qualifiedType.index = indexOfEnclosingType;
  2951. }
  2952. startingIndex++;
  2953. }
  2954. if (this.resolveBindings) {
  2955. this.recordNodes(currentType, typeReference);
  2956. }
  2957. type = currentType;
  2958. length -= sourceStart;
  2959. }
  2960. }
  2961. } else {
  2962. char[][] name = ((org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) typeReference)
  2963. .getTypeName();
  2964. int nameLength = name.length;
  2965. long[] positions = ((org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) typeReference).sourcePositions;
  2966. sourceStart = (int) (positions[0] >>> 32);
  2967. length = (int) (positions[nameLength - 1] & 0xFFFFFFFF) - sourceStart + 1;
  2968. final Name qualifiedName = this.setQualifiedNameNameAndSourceRanges(name, positions, typeReference);
  2969. final SimpleType simpleType = new SimpleType(this.ast);
  2970. simpleType.setName(qualifiedName);
  2971. type = simpleType;
  2972. type.setSourceRange(sourceStart, length);
  2973. }
  2974. if (dimensions != 0) {
  2975. type = this.ast.newArrayType(type, dimensions);
  2976. if (this.resolveBindings) {
  2977. completeRecord((ArrayType) type, typeReference);
  2978. }
  2979. int end = retrieveEndOfDimensionsPosition(sourceStart + length, this.compilationUnitSourceLength);
  2980. if (end != -1) {
  2981. type.setSourceRange(sourceStart, end - sourceStart + 1);
  2982. } else {
  2983. type.setSourceRange(sourceStart, length);
  2984. }
  2985. ArrayType subarrayType = (ArrayType) type;
  2986. int index = dimensions - 1;
  2987. while (index > 0) {
  2988. subarrayType = (ArrayType) subarrayType.getComponentType();
  2989. end = retrieveProperRightBracketPosition(index, sourceStart);
  2990. subarrayType.setSourceRange(sourceStart, end - sourceStart + 1);
  2991. index--;
  2992. }
  2993. }
  2994. }
  2995. if (this.resolveBindings) {
  2996. this.recordNodes(type, typeReference);
  2997. }
  2998. return type;
  2999. }
  3000. protected Comment createComment(int[] positions) {
  3001. // Create comment node
  3002. Comment comment = null;
  3003. int start = positions[0];
  3004. int end = positions[1];
  3005. if (positions[1] > 0) { // Javadoc comments have positive end position
  3006. Javadoc docComment = this.docParser.parse(positions);
  3007. if (docComment == null) {
  3008. return null;
  3009. }
  3010. comment = docComment;
  3011. } else {
  3012. end = -end;
  3013. if (positions[0] > 0) { // Block comment have positive start position
  3014. comment = new BlockComment(this.ast);
  3015. } else { // Line comment have negative start and end position
  3016. start = -start;
  3017. comment = new LineComment(this.ast);
  3018. }
  3019. comment.setSourceRange(start, end - start);
  3020. }
  3021. return comment;
  3022. }
  3023. protected Statement createFakeEmptyStatement(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Statement statement) {
  3024. EmptyStatement emptyStatement = new EmptyStatement(this.ast);
  3025. emptyStatement.setFlags(emptyStatement.getFlags() | ASTNode.MALFORMED);
  3026. int start = statement.sourceStart;
  3027. int end = statement.sourceEnd;
  3028. emptyStatement.setSourceRange(start, end - start + 1);
  3029. return emptyStatement;
  3030. }
  3031. /**
  3032. * @return a new modifier
  3033. */
  3034. private Modifier createModifier(ModifierKeyword keyword) {
  3035. final Modifier modifier = new Modifier(this.ast);
  3036. modifier.setKeyword(keyword);
  3037. int start = this.scanner.getCurrentTokenStartPosition();
  3038. int end = this.scanner.getCurrentTokenEndPosition();
  3039. modifier.setSourceRange(start, end - start + 1);
  3040. return modifier;
  3041. }
  3042. protected InfixExpression.Operator getOperatorFor(int operatorID) {
  3043. switch (operatorID) {
  3044. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.EQUAL_EQUAL:
  3045. return InfixExpression.Operator.EQUALS;
  3046. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.LESS_EQUAL:
  3047. return InfixExpression.Operator.LESS_EQUALS;
  3048. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.GREATER_EQUAL:
  3049. return InfixExpression.Operator.GREATER_EQUALS;
  3050. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.NOT_EQUAL:
  3051. return InfixExpression.Operator.NOT_EQUALS;
  3052. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.LEFT_SHIFT:
  3053. return InfixExpression.Operator.LEFT_SHIFT;
  3054. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.RIGHT_SHIFT:
  3055. return InfixExpression.Operator.RIGHT_SHIFT_SIGNED;
  3056. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.UNSIGNED_RIGHT_SHIFT:
  3057. return InfixExpression.Operator.RIGHT_SHIFT_UNSIGNED;
  3058. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.OR_OR:
  3059. return InfixExpression.Operator.CONDITIONAL_OR;
  3060. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.AND_AND:
  3061. return InfixExpression.Operator.CONDITIONAL_AND;
  3062. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.PLUS:
  3063. return InfixExpression.Operator.PLUS;
  3064. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.MINUS:
  3065. return InfixExpression.Operator.MINUS;
  3066. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.REMAINDER:
  3067. return InfixExpression.Operator.REMAINDER;
  3068. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.XOR:
  3069. return InfixExpression.Operator.XOR;
  3070. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.AND:
  3071. return InfixExpression.Operator.AND;
  3072. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.MULTIPLY:
  3073. return InfixExpression.Operator.TIMES;
  3074. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.OR:
  3075. return InfixExpression.Operator.OR;
  3076. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.DIVIDE:
  3077. return InfixExpression.Operator.DIVIDE;
  3078. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.GREATER:
  3079. return InfixExpression.Operator.GREATER;
  3080. case org.aspectj.org.eclipse.jdt.internal.compiler.ast.OperatorIds.LESS:
  3081. return InfixExpression.Operator.LESS;
  3082. }
  3083. return null;
  3084. }
  3085. protected PrimitiveType.Code getPrimitiveTypeCode(char[] name) {
  3086. switch (name[0]) {
  3087. case 'i':
  3088. if (name.length == 3 && name[1] == 'n' && name[2] == 't') {
  3089. return PrimitiveType.INT;
  3090. }
  3091. break;
  3092. case 'l':
  3093. if (name.length == 4 && name[1] == 'o' && name[2] == 'n' && name[3] == 'g') {
  3094. return PrimitiveType.LONG;
  3095. }
  3096. break;
  3097. case 'd':
  3098. if (name.length == 6 && name[1] == 'o' && name[2] == 'u' && name[3] == 'b' && name[4] == 'l' && name[5] == 'e') {
  3099. return PrimitiveType.DOUBLE;
  3100. }
  3101. break;
  3102. case 'f':
  3103. if (name.length == 5 && name[1] == 'l' && name[2] == 'o' && name[3] == 'a' && name[4] == 't') {
  3104. return PrimitiveType.FLOAT;
  3105. }
  3106. break;
  3107. case 'b':
  3108. if (name.length == 4 && name[1] == 'y' && name[2] == 't' && name[3] == 'e') {
  3109. return PrimitiveType.BYTE;
  3110. } else if (name.length == 7 && name[1] == 'o' && name[2] == 'o' && name[3] == 'l' && name[4] == 'e' && name[5] == 'a'
  3111. && name[6] == 'n') {
  3112. return PrimitiveType.BOOLEAN;
  3113. }
  3114. break;
  3115. case 'c':
  3116. if (name.length == 4 && name[1] == 'h' && name[2] == 'a' && name[3] == 'r') {
  3117. return PrimitiveType.CHAR;
  3118. }
  3119. break;
  3120. case 's':
  3121. if (name.length == 5 && name[1] == 'h' && name[2] == 'o' && name[3] == 'r' && name[4] == 't') {
  3122. return PrimitiveType.SHORT;
  3123. }
  3124. break;
  3125. case 'v':
  3126. if (name.length == 4 && name[1] == 'o' && name[2] == 'i' && name[3] == 'd') {
  3127. return PrimitiveType.VOID;
  3128. }
  3129. }
  3130. return null; // cannot be reached
  3131. }
  3132. protected boolean isPrimitiveType(char[] name) {
  3133. switch (name[0]) {
  3134. case 'i':
  3135. if (name.length == 3 && name[1] == 'n' && name[2] == 't') {
  3136. return true;
  3137. }
  3138. return false;
  3139. case 'l':
  3140. if (name.length == 4 && name[1] == 'o' && name[2] == 'n' && name[3] == 'g') {
  3141. return true;
  3142. }
  3143. return false;
  3144. case 'd':
  3145. if (name.length == 6 && name[1] == 'o' && name[2] == 'u' && name[3] == 'b' && name[4] == 'l' && name[5] == 'e') {
  3146. return true;
  3147. }
  3148. return false;
  3149. case 'f':
  3150. if (name.length == 5 && name[1] == 'l' && name[2] == 'o' && name[3] == 'a' && name[4] == 't') {
  3151. return true;
  3152. }
  3153. return false;
  3154. case 'b':
  3155. if (name.length == 4 && name[1] == 'y' && name[2] == 't' && name[3] == 'e') {
  3156. return true;
  3157. } else if (name.length == 7 && name[1] == 'o' && name[2] == 'o' && name[3] == 'l' && name[4] == 'e' && name[5] == 'a'
  3158. && name[6] == 'n') {
  3159. return true;
  3160. }
  3161. return false;
  3162. case 'c':
  3163. if (name.length == 4 && name[1] == 'h' && name[2] == 'a' && name[3] == 'r') {
  3164. return true;
  3165. }
  3166. return false;
  3167. case 's':
  3168. if (name.length == 5 && name[1] == 'h' && name[2] == 'o' && name[3] == 'r' && name[4] == 't') {
  3169. return true;
  3170. }
  3171. return false;
  3172. case 'v':
  3173. if (name.length == 4 && name[1] == 'o' && name[2] == 'i' && name[3] == 'd') {
  3174. return true;
  3175. }
  3176. return false;
  3177. }
  3178. return false;
  3179. }
  3180. private void lookupForScopes() {
  3181. if (this.pendingNameScopeResolution != null) {
  3182. for (Object o : this.pendingNameScopeResolution) {
  3183. Name name = (Name) o;
  3184. this.ast.getBindingResolver().recordScope(name, lookupScope(name));
  3185. }
  3186. }
  3187. if (this.pendingThisExpressionScopeResolution != null) {
  3188. for (Object o : this.pendingThisExpressionScopeResolution) {
  3189. ThisExpression thisExpression = (ThisExpression) o;
  3190. this.ast.getBindingResolver().recordScope(thisExpression, lookupScope(thisExpression));
  3191. }
  3192. }
  3193. }
  3194. private BlockScope lookupScope(ASTNode node) {
  3195. ASTNode currentNode = node;
  3196. while (currentNode != null && !(currentNode instanceof MethodDeclaration) && !(currentNode instanceof Initializer)
  3197. && !(currentNode instanceof FieldDeclaration)) {
  3198. currentNode = currentNode.getParent();
  3199. }
  3200. if (currentNode == null) {
  3201. return null;
  3202. }
  3203. if (currentNode instanceof Initializer) {
  3204. Initializer initializer = (Initializer) currentNode;
  3205. while (!(currentNode instanceof AbstractTypeDeclaration)) {
  3206. currentNode = currentNode.getParent();
  3207. }
  3208. if (currentNode instanceof TypeDeclaration || currentNode instanceof EnumDeclaration
  3209. || currentNode instanceof AnnotationTypeDeclaration) {
  3210. org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDecl = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) this.ast
  3211. .getBindingResolver().getCorrespondingNode(currentNode);
  3212. if ((initializer.getModifiers() & Modifier.STATIC) != 0) {
  3213. return typeDecl.staticInitializerScope;
  3214. } else {
  3215. return typeDecl.initializerScope;
  3216. }
  3217. }
  3218. } else if (currentNode instanceof FieldDeclaration) {
  3219. FieldDeclaration fieldDeclaration = (FieldDeclaration) currentNode;
  3220. while (!(currentNode instanceof AbstractTypeDeclaration)) {
  3221. currentNode = currentNode.getParent();
  3222. }
  3223. if (currentNode instanceof TypeDeclaration || currentNode instanceof EnumDeclaration
  3224. || currentNode instanceof AnnotationTypeDeclaration) {
  3225. org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDecl = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) this.ast
  3226. .getBindingResolver().getCorrespondingNode(currentNode);
  3227. if ((fieldDeclaration.getModifiers() & Modifier.STATIC) != 0) {
  3228. return typeDecl.staticInitializerScope;
  3229. } else {
  3230. return typeDecl.initializerScope;
  3231. }
  3232. }
  3233. }
  3234. AbstractMethodDeclaration abstractMethodDeclaration = (AbstractMethodDeclaration) this.ast.getBindingResolver()
  3235. .getCorrespondingNode(currentNode);
  3236. return abstractMethodDeclaration.scope;
  3237. }
  3238. protected void recordName(Name name, org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode compilerNode) {
  3239. if (compilerNode != null) {
  3240. recordNodes(name, compilerNode);
  3241. if (compilerNode instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) {
  3242. org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference typeRef = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) compilerNode;
  3243. if (name.isQualifiedName()) {
  3244. SimpleName simpleName = null;
  3245. while (name.isQualifiedName()) {
  3246. simpleName = ((QualifiedName) name).getName();
  3247. recordNodes(simpleName, typeRef);
  3248. name = ((QualifiedName) name).getQualifier();
  3249. recordNodes(name, typeRef);
  3250. }
  3251. }
  3252. }
  3253. }
  3254. }
  3255. protected void recordNodes(ASTNode node, org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode oldASTNode) {
  3256. this.ast.getBindingResolver().store(node, oldASTNode);
  3257. }
  3258. protected void recordNodes(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Javadoc javadoc, TagElement tagElement) {
  3259. for (Object value : tagElement.fragments()) {
  3260. ASTNode node = (ASTNode) value;
  3261. if (node.getNodeType() == ASTNode.MEMBER_REF) {
  3262. MemberRef memberRef = (MemberRef) node;
  3263. Name name = memberRef.getName();
  3264. // get compiler node and record nodes
  3265. int start = name.getStartPosition();
  3266. org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode compilerNode = javadoc.getNodeStartingAt(start);
  3267. if (compilerNode != null) {
  3268. recordNodes(name, compilerNode);
  3269. recordNodes(node, compilerNode);
  3270. }
  3271. // Replace qualifier to have all nodes recorded
  3272. if (memberRef.getQualifier() != null) {
  3273. TypeReference typeRef = null;
  3274. if (compilerNode instanceof JavadocFieldReference) {
  3275. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression = ((JavadocFieldReference) compilerNode).receiver;
  3276. if (expression instanceof TypeReference) {
  3277. typeRef = (TypeReference) expression;
  3278. }
  3279. } else if (compilerNode instanceof JavadocMessageSend) {
  3280. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression = ((JavadocMessageSend) compilerNode).receiver;
  3281. if (expression instanceof TypeReference) {
  3282. typeRef = (TypeReference) expression;
  3283. }
  3284. }
  3285. if (typeRef != null) {
  3286. recordName(memberRef.getQualifier(), typeRef);
  3287. }
  3288. }
  3289. } else if (node.getNodeType() == ASTNode.METHOD_REF) {
  3290. MethodRef methodRef = (MethodRef) node;
  3291. Name name = methodRef.getName();
  3292. // get compiler node and record nodes
  3293. int start = name.getStartPosition();
  3294. // get compiler node and record nodes
  3295. org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode compilerNode = javadoc.getNodeStartingAt(start);
  3296. // record nodes
  3297. if (compilerNode != null) {
  3298. recordNodes(methodRef, compilerNode);
  3299. // get type ref
  3300. TypeReference typeRef = null;
  3301. if (compilerNode instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocAllocationExpression) {
  3302. typeRef = ((org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocAllocationExpression) compilerNode).type;
  3303. if (typeRef != null) {
  3304. recordNodes(name, compilerNode);
  3305. }
  3306. } else if (compilerNode instanceof JavadocMessageSend) {
  3307. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression = ((JavadocMessageSend) compilerNode).receiver;
  3308. if (expression instanceof TypeReference) {
  3309. typeRef = (TypeReference) expression;
  3310. }
  3311. // TODO (frederic) remove following line to fix bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=62650
  3312. recordNodes(name, compilerNode);
  3313. }
  3314. // record name and qualifier
  3315. if (typeRef != null && methodRef.getQualifier() != null) {
  3316. recordName(methodRef.getQualifier(), typeRef);
  3317. }
  3318. }
  3319. // Resolve parameters
  3320. for (Object o : methodRef.parameters()) {
  3321. MethodRefParameter param = (MethodRefParameter) o;
  3322. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression) javadoc
  3323. .getNodeStartingAt(param.getStartPosition());
  3324. if (expression != null) {
  3325. recordNodes(param, expression);
  3326. if (expression instanceof JavadocArgumentExpression) {
  3327. JavadocArgumentExpression argExpr = (JavadocArgumentExpression) expression;
  3328. TypeReference typeRef = argExpr.argument.type;
  3329. if (this.ast.apiLevel >= AST.JLS3) {
  3330. param.setVarargs(argExpr.argument.isVarArgs());
  3331. }
  3332. recordNodes(param.getType(), typeRef);
  3333. if (param.getType().isSimpleType()) {
  3334. recordName(((SimpleType) param.getType()).getName(), typeRef);
  3335. } else if (param.getType().isArrayType()) {
  3336. Type type = ((ArrayType) param.getType()).getElementType();
  3337. recordNodes(type, typeRef);
  3338. if (type.isSimpleType()) {
  3339. recordName(((SimpleType) type).getName(), typeRef);
  3340. }
  3341. }
  3342. }
  3343. }
  3344. }
  3345. } else if (node.getNodeType() == ASTNode.SIMPLE_NAME || node.getNodeType() == ASTNode.QUALIFIED_NAME) {
  3346. org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode compilerNode = javadoc.getNodeStartingAt(node
  3347. .getStartPosition());
  3348. recordName((Name) node, compilerNode);
  3349. } else if (node.getNodeType() == ASTNode.TAG_ELEMENT) {
  3350. // resolve member and method references binding
  3351. recordNodes(javadoc, (TagElement) node);
  3352. }
  3353. }
  3354. }
  3355. protected void recordPendingNameScopeResolution(Name name) {
  3356. if (this.pendingNameScopeResolution == null) {
  3357. this.pendingNameScopeResolution = new HashSet();
  3358. }
  3359. this.pendingNameScopeResolution.add(name);
  3360. }
  3361. protected void recordPendingThisExpressionScopeResolution(ThisExpression thisExpression) {
  3362. if (this.pendingThisExpressionScopeResolution == null) {
  3363. this.pendingThisExpressionScopeResolution = new HashSet();
  3364. }
  3365. this.pendingThisExpressionScopeResolution.add(thisExpression);
  3366. }
  3367. // /**
  3368. // * Remove whitespaces and comments before and after the expression.
  3369. // */
  3370. // private void trimWhiteSpacesAndComments(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression) {
  3371. // int start = expression.sourceStart;
  3372. // int end = expression.sourceEnd;
  3373. // int token;
  3374. // int trimLeftPosition = expression.sourceStart;
  3375. // int trimRightPosition = expression.sourceEnd;
  3376. // boolean first = true;
  3377. // Scanner removeBlankScanner = this.ast.scanner;
  3378. // try {
  3379. // removeBlankScanner.setSource(this.compilationUnitSource);
  3380. // removeBlankScanner.resetTo(start, end);
  3381. // while (true) {
  3382. // token = removeBlankScanner.getNextToken();
  3383. // switch (token) {
  3384. // case TerminalTokens.TokenNameCOMMENT_JAVADOC :
  3385. // case TerminalTokens.TokenNameCOMMENT_LINE :
  3386. // case TerminalTokens.TokenNameCOMMENT_BLOCK :
  3387. // if (first) {
  3388. // trimLeftPosition = removeBlankScanner.currentPosition;
  3389. // }
  3390. // break;
  3391. // case TerminalTokens.TokenNameWHITESPACE :
  3392. // if (first) {
  3393. // trimLeftPosition = removeBlankScanner.currentPosition;
  3394. // }
  3395. // break;
  3396. // case TerminalTokens.TokenNameEOF :
  3397. // expression.sourceStart = trimLeftPosition;
  3398. // expression.sourceEnd = trimRightPosition;
  3399. // return;
  3400. // default :
  3401. // /*
  3402. // * if we find something else than a whitespace or a comment,
  3403. // * then we reset the trimRigthPosition to the expression
  3404. // * source end.
  3405. // */
  3406. // trimRightPosition = removeBlankScanner.currentPosition - 1;
  3407. // first = false;
  3408. // }
  3409. // }
  3410. // } catch (InvalidInputException e){
  3411. // // ignore
  3412. // }
  3413. // }
  3414. protected int retrieveEndingSemiColonPosition(int start, int end) {
  3415. int count = 0;
  3416. this.scanner.resetTo(start, end);
  3417. try {
  3418. int token;
  3419. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  3420. switch (token) {
  3421. case TerminalTokens.TokenNameSEMICOLON:
  3422. if (count == 0) {
  3423. return this.scanner.currentPosition - 1;
  3424. }
  3425. break;
  3426. case TerminalTokens.TokenNameLBRACE:
  3427. count++;
  3428. break;
  3429. case TerminalTokens.TokenNameRBRACE:
  3430. count--;
  3431. break;
  3432. case TerminalTokens.TokenNameLPAREN:
  3433. count++;
  3434. break;
  3435. case TerminalTokens.TokenNameRPAREN:
  3436. count--;
  3437. break;
  3438. case TerminalTokens.TokenNameLBRACKET:
  3439. count++;
  3440. break;
  3441. case TerminalTokens.TokenNameRBRACKET:
  3442. count--;
  3443. }
  3444. }
  3445. } catch (InvalidInputException e) {
  3446. // ignore
  3447. }
  3448. return -1;
  3449. }
  3450. /**
  3451. * This method is used to retrieve the ending position for a type declaration when the dimension is right after the type name.
  3452. * For example: int[] i; &rarr; return 5, but int i[] &rarr; return -1;
  3453. *
  3454. * @return int the dimension found
  3455. */
  3456. protected int retrieveEndOfDimensionsPosition(int start, int end) {
  3457. this.scanner.resetTo(start, end);
  3458. int foundPosition = -1;
  3459. try {
  3460. int token;
  3461. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  3462. switch (token) {
  3463. case TerminalTokens.TokenNameLBRACKET:
  3464. case TerminalTokens.TokenNameCOMMENT_BLOCK:
  3465. case TerminalTokens.TokenNameCOMMENT_JAVADOC:
  3466. case TerminalTokens.TokenNameCOMMENT_LINE:
  3467. break;
  3468. case TerminalTokens.TokenNameRBRACKET:// 166
  3469. foundPosition = this.scanner.currentPosition - 1;
  3470. break;
  3471. default:
  3472. return foundPosition;
  3473. }
  3474. }
  3475. } catch (InvalidInputException e) {
  3476. // ignore
  3477. }
  3478. return foundPosition;
  3479. }
  3480. /**
  3481. * This method is used to retrieve the start and end position of a name or primitive type token.
  3482. *
  3483. * @return int[] a single dimensional array, with two elements, for the start and end positions of the name respectively
  3484. */
  3485. protected int[] retrieveEndOfElementTypeNamePosition(int start, int end) {
  3486. this.scanner.resetTo(start, end);
  3487. boolean isAnnotation = false;
  3488. try {
  3489. int token;
  3490. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  3491. switch(token) {
  3492. case TerminalTokens.TokenNameAT:
  3493. isAnnotation = true;
  3494. break;
  3495. case TerminalTokens.TokenNameIdentifier:
  3496. if (isAnnotation) {
  3497. isAnnotation = false;
  3498. break;
  3499. }
  3500. //$FALL-THROUGH$
  3501. case TerminalTokens.TokenNamebyte:
  3502. case TerminalTokens.TokenNamechar:
  3503. case TerminalTokens.TokenNamedouble:
  3504. case TerminalTokens.TokenNamefloat:
  3505. case TerminalTokens.TokenNameint:
  3506. case TerminalTokens.TokenNamelong:
  3507. case TerminalTokens.TokenNameshort:
  3508. case TerminalTokens.TokenNameboolean:
  3509. return new int[]{this.scanner.startPosition, this.scanner.currentPosition - 1};
  3510. }
  3511. }
  3512. } catch(InvalidInputException e) {
  3513. // ignore
  3514. }
  3515. return new int[]{-1, -1};
  3516. }
  3517. /**
  3518. * This method is used to retrieve the position after the right parenthesis.
  3519. *
  3520. * @return int the position found
  3521. */
  3522. protected int retrieveEndOfRightParenthesisPosition(int start, int end) {
  3523. this.scanner.resetTo(start, end);
  3524. try {
  3525. int token;
  3526. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  3527. switch (token) {
  3528. case TerminalTokens.TokenNameRPAREN:
  3529. return this.scanner.currentPosition;
  3530. }
  3531. }
  3532. } catch (InvalidInputException e) {
  3533. // ignore
  3534. }
  3535. return -1;
  3536. }
  3537. /**
  3538. * This method is used to retrieve the array dimension declared after the name of a local or a field declaration. For example:
  3539. * int i, j[] = null, k[][] = {{}}; It should return 0 for i, 1 for j and 2 for k.
  3540. *
  3541. * @return int the dimension found
  3542. */
  3543. protected int retrieveExtraDimension(int start, int end) {
  3544. this.scanner.resetTo(start, end);
  3545. int dimensions = 0;
  3546. try {
  3547. int token;
  3548. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  3549. switch (token) {
  3550. case TerminalTokens.TokenNameLBRACKET:
  3551. case TerminalTokens.TokenNameCOMMENT_BLOCK:
  3552. case TerminalTokens.TokenNameCOMMENT_JAVADOC:
  3553. case TerminalTokens.TokenNameCOMMENT_LINE:
  3554. break;
  3555. case TerminalTokens.TokenNameRBRACKET:// 166
  3556. dimensions++;
  3557. break;
  3558. default:
  3559. return dimensions;
  3560. }
  3561. }
  3562. } catch (InvalidInputException e) {
  3563. // ignore
  3564. }
  3565. return dimensions;
  3566. }
  3567. protected void retrieveIdentifierAndSetPositions(int start, int end, Name name) {
  3568. this.scanner.resetTo(start, end);
  3569. int token;
  3570. try {
  3571. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  3572. if (token == TerminalTokens.TokenNameIdentifier) {
  3573. int startName = this.scanner.startPosition;
  3574. int endName = this.scanner.currentPosition - 1;
  3575. name.setSourceRange(startName, endName - startName + 1);
  3576. return;
  3577. }
  3578. }
  3579. } catch (InvalidInputException e) {
  3580. // ignore
  3581. }
  3582. }
  3583. /**
  3584. * This method is used to retrieve the start position of the block.
  3585. *
  3586. * @return int the dimension found, -1 if none
  3587. */
  3588. protected int retrieveIdentifierEndPosition(int start, int end) {
  3589. this.scanner.resetTo(start, end);
  3590. try {
  3591. int token;
  3592. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  3593. switch (token) {
  3594. case TerminalTokens.TokenNameIdentifier:// 110
  3595. return this.scanner.getCurrentTokenEndPosition();
  3596. }
  3597. }
  3598. } catch (InvalidInputException e) {
  3599. // ignore
  3600. }
  3601. return -1;
  3602. }
  3603. /**
  3604. * This method is used to retrieve position before the next comma or semi-colon.
  3605. *
  3606. * @return int the position found.
  3607. */
  3608. protected int retrievePositionBeforeNextCommaOrSemiColon(int start, int end) {
  3609. this.scanner.resetTo(start, end);
  3610. int braceCounter = 0;
  3611. try {
  3612. int token;
  3613. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  3614. switch (token) {
  3615. case TerminalTokens.TokenNameLBRACE:
  3616. braceCounter++;
  3617. break;
  3618. case TerminalTokens.TokenNameRBRACE:
  3619. braceCounter--;
  3620. break;
  3621. case TerminalTokens.TokenNameLPAREN:
  3622. braceCounter++;
  3623. break;
  3624. case TerminalTokens.TokenNameRPAREN:
  3625. braceCounter--;
  3626. break;
  3627. case TerminalTokens.TokenNameLBRACKET:
  3628. braceCounter++;
  3629. break;
  3630. case TerminalTokens.TokenNameRBRACKET:
  3631. braceCounter--;
  3632. break;
  3633. case TerminalTokens.TokenNameCOMMA:
  3634. case TerminalTokens.TokenNameSEMICOLON:
  3635. if (braceCounter == 0) {
  3636. return this.scanner.startPosition - 1;
  3637. }
  3638. }
  3639. }
  3640. } catch (InvalidInputException e) {
  3641. // ignore
  3642. }
  3643. return -1;
  3644. }
  3645. protected int retrieveProperRightBracketPosition(int bracketNumber, int start) {
  3646. this.scanner.resetTo(start, this.compilationUnitSourceLength);
  3647. try {
  3648. int token, count = 0;
  3649. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  3650. switch (token) {
  3651. case TerminalTokens.TokenNameRBRACKET:
  3652. count++;
  3653. if (count == bracketNumber) {
  3654. return this.scanner.currentPosition - 1;
  3655. }
  3656. }
  3657. }
  3658. } catch (InvalidInputException e) {
  3659. // ignore
  3660. }
  3661. return -1;
  3662. }
  3663. /**
  3664. * This method is used to retrieve position before the next right brace or semi-colon.
  3665. *
  3666. * @return int the position found.
  3667. */
  3668. protected int retrieveRightBraceOrSemiColonPosition(int start, int end) {
  3669. this.scanner.resetTo(start, end);
  3670. try {
  3671. int token;
  3672. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  3673. switch (token) {
  3674. case TerminalTokens.TokenNameRBRACE:
  3675. return this.scanner.currentPosition - 1;
  3676. case TerminalTokens.TokenNameSEMICOLON:
  3677. return this.scanner.currentPosition - 1;
  3678. }
  3679. }
  3680. } catch (InvalidInputException e) {
  3681. // ignore
  3682. }
  3683. return -1;
  3684. }
  3685. /**
  3686. * This method is used to retrieve position before the next right brace or semi-colon.
  3687. *
  3688. * @return int the position found.
  3689. */
  3690. protected int retrieveRightBrace(int start, int end) {
  3691. this.scanner.resetTo(start, end);
  3692. try {
  3693. int token;
  3694. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  3695. switch (token) {
  3696. case TerminalTokens.TokenNameRBRACE:
  3697. return this.scanner.currentPosition - 1;
  3698. }
  3699. }
  3700. } catch (InvalidInputException e) {
  3701. // ignore
  3702. }
  3703. return -1;
  3704. }
  3705. /**
  3706. * This method is used to retrieve the position of the right bracket.
  3707. *
  3708. * @return int the dimension found, -1 if none
  3709. */
  3710. protected int retrieveRightBracketPosition(int start, int end) {
  3711. this.scanner.resetTo(start, end);
  3712. try {
  3713. int token;
  3714. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  3715. switch (token) {
  3716. case TerminalTokens.TokenNameRBRACKET:
  3717. return this.scanner.currentPosition - 1;
  3718. }
  3719. }
  3720. } catch (InvalidInputException e) {
  3721. // ignore
  3722. }
  3723. return -1;
  3724. }
  3725. /*
  3726. * This method is used to set the right end position for expression statement. The actual AST nodes don't include the trailing
  3727. * semicolon. This method fixes the length of the corresponding node.
  3728. */
  3729. protected void retrieveSemiColonPosition(ASTNode node) {
  3730. int start = node.getStartPosition();
  3731. int length = node.getLength();
  3732. int end = start + length;
  3733. int count = 0;
  3734. this.scanner.resetTo(end, this.compilationUnitSourceLength);
  3735. try {
  3736. int token;
  3737. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  3738. switch (token) {
  3739. case TerminalTokens.TokenNameSEMICOLON:
  3740. if (count == 0) {
  3741. node.setSourceRange(start, this.scanner.currentPosition - start);
  3742. return;
  3743. }
  3744. break;
  3745. case TerminalTokens.TokenNameLBRACE:
  3746. count++;
  3747. break;
  3748. case TerminalTokens.TokenNameRBRACE:
  3749. count--;
  3750. break;
  3751. case TerminalTokens.TokenNameLPAREN:
  3752. count++;
  3753. break;
  3754. case TerminalTokens.TokenNameRPAREN:
  3755. count--;
  3756. break;
  3757. case TerminalTokens.TokenNameLBRACKET:
  3758. count++;
  3759. break;
  3760. case TerminalTokens.TokenNameRBRACKET:
  3761. count--;
  3762. }
  3763. }
  3764. } catch (InvalidInputException e) {
  3765. // ignore
  3766. }
  3767. }
  3768. /**
  3769. * This method is used to retrieve the start position of the block.
  3770. *
  3771. * @return int the dimension found, -1 if none
  3772. */
  3773. protected int retrieveStartBlockPosition(int start, int end) {
  3774. this.scanner.resetTo(start, end);
  3775. try {
  3776. int token;
  3777. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  3778. switch (token) {
  3779. case TerminalTokens.TokenNameLBRACE:// 110
  3780. return this.scanner.startPosition;
  3781. }
  3782. }
  3783. } catch (InvalidInputException e) {
  3784. // ignore
  3785. }
  3786. return -1;
  3787. }
  3788. /**
  3789. * This method is used to retrieve the starting position of the catch keyword.
  3790. *
  3791. * @return int the dimension found, -1 if none
  3792. */
  3793. protected int retrieveStartingCatchPosition(int start, int end) {
  3794. this.scanner.resetTo(start, end);
  3795. try {
  3796. int token;
  3797. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  3798. switch (token) {
  3799. case TerminalTokens.TokenNamecatch:// 225
  3800. return this.scanner.startPosition;
  3801. }
  3802. }
  3803. } catch (InvalidInputException e) {
  3804. // ignore
  3805. }
  3806. return -1;
  3807. }
  3808. public void setAST(AST ast) {
  3809. this.ast = ast;
  3810. this.docParser = new DocCommentParser(this.ast, this.scanner, this.insideComments);
  3811. }
  3812. protected void setModifiers(AnnotationTypeDeclaration typeDecl,
  3813. org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration) {
  3814. this.scanner.resetTo(typeDeclaration.declarationSourceStart, typeDeclaration.sourceStart);
  3815. this.setModifiers(typeDecl, typeDeclaration.annotations);
  3816. }
  3817. protected void setModifiers(AnnotationTypeMemberDeclaration annotationTypeMemberDecl,
  3818. org.aspectj.org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration annotationTypeMemberDeclaration) {
  3819. this.scanner.resetTo(annotationTypeMemberDeclaration.declarationSourceStart, annotationTypeMemberDeclaration.sourceStart);
  3820. this.setModifiers(annotationTypeMemberDecl, annotationTypeMemberDeclaration.annotations);
  3821. }
  3822. /**
  3823. * @param bodyDeclaration
  3824. */
  3825. protected void setModifiers(BodyDeclaration bodyDeclaration,
  3826. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation[] annotations) {
  3827. try {
  3828. int token;
  3829. int indexInAnnotations = 0;
  3830. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  3831. IExtendedModifier modifier = null;
  3832. switch (token) {
  3833. case TerminalTokens.TokenNameabstract:
  3834. modifier = createModifier(Modifier.ModifierKeyword.ABSTRACT_KEYWORD);
  3835. break;
  3836. case TerminalTokens.TokenNamepublic:
  3837. modifier = createModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
  3838. break;
  3839. case TerminalTokens.TokenNamestatic:
  3840. modifier = createModifier(Modifier.ModifierKeyword.STATIC_KEYWORD);
  3841. break;
  3842. case TerminalTokens.TokenNameprotected:
  3843. modifier = createModifier(Modifier.ModifierKeyword.PROTECTED_KEYWORD);
  3844. break;
  3845. case TerminalTokens.TokenNameprivate:
  3846. modifier = createModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD);
  3847. break;
  3848. case TerminalTokens.TokenNamefinal:
  3849. modifier = createModifier(Modifier.ModifierKeyword.FINAL_KEYWORD);
  3850. break;
  3851. case TerminalTokens.TokenNamenative:
  3852. modifier = createModifier(Modifier.ModifierKeyword.NATIVE_KEYWORD);
  3853. break;
  3854. case TerminalTokens.TokenNamesynchronized:
  3855. modifier = createModifier(Modifier.ModifierKeyword.SYNCHRONIZED_KEYWORD);
  3856. break;
  3857. case TerminalTokens.TokenNametransient:
  3858. modifier = createModifier(Modifier.ModifierKeyword.TRANSIENT_KEYWORD);
  3859. break;
  3860. case TerminalTokens.TokenNamevolatile:
  3861. modifier = createModifier(Modifier.ModifierKeyword.VOLATILE_KEYWORD);
  3862. break;
  3863. case TerminalTokens.TokenNamestrictfp:
  3864. modifier = createModifier(Modifier.ModifierKeyword.STRICTFP_KEYWORD);
  3865. break;
  3866. case TerminalTokens.TokenNameAT:
  3867. // we have an annotation
  3868. if (annotations != null && indexInAnnotations < annotations.length) {
  3869. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation annotation = annotations[indexInAnnotations++];
  3870. modifier = super.convert(annotation);
  3871. this.scanner.resetTo(annotation.declarationSourceEnd + 1, this.compilationUnitSourceLength);
  3872. }
  3873. break;
  3874. case TerminalTokens.TokenNameCOMMENT_BLOCK:
  3875. case TerminalTokens.TokenNameCOMMENT_LINE:
  3876. case TerminalTokens.TokenNameCOMMENT_JAVADOC:
  3877. break;
  3878. default:
  3879. return;
  3880. }
  3881. if (modifier != null) {
  3882. bodyDeclaration.modifiers().add(modifier);
  3883. }
  3884. }
  3885. } catch (InvalidInputException e) {
  3886. // ignore
  3887. }
  3888. }
  3889. protected void setModifiers(EnumDeclaration enumDeclaration,
  3890. org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration enumDeclaration2) {
  3891. this.scanner.resetTo(enumDeclaration2.declarationSourceStart, enumDeclaration2.sourceStart);
  3892. this.setModifiers(enumDeclaration, enumDeclaration2.annotations);
  3893. }
  3894. protected void setModifiers(EnumConstantDeclaration enumConstantDeclaration,
  3895. org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration) {
  3896. switch (this.ast.apiLevel) {
  3897. case AST.JLS2_INTERNAL:
  3898. enumConstantDeclaration.internalSetModifiers(fieldDeclaration.modifiers & ExtraCompilerModifiers.AccJustFlag);
  3899. if (fieldDeclaration.annotations != null) {
  3900. enumConstantDeclaration.setFlags(enumConstantDeclaration.getFlags() | ASTNode.MALFORMED);
  3901. }
  3902. break;
  3903. case AST.JLS3:
  3904. this.scanner.resetTo(fieldDeclaration.declarationSourceStart, fieldDeclaration.sourceStart);
  3905. this.setModifiers(enumConstantDeclaration, fieldDeclaration.annotations);
  3906. }
  3907. }
  3908. /**
  3909. * @param fieldDeclaration
  3910. * @param fieldDecl
  3911. */
  3912. protected void setModifiers(FieldDeclaration fieldDeclaration,
  3913. org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDecl) {
  3914. switch (this.ast.apiLevel) {
  3915. case AST.JLS2_INTERNAL:
  3916. fieldDeclaration.internalSetModifiers(fieldDecl.modifiers & ExtraCompilerModifiers.AccJustFlag);
  3917. if (fieldDecl.annotations != null) {
  3918. fieldDeclaration.setFlags(fieldDeclaration.getFlags() | ASTNode.MALFORMED);
  3919. }
  3920. break;
  3921. case AST.JLS3:
  3922. this.scanner.resetTo(fieldDecl.declarationSourceStart, fieldDecl.sourceStart);
  3923. this.setModifiers(fieldDeclaration, fieldDecl.annotations);
  3924. }
  3925. }
  3926. protected void setModifiers(org.aspectj.org.eclipse.jdt.core.dom.InterTypeFieldDeclaration fieldDeclaration,
  3927. InterTypeFieldDeclaration fieldDecl) {
  3928. // ajh02: method added
  3929. switch (this.ast.apiLevel) {
  3930. case AST.JLS2_INTERNAL:
  3931. fieldDeclaration.internalSetModifiers(fieldDecl.declaredModifiers & ExtraCompilerModifiers.AccJustFlag);
  3932. if (fieldDecl.annotations != null) {
  3933. fieldDeclaration.setFlags(fieldDeclaration.getFlags() | ASTNode.MALFORMED);
  3934. }
  3935. break;
  3936. case AST.JLS3:
  3937. this.scanner.resetTo(fieldDecl.declarationSourceStart, fieldDecl.sourceStart);
  3938. this.setModifiers(fieldDeclaration, fieldDecl.annotations);
  3939. }
  3940. }
  3941. /**
  3942. * @param initializer
  3943. * @param oldInitializer
  3944. */
  3945. protected void setModifiers(Initializer initializer,
  3946. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Initializer oldInitializer) {
  3947. switch (this.ast.apiLevel) {
  3948. case AST.JLS2_INTERNAL:
  3949. initializer.internalSetModifiers(oldInitializer.modifiers & ExtraCompilerModifiers.AccJustFlag);
  3950. if (oldInitializer.annotations != null) {
  3951. initializer.setFlags(initializer.getFlags() | ASTNode.MALFORMED);
  3952. }
  3953. break;
  3954. case AST.JLS3:
  3955. this.scanner.resetTo(oldInitializer.declarationSourceStart, oldInitializer.bodyStart);
  3956. this.setModifiers(initializer, oldInitializer.annotations);
  3957. }
  3958. }
  3959. /**
  3960. * @param methodDecl
  3961. * @param methodDeclaration
  3962. */
  3963. protected void setModifiers(MethodDeclaration methodDecl, AbstractMethodDeclaration methodDeclaration) {
  3964. switch (this.ast.apiLevel) {
  3965. case AST.JLS2_INTERNAL:
  3966. if (methodDeclaration instanceof InterTypeDeclaration) {
  3967. methodDecl.internalSetModifiers(((InterTypeDeclaration) methodDeclaration).declaredModifiers
  3968. & ExtraCompilerModifiers.AccJustFlag);
  3969. } else {
  3970. methodDecl.internalSetModifiers(methodDeclaration.modifiers & ExtraCompilerModifiers.AccJustFlag);
  3971. }
  3972. if (methodDeclaration.annotations != null) {
  3973. methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
  3974. }
  3975. break;
  3976. case AST.JLS3:
  3977. this.scanner.resetTo(methodDeclaration.declarationSourceStart, methodDeclaration.sourceStart);
  3978. this.setModifiers(methodDecl, methodDeclaration.annotations);
  3979. }
  3980. }
  3981. protected void setModifiers(org.aspectj.org.eclipse.jdt.core.dom.PointcutDeclaration pointcutDecl,
  3982. PointcutDeclaration pointcutDeclaration) {
  3983. // ajh02: method added
  3984. switch (this.ast.apiLevel) {
  3985. case AST.JLS2_INTERNAL:
  3986. pointcutDecl.internalSetModifiers(pointcutDeclaration.modifiers & ExtraCompilerModifiers.AccJustFlag);
  3987. if (pointcutDeclaration.annotations != null) {
  3988. pointcutDecl.setFlags(pointcutDecl.getFlags() | ASTNode.MALFORMED);
  3989. }
  3990. break;
  3991. case AST.JLS3:
  3992. this.scanner.resetTo(pointcutDeclaration.declarationSourceStart, pointcutDeclaration.sourceStart);
  3993. this.setModifiers(pointcutDecl, pointcutDeclaration.annotations);
  3994. }
  3995. }
  3996. /**
  3997. * @param variableDecl
  3998. * @param argument
  3999. */
  4000. protected void setModifiers(SingleVariableDeclaration variableDecl, Argument argument) {
  4001. switch (this.ast.apiLevel) {
  4002. case AST.JLS2_INTERNAL:
  4003. variableDecl.internalSetModifiers(argument.modifiers & ExtraCompilerModifiers.AccJustFlag);
  4004. if (argument.annotations != null) {
  4005. variableDecl.setFlags(variableDecl.getFlags() | ASTNode.MALFORMED);
  4006. }
  4007. break;
  4008. case AST.JLS3:
  4009. this.scanner.resetTo(argument.declarationSourceStart, argument.sourceStart);
  4010. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation[] annotations = argument.annotations;
  4011. int indexInAnnotations = 0;
  4012. try {
  4013. int token;
  4014. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  4015. IExtendedModifier modifier = null;
  4016. switch (token) {
  4017. case TerminalTokens.TokenNameabstract:
  4018. modifier = createModifier(Modifier.ModifierKeyword.ABSTRACT_KEYWORD);
  4019. break;
  4020. case TerminalTokens.TokenNamepublic:
  4021. modifier = createModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
  4022. break;
  4023. case TerminalTokens.TokenNamestatic:
  4024. modifier = createModifier(Modifier.ModifierKeyword.STATIC_KEYWORD);
  4025. break;
  4026. case TerminalTokens.TokenNameprotected:
  4027. modifier = createModifier(Modifier.ModifierKeyword.PROTECTED_KEYWORD);
  4028. break;
  4029. case TerminalTokens.TokenNameprivate:
  4030. modifier = createModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD);
  4031. break;
  4032. case TerminalTokens.TokenNamefinal:
  4033. modifier = createModifier(Modifier.ModifierKeyword.FINAL_KEYWORD);
  4034. break;
  4035. case TerminalTokens.TokenNamenative:
  4036. modifier = createModifier(Modifier.ModifierKeyword.NATIVE_KEYWORD);
  4037. break;
  4038. case TerminalTokens.TokenNamesynchronized:
  4039. modifier = createModifier(Modifier.ModifierKeyword.SYNCHRONIZED_KEYWORD);
  4040. break;
  4041. case TerminalTokens.TokenNametransient:
  4042. modifier = createModifier(Modifier.ModifierKeyword.TRANSIENT_KEYWORD);
  4043. break;
  4044. case TerminalTokens.TokenNamevolatile:
  4045. modifier = createModifier(Modifier.ModifierKeyword.VOLATILE_KEYWORD);
  4046. break;
  4047. case TerminalTokens.TokenNamestrictfp:
  4048. modifier = createModifier(Modifier.ModifierKeyword.STRICTFP_KEYWORD);
  4049. break;
  4050. case TerminalTokens.TokenNameAT:
  4051. // we have an annotation
  4052. if (annotations != null && indexInAnnotations < annotations.length) {
  4053. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation annotation = annotations[indexInAnnotations++];
  4054. modifier = super.convert(annotation);
  4055. this.scanner.resetTo(annotation.declarationSourceEnd + 1, this.compilationUnitSourceLength);
  4056. }
  4057. break;
  4058. case TerminalTokens.TokenNameCOMMENT_BLOCK:
  4059. case TerminalTokens.TokenNameCOMMENT_LINE:
  4060. case TerminalTokens.TokenNameCOMMENT_JAVADOC:
  4061. break;
  4062. default:
  4063. return;
  4064. }
  4065. if (modifier != null) {
  4066. variableDecl.modifiers().add(modifier);
  4067. }
  4068. }
  4069. } catch (InvalidInputException e) {
  4070. // ignore
  4071. }
  4072. }
  4073. }
  4074. protected void setModifiers(SingleVariableDeclaration variableDecl, LocalDeclaration localDeclaration) {
  4075. switch (this.ast.apiLevel) {
  4076. case AST.JLS2_INTERNAL:
  4077. variableDecl.internalSetModifiers(localDeclaration.modifiers & ExtraCompilerModifiers.AccJustFlag);
  4078. if (localDeclaration.annotations != null) {
  4079. variableDecl.setFlags(variableDecl.getFlags() | ASTNode.MALFORMED);
  4080. }
  4081. break;
  4082. case AST.JLS3:
  4083. this.scanner.resetTo(localDeclaration.declarationSourceStart, localDeclaration.sourceStart);
  4084. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation[] annotations = localDeclaration.annotations;
  4085. int indexInAnnotations = 0;
  4086. try {
  4087. int token;
  4088. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  4089. IExtendedModifier modifier = null;
  4090. switch (token) {
  4091. case TerminalTokens.TokenNameabstract:
  4092. modifier = createModifier(Modifier.ModifierKeyword.ABSTRACT_KEYWORD);
  4093. break;
  4094. case TerminalTokens.TokenNamepublic:
  4095. modifier = createModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
  4096. break;
  4097. case TerminalTokens.TokenNamestatic:
  4098. modifier = createModifier(Modifier.ModifierKeyword.STATIC_KEYWORD);
  4099. break;
  4100. case TerminalTokens.TokenNameprotected:
  4101. modifier = createModifier(Modifier.ModifierKeyword.PROTECTED_KEYWORD);
  4102. break;
  4103. case TerminalTokens.TokenNameprivate:
  4104. modifier = createModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD);
  4105. break;
  4106. case TerminalTokens.TokenNamefinal:
  4107. modifier = createModifier(Modifier.ModifierKeyword.FINAL_KEYWORD);
  4108. break;
  4109. case TerminalTokens.TokenNamenative:
  4110. modifier = createModifier(Modifier.ModifierKeyword.NATIVE_KEYWORD);
  4111. break;
  4112. case TerminalTokens.TokenNamesynchronized:
  4113. modifier = createModifier(Modifier.ModifierKeyword.SYNCHRONIZED_KEYWORD);
  4114. break;
  4115. case TerminalTokens.TokenNametransient:
  4116. modifier = createModifier(Modifier.ModifierKeyword.TRANSIENT_KEYWORD);
  4117. break;
  4118. case TerminalTokens.TokenNamevolatile:
  4119. modifier = createModifier(Modifier.ModifierKeyword.VOLATILE_KEYWORD);
  4120. break;
  4121. case TerminalTokens.TokenNamestrictfp:
  4122. modifier = createModifier(Modifier.ModifierKeyword.STRICTFP_KEYWORD);
  4123. break;
  4124. case TerminalTokens.TokenNameAT:
  4125. // we have an annotation
  4126. if (annotations != null && indexInAnnotations < annotations.length) {
  4127. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation annotation = annotations[indexInAnnotations++];
  4128. modifier = super.convert(annotation);
  4129. this.scanner.resetTo(annotation.declarationSourceEnd + 1, this.compilationUnitSourceLength);
  4130. }
  4131. break;
  4132. case TerminalTokens.TokenNameCOMMENT_BLOCK:
  4133. case TerminalTokens.TokenNameCOMMENT_LINE:
  4134. case TerminalTokens.TokenNameCOMMENT_JAVADOC:
  4135. break;
  4136. default:
  4137. return;
  4138. }
  4139. if (modifier != null) {
  4140. variableDecl.modifiers().add(modifier);
  4141. }
  4142. }
  4143. } catch (InvalidInputException e) {
  4144. // ignore
  4145. }
  4146. }
  4147. }
  4148. /**
  4149. * @param typeDecl
  4150. * @param typeDeclaration
  4151. */
  4152. protected void setModifiers(TypeDeclaration typeDecl,
  4153. org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration) {
  4154. switch (this.ast.apiLevel) {
  4155. case AST.JLS2_INTERNAL:
  4156. int modifiers = typeDeclaration.modifiers;
  4157. modifiers &= ~ClassFileConstants.AccInterface; // remove AccInterface flags
  4158. modifiers &= ExtraCompilerModifiers.AccJustFlag;
  4159. typeDecl.internalSetModifiers(modifiers);
  4160. if (typeDeclaration.annotations != null) {
  4161. typeDecl.setFlags(typeDecl.getFlags() | ASTNode.MALFORMED);
  4162. }
  4163. break;
  4164. case AST.JLS3:
  4165. this.scanner.resetTo(typeDeclaration.declarationSourceStart, typeDeclaration.sourceStart);
  4166. this.setModifiers(typeDecl, typeDeclaration.annotations);
  4167. }
  4168. }
  4169. /**
  4170. * @param variableDeclarationExpression
  4171. * @param localDeclaration
  4172. */
  4173. protected void setModifiers(VariableDeclarationExpression variableDeclarationExpression, LocalDeclaration localDeclaration) {
  4174. switch (this.ast.apiLevel) {
  4175. case AST.JLS2_INTERNAL:
  4176. int modifiers = localDeclaration.modifiers & ExtraCompilerModifiers.AccJustFlag;
  4177. modifiers &= ~ExtraCompilerModifiers.AccBlankFinal;
  4178. variableDeclarationExpression.internalSetModifiers(modifiers);
  4179. if (localDeclaration.annotations != null) {
  4180. variableDeclarationExpression.setFlags(variableDeclarationExpression.getFlags() | ASTNode.MALFORMED);
  4181. }
  4182. break;
  4183. case AST.JLS3:
  4184. this.scanner.resetTo(localDeclaration.declarationSourceStart, localDeclaration.sourceStart);
  4185. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation[] annotations = localDeclaration.annotations;
  4186. int indexInAnnotations = 0;
  4187. try {
  4188. int token;
  4189. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  4190. IExtendedModifier modifier = null;
  4191. switch (token) {
  4192. case TerminalTokens.TokenNameabstract:
  4193. modifier = createModifier(Modifier.ModifierKeyword.ABSTRACT_KEYWORD);
  4194. break;
  4195. case TerminalTokens.TokenNamepublic:
  4196. modifier = createModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
  4197. break;
  4198. case TerminalTokens.TokenNamestatic:
  4199. modifier = createModifier(Modifier.ModifierKeyword.STATIC_KEYWORD);
  4200. break;
  4201. case TerminalTokens.TokenNameprotected:
  4202. modifier = createModifier(Modifier.ModifierKeyword.PROTECTED_KEYWORD);
  4203. break;
  4204. case TerminalTokens.TokenNameprivate:
  4205. modifier = createModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD);
  4206. break;
  4207. case TerminalTokens.TokenNamefinal:
  4208. modifier = createModifier(Modifier.ModifierKeyword.FINAL_KEYWORD);
  4209. break;
  4210. case TerminalTokens.TokenNamenative:
  4211. modifier = createModifier(Modifier.ModifierKeyword.NATIVE_KEYWORD);
  4212. break;
  4213. case TerminalTokens.TokenNamesynchronized:
  4214. modifier = createModifier(Modifier.ModifierKeyword.SYNCHRONIZED_KEYWORD);
  4215. break;
  4216. case TerminalTokens.TokenNametransient:
  4217. modifier = createModifier(Modifier.ModifierKeyword.TRANSIENT_KEYWORD);
  4218. break;
  4219. case TerminalTokens.TokenNamevolatile:
  4220. modifier = createModifier(Modifier.ModifierKeyword.VOLATILE_KEYWORD);
  4221. break;
  4222. case TerminalTokens.TokenNamestrictfp:
  4223. modifier = createModifier(Modifier.ModifierKeyword.STRICTFP_KEYWORD);
  4224. break;
  4225. case TerminalTokens.TokenNameAT:
  4226. // we have an annotation
  4227. if (annotations != null && indexInAnnotations < annotations.length) {
  4228. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation annotation = annotations[indexInAnnotations++];
  4229. modifier = super.convert(annotation);
  4230. this.scanner.resetTo(annotation.declarationSourceEnd + 1, this.compilationUnitSourceLength);
  4231. }
  4232. break;
  4233. case TerminalTokens.TokenNameCOMMENT_BLOCK:
  4234. case TerminalTokens.TokenNameCOMMENT_LINE:
  4235. case TerminalTokens.TokenNameCOMMENT_JAVADOC:
  4236. break;
  4237. default:
  4238. return;
  4239. }
  4240. if (modifier != null) {
  4241. variableDeclarationExpression.modifiers().add(modifier);
  4242. }
  4243. }
  4244. } catch (InvalidInputException e) {
  4245. // ignore
  4246. }
  4247. }
  4248. }
  4249. /**
  4250. * @param variableDeclarationStatement
  4251. * @param localDeclaration
  4252. */
  4253. protected void setModifiers(VariableDeclarationStatement variableDeclarationStatement, LocalDeclaration localDeclaration) {
  4254. switch (this.ast.apiLevel) {
  4255. case AST.JLS2_INTERNAL:
  4256. int modifiers = localDeclaration.modifiers & ExtraCompilerModifiers.AccJustFlag;
  4257. modifiers &= ~ExtraCompilerModifiers.AccBlankFinal;
  4258. variableDeclarationStatement.internalSetModifiers(modifiers);
  4259. if (localDeclaration.annotations != null) {
  4260. variableDeclarationStatement.setFlags(variableDeclarationStatement.getFlags() | ASTNode.MALFORMED);
  4261. }
  4262. break;
  4263. case AST.JLS3:
  4264. this.scanner.resetTo(localDeclaration.declarationSourceStart, localDeclaration.sourceStart);
  4265. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation[] annotations = localDeclaration.annotations;
  4266. int indexInAnnotations = 0;
  4267. try {
  4268. int token;
  4269. while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
  4270. IExtendedModifier modifier = null;
  4271. switch (token) {
  4272. case TerminalTokens.TokenNameabstract:
  4273. modifier = createModifier(Modifier.ModifierKeyword.ABSTRACT_KEYWORD);
  4274. break;
  4275. case TerminalTokens.TokenNamepublic:
  4276. modifier = createModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
  4277. break;
  4278. case TerminalTokens.TokenNamestatic:
  4279. modifier = createModifier(Modifier.ModifierKeyword.STATIC_KEYWORD);
  4280. break;
  4281. case TerminalTokens.TokenNameprotected:
  4282. modifier = createModifier(Modifier.ModifierKeyword.PROTECTED_KEYWORD);
  4283. break;
  4284. case TerminalTokens.TokenNameprivate:
  4285. modifier = createModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD);
  4286. break;
  4287. case TerminalTokens.TokenNamefinal:
  4288. modifier = createModifier(Modifier.ModifierKeyword.FINAL_KEYWORD);
  4289. break;
  4290. case TerminalTokens.TokenNamenative:
  4291. modifier = createModifier(Modifier.ModifierKeyword.NATIVE_KEYWORD);
  4292. break;
  4293. case TerminalTokens.TokenNamesynchronized:
  4294. modifier = createModifier(Modifier.ModifierKeyword.SYNCHRONIZED_KEYWORD);
  4295. break;
  4296. case TerminalTokens.TokenNametransient:
  4297. modifier = createModifier(Modifier.ModifierKeyword.TRANSIENT_KEYWORD);
  4298. break;
  4299. case TerminalTokens.TokenNamevolatile:
  4300. modifier = createModifier(Modifier.ModifierKeyword.VOLATILE_KEYWORD);
  4301. break;
  4302. case TerminalTokens.TokenNamestrictfp:
  4303. modifier = createModifier(Modifier.ModifierKeyword.STRICTFP_KEYWORD);
  4304. break;
  4305. case TerminalTokens.TokenNameAT:
  4306. // we have an annotation
  4307. if (annotations != null && indexInAnnotations < annotations.length) {
  4308. org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation annotation = annotations[indexInAnnotations++];
  4309. modifier = super.convert(annotation);
  4310. this.scanner.resetTo(annotation.declarationSourceEnd + 1, this.compilationUnitSourceLength);
  4311. }
  4312. break;
  4313. case TerminalTokens.TokenNameCOMMENT_BLOCK:
  4314. case TerminalTokens.TokenNameCOMMENT_LINE:
  4315. case TerminalTokens.TokenNameCOMMENT_JAVADOC:
  4316. break;
  4317. default:
  4318. return;
  4319. }
  4320. if (modifier != null) {
  4321. variableDeclarationStatement.modifiers().add(modifier);
  4322. }
  4323. }
  4324. } catch (InvalidInputException e) {
  4325. // ignore
  4326. }
  4327. }
  4328. }
  4329. protected QualifiedName setQualifiedNameNameAndSourceRanges(char[][] typeName, long[] positions,
  4330. org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode node) {
  4331. int length = typeName.length;
  4332. final SimpleName firstToken = new SimpleName(this.ast);
  4333. firstToken.internalSetIdentifier(new String(typeName[0]));
  4334. firstToken.index = 1;
  4335. int start0 = (int) (positions[0] >>> 32);
  4336. int start = start0;
  4337. int end = (int) (positions[0] & 0xFFFFFFFF);
  4338. firstToken.setSourceRange(start, end - start + 1);
  4339. final SimpleName secondToken = new SimpleName(this.ast);
  4340. secondToken.internalSetIdentifier(new String(typeName[1]));
  4341. secondToken.index = 2;
  4342. start = (int) (positions[1] >>> 32);
  4343. end = (int) (positions[1] & 0xFFFFFFFF);
  4344. secondToken.setSourceRange(start, end - start + 1);
  4345. QualifiedName qualifiedName = new QualifiedName(this.ast);
  4346. qualifiedName.setQualifier(firstToken);
  4347. qualifiedName.setName(secondToken);
  4348. if (this.resolveBindings) {
  4349. recordNodes(qualifiedName, node);
  4350. recordPendingNameScopeResolution(qualifiedName);
  4351. recordNodes(firstToken, node);
  4352. recordNodes(secondToken, node);
  4353. recordPendingNameScopeResolution(firstToken);
  4354. recordPendingNameScopeResolution(secondToken);
  4355. }
  4356. qualifiedName.index = 2;
  4357. qualifiedName.setSourceRange(start0, end - start0 + 1);
  4358. SimpleName newPart = null;
  4359. for (int i = 2; i < length; i++) {
  4360. newPart = new SimpleName(this.ast);
  4361. newPart.internalSetIdentifier(new String(typeName[i]));
  4362. newPart.index = i + 1;
  4363. start = (int) (positions[i] >>> 32);
  4364. end = (int) (positions[i] & 0xFFFFFFFF);
  4365. newPart.setSourceRange(start, end - start + 1);
  4366. QualifiedName qualifiedName2 = new QualifiedName(this.ast);
  4367. qualifiedName2.setQualifier(qualifiedName);
  4368. qualifiedName2.setName(newPart);
  4369. qualifiedName = qualifiedName2;
  4370. qualifiedName.index = newPart.index;
  4371. qualifiedName.setSourceRange(start0, end - start0 + 1);
  4372. if (this.resolveBindings) {
  4373. recordNodes(qualifiedName, node);
  4374. recordNodes(newPart, node);
  4375. recordPendingNameScopeResolution(qualifiedName);
  4376. recordPendingNameScopeResolution(newPart);
  4377. }
  4378. }
  4379. QualifiedName name = qualifiedName;
  4380. if (this.resolveBindings) {
  4381. recordNodes(name, node);
  4382. recordPendingNameScopeResolution(name);
  4383. }
  4384. return name;
  4385. }
  4386. protected QualifiedName setQualifiedNameNameAndSourceRanges(char[][] typeName, long[] positions, int endingIndex,
  4387. org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode node) {
  4388. int length = endingIndex + 1;
  4389. final SimpleName firstToken = new SimpleName(this.ast);
  4390. firstToken.internalSetIdentifier(new String(typeName[0]));
  4391. firstToken.index = 1;
  4392. int start0 = (int) (positions[0] >>> 32);
  4393. int start = start0;
  4394. int end = (int) positions[0];
  4395. firstToken.setSourceRange(start, end - start + 1);
  4396. final SimpleName secondToken = new SimpleName(this.ast);
  4397. secondToken.internalSetIdentifier(new String(typeName[1]));
  4398. secondToken.index = 2;
  4399. start = (int) (positions[1] >>> 32);
  4400. end = (int) positions[1];
  4401. secondToken.setSourceRange(start, end - start + 1);
  4402. QualifiedName qualifiedName = new QualifiedName(this.ast);
  4403. qualifiedName.setQualifier(firstToken);
  4404. qualifiedName.setName(secondToken);
  4405. if (this.resolveBindings) {
  4406. recordNodes(qualifiedName, node);
  4407. recordPendingNameScopeResolution(qualifiedName);
  4408. recordNodes(firstToken, node);
  4409. recordNodes(secondToken, node);
  4410. recordPendingNameScopeResolution(firstToken);
  4411. recordPendingNameScopeResolution(secondToken);
  4412. }
  4413. qualifiedName.index = 2;
  4414. qualifiedName.setSourceRange(start0, end - start0 + 1);
  4415. SimpleName newPart = null;
  4416. for (int i = 2; i < length; i++) {
  4417. newPart = new SimpleName(this.ast);
  4418. newPart.internalSetIdentifier(new String(typeName[i]));
  4419. newPart.index = i + 1;
  4420. start = (int) (positions[i] >>> 32);
  4421. end = (int) positions[i];
  4422. newPart.setSourceRange(start, end - start + 1);
  4423. QualifiedName qualifiedName2 = new QualifiedName(this.ast);
  4424. qualifiedName2.setQualifier(qualifiedName);
  4425. qualifiedName2.setName(newPart);
  4426. qualifiedName = qualifiedName2;
  4427. qualifiedName.index = newPart.index;
  4428. qualifiedName.setSourceRange(start0, end - start0 + 1);
  4429. if (this.resolveBindings) {
  4430. recordNodes(qualifiedName, node);
  4431. recordNodes(newPart, node);
  4432. recordPendingNameScopeResolution(qualifiedName);
  4433. recordPendingNameScopeResolution(newPart);
  4434. }
  4435. }
  4436. if (newPart == null && this.resolveBindings) {
  4437. recordNodes(qualifiedName, node);
  4438. recordPendingNameScopeResolution(qualifiedName);
  4439. }
  4440. return qualifiedName;
  4441. }
  4442. protected void setTypeNameForAnnotation(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation compilerAnnotation,
  4443. Annotation annotation) {
  4444. TypeReference typeReference = compilerAnnotation.type;
  4445. if (typeReference instanceof QualifiedTypeReference) {
  4446. QualifiedTypeReference qualifiedTypeReference = (QualifiedTypeReference) typeReference;
  4447. char[][] tokens = qualifiedTypeReference.tokens;
  4448. long[] positions = qualifiedTypeReference.sourcePositions;
  4449. // QualifiedName
  4450. annotation.setTypeName(setQualifiedNameNameAndSourceRanges(tokens, positions, typeReference));
  4451. } else {
  4452. SingleTypeReference singleTypeReference = (SingleTypeReference) typeReference;
  4453. final SimpleName name = new SimpleName(this.ast);
  4454. name.internalSetIdentifier(new String(singleTypeReference.token));
  4455. int start = singleTypeReference.sourceStart;
  4456. int end = singleTypeReference.sourceEnd;
  4457. name.setSourceRange(start, end - start + 1);
  4458. annotation.setTypeName(name);
  4459. if (this.resolveBindings) {
  4460. recordNodes(name, typeReference);
  4461. }
  4462. }
  4463. }
  4464. protected void setTypeForField(FieldDeclaration fieldDeclaration, Type type, int extraDimension) {
  4465. if (extraDimension != 0) {
  4466. if (type.isArrayType()) {
  4467. ArrayType arrayType = (ArrayType) type;
  4468. int remainingDimensions = arrayType.getDimensions() - extraDimension;
  4469. if (remainingDimensions == 0) {
  4470. // the dimensions are after the name so the type of the fieldDeclaration is a simpleType
  4471. Type elementType = arrayType.getElementType();
  4472. // cut the child loose from its parent (without creating garbage)
  4473. elementType.setParent(null, null);
  4474. this.ast.getBindingResolver().updateKey(type, elementType);
  4475. fieldDeclaration.setType(elementType);
  4476. } else {
  4477. int start = type.getStartPosition();
  4478. ArrayType subarrayType = arrayType;
  4479. int index = extraDimension;
  4480. while (index > 0) {
  4481. subarrayType = (ArrayType) subarrayType.getComponentType();
  4482. index--;
  4483. }
  4484. int end = retrieveProperRightBracketPosition(remainingDimensions, start);
  4485. subarrayType.setSourceRange(start, end - start + 1);
  4486. // cut the child loose from its parent (without creating garbage)
  4487. subarrayType.setParent(null, null);
  4488. fieldDeclaration.setType(subarrayType);
  4489. updateInnerPositions(subarrayType, remainingDimensions);
  4490. this.ast.getBindingResolver().updateKey(type, subarrayType);
  4491. }
  4492. } else {
  4493. fieldDeclaration.setType(type);
  4494. }
  4495. } else {
  4496. if (type.isArrayType()) {
  4497. // update positions of the component types of the array type
  4498. int dimensions = ((ArrayType) type).getDimensions();
  4499. updateInnerPositions(type, dimensions);
  4500. }
  4501. fieldDeclaration.setType(type);
  4502. }
  4503. }
  4504. protected void setTypeForAroundAdviceDeclaration(AroundAdviceDeclaration adviceDeclaration, Type type) {
  4505. // ajh02: method added
  4506. switch (this.ast.apiLevel) {
  4507. case AST.JLS2_INTERNAL:
  4508. adviceDeclaration.internalSetReturnType(type);
  4509. break;
  4510. case AST.JLS3:
  4511. adviceDeclaration.setReturnType2(type);
  4512. break;
  4513. }
  4514. }
  4515. protected void setTypeForMethodDeclaration(MethodDeclaration methodDeclaration, Type type, int extraDimension) {
  4516. if (extraDimension != 0) {
  4517. if (type.isArrayType()) {
  4518. ArrayType arrayType = (ArrayType) type;
  4519. int remainingDimensions = arrayType.getDimensions() - extraDimension;
  4520. if (remainingDimensions == 0) {
  4521. // the dimensions are after the name so the type of the fieldDeclaration is a simpleType
  4522. Type elementType = arrayType.getElementType();
  4523. // cut the child loose from its parent (without creating garbage)
  4524. elementType.setParent(null, null);
  4525. this.ast.getBindingResolver().updateKey(type, elementType);
  4526. switch (this.ast.apiLevel) {
  4527. case AST.JLS2_INTERNAL:
  4528. methodDeclaration.internalSetReturnType(elementType);
  4529. break;
  4530. case AST.JLS3:
  4531. methodDeclaration.setReturnType2(elementType);
  4532. break;
  4533. }
  4534. } else {
  4535. int start = type.getStartPosition();
  4536. ArrayType subarrayType = arrayType;
  4537. int index = extraDimension;
  4538. while (index > 0) {
  4539. subarrayType = (ArrayType) subarrayType.getComponentType();
  4540. index--;
  4541. }
  4542. int end = retrieveProperRightBracketPosition(remainingDimensions, start);
  4543. subarrayType.setSourceRange(start, end - start + 1);
  4544. // cut the child loose from its parent (without creating garbage)
  4545. subarrayType.setParent(null, null);
  4546. updateInnerPositions(subarrayType, remainingDimensions);
  4547. switch (this.ast.apiLevel) {
  4548. case AST.JLS2_INTERNAL:
  4549. methodDeclaration.internalSetReturnType(subarrayType);
  4550. break;
  4551. case AST.JLS3:
  4552. methodDeclaration.setReturnType2(subarrayType);
  4553. break;
  4554. }
  4555. this.ast.getBindingResolver().updateKey(type, subarrayType);
  4556. }
  4557. } else {
  4558. switch (this.ast.apiLevel) {
  4559. case AST.JLS2_INTERNAL:
  4560. methodDeclaration.internalSetReturnType(type);
  4561. break;
  4562. case AST.JLS3:
  4563. methodDeclaration.setReturnType2(type);
  4564. break;
  4565. }
  4566. }
  4567. } else {
  4568. switch (this.ast.apiLevel) {
  4569. case AST.JLS2_INTERNAL:
  4570. methodDeclaration.internalSetReturnType(type);
  4571. break;
  4572. case AST.JLS3:
  4573. methodDeclaration.setReturnType2(type);
  4574. break;
  4575. }
  4576. }
  4577. }
  4578. protected void setTypeForMethodDeclaration(AnnotationTypeMemberDeclaration annotationTypeMemberDeclaration, Type type,
  4579. int extraDimension) {
  4580. annotationTypeMemberDeclaration.setType(type);
  4581. }
  4582. protected void setTypeForSingleVariableDeclaration(SingleVariableDeclaration singleVariableDeclaration, Type type,
  4583. int extraDimension) {
  4584. if (extraDimension != 0) {
  4585. if (type.isArrayType()) {
  4586. ArrayType arrayType = (ArrayType) type;
  4587. int remainingDimensions = arrayType.getDimensions() - extraDimension;
  4588. if (remainingDimensions == 0) {
  4589. // the dimensions are after the name so the type of the fieldDeclaration is a simpleType
  4590. Type elementType = arrayType.getElementType();
  4591. // cut the child loose from its parent (without creating garbage)
  4592. elementType.setParent(null, null);
  4593. this.ast.getBindingResolver().updateKey(type, elementType);
  4594. singleVariableDeclaration.setType(elementType);
  4595. } else {
  4596. int start = type.getStartPosition();
  4597. ArrayType subarrayType = arrayType;
  4598. int index = extraDimension;
  4599. while (index > 0) {
  4600. subarrayType = (ArrayType) subarrayType.getComponentType();
  4601. index--;
  4602. }
  4603. int end = retrieveProperRightBracketPosition(remainingDimensions, start);
  4604. subarrayType.setSourceRange(start, end - start + 1);
  4605. // cut the child loose from its parent (without creating garbage)
  4606. subarrayType.setParent(null, null);
  4607. updateInnerPositions(subarrayType, remainingDimensions);
  4608. singleVariableDeclaration.setType(subarrayType);
  4609. this.ast.getBindingResolver().updateKey(type, subarrayType);
  4610. }
  4611. } else {
  4612. singleVariableDeclaration.setType(type);
  4613. }
  4614. } else {
  4615. singleVariableDeclaration.setType(type);
  4616. }
  4617. }
  4618. protected void setTypeForVariableDeclarationExpression(VariableDeclarationExpression variableDeclarationExpression, Type type,
  4619. int extraDimension) {
  4620. if (extraDimension != 0) {
  4621. if (type.isArrayType()) {
  4622. ArrayType arrayType = (ArrayType) type;
  4623. int remainingDimensions = arrayType.getDimensions() - extraDimension;
  4624. if (remainingDimensions == 0) {
  4625. // the dimensions are after the name so the type of the fieldDeclaration is a simpleType
  4626. Type elementType = arrayType.getElementType();
  4627. // cut the child loose from its parent (without creating garbage)
  4628. elementType.setParent(null, null);
  4629. this.ast.getBindingResolver().updateKey(type, elementType);
  4630. variableDeclarationExpression.setType(elementType);
  4631. } else {
  4632. int start = type.getStartPosition();
  4633. ArrayType subarrayType = arrayType;
  4634. int index = extraDimension;
  4635. while (index > 0) {
  4636. subarrayType = (ArrayType) subarrayType.getComponentType();
  4637. index--;
  4638. }
  4639. int end = retrieveProperRightBracketPosition(remainingDimensions, start);
  4640. subarrayType.setSourceRange(start, end - start + 1);
  4641. // cut the child loose from its parent (without creating garbage)
  4642. subarrayType.setParent(null, null);
  4643. updateInnerPositions(subarrayType, remainingDimensions);
  4644. variableDeclarationExpression.setType(subarrayType);
  4645. this.ast.getBindingResolver().updateKey(type, subarrayType);
  4646. }
  4647. } else {
  4648. variableDeclarationExpression.setType(type);
  4649. }
  4650. } else {
  4651. variableDeclarationExpression.setType(type);
  4652. }
  4653. }
  4654. protected void setTypeForVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement, Type type,
  4655. int extraDimension) {
  4656. if (extraDimension != 0) {
  4657. if (type.isArrayType()) {
  4658. ArrayType arrayType = (ArrayType) type;
  4659. int remainingDimensions = arrayType.getDimensions() - extraDimension;
  4660. if (remainingDimensions == 0) {
  4661. // the dimensions are after the name so the type of the fieldDeclaration is a simpleType
  4662. Type elementType = arrayType.getElementType();
  4663. // cut the child loose from its parent (without creating garbage)
  4664. elementType.setParent(null, null);
  4665. this.ast.getBindingResolver().updateKey(type, elementType);
  4666. variableDeclarationStatement.setType(elementType);
  4667. } else {
  4668. int start = type.getStartPosition();
  4669. ArrayType subarrayType = arrayType;
  4670. int index = extraDimension;
  4671. while (index > 0) {
  4672. subarrayType = (ArrayType) subarrayType.getComponentType();
  4673. index--;
  4674. }
  4675. int end = retrieveProperRightBracketPosition(remainingDimensions, start);
  4676. subarrayType.setSourceRange(start, end - start + 1);
  4677. // cut the child loose from its parent (without creating garbage)
  4678. subarrayType.setParent(null, null);
  4679. updateInnerPositions(subarrayType, remainingDimensions);
  4680. variableDeclarationStatement.setType(subarrayType);
  4681. this.ast.getBindingResolver().updateKey(type, subarrayType);
  4682. }
  4683. } else {
  4684. variableDeclarationStatement.setType(type);
  4685. }
  4686. } else {
  4687. variableDeclarationStatement.setType(type);
  4688. }
  4689. }
  4690. protected void updateInnerPositions(Type type, int dimensions) {
  4691. if (dimensions > 1) {
  4692. // need to set positions for intermediate array type see 42839
  4693. int start = type.getStartPosition();
  4694. Type currentComponentType = ((ArrayType) type).getComponentType();
  4695. int searchedDimension = dimensions - 1;
  4696. int rightBracketEndPosition = start;
  4697. while (currentComponentType.isArrayType()) {
  4698. rightBracketEndPosition = retrieveProperRightBracketPosition(searchedDimension, start);
  4699. currentComponentType.setSourceRange(start, rightBracketEndPosition - start + 1);
  4700. currentComponentType = ((ArrayType) currentComponentType).getComponentType();
  4701. searchedDimension--;
  4702. }
  4703. }
  4704. }
  4705. }