654
673
WeaverStateInfo info = onType.getWeaverState();
656
// this test isnt quite right - there will be a case where we fail to
658
// with a 'dangerous interface' because the type is reweavable when we
660
// because the type wasn't going to be rewoven... if that happens, we
662
// move this test and dangerous interface processing to the end of this
664
// make it conditional on whether any of the typeMungers passed into
666
// matched this type.
667
if (info != null && !info.isOldStyle() && !info.isReweavable()) {
668
processTypeMungersFromExistingWeaverState(sourceType, onType);
669
CompilationAndWeavingContext.leavingPhase(tok);
673
// Check if the type we are looking at is the topMostImplementor of a
674
// dangerous interface -
675
// report a problem if it is.
676
for (Iterator i = dangerousInterfaces.entrySet().iterator(); i.hasNext();) {
677
Map.Entry entry = (Map.Entry) i.next();
678
ResolvedType interfaceType = (ResolvedType) entry.getKey();
679
if (onType.isTopmostImplementor(interfaceType)) {
680
factory.showMessage(IMessage.ERROR, onType + ": " + entry.getValue(), onType.getSourceLocation(), null);
684
boolean needOldStyleWarning = (info != null && info.isOldStyle());
686
onType.clearInterTypeMungers();
687
onType.ensureConsistent();
689
// FIXME asc perf Could optimize here, after processing the expected set
690
// of types we may bring
691
// binary types that are not exposed to the weaver, there is no need to
692
// attempt declare parents
693
// or declare annotation really - unless we want to report the
694
// not-exposed to weaver
697
List decpToRepeat = new ArrayList();
698
List<DeclareAnnotation> decaToRepeat = new ArrayList<DeclareAnnotation>();
699
boolean anyNewParents = false;
700
boolean anyNewAnnotations = false;
703
// try and apply all decps - if they match, then great. If they don't
705
// check if they are starred-annotation patterns. If they are not
707
// annotation patterns then they might match later...remember that...
708
for (Iterator i = declareParents.iterator(); i.hasNext();) {
709
DeclareParents decp = (DeclareParents) i.next();
710
if (!decp.isMixin()) {
711
boolean didSomething = doDeclareParents(decp, sourceType);
676
// this test isnt quite right - there will be a case where we fail to
678
// with a 'dangerous interface' because the type is reweavable when we
680
// because the type wasn't going to be rewoven... if that happens, we
682
// move this test and dangerous interface processing to the end of this
684
// make it conditional on whether any of the typeMungers passed into
686
// matched this type.
687
if (info != null && !info.isOldStyle() && !info.isReweavable()) {
688
processTypeMungersFromExistingWeaverState(sourceType, onType);
689
CompilationAndWeavingContext.leavingPhase(tok);
693
// Check if the type we are looking at is the topMostImplementor of a
694
// dangerous interface -
695
// report a problem if it is.
696
for (Iterator i = dangerousInterfaces.entrySet().iterator(); i.hasNext();) {
697
Map.Entry entry = (Map.Entry) i.next();
698
ResolvedType interfaceType = (ResolvedType) entry.getKey();
699
if (onType.isTopmostImplementor(interfaceType)) {
700
factory.showMessage(IMessage.ERROR, onType + ": " + entry.getValue(), onType.getSourceLocation(), null);
704
boolean needOldStyleWarning = (info != null && info.isOldStyle());
706
onType.clearInterTypeMungers();
707
onType.ensureConsistent();
709
// FIXME asc perf Could optimize here, after processing the expected set
710
// of types we may bring
711
// binary types that are not exposed to the weaver, there is no need to
712
// attempt declare parents
713
// or declare annotation really - unless we want to report the
714
// not-exposed to weaver
717
List<DeclareParents> decpToRepeat = new ArrayList<DeclareParents>();
718
List<DeclareAnnotation> decaToRepeat = new ArrayList<DeclareAnnotation>();
719
boolean anyNewParents = false;
720
boolean anyNewAnnotations = false;
723
// try and apply all decps - if they match, then great. If they don't
725
// check if they are starred-annotation patterns. If they are not
727
// annotation patterns then they might match later...remember that...
728
for (DeclareParents decp : declareParents) {
729
if (!decp.isMixin()) {
730
boolean didSomething = doDeclareParents(decp, sourceType);
732
if (factory.pushinCollector != null) {
733
factory.pushinCollector.tagAsMunged(sourceType, decp.getParents().get(0));
735
anyNewParents = true;
737
if (!decp.getChild().isStarAnnotation()) {
738
decpToRepeat.add(decp);
744
for (DeclareAnnotation deca : declareAnnotationOnTypes) {
745
boolean didSomething = doDeclareAnnotations(deca, sourceType, true);
712
746
if (didSomething) {
713
if (factory.pushinCollector != null) {
714
factory.pushinCollector.tagAsMunged(sourceType, decp.getParents().get(0));
716
anyNewParents = true;
747
anyNewAnnotations = true;
718
if (!decp.getChild().isStarAnnotation()) {
719
decpToRepeat.add(decp);
749
if (!deca.getTypePattern().isStar()) {
750
decaToRepeat.add(deca);
725
for (Iterator<DeclareAnnotation> i = declareAnnotationOnTypes.iterator(); i.hasNext();) {
726
DeclareAnnotation deca = i.next();
727
boolean didSomething = doDeclareAnnotations(deca, sourceType, true);
729
anyNewAnnotations = true;
731
if (!deca.getTypePattern().isStar()) {
732
decaToRepeat.add(deca);
737
// now lets loop over and over until we have done all we can
738
while ((anyNewAnnotations || anyNewParents) && (!decpToRepeat.isEmpty() || !decaToRepeat.isEmpty())) {
739
anyNewParents = anyNewAnnotations = false;
740
755
List forRemoval = new ArrayList();
741
for (Iterator i = decpToRepeat.iterator(); i.hasNext();) {
742
DeclareParents decp = (DeclareParents) i.next();
743
boolean didSomething = doDeclareParents(decp, sourceType);
745
if (factory.pushinCollector != null) {
746
factory.pushinCollector.tagAsMunged(sourceType, decp.getParents().get(0));
756
// now lets loop over and over until we have done all we can
757
while ((anyNewAnnotations || anyNewParents) && (!decpToRepeat.isEmpty() || !decaToRepeat.isEmpty())) {
758
anyNewParents = anyNewAnnotations = false;
760
for (DeclareParents decp : decpToRepeat) {
761
boolean didSomething = doDeclareParents(decp, sourceType);
763
if (factory.pushinCollector != null) {
764
factory.pushinCollector.tagAsMunged(sourceType, decp.getParents().get(0));
766
anyNewParents = true;
767
forRemoval.add(decp);
748
anyNewParents = true;
749
forRemoval.add(decp);
752
decpToRepeat.removeAll(forRemoval);
770
decpToRepeat.removeAll(forRemoval);
755
for (Iterator i = declareAnnotationOnTypes.iterator(); i.hasNext();) {
756
DeclareAnnotation deca = (DeclareAnnotation) i.next();
757
boolean didSomething = doDeclareAnnotations(deca, sourceType, false);
759
if (factory.pushinCollector != null) {
760
factory.pushinCollector.tagAsMunged(sourceType, deca.getAnnotationString());
773
for (DeclareAnnotation deca : decaToRepeat) {
774
boolean didSomething = doDeclareAnnotations(deca, sourceType, false);
776
if (factory.pushinCollector != null) {
777
factory.pushinCollector.tagAsMunged(sourceType, deca.getAnnotationString());
779
anyNewAnnotations = true;
780
forRemoval.add(deca);
762
anyNewAnnotations = true;
763
forRemoval.add(deca);
783
decaToRepeat.removeAll(forRemoval);
766
decaToRepeat.removeAll(forRemoval);
786
if (mode == 0 || mode == 2) {
787
for (Iterator<ConcreteTypeMunger> i = typeMungers.iterator(); i.hasNext();) {
788
EclipseTypeMunger munger = (EclipseTypeMunger) i.next();
789
if (munger.matches(onType)) {
790
// if (needOldStyleWarning) {
791
// factory.showMessage(IMessage.WARNING, "The class for " + onType
792
// + " should be recompiled with ajc-1.1.1 for best results", onType.getSourceLocation(), null);
793
// needOldStyleWarning = false;
795
onType.addInterTypeMunger(munger, true);
796
if (munger.getMunger() != null && munger.getMunger().getKind() == ResolvedTypeMunger.InnerClass) {
797
// Must do these right now, because if we do an ITD member afterwards it may attempt to reference the
798
// type being applied (the call above 'addInterTypeMunger' will fail for these ITDs if it needed
799
// it to be in place)
800
if (munger.munge(sourceType, onType)) {
801
if (factory.pushinCollector != null) {
802
factory.pushinCollector.tagAsMunged(sourceType, munger.getSourceMethod());
769
for (Iterator<ConcreteTypeMunger> i = typeMungers.iterator(); i.hasNext();) {
770
EclipseTypeMunger munger = (EclipseTypeMunger) i.next();
771
if (munger.matches(onType)) {
772
if (needOldStyleWarning) {
773
factory.showMessage(IMessage.WARNING, "The class for " + onType
774
+ " should be recompiled with ajc-1.1.1 for best results", onType.getSourceLocation(), null);
775
needOldStyleWarning = false;
777
onType.addInterTypeMunger(munger, true);
778
if (munger.getMunger()!=null && munger.getMunger().getKind() == ResolvedTypeMunger.InnerClass) {
779
// Must do these right now, because if we do an ITD member afterwards it may attempt to reference the
780
// type being applied (the call above 'addInterTypeMunger' will fail for these ITDs if it needed
781
// it to be in place)
809
onType.checkInterTypeMungers();
810
for (Iterator i = onType.getInterTypeMungers().iterator(); i.hasNext();) {
811
EclipseTypeMunger munger = (EclipseTypeMunger) i.next();
812
if (munger.getMunger() == null || munger.getMunger().getKind() != ResolvedTypeMunger.InnerClass) {
782
813
if (munger.munge(sourceType, onType)) {
783
814
if (factory.pushinCollector != null) {
784
815
factory.pushinCollector.tagAsMunged(sourceType, munger.getSourceMethod());
980
999
// Might have to retrieve the annotation through BCEL and construct an
981
1000
// eclipse one for it.
982
1001
if (stb instanceof BinaryTypeBinding) {
983
ReferenceType rt = (ReferenceType) factory.fromEclipse(stb);
984
ResolvedMember[] methods = rt.getDeclaredMethods();
985
ResolvedMember decaMethod = null;
986
String nameToLookFor = decA.getAnnotationMethod();
987
for (int i = 0; i < methods.length; i++) {
988
if (methods[i].getName().equals(nameToLookFor)) {
989
decaMethod = methods[i];
993
if (decaMethod != null) { // could assert this ...
994
AnnotationAJ[] axs = decaMethod.getAnnotations();
995
if (axs != null) { // another error has occurred, dont crash here because of it
996
toAdd = new Annotation[1];
997
toAdd[0] = createAnnotationFromBcelAnnotation(axs[0], decaMethod.getSourceLocation().getOffset(), factory);
998
// BUG BUG BUG - We dont test these abits are correct, in fact
999
// we'll be very lucky if they are.
1000
// What does that mean? It means on an incremental compile you
1001
// might get away with an
1002
// annotation that isn't allowed on a type being put on a type.
1003
if (toAdd[0].resolvedType != null) {
1004
abits = toAdd[0].resolvedType.getAnnotationTagBits();
1002
toAdd = retrieveAnnotationFromBinaryTypeBinding(decA, stb);
1003
if (toAdd != null && toAdd.length > 0 && toAdd[0].resolvedType != null) {
1004
abits = toAdd[0].resolvedType.getAnnotationTagBits();
1008
1006
} else if (stb != null) {
1009
1007
// much nicer, its a real SourceTypeBinding so we can stay in
1010
1008
// eclipse land
1011
1009
// if (decA.getAnnotationMethod() != null) {
1012
MethodBinding[] mbs = stb.getMethods(decA.getAnnotationMethod().toCharArray());
1013
abits = mbs[0].getAnnotationTagBits(); // ensure resolved
1014
TypeDeclaration typeDecl = ((SourceTypeBinding) mbs[0].declaringClass).scope.referenceContext;
1015
methodDecl = typeDecl.declarationOf(mbs[0]);
1016
toAdd = methodDecl.annotations; // this is what to add
1017
toAdd[0] = createAnnotationCopy(toAdd[0]);
1018
if (toAdd[0].resolvedType != null) {
1019
abits = toAdd[0].resolvedType.getAnnotationTagBits();
1010
char[] declareSelector = decA.getAnnotationMethod().toCharArray();
1012
ReferenceBinding rb = stb;
1013
String declaringAspectName = decA.getDeclaringType().getRawName();
1014
while (rb != null && !new String(CharOperation.concatWith(rb.compoundName, '.')).equals(declaringAspectName)) {
1015
rb = rb.superclass();
1017
MethodBinding[] mbs = rb.getMethods(declareSelector);
1019
ReferenceBinding declaringBinding = mbs[0].declaringClass;
1020
if (declaringBinding instanceof ParameterizedTypeBinding) {
1021
// Unwrap - this means we don't allow the type of the annotation to be parameterized, may need to revisit that
1022
declaringBinding = ((ParameterizedTypeBinding) declaringBinding).type;
1024
if (declaringBinding instanceof BinaryTypeBinding) {
1025
toAdd = retrieveAnnotationFromBinaryTypeBinding(decA, declaringBinding);
1026
if (toAdd != null && toAdd.length > 0 && toAdd[0].resolvedType != null) {
1027
abits = toAdd[0].resolvedType.getAnnotationTagBits();
1030
abits = mbs[0].getAnnotationTagBits(); // ensure resolved
1031
TypeDeclaration typeDecl = ((SourceTypeBinding) declaringBinding).scope.referenceContext;
1032
methodDecl = typeDecl.declarationOf(mbs[0]);
1033
toAdd = methodDecl.annotations; // this is what to add
1034
toAdd[0] = createAnnotationCopy(toAdd[0]);
1035
if (toAdd[0].resolvedType != null) {
1036
abits = toAdd[0].resolvedType.getAnnotationTagBits();