From 39952fcbffb1ec40dce884cc5b0046c08308afdf Mon Sep 17 00:00:00 2001 From: John Camelon Date: Wed, 26 Jan 2005 17:03:26 +0000 Subject: [PATCH] Patch for Devin Steffler. UI Infrastructure for testing the DOM AST Interfaces. --- .../org.eclipse.cdt.ui.tests/icons/sample.gif | Bin 0 -> 855 bytes .../icons/used/brkpd_obj.gif | Bin 0 -> 136 bytes .../icons/used/cdeclaration_obj.gif | Bin 0 -> 146 bytes .../icons/used/define_obj.gif | Bin 0 -> 109 bytes .../icons/used/disassembly.gif | Bin 0 -> 158 bytes .../icons/used/enumerator_obj.gif | Bin 0 -> 853 bytes .../icons/used/expression_obj.gif | Bin 0 -> 909 bytes .../icons/used/jump_co.gif | Bin 0 -> 92 bytes .../icons/used/method_public_obj.gif | Bin 0 -> 97 bytes .../icons/used/output_obj.gif | Bin 0 -> 161 bytes .../icons/used/showasarray_co.gif | Bin 0 -> 117 bytes .../icons/used/source_attach_attrib.gif | Bin 0 -> 157 bytes .../icons/used/statement_obj.gif | Bin 0 -> 891 bytes .../icons/used/tnames_co.gif | Bin 0 -> 101 bytes .../icons/used/types.gif | Bin 0 -> 364 bytes .../icons/used/var_declaration_obj.gif | Bin 0 -> 895 bytes .../icons/used/var_pointer.gif | Bin 0 -> 130 bytes .../icons/used/var_simple.gif | Bin 0 -> 132 bytes .../icons/used/variable_local_obj.gif | Bin 0 -> 94 bytes .../icons/used/variable_obj.gif | Bin 0 -> 78 bytes .../icons/used/warning_obj.gif | Bin 0 -> 139 bytes .../icons/used/watch_globals.gif | Bin 0 -> 105 bytes core/org.eclipse.cdt.ui.tests/plugin.xml | 45 ++ .../DOMAST/CPPPopulateASTViewAction.java | 165 ++++++ .../tests/DOMAST/CPopulateASTViewAction.java | 146 +++++ .../eclipse/cdt/ui/tests/DOMAST/DOMAST.java | 535 ++++++++++++++++++ .../ui/tests/DOMAST/DOMASTPluginImages.java | 122 ++++ .../tests/DOMAST/IPopulateDOMASTAction.java | 18 + .../ui/tests/DOMAST/OpenDOMViewAction.java | 120 ++++ .../cdt/ui/tests/DOMAST/TreeObject.java | 96 ++++ .../cdt/ui/tests/DOMAST/TreeParent.java | 79 +++ 31 files changed, 1326 insertions(+) create mode 100644 core/org.eclipse.cdt.ui.tests/icons/sample.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/brkpd_obj.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/cdeclaration_obj.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/define_obj.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/disassembly.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/enumerator_obj.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/expression_obj.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/jump_co.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/method_public_obj.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/output_obj.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/showasarray_co.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/source_attach_attrib.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/statement_obj.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/tnames_co.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/types.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/var_declaration_obj.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/var_pointer.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/var_simple.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/variable_local_obj.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/variable_obj.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/warning_obj.gif create mode 100644 core/org.eclipse.cdt.ui.tests/icons/used/watch_globals.gif create mode 100644 core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java create mode 100644 core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java create mode 100644 core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java create mode 100644 core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMASTPluginImages.java create mode 100644 core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/IPopulateDOMASTAction.java create mode 100644 core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/OpenDOMViewAction.java create mode 100644 core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/TreeObject.java create mode 100644 core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/TreeParent.java diff --git a/core/org.eclipse.cdt.ui.tests/icons/sample.gif b/core/org.eclipse.cdt.ui.tests/icons/sample.gif new file mode 100644 index 0000000000000000000000000000000000000000..7952e2ef215af432706d76f9b0927bc2df937413 GIT binary patch literal 855 zcmZ?wbhEHb6krfw_|CxKYUg-n!?izO{@9*?jxd%4aX0yzy`dymabz zw#(eg=y~&N&n)dZv2xzduG}5lraiApo3(c4*{Ylg5#|$JO_EEZ<^|a2`Z*=9ns7DV zy=TR&gYw*7f%auV?ip3tvjRPmcdoho{K?x$_vR?C#t5&<;~V}S*>OMCr>h}%%bLZ9 zmo3`hYEwTICo-TTCZwgTsC&VjZRgJ1eE#fBa^%9R zmmfWS@;bnyJ27HWY}kxYzv(Hl>yu;FCPlAEh+34Muq-8Rb6C)<8qA3{r2e5 z`$vyngh#H=FWlqqvnapfc5%(!sQ4v?r7J61-&eJNEN^;KTK}T7{#i-gJh%G*9vcYdwv_*~xdw!Gz4Va?T!sXyyF@8?w<>X`X=#a1qF}*{b|(2QMiawDN4tcL nv-ZrGsN~uypyIzoN6;jK4l^yz+epkPv`PQ literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui.tests/icons/used/brkpd_obj.gif b/core/org.eclipse.cdt.ui.tests/icons/used/brkpd_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..8e8cac5a9d73096ef89b348f0db1a46dfc3758ab GIT binary patch literal 136 zcmZ?wbhEHb6krfw*!-X2z<~n`7A%=RzkdJz`SyN z{$ycfVBliV0SSZ5U|_KiIO(~1uSK%aFNMf(8TX5^GL;f6iVD{Z*5#@nQ8~@))bM&+ j+?s&LoDAE!($y{45)2y!1w2w>8V`6Mep{t4$Y2cs5SBFV literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui.tests/icons/used/define_obj.gif b/core/org.eclipse.cdt.ui.tests/icons/used/define_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..b3ddb5deebc87204a0bce5e530ddb3378e8fa772 GIT binary patch literal 109 zcmZ?wbhEHb6krfwSj50^|Ned;m_L7hLqkJ+d^`gK!~g&Pfu!P37DfgJHU=Fa8>mu% zfq~g5W7nO325t^*3&q-$&b+%2z|!Vn<+^I!IfY&8f6sXOV@<`yV}F!y?7zH*VTGvb Mi6xgNGB8*J0C!U>{{R30 literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui.tests/icons/used/disassembly.gif b/core/org.eclipse.cdt.ui.tests/icons/used/disassembly.gif new file mode 100644 index 0000000000000000000000000000000000000000..dbde1a090aa5f9a31893f9e805250b461735fb18 GIT binary patch literal 158 zcmZ?wbhEHb6krfw_{_j?|Ni~cr%zwJc=71bqsNaQZ*6V8bLY;aNt5#O@_g z%qb`+V1NO|pDc_Zwho8@nc>XhEpWo~waqaem5tAYniY8}?5XMiaQXxZd3y9!Sb%vZdHK+*Ioa zXr)V$jyGiJn!R=rQH;O)AA~oTyL;|=o_n+RZg=PP`@Zz$msE7^)3rxO)^(S}?d6vr zcT_}F#6(;qM6xnfQ4@915X~x@ikX;;g;-XvtGJ1~c!+0>hDw-(ON2y%B&m`n>5?Hy z0yfZKF-&*Xo(fZS)lkh^OJ=6#YN3|Jf})$ctA~0PDSE>+Tq86Rj*M!WrfY^KTVV|t zq+tmyYAgmDXs{U05>z?iW?`14kF{j(=3$;C7Zw!5Ey5yE4=H*r-7+kZhab>n8avPr z2^7K_Fi69aR(P-&Y@or)a<0ncM7U=ei9XhnMR+8>A{Q1EJ;M_paT){QMLR~L7Ax@s znoMH{oDhscSOW%WCZPon7K06R)`_Z{GC7f43?tFUTC&Kj1Ge)Qi+0hvXFF1nYQEQb zo0Y|}xl`9}f{Sv~P{(hyNX) zbRi+mi-_)$5|VCO{y^kSH^I6{D@-LLOkufItoQwNYQ1p2_vd-u@4V0Vol{+V(o=TP zjy(JX(&_Z<>`Ss}G^%M@AP^`o4;W$8K?jM_y4_k3f*WmUN9$&}5M`2G;am{Wd>>95 zEQlD)Fl;awAN*y(=v)?Wis15}oAbKeP$(WgaUS3GX4!8Xv*W5ETXr!~?^zI$;zcoY zJ0S{Wb!#a~THr#?W}%Mqj%+J_%&iH)DiO}(16DW*V;f0Z@Ni#Jc;iVyy3=_n3v#Oy zf_Y(z*)-{`sH8ZI>uC1b$eZ->al6EM$@Ke)+fkPgHHsDe6t9uSj9u8+Z%7ZRExvRP z4!2Fhthbt?OpPdT5WoHSqBy0_h)IfzClVrdEhXIKy^)kyo?L%_&zCjfAza(BrPWFO zoU^f}cl8P3p;@+T{Y~}Etb7k9;_?{`Q~ki}WqD@Y&+p0H6X!lO!H)*=XQd9eoE*4J zeGcrBXIk}qRk+@)$}{DA8#Md=*+-?Cf90s_)=EtGzb6PoypVmQg9wH@I)hzZ?VPuS z+-)jtSWZv>!39x6nx47VXEnhH2i1Aj$DK7y$DygMJ2Kv@lzF7YCTBTJ*b?zrGjp{K zyf8_hI?O2IBL5R!QwX*_>aZ5mDW?3rjRPZ}x_ixvsVP3Pe_WSclG}Xetyc+o?|X7ATIq*waVT4{}OdtD3xpukNe$cI|zaI(66Go%j|Wou4!uQ9fT8 SJM*=%&;KO!;YF#6V}AkPPywv~ literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui.tests/icons/used/jump_co.gif b/core/org.eclipse.cdt.ui.tests/icons/used/jump_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..0107e2ecc6c52dc341e7023e00f567702a04f215 GIT binary patch literal 92 zcmZ?wbhEHb6krfw_{hNU|NsB}`}fbEKc9htLGdRGBamXy0TCd1Mkd{seoo^v+;y!{D^0dnbH&uXw<`X$wKFkT0{~MoAm0E0 literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui.tests/icons/used/method_public_obj.gif b/core/org.eclipse.cdt.ui.tests/icons/used/method_public_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..18103b11fc7ea74276adbc2cad5252b670854661 GIT binary patch literal 97 zcmZ?wbhEHb6krfwSj50!UvF<8Z(lz@e*XUW|Ns9pz<}aU7DfgJ76u)V07xwZvzo`Q sJO2z$oorwg?y+^caz~+p|3vSEoeNVnHu!(omm+eF&jq`afn{e6nZ5n-= zVOobRa-9}j3ezw?t6?T{pupin4VO!!fgn$ZTjVB#jDR^8o-}5yO%UwJ6>SzRKgqbx NU5R7P^%)!t)&LQoKra9Q literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui.tests/icons/used/showasarray_co.gif b/core/org.eclipse.cdt.ui.tests/icons/used/showasarray_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..a87ddbf9ca8d2f45f5914cf19523f5ccc89e27f5 GIT binary patch literal 117 zcmZ?wbhEHb6krfwSj51&=4OV4-^G*L6R6i@h1x-0|N(x z4oC)M1_O(iz)4SSU5jMxZV815i5S5)xyYH!4N@O&H63SUd*yQGc|$mh_}XWuJ4e5Crl#P!$3L~WW0y%fhuW6GLV?;B7T~ODAGt{6a!F$XA9EB09P9{j1;N!b!N2xvtel{hYJ0 zrVsTo;iOqMYF(y!YF2&+9dUUFgH$hm6_q>Ve*RACojCX4B)n)Oe@yCd$jO0L>N6ux z?$rHwQP^KE%ANAN_3J(V++(4dccI*VWno zzW`k`RHOH_N@G5B*#*b@Myx}7He0Q??B1^v-C5SHO~Io@FM9F{AHCC^`||QyL4Eb| zaPQ#Lo{X{w{U6^Jz3D63cDL0Pu)6P*AK8^z?6);sckldEclxH~{eAcCgO~CQ*!veZ C$NWM7 literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui.tests/icons/used/tnames_co.gif b/core/org.eclipse.cdt.ui.tests/icons/used/tnames_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..764201b3783df9638e21fffc6ef74fa7b8b96c5c GIT binary patch literal 101 zcmZ?wbhEHb6krfwn8?7efB*jZ^XLEn|DS<@LGdRGBLf2ygAR}llobH7&8GBs3M@F~ zB=AO3b7r;V`{ynWEs2LjBA;i4aYoI0f3qUS%~Wia(q;Z77gg3Md@O${sK4>qLIwtF E0D<}>KL7v# literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui.tests/icons/used/types.gif b/core/org.eclipse.cdt.ui.tests/icons/used/types.gif new file mode 100644 index 0000000000000000000000000000000000000000..5ba5b91c5bb2b2a14f7610128ee4b3daf27dea13 GIT binary patch literal 364 zcmZ?wbhEHb6krfwxXQq=Z~MNs%GJdwODeLL^)#&w^O%|$v#`2gLu&N=y0SG(=ACgU zS>alyXdyNuDP_;d1|QtocIZcXFGQK zx=#;qpC0G|MAHKO=ZE^w3$0pPP_+h#3Rj-!`Tzev1NDI7PZmZ71~mp9kdYuiF|c(y zOfK-y;nSD&erCiXz{b+>AxSe**XMx4L0Jz&3`}a}nm@U(K^@ rxf-v~rcJ!-)p!JU?&R6VBe;M6p7p}qe8;%g9p>R)yX~BlBZD;ng)eNk literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui.tests/icons/used/var_declaration_obj.gif b/core/org.eclipse.cdt.ui.tests/icons/used/var_declaration_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..74a3d222c700233db61a466ee8c7e313384d1a20 GIT binary patch literal 895 zcmW-gu}jqf5XbL@q=wNG8ZsJsMiNJxOW~klRK^=xZV*}|kfsPBaJwHwv>4cEG&rQg z(GdOvN;HHx)eR1_eMMbmzo_R)|v z%^vY%Z+rikiinDsh>L_sR;DUyqAnVuSw&MZ6LYZ;%j$I%H*psa@vPBM36pS%kVudu zRnjC~G9*dB1{y4e>CW0yVXCegs#$Bv%+y>h)UsGmbW?ZrP|qSoZ#b5&s7QcmdxEe%(LXef?~KuSS0EpMX#k>h9&aw z1DZ@@2l^p_LRbR^X;{(<4;F(BG+0^ARhgU!_bemP$6B%okHlBx!h)h_c;X{YV*tEp z$7s}IC4NAYY3zU#f>8)-z#z>ewBW&Fuz}7xQFT)$Cz6X{B>GrO7MXRx_WZ@7y=dLD zJyMZseXsMjRu;$Bow{}_xG1+8>i8|KQqXP!n%99VVIG>=RWddbJ_u$~*@bK{H=;-9+Wbo&BbMr&fGy~q{ zfehLQPrebo)1glNe6!y4`cKS_JeI-el?R`$-dP>|?9IvOx27{U_V4BJh4*vMFJ3=) zSH{0KtC!~=e!TIhH~;$V_}2Ol$RF8}}l literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui.tests/icons/used/var_pointer.gif b/core/org.eclipse.cdt.ui.tests/icons/used/var_pointer.gif new file mode 100644 index 0000000000000000000000000000000000000000..ca17bd232f6a62b6165aea4fa991d043477cefa6 GIT binary patch literal 130 zcmZ?wbhEHb6krfw*v!E2|NsA!Cr@tLv}yI~)e|R9?CI$#EG*2=&(F)ti;s`@_4W1k z_BJ#$R99DL04rAf$->CMz|Wuq+Z^fq|1j2P6(MgMr1+;H2m3y%y1js`aB4*iIDkI8;bDb;r3J*rh46`Y literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui.tests/icons/used/variable_local_obj.gif b/core/org.eclipse.cdt.ui.tests/icons/used/variable_local_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..461c4e79feb00ab7c2bab383f9aeec420965a8c7 GIT binary patch literal 94 zcmZ?wbhEHb6krfwSj50!AHP4oe*gUa`}g19{~rt(z(DaQ3nK#qD}xS*2U5$xtQfKD o&Od`wo~kQYJFMLm4jM4JoOEn<%TZ$4^P%%>Nv=32gEcP~02SsRhyVZp literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui.tests/icons/used/variable_obj.gif b/core/org.eclipse.cdt.ui.tests/icons/used/variable_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..9fa6383efc9643aedb381e95db802a0f0b40e8f6 GIT binary patch literal 78 zcmZ?wbhEHb6krfwn8?6jAHUx|zTSTR{{R2~EB<6*WME)s&|v@qkURsE?416Ur{D5R ga|m)c&OiF=-kF^FPbw3HmSjn7efL^~!J3x~0I2L55dZ)H literal 0 HcmV?d00001 diff --git a/core/org.eclipse.cdt.ui.tests/icons/used/warning_obj.gif b/core/org.eclipse.cdt.ui.tests/icons/used/warning_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..cf8d571833dcf0457fad44f638d981f28d43eee2 GIT binary patch literal 139 zcmZ?wbhEHb6krfw*v!E2|9|}b`}_ajx4*yN{{Q{>{qybr@3)^{Zyz5Y&j6DB4 + + + @@ -37,6 +40,48 @@ id="org.eclipse.cdt.ui.tests.chelp.extension.3"/> + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java new file mode 100644 index 00000000000..aa96859eb28 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java @@ -0,0 +1,165 @@ +/********************************************************************** + * Copyright (c) 2005 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.ui.tests.DOMAST; + +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTInitializer; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction; + +/** + * @author dsteffle + */ +public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IPopulateDOMASTAction { + { + processNames = true; + processDeclarations = true; + processInitializers = true; + processParameterDeclarations = true; + processDeclarators = true; + processDeclSpecifiers = true; + processExpressions = true; + processStatements = true; + processTypeIds = true; + processEnumerators = true; + processBaseSpecifiers = true; + processNamespaces = true; + } + + TreeParent root = null; + + public CPPPopulateASTViewAction(IASTTranslationUnit tu) { + root = new TreeParent(tu); + } + + private void addRoot(IASTNode node) { + TreeParent parent = root.findParentOfNode(node); + + if ( parent != null ) { + parent.addChild(new TreeParent(node)); + } else { + root.addChild(new TreeParent(node)); + } + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) + */ + public int processDeclaration(IASTDeclaration declaration) { + addRoot(declaration); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) + */ + public int processDeclarator(IASTDeclarator declarator) { + addRoot(declarator); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processBaseSpecifier(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier) + */ + public int processBaseSpecifier(ICPPASTBaseSpecifier specifier) { + addRoot(specifier); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) + */ + public int processDeclSpecifier(IASTDeclSpecifier declSpec) { + addRoot(declSpec); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) + */ + public int processEnumerator(IASTEnumerator enumerator) { + addRoot(enumerator); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public int processExpression(IASTExpression expression) { + addRoot(expression); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer) + */ + public int processInitializer(IASTInitializer initializer) { + addRoot(initializer); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public int processName(IASTName name) { + addRoot(name); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processNamespace(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition) + */ + public int processNamespace(ICPPASTNamespaceDefinition namespace) { + addRoot(namespace); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration) + */ + public int processParameterDeclaration( + IASTParameterDeclaration parameterDeclaration) { + addRoot(parameterDeclaration); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public int processStatement(IASTStatement statement) { + addRoot(statement); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) + */ + public int processTypeId(IASTTypeId typeId) { + addRoot(typeId); + return PROCESS_CONTINUE; + } + + public TreeParent getTree() { + return root; + } +} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java new file mode 100644 index 00000000000..354b91fe955 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java @@ -0,0 +1,146 @@ +/********************************************************************** + * Copyright (c) 2005 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.ui.tests.DOMAST; + +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTInitializer; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; +import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction; + +/** + * @author dsteffle + */ +public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopulateDOMASTAction { + { + processNames = true; + processDeclarations = true; + processInitializers = true; + processParameterDeclarations = true; + processDeclarators = true; + processDeclSpecifiers = true; + processExpressions = true; + processStatements = true; + processTypeIds = true; + processEnumerators = true; + } + + TreeParent root = null; // TODO what about using a hashtable/hashmap for the tree? + + public CPopulateASTViewAction(IASTTranslationUnit tu) { + root = new TreeParent(tu); + } + + private void addRoot(IASTNode node) { + TreeParent parent = root.findParentOfNode(node); + + if ( parent != null ) { + parent.addChild(new TreeParent(node)); + } else { + root.addChild(new TreeParent(node)); + } + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) + */ + public int processDeclaration(IASTDeclaration declaration) { + addRoot(declaration); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) + */ + public int processDeclarator(IASTDeclarator declarator) { + addRoot(declarator); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) + */ + public int processDeclSpecifier(IASTDeclSpecifier declSpec) { + addRoot(declSpec); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) + */ + public int processEnumerator(IASTEnumerator enumerator) { + addRoot(enumerator); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public int processExpression(IASTExpression expression) { + addRoot(expression); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer) + */ + public int processInitializer(IASTInitializer initializer) { + addRoot(initializer); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public int processName(IASTName name) { + addRoot(name); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration) + */ + public int processParameterDeclaration( + IASTParameterDeclaration parameterDeclaration) { + addRoot(parameterDeclaration); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public int processStatement(IASTStatement statement) { + addRoot(statement); + return PROCESS_CONTINUE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) + */ + public int processTypeId(IASTTypeId typeId) { + addRoot(typeId); + return PROCESS_CONTINUE; + } + + public TreeParent getTree() { + return root; + } + +} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java new file mode 100644 index 00000000000..8f0fd355692 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java @@ -0,0 +1,535 @@ +/********************************************************************** + * Copyright (c) 2005 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.ui.tests.DOMAST; + +import java.io.IOException; +import java.util.Hashtable; +import java.util.Map; + +import org.eclipse.cdt.ui.tests.DOMAST.DOMASTPluginImages; +import org.eclipse.cdt.ui.tests.DOMAST.CPPPopulateASTViewAction; +import org.eclipse.cdt.ui.tests.DOMAST.CPopulateASTViewAction; +import org.eclipse.cdt.ui.tests.DOMAST.IPopulateDOMASTAction; +import org.eclipse.cdt.ui.tests.DOMAST.TreeObject; +import org.eclipse.cdt.ui.tests.DOMAST.TreeParent; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.part.*; +import org.eclipse.jface.viewers.*; +import org.eclipse.swt.graphics.Image; +import org.eclipse.jface.action.*; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.ui.*; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.SWT; +import org.eclipse.cdt.core.parser.CodeReader; +import org.eclipse.cdt.core.parser.IScannerInfo; +import org.eclipse.cdt.core.parser.NullLogService; +import org.eclipse.cdt.core.parser.NullSourceElementRequestor; +import org.eclipse.cdt.core.parser.ParserFactory; +import org.eclipse.cdt.core.parser.ParserLanguage; +import org.eclipse.cdt.core.parser.IScanner; +import org.eclipse.cdt.core.parser.ParserMode; +import org.eclipse.cdt.core.parser.ScannerInfo; +import org.eclipse.cdt.core.parser.ast.IASTEnumerator; +import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTInitializer; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; +import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement; +import org.eclipse.cdt.core.dom.ast.IASTProblem; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; +import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser; +import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; +import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction; +import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration; +import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction; +import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; +import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration; +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; + + +/** + * This sample class demonstrates how to plug-in a new + * workbench view. The view shows data obtained from the + * model. The sample creates a dummy model on the fly, + * but a real implementation would connect to the model + * available either in this or another plug-in (e.g. the workspace). + * The view is connected to the model using a content provider. + *

+ * The view uses a label provider to define how model + * objects should be presented in the view. Each + * view can present the same model objects using + * different labels and icons, if needed. Alternatively, + * a single label provider can be shared between views + * in order to ensure that objects of the same type are + * presented in the same way everywhere. + *

+ */ + +public class DOMAST extends ViewPart { + private static final String VIEW_NAME = "DOM View"; //$NON-NLS-1$ + private static final String POPUPMENU = "#PopupMenu"; //$NON-NLS-1$ + private static final String OPEN_DEFINITIONS = "Open Definitions"; //$NON-NLS-1$ + private static final String OPEN_REFERENCES = "Open References"; //$NON-NLS-1$ + private TreeViewer viewer; + private DrillDownAdapter drillDownAdapter; + private Action action1; + private Action action2; + private Action singleClickAction; + private IFile file = null; + private IEditorPart part = null; + private ParserLanguage lang = null; + + /* + * The content provider class is responsible for + * providing objects to the view. It can wrap + * existing objects in adapters or simply return + * objects as-is. These objects may be sensitive + * to the current input of the view, or ignore + * it and always show the same content + * (like Task List, for example). + */ + + public class ViewContentProvider implements IStructuredContentProvider, + ITreeContentProvider { + private TreeParent invisibleRoot; + private IFile aFile = null; + + /** + * + */ + public ViewContentProvider() {} + + /** + * + */ + public ViewContentProvider(IFile file) { + this.aFile = file; + } + + public void inputChanged(Viewer v, Object oldInput, Object newInput) { + } + public void dispose() { + } + public Object[] getElements(Object parent) { + if (parent.equals(getViewSite())) { + if (invisibleRoot==null) initialize(); + return getChildren(invisibleRoot); + } + return getChildren(parent); + } + public Object getParent(Object child) { + if (child instanceof TreeObject) { + return ((TreeObject)child).getParent(); + } + return null; + } + public Object [] getChildren(Object parent) { + if (parent instanceof TreeParent) { + return ((TreeParent)parent).getChildren(); + } + return new Object[0]; + } + public boolean hasChildren(Object parent) { + if (parent instanceof TreeParent) + return ((TreeParent)parent).hasChildren(); + return false; + } + + private void initialize() { + if ( aFile == null || lang == null) return; + + IPopulateDOMASTAction action = null; + + // TODO could use something like below to work with working copy... i.e. refresh button +// IProject currentProject = aFile.getProject(); +// IWorkingCopy workingCopy = null; +// if( editor.isDirty() ){ +// IWorkingCopy [] workingCopies = CUIPlugin.getSharedWorkingCopies(); +// if( workingCopies != null ){ +// for( int i = 0; i < workingCopies.length; i++ ){ +// if( workingCopies[i].getUnderlyingResource().equals( file ) ){ +// workingCopy = workingCopies[i]; +// break; +// } +// } +// } +// } + + CodeReader reader = null; + try { +// if( workingCopy == null ) + reader = new CodeReader(aFile.getLocation().toOSString(), aFile.getCharset() ); +// else +// reader = new CodeReader(file.getLocation().toOSString(), workingCopy.getContents()); + } catch (IOException e) { + e.printStackTrace(); + } catch ( CoreException e ) { + e.printStackTrace(); + } + + // get IFile +// IWorkspace workspace= ResourcesPlugin.getWorkspace(); +// workspace.setDescription(desc); +// getWorkbench().getActiveWorkbenchWindow(); + + // parse IFile + ParserMode mode = ParserMode.COMPLETE_PARSE; + Map definitions = new Hashtable(); + + String [] includePaths = new String[0]; + IScannerInfo scannerInfo = new ScannerInfo( definitions, includePaths ); + IScanner scanner = ParserFactory.createScanner( + reader, + scannerInfo, + mode, + lang, + new NullSourceElementRequestor(), + null, + null ); + AbstractGNUSourceCodeParser parser = null; + if ( lang == ParserLanguage.C ) { + parser = new GNUCSourceParser( + scanner, + mode, + new NullLogService(), + new GCCParserExtensionConfiguration() + ); + + IASTTranslationUnit tu = parser.parse(); + + action = new CPopulateASTViewAction(tu); + CVisitor.visitTranslationUnit(tu, (CBaseVisitorAction)action); + } else if ( lang == ParserLanguage.CPP ){ + parser = new GNUCPPSourceParser( + scanner, + mode, + new NullLogService(), + new GPPParserExtensionConfiguration() + ); + + IASTTranslationUnit tu = parser.parse(); + + action = new CPPPopulateASTViewAction(tu); + CPPVisitor.visitTranslationUnit(tu, (CPPBaseVisitorAction)action); + } + + // display roots + invisibleRoot = new TreeParent(null); //$NON-NLS-1$ + invisibleRoot.addChild(action.getTree()); + + } + } + + class ViewLabelProvider extends LabelProvider { + + public String getText(Object obj) { + return obj.toString(); + } + public Image getImage(Object obj) { + String imageKey = DOMASTPluginImages.IMG_DEFAULT; + + IASTNode node = null; + if (obj instanceof TreeObject) { + node = ((TreeObject)obj).getNode(); + } + + if ( node instanceof IASTArrayModifier ) { + imageKey = DOMASTPluginImages.IMG_IASTArrayModifier; + } else if ( node instanceof IASTDeclaration ) { + imageKey = DOMASTPluginImages.IMG_IASTDeclaration; + } else if ( node instanceof IASTDeclarator ) { + imageKey = DOMASTPluginImages.IMG_IASTDeclarator; + } else if ( node instanceof IASTDeclSpecifier ) { + imageKey = DOMASTPluginImages.IMG_IASTDeclSpecifier; + } else if ( node instanceof IASTEnumerator ) { + imageKey = DOMASTPluginImages.IMG_IASTEnumerator; + } else if ( node instanceof IASTExpression ) { + imageKey = DOMASTPluginImages.IMG_IASTExpression; + } else if ( node instanceof IASTInitializer ) { + imageKey = DOMASTPluginImages.IMG_IASTInitializer; + } else if ( node instanceof IASTName ) { + imageKey = DOMASTPluginImages.IMG_IASTName; + } else if ( node instanceof IASTParameterDeclaration ) { + imageKey = DOMASTPluginImages.IMG_IASTParameterDeclaration; + } else if ( node instanceof IASTPointerOperator ) { + imageKey = DOMASTPluginImages.IMG_IASTPointerOperator; + } else if ( node instanceof IASTPreprocessorStatement ) { + imageKey = DOMASTPluginImages.IMG_IASTPreprocessorStatement; + } else if ( node instanceof IASTProblem ) { + imageKey = DOMASTPluginImages.IMG_IASTProblem; + } else if ( node instanceof IASTSimpleDeclaration ) { + imageKey = DOMASTPluginImages.IMG_IASTSimpleDeclaration; + } else if ( node instanceof IASTStatement ) { + imageKey = DOMASTPluginImages.IMG_IASTStatement; + } else if ( node instanceof IASTTranslationUnit ) { + imageKey = DOMASTPluginImages.IMG_IASTTranslationUnit; + } else if ( node instanceof IASTTypeId ) { + imageKey = DOMASTPluginImages.IMG_IASTTypeId; + } else if ( node instanceof ICASTDesignator ) { + imageKey = DOMASTPluginImages.IMG_ICASTDesignator; + } else if ( node instanceof ICPPASTConstructorChainInitializer ) { + imageKey = DOMASTPluginImages.IMG_ICPPASTConstructorChainInitializer; + } else if ( node instanceof ICPPASTTemplateParameter ) { + imageKey = DOMASTPluginImages.IMG_ICPPASTTemplateParameter; + } + + return DOMASTPluginImages.get(imageKey); + } + } + class NameSorter extends ViewerSorter { + } + + public DOMAST() { + + } + + /** + * This is a callback that will allow us + * to create the viewer and initialize it. + */ + public void createPartControl(Composite parent) { + + if (part == null) { + IWorkbenchPage[] pages = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages(); + + if (pages.length == 0) { + // TODO determine how to hide view if no pages found and part==null + } + + outerLoop: for(int i=0; i0; + } + + private TreeParent findParentOfNode(TreeObject[] trees, IASTNode node) { + for (int i=0; i