From: aclement Date: Fri, 29 Jan 2010 20:30:35 +0000 (+0000) Subject: extended definition and code gen to allow for deows X-Git-Tag: V1_6_9M1~60 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b21cd2fcde00255aef5de268c66350c6fb1d8441;p=aspectj.git extended definition and code gen to allow for deows --- diff --git a/loadtime/src/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java b/loadtime/src/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java index 41b9b4ca3..32293bee1 100644 --- a/loadtime/src/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java +++ b/loadtime/src/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java @@ -26,6 +26,7 @@ import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; import org.aspectj.apache.bcel.classfile.annotation.ElementValue; import org.aspectj.apache.bcel.classfile.annotation.NameValuePair; import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValue; +import org.aspectj.apache.bcel.generic.FieldGen; import org.aspectj.apache.bcel.generic.InstructionConstants; import org.aspectj.apache.bcel.generic.InstructionList; import org.aspectj.apache.bcel.generic.ObjectType; @@ -48,6 +49,7 @@ import org.aspectj.weaver.loadtime.definition.Definition; import org.aspectj.weaver.patterns.PerClause; import org.aspectj.weaver.patterns.PerSingleton; + /** * Generates bytecode for concrete-aspect. *

@@ -176,14 +178,14 @@ public class ConcreteAspectCodeGen { return false; } - // extends must be abstract - if (!parent.isAbstract()) { + // extends must be abstract (allow for special case of Object where just using aspect for deows) + if (!(parent.isAbstract() || parent.equals(ResolvedType.OBJECT))) { reportError("Attempt to concretize a non-abstract aspect: " + stringify()); return false; } - // m_parent must be aspect - if (!parent.isAspect()) { + // m_parent must be aspect (allow for special case of Object where just using aspect for deows) + if (!(parent.isAspect() || parent.equals(ResolvedType.OBJECT))) { reportError("Attempt to concretize a non aspect: " + stringify()); return false; } @@ -430,6 +432,31 @@ public class ConcreteAspectCodeGen { cg.addMethodGen(mg); } + if (concreteAspect.deows.size() > 0) { + + int counter = 1; + for (Definition.DeclareErrorOrWarning deow : concreteAspect.deows) { + + // Building this: + + // @DeclareWarning("call(* javax.sql..*(..)) && !within(org.xyz.daos..*)") + // static final String aMessage = "Only DAOs should be calling JDBC."; + + FieldGen field = new FieldGen(Modifier.FINAL, ObjectType.STRING, "rule" + (counter++), cg.getConstantPool()); + SimpleElementValue svg = new SimpleElementValue(ElementValue.STRING, cg.getConstantPool(), deow.pointcut); + List elems = new ArrayList(); + elems.add(new NameValuePair("value", svg, cg.getConstantPool())); + AnnotationGen mag = new AnnotationGen(new ObjectType("org/aspectj/lang/annotation/Declare" + + (deow.isError ? "Error" : "Warning")), elems, true, cg.getConstantPool()); + field.addAnnotation(mag); + + field.setValue(deow.message); + cg.addField(field, null); + + + } + } + // handle the perClause ReferenceType rt = new ReferenceType(ResolvedType.forName(concreteAspect.name).getSignature(), world); GeneratedReferenceTypeDelegate grtd = new GeneratedReferenceTypeDelegate(rt);