From d532892d89865511ea39286e4ebd34fc20b96a5d Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 6 Oct 2006 16:29:03 +0000 Subject: [PATCH] tests and fixes for jdtlikehandleprovider, bug 159896 --- .../jdtlikehandleprovider/AdviceAndInjar.aj | 17 +++++ .../AspectOnAspectPath.aj | 17 +++++ .../ClassForAspectpath.java | 10 +++ .../jdtlikehandleprovider/DeclareAndInjar.aj | 9 +++ .../jdtlikehandleprovider/README.txt | 7 ++ .../jdtlikehandleprovider/advice.jar | Bin 0 -> 1580 bytes .../jdtlikehandleprovider/declare.jar | Bin 0 -> 1341 bytes .../jarForAspectPath.jar | Bin 0 -> 1507 bytes .../ajc153/JDTLikeHandleProviderTests.java | 61 +++++++++++++++++ .../ajc153/jdtlikehandleprovider.xml | 25 +++++++ .../src/org/aspectj/weaver/ShadowMunger.java | 64 ++++++++++++++---- .../patterns/DeclareErrorOrWarning.java | 14 ++++ 12 files changed, 209 insertions(+), 15 deletions(-) create mode 100644 tests/features153/jdtlikehandleprovider/AdviceAndInjar.aj create mode 100644 tests/features153/jdtlikehandleprovider/AspectOnAspectPath.aj create mode 100644 tests/features153/jdtlikehandleprovider/ClassForAspectpath.java create mode 100644 tests/features153/jdtlikehandleprovider/DeclareAndInjar.aj create mode 100644 tests/features153/jdtlikehandleprovider/README.txt create mode 100644 tests/features153/jdtlikehandleprovider/advice.jar create mode 100644 tests/features153/jdtlikehandleprovider/declare.jar create mode 100644 tests/features153/jdtlikehandleprovider/jarForAspectPath.jar diff --git a/tests/features153/jdtlikehandleprovider/AdviceAndInjar.aj b/tests/features153/jdtlikehandleprovider/AdviceAndInjar.aj new file mode 100644 index 000000000..68a6ad56a --- /dev/null +++ b/tests/features153/jdtlikehandleprovider/AdviceAndInjar.aj @@ -0,0 +1,17 @@ +public aspect AdviceAndInjar { + + pointcut p() : call(* *.*(..)) && !within(AdviceAndInjar); + + before() : p() { + } + + after() : p() { + } + + pointcut p1() : execution(* *.*(..)) && !within(AdviceAndInjar); + + Object around() : p1() { + return proceed(); + } + +} diff --git a/tests/features153/jdtlikehandleprovider/AspectOnAspectPath.aj b/tests/features153/jdtlikehandleprovider/AspectOnAspectPath.aj new file mode 100644 index 000000000..d111fda02 --- /dev/null +++ b/tests/features153/jdtlikehandleprovider/AspectOnAspectPath.aj @@ -0,0 +1,17 @@ +package pkg; + +public aspect AspectOnAspectPath { + + pointcut p() : call(* *.*(..)) && !within(AspectOnAspectPath); + declare warning: p() : "blah"; + + before() : p() { + } + + pointcut exec() : execution(* *.*(..)) && !within(AspectOnAspectPath); + declare warning : exec() : "blah2"; + before() : exec() { + + } + +} diff --git a/tests/features153/jdtlikehandleprovider/ClassForAspectpath.java b/tests/features153/jdtlikehandleprovider/ClassForAspectpath.java new file mode 100644 index 000000000..c30da9b97 --- /dev/null +++ b/tests/features153/jdtlikehandleprovider/ClassForAspectpath.java @@ -0,0 +1,10 @@ +public class ClassForAspectpath { + + public void foo() { + bar(); + } + + public void bar() { + + } +} diff --git a/tests/features153/jdtlikehandleprovider/DeclareAndInjar.aj b/tests/features153/jdtlikehandleprovider/DeclareAndInjar.aj new file mode 100644 index 000000000..d1b94b9c7 --- /dev/null +++ b/tests/features153/jdtlikehandleprovider/DeclareAndInjar.aj @@ -0,0 +1,9 @@ +public aspect DeclareAndInjar { + + pointcut p() : call(* *.*(..)) && !within(DeclareAndInjar); + declare warning: p() : "warning"; + + pointcut exec() : execution(* *.*(..)) && !within(DeclareAndInjar); + declare error : exec() : "error"; + +} diff --git a/tests/features153/jdtlikehandleprovider/README.txt b/tests/features153/jdtlikehandleprovider/README.txt new file mode 100644 index 000000000..cca1b5254 --- /dev/null +++ b/tests/features153/jdtlikehandleprovider/README.txt @@ -0,0 +1,7 @@ +To regenerate the jars in this directory: + +1. ajc AspectOnAspectPath.aj -outjar jarForAspectPath.jar + +2. ajc DeclareAndInjar.aj -outjar declare.jar + +3. ajc AdviceAndInjar.aj -outjar advice.jar diff --git a/tests/features153/jdtlikehandleprovider/advice.jar b/tests/features153/jdtlikehandleprovider/advice.jar new file mode 100644 index 0000000000000000000000000000000000000000..7e99367ef2d63885d48ae76874850801a7cc28e0 GIT binary patch literal 1580 zcmZ{kdpOez7{`AxG3gkM+~(573LBBqImq-FYkq6xp3)hbW?GAWV&#%FV=k4N79r06{Bw?;bI$ksywCf5pXYtv?|&aMQ4xj&R2JR27jFwJ z6B2*{po=FCLm=TTK^%#Ick%GVg7|N305A;-+TDp5?DN$`j9I6k>)t-A9-9$aICeK^ zK>(ja#TEOQ7FahB`*9z$vkUV?K)^_35}5)(CMv7k?eR(3u~@Wyamatycm1m#0C2&P zw4lQ{MlgX9N(sjXg;63R-g<#y`Yy;=Y2F-qu!k^EA-hFOpdCe5PSkYlSu>!wi+qk? zUaP8FiA?Luj2e1dR#`_%K!hYBls7P#*enA#^9xQc?L}?}aL$r8RI;MaNJmsq`CBkM zKfHans8cW~AC^;xv#WQ0{W`QBaC7E49jbb8^NB^t<#M`LC@dbq@f_C!i#+|op-o== zFr`M~h)!wSUKfws(Zz+(S=o`HU|9O7|3I}FyPiZe%if4Edr+>a^fm&FNmLZt9Jk@)HT@kMKgedRi)Z1M_i3`05O})NF&+D7=rcwv zXFD!J=R~q8pa@HUt(Au9dC$9YoVyCH_6p(`b9=~h1KP6!cqp7*6JeC(Jc0>j(I zB$tk@34C4YANxvFCkN5=FxEerb7X)RBt8 zac>mF>u-1uEO_43&`YiM@qa&pNQimxt=6NhsWS1bynx1j#a386iroj!A-DfSBh-4rC4P)}L zAPJX)YL3o0&+NE<^Ke_$47y7EikI)uiLy;}(`&jjG^ez6wuxJ#XM#ia0^jZ!U7~UH zGRWGQSszfyvYJGjboh1-Y1>$!^nI3pST3U~17Q@=t=<}(h1s-0Iar!>N{@ZCYC86W zr0B-r*f*zzr%>GJ8m4`nz_rD-)Bfx``_rRAzgT^SGGhu&DqhY{YH_MI7OJBtCm*eg z((-YO+j8bZ30|BeB4XUVX7+ZNl{2t{FRfFgZ}s?zj*MRtBl4rH?edDBrbT*&(CFjGEk5zX zNh5v(Y`!v+Lf?a4QDZ^9XO$#fI~3<9PRUBmLuh1+)M3ptmEi*pQWJ1}nTa(gtWkP= z{%iy*lh`B$QgBN1|h=$++j zG$&6ZL!-gi@TJsYOMuwV6#P_DBTT$3l&#z5euH{fa-SjGLieOnpEHiMs`j>-)zQZ2 zyZO22&-Y@}sUK zqNSW8Ld1zbvNd8jDqZ;vp7D7B04ypr4zlbDnemfn-yhV?J(&kZ_G;_X z?mCDZCnk#-Vc(DCL9;JzeG)c1)-^Z|M)ZfMf0-PPnLV_G!!I99sybi*KvQ4B;R*#L v@DGodqjHJIKkEPJy!^`&R+l#*e|QnMnEng0WTMi_r9*{9a~5~H(o*^hhmW%U literal 0 HcmV?d00001 diff --git a/tests/features153/jdtlikehandleprovider/declare.jar b/tests/features153/jdtlikehandleprovider/declare.jar new file mode 100644 index 0000000000000000000000000000000000000000..1278b4f1104715275d34da00f9d65a4e27ed5538 GIT binary patch literal 1341 zcmWIWW@Zs#-~hsHK5nKANI-;vg~8V~#8KDN&rRRg(a+P(H8@1i*X`da28PeRXHNTg z>*`(P_14uocjo-&AcHH$51tn3dHL#i`d%zuwI!%PN6*7o?_*HGx%0Xw&UorRdiv-o z6GMPEJIAIg;a!$Mi_C#I0B-$uH0woyvM#B~If+H7j(I7bd0B}?dO%)r@!L@EeCbe; zf9vEWZyV-LvI}0|>yhzUgDy>PR3eUETK@Zl<^7-MEX)1m?0$W- zYY_4?dSj=aGu_+p_0@CLyn4C@ZTr~bp9brF4_hWSP5Mxn*d?Co%ENM{HtuH&kLP*@ zK3nTx@MiY=i1>Bh`_E2~Eu5tozw_P7T>*V(3j%hVwXU(a*QGt>{oL%^A|w`s zJeT#4$=SPK=SgbqNdtrTx9`M0xpeXQi%rjaIAf30`OZ7Y$hH2JpF>dTkEj)8obAMRz75j0V1>9z-}ou=t=gnrLXjEb?`cb)T0fyKeZZGx+>PSa3dp|J4qp-`{< zoEq<=T_+URUzSg@aQhQ1SRc{a{cnxsysy!5Z@-#Gn`~9%KL502z521FzpFJoWv%Ak zxcJdEcG7chiGzW!^5(KDu6=pYdKYiVN~fdwp3!G4m+gtQ^4@c>z(n!C_rAxPyO$=Z zCQEo3)ZEtTc49mBB%sMtWOAax$_o=8sk{rQy!m}fMDWR4uEXIX;Y^386twMIB*OLU zW8=Z5f4r~aa^~q+iC*x2t~9sr@~I5ny5_s{mA_v*V*BO3p?PM~4d>l^x4btrzg6^q z+4GPmGv`JeKWMG?#?DtHF6e^I+QRe)0+#7YlK#R)EV?(289(#8?B}*kXUQ9Zl%y{@ zi`eJ+F1WIM{=Ak;UJK4VHt3rWdi-zdVnK@n@x%8Q=QAsZv$?%rR4;p6?!wjZ*d=Es zEaSN zs^!d0|0VzQr{qKKL%N5i`_FjJ_K^M1^_KRQ>WfvU*I2FgJXSP&Qqnwo;X21KkC)z` zdm7_EE_$bOd&{h4kKH3Q_eZHp`WXvc-KM{u)iu;W3l`tqK<2w8~{c z)2q;fqJL-eEQ_~_%)K(@b&T-B*w6aA*M2tqwW5tfnZ@r%L&4+^$`8#Cy|-}OSrg+J z@tpswq3w_L&o26WS(|6xKWYBY`)8KsO+TJ~4 z*#8bQ14B3usCZyx5@A4;Psl|FsC+^NxJoNzQ$WQGvJIeO1_A1UOss`YfHx}}NEs6l Kb^_^nV7mcHkvoR~ literal 0 HcmV?d00001 diff --git a/tests/features153/jdtlikehandleprovider/jarForAspectPath.jar b/tests/features153/jdtlikehandleprovider/jarForAspectPath.jar new file mode 100644 index 0000000000000000000000000000000000000000..bc12b8b316e3c34cb1c3acaa2d1481398b676477 GIT binary patch literal 1507 zcmWIWW@Zs#-~hrU9&V-#NI-;vg~8V~#8KDN&rRRg(a+P(H8@1i*X`da28PeRXHNTg z>*`(P_14uocjo-&AcHH$51tn3dHL#i`d%zuwI!%PN6*7o?_*HGx%0Xw&UorRdiv-o z6GMPEJIAIg;a!$Mi_C#I0H^gbK-q%qbbZI-g4E;^|2zmCkXVwTmzLgHI$zpV z#jw^LsAAePeJN_nW_hXemEJuu; zoc4&jI4*JJS|rpVzM|rZVBCY={R~1=j5p7&5YFd#*tsa`mx=iN&vQ@DDSq?*|DR9V z43R#DU#?sWE53ebmcf%bPuG5qnI@dTBP+V^TybdL+Go$YM1QF@Y8>{AGc;P3dP*`c z>~-IaXQkl=CFjkSh@a})d$2pSuyvv7|7ohHoo2B)uMb+wsh%ITI#e8Ex`gqpavZq`AS@kAocq=wN&OCDQlGkp&Hetm$ z)eA>2*kwmOO8a|uQGwVMRp;w#azDIMD)%YvHB7jZYGO6DuRlV%z*u_o?(~ zl^@x(!F<|riA~!!&w6_6r&pQthth{B@#33urmxF()bqWaC6Q(!yr^KUkjKpln}S5N zw<#Mt^qfO_#8pQ*9GGM`FIlR5eeVmx1Tk8hqj9 zll>Bxsd91Er24*xOqNqV%YM4|VAsqeezObljjZ4=Z-2LLtu@l!zzTVuYF~dyYBB$ih&DAT~YBy_M`YrbH#@rWknYRXK zwFN(kGirX>{i61Et;@7+6Zf{C`RBqGd*bC?*Pe^NJ|48!ofRbNKF9EFvJIcxyJJ$F zdG|E0=Lvjjkv!z2B=mFkeEk&>Oh=D%@;wwgsH*exbx+*!(mjE1!>x=r|FKca@Mhky zv+KUvp5};+r%nf)W!kg)@!u~KD*i@wZGJJ)>0jdq<%f(9moIMpqy5nQkbcX3PW#`l znfI<@a4%^%8+y<4g=5T7i*?dmYviY25#AiDd6jkkVxzxKjcltTi(L~BmtDIfW!@6~ z;d#=+Gi!rF&scxk6)EKB$Q8b;RrH|h-}=JiYU*55C#{*4eQ5IPwBYz-!hk3~kxMpE@rep>6{hH>Alm>c1reYg$i!DB26(fwfmAaA M;RGOU%L?KF05OG{wg3PC literal 0 HcmV?d00001 diff --git a/tests/src/org/aspectj/systemtest/ajc153/JDTLikeHandleProviderTests.java b/tests/src/org/aspectj/systemtest/ajc153/JDTLikeHandleProviderTests.java index 4dd33640e..eba17ef8b 100644 --- a/tests/src/org/aspectj/systemtest/ajc153/JDTLikeHandleProviderTests.java +++ b/tests/src/org/aspectj/systemtest/ajc153/JDTLikeHandleProviderTests.java @@ -316,6 +316,67 @@ public class JDTLikeHandleProviderTests extends XMLBasedAjcTestCase { + ", but did not",top.getElement(handle2)); } + public void testTwoPiecesOfBeforeAdviceInInjarAspectHaveUniqueHandles_pr159896() { + runTest("advice with same name in injar aspect should have unique handles"); + IHierarchy top = AsmManager.getDefault().getHierarchy(); + String handle1 = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.ADVICE,"before(): p..").getHandleIdentifier(); + String handle2 = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.ADVICE,"before(): exec..").getHandleIdentifier(); + assertFalse("expected the two advice nodes to have unique handles but" + + " did not", handle1.equals(handle2)); + } + + public void testTwoDeclareWarningsInInjarAspectHaveUniqueHandles_pr159896() { + runTest("declare warnings in injar aspect should have unique handles"); + IHierarchy top = AsmManager.getDefault().getHierarchy(); + String handle1 = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.DECLARE_WARNING,"declare warning: \"blah\"").getHandleIdentifier(); + String handle2 = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.DECLARE_WARNING,"declare warning: \"blah2\"").getHandleIdentifier(); + assertFalse("expected the two declare warning nodes to have unique handles but" + + " did not", handle1.equals(handle2)); + } + + // if have one declare warning and one declare error statement within an injar + // aspect, neither of them should have a counter (i.e. "!2") at the end of + // their handle + public void testOnlyIncrementSameDeclareTypeFromInjar_pr159896() { + runTest("dont increment counter for different declares"); + IHierarchy top = AsmManager.getDefault().getHierarchy(); + String warning = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.DECLARE_WARNING,"declare warning: \"warning\"").getHandleIdentifier(); + assertTrue("shouldn't have incremented counter for declare warning handle " + + "because only one declare warning statement", + warning.indexOf("!0") == -1 && warning.indexOf("!2") == -1); + String error = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.DECLARE_ERROR,"declare error: \"error\"").getHandleIdentifier(); + assertTrue("shouldn't have incremented counter for declare error handle " + + "because only one declare error statement", + error.indexOf("!0") == -1 && error.indexOf("!2") == -1); + } + + public void testOnlyIncrementSameAdviceKindFromInjar_pr159896() { + runTest("dont increment counter for different advice kinds"); + IHierarchy top = AsmManager.getDefault().getHierarchy(); + String before = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.ADVICE,"before(): p..").getHandleIdentifier(); + assertTrue("shouldn't have incremented counter for before handle " + + "because only one before advice", + before.indexOf("!0") == -1 && before.indexOf("!2") == -1 && before.indexOf("!3") == -1 ); + String after = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.ADVICE,"after(): p..").getHandleIdentifier(); + assertTrue("shouldn't have incremented counter for after handle " + + "because only one after advice", + after.indexOf("!0") == -1 && after.indexOf("!2") == -1 && after.indexOf("!3") == -1 ); + String around = top.findElementForLabel(top.getRoot(), + IProgramElement.Kind.ADVICE,"around(): p1..").getHandleIdentifier(); + assertTrue("shouldn't have incremented counter for around handle " + + "because only one around advice", + around.indexOf("!0") == -1 && around.indexOf("!2") == -1 && around.indexOf("!3") == -1 ); + + } + //---------- following tests ensure we produce the same handles as jdt -----// //---------- (apart from the prefix) diff --git a/tests/src/org/aspectj/systemtest/ajc153/jdtlikehandleprovider.xml b/tests/src/org/aspectj/systemtest/ajc153/jdtlikehandleprovider.xml index 3d0172e0a..fa4854194 100644 --- a/tests/src/org/aspectj/systemtest/ajc153/jdtlikehandleprovider.xml +++ b/tests/src/org/aspectj/systemtest/ajc153/jdtlikehandleprovider.xml @@ -228,4 +228,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/weaver/src/org/aspectj/weaver/ShadowMunger.java b/weaver/src/org/aspectj/weaver/ShadowMunger.java index a4ac3f8e1..a376187a6 100644 --- a/weaver/src/org/aspectj/weaver/ShadowMunger.java +++ b/weaver/src/org/aspectj/weaver/ShadowMunger.java @@ -273,31 +273,65 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, IH } private void addChildNodes(IProgramElement parent, Collection children) { + int afterCtr = 1; + int aroundCtr = 1; + int beforeCtr = 1; + int deCtr = 1; + int dwCtr = 1; for (Iterator iter = children.iterator(); iter.hasNext();) { Object element = (Object) iter.next(); if (element instanceof DeclareErrorOrWarning) { DeclareErrorOrWarning decl = (DeclareErrorOrWarning)element; - IProgramElement deowNode = new ProgramElement( - decl.isError() ? "declare error" : "declare warning", - decl.isError() ? IProgramElement.Kind.DECLARE_ERROR : IProgramElement.Kind.DECLARE_WARNING, - getBinarySourceLocation(decl.getSourceLocation()), - decl.getDeclaringType().getModifiers(), - null,null); - deowNode.setDetails("\"" + AsmRelationshipUtils.genDeclareMessage(decl.getMessage()) + "\""); - parent.addChild(deowNode); + int counter = 0; + if (decl.isError()) { + counter = deCtr++; + } else { + counter = dwCtr++; + } + parent.addChild(createDeclareErrorOrWarningChild(decl,counter)); } else if (element instanceof BcelAdvice) { BcelAdvice advice = (BcelAdvice)element; - IProgramElement adviceNode = new ProgramElement( - advice.kind.getName(), - IProgramElement.Kind.ADVICE, - getBinarySourceLocation(advice.getSourceLocation()), - advice.signature.getModifiers(),null,Collections.EMPTY_LIST); - adviceNode.setDetails(AsmRelationshipUtils.genPointcutDetails(advice.getPointcut())); - parent.addChild(adviceNode); + int counter = 0; + if (advice.getKind().equals(AdviceKind.Before)) { + counter = beforeCtr++; + } else if (advice.getKind().equals(AdviceKind.Around)){ + counter = aroundCtr++; + } else { + counter = afterCtr++; + } + parent.addChild(createAdviceChild(advice,counter)); } } } + private IProgramElement createDeclareErrorOrWarningChild( + DeclareErrorOrWarning decl, int count) { + IProgramElement deowNode = new ProgramElement( + decl.getName(), + decl.isError() ? IProgramElement.Kind.DECLARE_ERROR : IProgramElement.Kind.DECLARE_WARNING, + getBinarySourceLocation(decl.getSourceLocation()), + decl.getDeclaringType().getModifiers(), + null,null); + deowNode.setDetails("\"" + AsmRelationshipUtils.genDeclareMessage(decl.getMessage()) + "\""); + if (count != -1) { + deowNode.setBytecodeName(decl.getName() + "_" + count); + } + return deowNode; + } + + private IProgramElement createAdviceChild(BcelAdvice advice, int counter ) { + IProgramElement adviceNode = new ProgramElement( + advice.kind.getName(), + IProgramElement.Kind.ADVICE, + getBinarySourceLocation(advice.getSourceLocation()), + advice.signature.getModifiers(),null,Collections.EMPTY_LIST); + adviceNode.setDetails(AsmRelationshipUtils.genPointcutDetails(advice.getPointcut())); + if (counter != 1) { + adviceNode.setBytecodeName(advice.getKind().getName() + "$" + counter + "$"); + } + return adviceNode; + } + /** * Returns the binarySourceLocation for the given sourcelocation. This * isn't cached because it's used when faulting in the binary nodes diff --git a/weaver/src/org/aspectj/weaver/patterns/DeclareErrorOrWarning.java b/weaver/src/org/aspectj/weaver/patterns/DeclareErrorOrWarning.java index c4a3948ba..c9b663728 100644 --- a/weaver/src/org/aspectj/weaver/patterns/DeclareErrorOrWarning.java +++ b/weaver/src/org/aspectj/weaver/patterns/DeclareErrorOrWarning.java @@ -31,6 +31,9 @@ public class DeclareErrorOrWarning extends Declare { this.message = message; } + /** + * returns "declare warning: " or "declare error: " + */ public String toString() { StringBuffer buf = new StringBuffer(); buf.append("declare "); @@ -111,4 +114,15 @@ public class DeclareErrorOrWarning extends Declare { public String getNameSuffix() { return "eow"; } + + /** + * returns "declare warning" or "declare error" + */ + public String getName() { + StringBuffer buf = new StringBuffer(); + buf.append("declare "); + if (isError) buf.append("error"); + else buf.append("warning"); + return buf.toString(); + } } -- 2.39.5