From d929114a6659d64d71c47f7bf8f70e9973e5c857 Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Wed, 27 Aug 2014 13:25:21 -0700 Subject: [PATCH] 442425: fix error on attempted annotation style decp --- tests/bugs183/442425/EntityController.java | 10 +++++ .../442425/EntityControllerAspect.java | 16 +++++++ .../bugs183/442425/EntityMongoController.java | 8 ++++ tests/bugs183/442425/IEntityController.java | 6 +++ .../bugs183/442425/MyAnnotatedController.java | 37 +++++++++++++++++ .../scrum_master/app/EntityController.class | Bin 0 -> 403 bytes .../app/EntityControllerAspect.class | Bin 0 -> 1667 bytes .../app/EntityMongoController.class | Bin 0 -> 996 bytes .../scrum_master/app/IEntityController.class | Bin 0 -> 639 bytes .../app/MyAnnotatedController.class | Bin 0 -> 3588 bytes .../systemtest/ajc183/Ajc183Tests.java | 39 ++++++++++++++++++ .../systemtest/ajc183/AllTestsAspectJ183.java | 27 ++++++++++++ .../org/aspectj/systemtest/ajc183/ajc183.xml | 25 +++++++++++ .../aspectj/weaver/bcel/AtAjAttributes.java | 26 +++++------- 14 files changed, 178 insertions(+), 16 deletions(-) create mode 100644 tests/bugs183/442425/EntityController.java create mode 100644 tests/bugs183/442425/EntityControllerAspect.java create mode 100644 tests/bugs183/442425/EntityMongoController.java create mode 100644 tests/bugs183/442425/IEntityController.java create mode 100644 tests/bugs183/442425/MyAnnotatedController.java create mode 100644 tests/bugs183/442425/de/scrum_master/app/EntityController.class create mode 100644 tests/bugs183/442425/de/scrum_master/app/EntityControllerAspect.class create mode 100644 tests/bugs183/442425/de/scrum_master/app/EntityMongoController.class create mode 100644 tests/bugs183/442425/de/scrum_master/app/IEntityController.class create mode 100644 tests/bugs183/442425/de/scrum_master/app/MyAnnotatedController.class create mode 100644 tests/src/org/aspectj/systemtest/ajc183/Ajc183Tests.java create mode 100644 tests/src/org/aspectj/systemtest/ajc183/AllTestsAspectJ183.java create mode 100644 tests/src/org/aspectj/systemtest/ajc183/ajc183.xml diff --git a/tests/bugs183/442425/EntityController.java b/tests/bugs183/442425/EntityController.java new file mode 100644 index 000000000..2423b642d --- /dev/null +++ b/tests/bugs183/442425/EntityController.java @@ -0,0 +1,10 @@ +package de.scrum_master.app; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface EntityController {} diff --git a/tests/bugs183/442425/EntityControllerAspect.java b/tests/bugs183/442425/EntityControllerAspect.java new file mode 100644 index 000000000..7540db933 --- /dev/null +++ b/tests/bugs183/442425/EntityControllerAspect.java @@ -0,0 +1,16 @@ +package de.scrum_master.app; + +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.*; + +@Aspect +public class EntityControllerAspect { + @DeclareParents(value = "@EntityController *", defaultImpl = EntityMongoController.class) + private IEntityController iEntityController; +/* + @DeclareMixin("@EntityController *") + private IEntityController createEntityControllerInstance() { + return new EntityMongoController(); + } +*/ +} diff --git a/tests/bugs183/442425/EntityMongoController.java b/tests/bugs183/442425/EntityMongoController.java new file mode 100644 index 000000000..345f32043 --- /dev/null +++ b/tests/bugs183/442425/EntityMongoController.java @@ -0,0 +1,8 @@ +package de.scrum_master.app; + +public class EntityMongoController implements IEntityController { + private T entity; + + public void setEntity(T entity) { this.entity = entity; } + public T getEntity() { return entity; } +} diff --git a/tests/bugs183/442425/IEntityController.java b/tests/bugs183/442425/IEntityController.java new file mode 100644 index 000000000..440edcd31 --- /dev/null +++ b/tests/bugs183/442425/IEntityController.java @@ -0,0 +1,6 @@ +package de.scrum_master.app; + +public interface IEntityController { + void setEntity(T entity); + T getEntity(); +} diff --git a/tests/bugs183/442425/MyAnnotatedController.java b/tests/bugs183/442425/MyAnnotatedController.java new file mode 100644 index 000000000..fab43b835 --- /dev/null +++ b/tests/bugs183/442425/MyAnnotatedController.java @@ -0,0 +1,37 @@ +package de.scrum_master.app; + +import java.lang.reflect.Method; + +@EntityController +public class MyAnnotatedController { + public void doSomething() { + System.out.println("Doing something"); + } + + public static void main(String[] args) { + // Use class type directly so as to call its method + MyAnnotatedController annotatedTextController = new MyAnnotatedController<>(); + annotatedTextController.doSomething(); + + // Print all declared methods (should also show interface methods introduced via ITD) + for (Method method : annotatedTextController.getClass().getDeclaredMethods()) { + if (!method.getName().startsWith("ajc$")) + System.out.println(method); + } + + // Prove that class type is compatible with interface type + //IEntityController entityTextController = annotatedTextController; + //entityTextController.setEntity("foo"); + // Would not work here because generic interface type is type-safe: + // entityNumberController.setEntity(123); + //System.out.println("Entity value = " + entityTextController.getEntity()); + + // Create another object and directly assign it to interface type + //IEntityController entityNumberController = new MyAnnotatedController<>(); + //entityNumberController.setEntity(123); + // Would not work here because generic interface type is type-safe: + // entityNumberController.setEntity("foo"); + //System.out.println("Entity value = " + entityNumberController.getEntity()); + } +} + diff --git a/tests/bugs183/442425/de/scrum_master/app/EntityController.class b/tests/bugs183/442425/de/scrum_master/app/EntityController.class new file mode 100644 index 0000000000000000000000000000000000000000..e224f8fea3e5fc24e77a131194e9de38a09f65bd GIT binary patch literal 403 zcmaiwPfNo<5XIlr)@c1#4<1BB5$Vw!JbEe;LGVwBQ4kNZjYHY8*$tabAz#gdAHWYK zPCZzVfQOxZv-5uQU_Za!KLDI#H$sPS`o?jU`?`27R2A6Asx0Hg1|6D9XM=afu#eCs z3}$MsVx#OdzMsrE4-r-gN6S}btqUq>XXDYYB=jF#?Q_1;h6#IrSD!6-!hTvyX2DOo z(i6i=z9Jmov}U9nSQuw72)(&7wX7fhV;wuA^G1LueZ0%AZxg~{JCZ3sUG4+v`!d^LY+?)B3;6|pQ>H&Aw5 literal 0 HcmV?d00001 diff --git a/tests/bugs183/442425/de/scrum_master/app/EntityControllerAspect.class b/tests/bugs183/442425/de/scrum_master/app/EntityControllerAspect.class new file mode 100644 index 0000000000000000000000000000000000000000..2e64a3da082ce781240d5b8019e177ca1299728b GIT binary patch literal 1667 zcmb7ETTk3Z7(KI>?6NF(D3GLuG$etA+HKP&RY6rLB?;>0qHMHP`ce&M0B^na${v&Q zoF9`H9&&jg3R3cxO8rHBs(QwzyNFmwS;;dy-+Z@o&S(Gq@0+&(uH$A2If2@ivLh#q z+rPJEq*Z9kPRCyNwX65n0$+!L=c#Zt>L^E-P!Jey$vtU%(%-S~Z?8VxU546;7;70;W^&s4_Wm3JB7M0z5`)B2NGE@)v_&Q>$ z;-2(kB{25m={mDDf&MMEEn`n_v^$=_VrGMB+}*(633}+6`P_=@yZQ%#{QN>wps*Hf zsS5HKsbT_V{0%?S(svm08O5@W#j>6#xu-&FwbdGA00m$-6>`FAuu=T+`Ru)qyk@(^SA)PymYjW3UL zEhhPa3IpGxSUAWZ&?7Uvd>mde@-m-kr+GTvz zCESQc4+e=dvLE2MK9{)&Kwi literal 0 HcmV?d00001 diff --git a/tests/bugs183/442425/de/scrum_master/app/EntityMongoController.class b/tests/bugs183/442425/de/scrum_master/app/EntityMongoController.class new file mode 100644 index 0000000000000000000000000000000000000000..028780fb103cbf78a7c9e57d879e6790b96db80e GIT binary patch literal 996 zcma)4U2oGc6g^JbWG#h_vJEI7V@OEpCM8I`K~)J2kdQifSk+hLrdF0JjVs3;+K=GB zfCNI~foH^zLR=?hWlbLTU|;+A`kZ^N{rk_4p8%fWu?vf#I}t$^s>STXjAvS?fY0Z_ z>r}`3{8*-uJd&waGD(DTQDfMe@-rSJJdJ|)3y0xJ70KIzWktZ?h@6? z!O%E~qm=7~5)AfmNQl#m(^&Uu>vcyAwIewZP1x9M;Tl>Dn}awN?-sMMP(waW=w5pu zL!OMdip_or*7RwdF&qx6%B=KC+PjyT&gcKwo?e}%M=tutStfL$!?5F(y&H3mN6BX4 zOBMM%n^SYA{zt*jgz}GtK9!SKB22jAI+p3mcmoXgT5z#JI?+mJ+v}Ev80ua(Z*B8L zE>tMq#HMSV$|m^cjTnZ#;qx+6zYJCOrSuDmo?xHKwrSL9Sf+Z44f>ZB%mXv?zBFGa ze?MuiG?dUaeo9-0?cW{@m4H^!OPr1m5 zge`*{9DYM*UB$^&c8iRqin(2sZS+=WMz1()k}ku2Jh)JPc%kf4&aX9lU(xwY@c;JQ QE7`NKNB1l|S{mH{3*VvIS^xk5 literal 0 HcmV?d00001 diff --git a/tests/bugs183/442425/de/scrum_master/app/IEntityController.class b/tests/bugs183/442425/de/scrum_master/app/IEntityController.class new file mode 100644 index 0000000000000000000000000000000000000000..b3cd36beb2371658bd9d85c1d65d153fd0942d80 GIT binary patch literal 639 zcmb_Z%Syvg5Ir~cZPh9&xDhvE3X&|`SrNns3e^fJb*Z=M5EIg*+}u?B6TiiUAK*uc z(^M)nb?0L4Ff(V)oICUR_5K0i2peS>0{a896IZ3f$DvF#DO-+4_RVFaef@eKM_R>U zNUDs2KqHW2X@@fM>`p%*R|`}V(o?L!mf4;Mw3`KqcwOXWkrsc;;by(S7I7dzKxd S#T`!*K5_7GdX1URAKl+iwUICY literal 0 HcmV?d00001 diff --git a/tests/bugs183/442425/de/scrum_master/app/MyAnnotatedController.class b/tests/bugs183/442425/de/scrum_master/app/MyAnnotatedController.class new file mode 100644 index 0000000000000000000000000000000000000000..dae29b206d2a83dd762e152e18d37222b81bb4d9 GIT binary patch literal 3588 zcmd5;T~`}b6y28uh73bLpp?=AqWuaVCbep<4FxG}EeZu2O24dlNycNbWD-IRE+0(R%$y__W-jjV;e5g_}p%|a6vk1;Wz_WA< zimGUMp*I4(vT~jl%`d&`nd0eD73bsyPDU864Vkq$d4O_`;Dr0D>h8>XGWYqMT=S2c zhA9m*0;i(h?%7q(I_qxEylJUJd$OS@q*R_*LRqU|OK;t!VRC%&O2mhdqKUmj0)2PZ zZO^d!)N;dI6e& z2bk=@eLUnS&qOd#B?n4}DQFQV})yh8KBfM+urP&HKI`RzdKk%Ui9lRUCAlpv%bY5yfaHp)%N-dsY zt40$)qO0q~CQd4VSOg#u0vzIa0I5a}v!@_+E(hBAPvEHk1RwTm_J`X7&MAKfeeXKy?;%EUl=fZZ zuN#;6Jjvco+FV6!hlXt$-q*NH2o1M@9rRX)G+fvnWMH*+yELdA{K56CFWwc`^L`?M z{*j-M{S}8sp5rd*So#@RHL`_ef$wP-rN2Lzqu6$W0w`SO;tvGJ5*|) z6P8_7pQqSkiB$DDR-?vywYnl*O6UWr<(HbT*tHV-68%$aP#`Np76{v1RM7qgtiN^r literal 0 HcmV?d00001 diff --git a/tests/src/org/aspectj/systemtest/ajc183/Ajc183Tests.java b/tests/src/org/aspectj/systemtest/ajc183/Ajc183Tests.java new file mode 100644 index 000000000..80541fc0f --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc183/Ajc183Tests.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2014 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial API and implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc183; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + +/** + * @author Andy Clement + */ +public class Ajc183Tests extends org.aspectj.testing.XMLBasedAjcTestCase { + + public void testAnnoStyleDecp_442425() { + runTest("anno style decp"); + } + + // --- + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(Ajc183Tests.class); + } + + @Override + protected File getSpecFile() { + return getClassResource("ajc183.xml"); + } + +} diff --git a/tests/src/org/aspectj/systemtest/ajc183/AllTestsAspectJ183.java b/tests/src/org/aspectj/systemtest/ajc183/AllTestsAspectJ183.java new file mode 100644 index 000000000..6caef2609 --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc183/AllTestsAspectJ183.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2014 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial API and implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc183; + +import junit.framework.Test; +import junit.framework.TestSuite; +import org.aspectj.systemtest.apt.AptTests; + +public class AllTestsAspectJ183 { + + public static Test suite() { + TestSuite suite = new TestSuite("AspectJ 1.8.3 tests"); + // $JUnit-BEGIN$ + suite.addTest(Ajc183Tests.suite()); + suite.addTest(AptTests.suite()); + // $JUnit-END$ + return suite; + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc183/ajc183.xml b/tests/src/org/aspectj/systemtest/ajc183/ajc183.xml new file mode 100644 index 000000000..5a77148b7 --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc183/ajc183.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + diff --git a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java index 41f9f1ab7..dbb81b53e 100644 --- a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java +++ b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java @@ -726,6 +726,9 @@ public class AtAjAttributes { TypePattern typePattern = parseTypePattern(decpPattern, struct); ResolvedType fieldType = UnresolvedType.forSignature(struct.field.getSignature()).resolve( struct.enclosingType.getWorld()); + if (fieldType.isParameterizedOrRawType()) { + fieldType = fieldType.getGenericType(); + } if (fieldType.isInterface()) { TypePattern parent = parseTypePattern(fieldType.getName(), struct); FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0]; @@ -772,9 +775,7 @@ public class AtAjAttributes { hasNoCtorOrANoArgOne = false; if (resolvedMember.getParameterTypes().length == 0) { - if (defaultVisibilityImpl) { // default - // visibility - // implementation + if (defaultVisibilityImpl) { // default visibility implementation if (resolvedMember.isPublic() || resolvedMember.isDefault()) { hasNoCtorOrANoArgOne = true; } else { @@ -819,11 +820,6 @@ public class AtAjAttributes { Iterator methodIterator = fieldType.getMethodsIncludingIntertypeDeclarations(false, true); while (methodIterator.hasNext()) { ResolvedMember method = methodIterator.next(); - - // ResolvedMember[] methods = fieldType.getMethodsWithoutIterator(true, false, false).toArray( - // new ResolvedMember[0]); - // for (int i = 0; i < methods.length; i++) { - // ResolvedMember method = methods[i]; if (method.isAbstract()) { // moved to be detected at weave time if the target // doesnt implement the methods @@ -849,22 +845,19 @@ public class AtAjAttributes { // So here we create a modified method with an // alternative declaring type so that we lookup // the right field. See pr164016. - MethodDelegateTypeMunger mdtm = new MethodDelegateTypeMunger(method, struct.enclosingType, - defaultImplClassName, typePattern); + MethodDelegateTypeMunger mdtm = new MethodDelegateTypeMunger(method, struct.enclosingType, defaultImplClassName, typePattern); mdtm.setFieldType(fieldType); mdtm.setSourceLocation(struct.enclosingType.getSourceLocation()); struct.ajAttributes.add(new AjAttribute.TypeMunger(mdtm)); } } - // successfull so far, we thus need a bcel type munger to - // have + // successful so far, we thus need a bcel type munger to have // a field hosting the mixin in the target type if (hasAtLeastOneMethod && defaultImplClassName != null) { ResolvedMember fieldHost = AjcMemberMaker.itdAtDeclareParentsField(null, fieldType, struct.enclosingType); struct.ajAttributes.add(new AjAttribute.TypeMunger(new MethodDelegateTypeMunger.FieldHostTypeMunger( fieldHost, struct.enclosingType, typePattern))); } - return true; } else { reportError("@DeclareParents: can only be used on a field whose type is an interface", struct); @@ -915,7 +908,6 @@ public class AtAjAttributes { // No annotation found return false; } - Method annotatedMethod = struct.method; World world = struct.enclosingType.getWorld(); NameValuePair declareMixinPatternNameValuePair = getAnnotationElement(declareMixinAnnotation, VALUE); @@ -926,7 +918,9 @@ public class AtAjAttributes { // Return value of the annotated method is the interface or class that the mixin delegate should have ResolvedType methodReturnType = UnresolvedType.forSignature(annotatedMethod.getReturnType().getSignature()).resolve(world); - + if (methodReturnType.isParameterizedOrRawType()) { + methodReturnType = methodReturnType.getGenericType(); + } if (methodReturnType.isPrimitiveType()) { reportError(getMethodForMessage(struct) + ": factory methods for a mixin cannot return void or a primitive type", struct); @@ -942,7 +936,7 @@ public class AtAjAttributes { // supplied as a list in the 'Class[] interfaces' value in the annotation value // supplied as just the interface return value of the annotated method // supplied as just the class return value of the annotated method - NameValuePair interfaceListSpecified = getAnnotationElement(declareMixinAnnotation, "interfaces"); + NameValuePair interfaceListSpecified = getAnnotationElement(declareMixinAnnotation, "interfaces"); List newParents = new ArrayList(1); List newInterfaceTypes = new ArrayList(1); -- 2.39.5