diff options
author | Andy Clement <andrew.clement@gmail.com> | 2012-04-04 12:40:30 -0700 |
---|---|---|
committer | Andy Clement <andrew.clement@gmail.com> | 2012-04-04 12:40:30 -0700 |
commit | f340cea270dbc56dde9a938bd9c88c89f88e4db5 (patch) | |
tree | afa0c3cf8756f061b4cd583b5d79ea7401042161 /weaver | |
parent | e0e08d764baff374fa8c3251b72c4e6aeb7699c4 (diff) | |
download | aspectj-f340cea270dbc56dde9a938bd9c88c89f88e4db5.tar.gz aspectj-f340cea270dbc56dde9a938bd9c88c89f88e4db5.zip |
376030
Diffstat (limited to 'weaver')
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java | 21 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelWorld.java | 49 |
2 files changed, 54 insertions, 16 deletions
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java index fcf61a085..ac9bacf84 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.Set; import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.ClassFormatException; import org.aspectj.apache.bcel.classfile.ConstantPool; import org.aspectj.apache.bcel.classfile.Signature; import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; @@ -739,13 +740,19 @@ public class BcelTypeMunger extends ConcreteTypeMunger { } protected LazyMethodGen makeMethodGen(LazyClassGen gen, ResolvedMember member) { - LazyMethodGen ret = new LazyMethodGen(member.getModifiers(), BcelWorld.makeBcelType(member.getReturnType()), - member.getName(), BcelWorld.makeBcelTypes(member.getParameterTypes()), UnresolvedType.getNames(member - .getExceptions()), gen); - - // 43972 : Static crosscutting makes interfaces unusable for javac - // ret.makeSynthetic(); - return ret; + try { + Type returnType = BcelWorld.makeBcelType(member.getReturnType()); + Type[] parameterTypes = BcelWorld.makeBcelTypes(member.getParameterTypes()); + LazyMethodGen ret = new LazyMethodGen(member.getModifiers(), returnType, + member.getName(), parameterTypes, UnresolvedType.getNames(member + .getExceptions()), gen); + + // 43972 : Static crosscutting makes interfaces unusable for javac + // ret.makeSynthetic(); + return ret; + } catch (ClassFormatException cfe) { + throw new RuntimeException("Problem with makeMethodGen for method "+member.getName()+" in type "+gen.getName()+" ret="+member.getReturnType(),cfe); + } } protected FieldGen makeFieldGen(LazyClassGen gen, ResolvedMember member) { diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java index f16ed3491..c46c68985 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java @@ -791,7 +791,28 @@ public class BcelWorld extends World implements Repository { } return didSomething; } - + + /** + * Apply the specified declare @field construct to any matching fields in the specified type. + * @param deca the declare annotation targeting fields + * @param type the type to check for members matching the declare annotation + * @return true if something matched and the type was modified + */ + private boolean applyDeclareAtField(DeclareAnnotation deca, ResolvedType type) { + boolean changedType = false; + ResolvedMember[] fields = type.getDeclaredFields(); + for (ResolvedMember field: fields) { + if (deca.matches(field, this)) { + AnnotationAJ anno = deca.getAnnotation(); + if (!field.hasAnnotation(anno.getType())) { + field.addAnnotation(anno); + changedType=true; + } + } + } + return changedType; + } + /** * Checks for an @target() on the annotation and if found ensures it allows the annotation to be attached to the target type * that matched. @@ -842,29 +863,39 @@ public class BcelWorld extends World implements Repository { anAnnotationChangeOccurred = true; } } + + // apply declare @field + for (DeclareAnnotation deca: getCrosscuttingMembersSet().getDeclareAnnotationOnFields()) { + if (applyDeclareAtField(deca,onType)) { + anAnnotationChangeOccurred = true; + } + } while ((aParentChangeOccurred || anAnnotationChangeOccurred) && !decpToRepeat.isEmpty()) { anAnnotationChangeOccurred = aParentChangeOccurred = false; List<DeclareParents> decpToRepeatNextTime = new ArrayList<DeclareParents>(); - for (Iterator<DeclareParents> iter = decpToRepeat.iterator(); iter.hasNext();) { - DeclareParents decp = iter.next(); - boolean typeChanged = applyDeclareParents(decp, onType); - if (typeChanged) { + for (DeclareParents decp: decpToRepeat) { + if (applyDeclareParents(decp, onType)) { aParentChangeOccurred = true; } else { decpToRepeatNextTime.add(decp); } } - for (Iterator iter = getCrosscuttingMembersSet().getDeclareAnnotationOnTypes().iterator(); iter.hasNext();) { - DeclareAnnotation decA = (DeclareAnnotation) iter.next(); - boolean typeChanged = applyDeclareAtType(decA, onType, false); - if (typeChanged) { + for (DeclareAnnotation deca: getCrosscuttingMembersSet().getDeclareAnnotationOnTypes()) { + if (applyDeclareAtType(deca, onType, false)) { + anAnnotationChangeOccurred = true; + } + } + + for (DeclareAnnotation deca: getCrosscuttingMembersSet().getDeclareAnnotationOnFields()) { + if (applyDeclareAtField(deca, onType)) { anAnnotationChangeOccurred = true; } } decpToRepeat = decpToRepeatNextTime; } + } @Override |