Browse Source

359159

tags/V1_6_12
aclement 12 years ago
parent
commit
d825f323f5
1 changed files with 11 additions and 18 deletions
  1. 11
    18
      loadtime/src/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java

+ 11
- 18
loadtime/src/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java View File

/** /**
* Generates bytecode for concrete-aspect. * Generates bytecode for concrete-aspect.
* <p> * <p>
* The concrete aspect is @AspectJ code generated. As it is build during aop.xml definitions registration we perform the type
* munging for perclause, ie. aspectOf() artifact directly, instead of waiting for it to go thru the weaver (that we are in the
* middle of configuring).
* The concrete aspect is generated annotation style aspect (so traditional Java constructs annotated with our AspectJ annotations).
* As it is built during aop.xml definitions registration we perform the type munging for perclause, ie. aspectOf() artifact
* directly, instead of waiting for it to go thru the weaver (that we are in the middle of configuring).
* *
* @author Alexandre Vasseur * @author Alexandre Vasseur
* @author Andy Clement * @author Andy Clement
private byte[] bytes; private byte[] bytes;


/** /**
* Create a new compiler for a concrete aspect
* Create a new generator for a concrete aspect
* *
* @param concreteAspect
* @param world
* @param concreteAspect the aspect definition
* @param world the related world (for type resolution, etc)
*/ */
ConcreteAspectCodeGen(Definition.ConcreteAspect concreteAspect, World world) { ConcreteAspectCodeGen(Definition.ConcreteAspect concreteAspect, World world) {
this.concreteAspect = concreteAspect; this.concreteAspect = concreteAspect;
} }


/** /**
* Checks that concrete aspect is valid
* Checks that concrete aspect is valid.
* *
* @return true if ok, false otherwise * @return true if ok, false otherwise
*/ */
List<String> elligibleAbstractions = new ArrayList<String>(); List<String> elligibleAbstractions = new ArrayList<String>();


Collection<ResolvedMember> abstractMethods = getOutstandingAbstractMethods(parent); Collection<ResolvedMember> abstractMethods = getOutstandingAbstractMethods(parent);
// for (Iterator iter = abstractMethods.iterator(); iter.hasNext();) {
// ResolvedMember method = (ResolvedMember) iter.next();
for (ResolvedMember method : abstractMethods) { for (ResolvedMember method : abstractMethods) {
if ("()V".equals(method.getSignature())) { if ("()V".equals(method.getSignature())) {
String n = method.getName(); String n = method.getName();
} }
} else { } else {
if (method.getName().startsWith("ajc$pointcut") || hasPointcutAnnotation(method)) { if (method.getName().startsWith("ajc$pointcut") || hasPointcutAnnotation(method)) {
// it may be a pointcut but it doesn't meet the requirements
// for XML concretization
// it may be a pointcut but it doesn't meet the requirements for XML concretization
reportError("Abstract method '" reportError("Abstract method '"
+ method.toString() + method.toString()
+ "' cannot be concretized as a pointcut (illegal signature, must have no arguments, must return void): " + "' cannot be concretized as a pointcut (illegal signature, must have no arguments, must return void): "
sb.append("' perclause='"); sb.append("' perclause='");
sb.append(concreteAspect.perclause); sb.append(concreteAspect.perclause);
sb.append("'/> in aop.xml"); sb.append("'/> in aop.xml");
// TODO needs the extra state from the definition (concretized pointcuts and advice definitions)
return sb.toString(); return sb.toString();
} }


} }
} }


// TODO AV - abstract away from BCEL...
// @Aspect //inherit clause from m_parent // @Aspect //inherit clause from m_parent
// @DeclarePrecedence("....") // if any // @DeclarePrecedence("....") // if any
// public class xxxName [extends xxxExtends] { // public class xxxName [extends xxxExtends] {
} }
} }
// @Aspect public class ... // @Aspect public class ...
// TODO AV - we could point to the aop.xml that defines it and use
// JSR-45
// TODO AV - we could point to the aop.xml that defines it and use JSR-45
LazyClassGen cg = new LazyClassGen(concreteAspect.name.replace('.', '/'), parentName, null, Modifier.PUBLIC LazyClassGen cg = new LazyClassGen(concreteAspect.name.replace('.', '/'), parentName, null, Modifier.PUBLIC
+ Constants.ACC_SUPER, EMPTY_STRINGS, world); + Constants.ACC_SUPER, EMPTY_STRINGS, world);
if (parent != null && parent.isParameterizedType()) { if (parent != null && parent.isParameterizedType()) {
cg.addMethodGen(mg); cg.addMethodGen(mg);
} }


// Construct any defined declare error/warnings
if (concreteAspect.deows.size() > 0) { if (concreteAspect.deows.size() > 0) {

int counter = 1; int counter = 1;
for (Definition.DeclareErrorOrWarning deow : concreteAspect.deows) { for (Definition.DeclareErrorOrWarning deow : concreteAspect.deows) {

// Building this: // Building this:

// @DeclareWarning("call(* javax.sql..*(..)) && !within(org.xyz.daos..*)") // @DeclareWarning("call(* javax.sql..*(..)) && !within(org.xyz.daos..*)")
// static final String aMessage = "Only DAOs should be calling JDBC."; // static final String aMessage = "Only DAOs should be calling JDBC.";




field.setValue(deow.message); field.setValue(deow.message);
cg.addField(field, null); cg.addField(field, null);

} }
} }



Loading…
Cancel
Save