~ubuntu-branches/ubuntu/wily/aspectj/wily-proposed

« back to all changes in this revision

Viewing changes to org.aspectj/modules/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2011-03-15 23:54:31 UTC
  • mfrom: (1.2.5 upstream)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20110315235431-iq2gxbsx08kpwuiw
* New upstream release.
* Updated Standards-Version to 3.9.1 (no changes needed).
* Fix local Javadoc links:
  - d/patches/07_javadoc_links.diff: Use locally installed
   javadoc packages and hyperlink with them.
  - d/control: Add B-D on default-java-doc and libasm3-java-doc.
* d/control: Drop B-D on itself (our new bootstrap infrastructure doesn't need
  that anymore).
* Split packages into :
  - aspectj: only contains CLI tools.
  - libaspectj-java: JAR librairies for /usr/share/java.
  - libaspectj-java-doc: 4 API's Javadoc.
  - aspectj-doc: Programming Guides and SDK Documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
232
232
                // - weaving that brings new types in for processing (see
233
233
                // pendingTypesToWeave.add() calls) after we thought
234
234
                // we had the full list.
235
 
                // 
 
235
                //
236
236
                // but these aren't common cases (he bravely said...)
237
237
                boolean typeProcessingOrderIsImportant = declareParents.size() > 0 || declareAnnotationOnTypes.size() > 0; // DECAT
238
238
 
239
239
                if (typeProcessingOrderIsImportant) {
240
 
                        typesToProcess = new ArrayList();
 
240
                        typesToProcess = new ArrayList<SourceTypeBinding>();
241
241
                        for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
242
242
                                CompilationUnitScope cus = units[i].scope;
243
243
                                SourceTypeBinding[] stbs = cus.topLevelTypes;
247
247
                                }
248
248
                        }
249
249
 
 
250
                        List<SourceTypeBinding> stb2 = new ArrayList<SourceTypeBinding>();
 
251
                        stb2.addAll(typesToProcess);
 
252
 
250
253
                        while (typesToProcess.size() > 0) {
251
 
                                // A side effect of weaveIntertypes() is that the processed type
252
 
                                // is removed from the collection
253
 
                                weaveIntertypes(typesToProcess, typesToProcess.get(0), typeMungers, declareParents, declareAnnotationOnTypes);
 
254
                                // A side effect of weaveIntertypes() is that the processed type is removed from the collection
 
255
                                weaveIntertypes(typesToProcess, typesToProcess.get(0), typeMungers, declareParents, declareAnnotationOnTypes, 1);
 
256
                        }
 
257
 
 
258
                        while (stb2.size() > 0) {
 
259
                                // A side effect of weaveIntertypes() is that the processed type is removed from the collection
 
260
                                weaveIntertypes(stb2, stb2.get(0), typeMungers, declareParents, declareAnnotationOnTypes, 2);
254
261
                        }
255
262
 
256
263
                } else {
383
390
         * compile... it stops recursing the first time it hits a type we aren't going to process during this compile. This could cause
384
391
         * problems if you supply 'pieces' of a hierarchy, i.e. the bottom and the top, but not the middle - but what the hell are you
385
392
         * doing if you do that?
 
393
         * 
 
394
         * @param mode 0=do everything, 1=do declare parents, 2=do ITDs
386
395
         */
387
396
        private void weaveIntertypes(List<SourceTypeBinding> typesToProcess, SourceTypeBinding typeToWeave,
388
397
                        List<ConcreteTypeMunger> typeMungers, List<DeclareParents> declareParents,
389
 
                        List<DeclareAnnotation> declareAnnotationOnTypes) {
 
398
                        List<DeclareAnnotation> declareAnnotationOnTypes, int mode) {
390
399
                // Look at the supertype first
391
400
                ReferenceBinding superType = typeToWeave.superclass();
392
401
                if (typesToProcess.contains(superType) && superType instanceof SourceTypeBinding) {
393
402
                        // System.err.println("Recursing to supertype "+new
394
403
                        // String(superType.getFileName()));
395
 
                        weaveIntertypes(typesToProcess, (SourceTypeBinding) superType, typeMungers, declareParents, declareAnnotationOnTypes);
 
404
                        weaveIntertypes(typesToProcess, (SourceTypeBinding) superType, typeMungers, declareParents, declareAnnotationOnTypes,
 
405
                                        mode);
396
406
                }
397
407
                // Then look at the superinterface list
398
408
                ReferenceBinding[] interfaceTypes = typeToWeave.superInterfaces();
401
411
                        if (typesToProcess.contains(binding) && binding instanceof SourceTypeBinding) {
402
412
                                // System.err.println("Recursing to superinterface "+new
403
413
                                // String(binding.getFileName()));
404
 
                                weaveIntertypes(typesToProcess, (SourceTypeBinding) binding, typeMungers, declareParents, declareAnnotationOnTypes);
 
414
                                weaveIntertypes(typesToProcess, (SourceTypeBinding) binding, typeMungers, declareParents, declareAnnotationOnTypes,
 
415
                                                mode);
405
416
                        }
406
417
                }
407
 
                weaveInterTypeDeclarations(typeToWeave, typeMungers, declareParents, declareAnnotationOnTypes, false);
 
418
                weaveInterTypeDeclarations(typeToWeave, typeMungers, declareParents, declareAnnotationOnTypes, false, mode);
408
419
                typesToProcess.remove(typeToWeave);
409
420
        }
410
421
 
532
543
                }
533
544
 
534
545
                ReferenceBinding[] memberTypes = sourceType.memberTypes;
535
 
                for (int i = 0, length = memberTypes.length; i < length; i++) {
536
 
                        buildInterTypeAndPerClause(((SourceTypeBinding) memberTypes[i]).scope);
 
546
                if (memberTypes == null) {
 
547
                        System.err.println("Unexpectedly found null for memberTypes of " + sourceType.debugName());
 
548
                }
 
549
                if (memberTypes != null) {
 
550
                        for (int i = 0, length = memberTypes.length; i < length; i++) {
 
551
                                buildInterTypeAndPerClause(((SourceTypeBinding) memberTypes[i]).scope);
 
552
                        }
537
553
                }
538
554
        }
539
555
 
579
595
        private void weaveInterTypeDeclarations(CompilationUnitScope unit, List<ConcreteTypeMunger> typeMungers,
580
596
                        List<DeclareParents> declareParents, List<DeclareAnnotation> declareAnnotationOnTypes) {
581
597
                for (int i = 0, length = unit.topLevelTypes.length; i < length; i++) {
582
 
                        weaveInterTypeDeclarations(unit.topLevelTypes[i], typeMungers, declareParents, declareAnnotationOnTypes, false);
 
598
                        weaveInterTypeDeclarations(unit.topLevelTypes[i], typeMungers, declareParents, declareAnnotationOnTypes, false, 0);
583
599
                }
584
600
        }
585
601
 
588
604
                        if (!pendingTypesToWeave.contains(sourceType)) {
589
605
                                pendingTypesToWeave.add(sourceType);
590
606
 
591
 
// inner type ITD support - may need this for some incremental cases...
 
607
                                // inner type ITD support - may need this for some incremental cases...
592
608
                                // List<ConcreteTypeMunger> ctms = factory.getWorld().getCrosscuttingMembersSet().getTypeMungersOfKind(
593
609
                                // ResolvedTypeMunger.InnerClass);
594
610
                                // // List<ConcreteTypeMunger> innerTypeMungers = new ArrayList<ConcreteTypeMunger>();
633
649
 
634
650
                        }
635
651
                } else {
636
 
                        weaveInterTypeDeclarations(sourceType, factory.getTypeMungers(), factory.getDeclareParents(), factory
637
 
                                        .getDeclareAnnotationOnTypes(), true);
 
652
                        weaveInterTypeDeclarations(sourceType, factory.getTypeMungers(), factory.getDeclareParents(),
 
653
                                        factory.getDeclareAnnotationOnTypes(), true, 0);
638
654
                }
639
655
        }
640
656
 
 
657
        /**
 
658
         * @param mode 0=do everything, 1=do declare parents, 2=do ITDs
 
659
         */
641
660
        private void weaveInterTypeDeclarations(SourceTypeBinding sourceType, List<ConcreteTypeMunger> typeMungers,
642
 
                        List<DeclareParents> declareParents, List<DeclareAnnotation> declareAnnotationOnTypes, boolean skipInners) {
 
661
                        List<DeclareParents> declareParents, List<DeclareAnnotation> declareAnnotationOnTypes, boolean skipInners, int mode) {
643
662
 
644
663
                ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_INTERTYPE_DECLARATIONS,
645
664
                                sourceType.sourceName);
653
672
 
654
673
                WeaverStateInfo info = onType.getWeaverState();
655
674
 
656
 
                // this test isnt quite right - there will be a case where we fail to
657
 
                // flag a problem
658
 
                // with a 'dangerous interface' because the type is reweavable when we
659
 
                // should have
660
 
                // because the type wasn't going to be rewoven... if that happens, we
661
 
                // should perhaps
662
 
                // move this test and dangerous interface processing to the end of this
663
 
                // method and
664
 
                // make it conditional on whether any of the typeMungers passed into
665
 
                // here actually
666
 
                // matched this type.
667
 
                if (info != null && !info.isOldStyle() && !info.isReweavable()) {
668
 
                        processTypeMungersFromExistingWeaverState(sourceType, onType);
669
 
                        CompilationAndWeavingContext.leavingPhase(tok);
670
 
                        return;
671
 
                }
672
 
 
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);
681
 
                        }
682
 
                }
683
 
 
684
 
                boolean needOldStyleWarning = (info != null && info.isOldStyle());
685
 
 
686
 
                onType.clearInterTypeMungers();
687
 
                onType.ensureConsistent();
688
 
 
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
695
 
                // messages...
696
 
 
697
 
                List decpToRepeat = new ArrayList();
698
 
                List<DeclareAnnotation> decaToRepeat = new ArrayList<DeclareAnnotation>();
699
 
                boolean anyNewParents = false;
700
 
                boolean anyNewAnnotations = false;
701
 
 
702
 
                // first pass
703
 
                // try and apply all decps - if they match, then great. If they don't
704
 
                // then
705
 
                // check if they are starred-annotation patterns. If they are not
706
 
                // starred
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);
 
675
                if (mode < 2) {
 
676
                        // this test isnt quite right - there will be a case where we fail to
 
677
                        // flag a problem
 
678
                        // with a 'dangerous interface' because the type is reweavable when we
 
679
                        // should have
 
680
                        // because the type wasn't going to be rewoven... if that happens, we
 
681
                        // should perhaps
 
682
                        // move this test and dangerous interface processing to the end of this
 
683
                        // method and
 
684
                        // make it conditional on whether any of the typeMungers passed into
 
685
                        // here actually
 
686
                        // matched this type.
 
687
                        if (info != null && !info.isOldStyle() && !info.isReweavable()) {
 
688
                                processTypeMungersFromExistingWeaverState(sourceType, onType);
 
689
                                CompilationAndWeavingContext.leavingPhase(tok);
 
690
                                return;
 
691
                        }
 
692
 
 
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);
 
701
                                }
 
702
                        }
 
703
 
 
704
                        boolean needOldStyleWarning = (info != null && info.isOldStyle());
 
705
 
 
706
                        onType.clearInterTypeMungers();
 
707
                        onType.ensureConsistent();
 
708
 
 
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
 
715
                        // messages...
 
716
 
 
717
                        List<DeclareParents> decpToRepeat = new ArrayList<DeclareParents>();
 
718
                        List<DeclareAnnotation> decaToRepeat = new ArrayList<DeclareAnnotation>();
 
719
                        boolean anyNewParents = false;
 
720
                        boolean anyNewAnnotations = false;
 
721
 
 
722
                        // first pass
 
723
                        // try and apply all decps - if they match, then great. If they don't
 
724
                        // then
 
725
                        // check if they are starred-annotation patterns. If they are not
 
726
                        // starred
 
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);
 
731
                                        if (didSomething) {
 
732
                                                if (factory.pushinCollector != null) {
 
733
                                                        factory.pushinCollector.tagAsMunged(sourceType, decp.getParents().get(0));
 
734
                                                }
 
735
                                                anyNewParents = true;
 
736
                                        } else {
 
737
                                                if (!decp.getChild().isStarAnnotation()) {
 
738
                                                        decpToRepeat.add(decp);
 
739
                                                }
 
740
                                        }
 
741
                                }
 
742
                        }
 
743
 
 
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));
715
 
                                        }
716
 
                                        anyNewParents = true;
 
747
                                        anyNewAnnotations = true;
717
748
                                } else {
718
 
                                        if (!decp.getChild().isStarAnnotation()) {
719
 
                                                decpToRepeat.add(decp);
 
749
                                        if (!deca.getTypePattern().isStar()) {
 
750
                                                decaToRepeat.add(deca);
720
751
                                        }
721
752
                                }
722
753
                        }
723
 
                }
724
 
 
725
 
                for (Iterator<DeclareAnnotation> i = declareAnnotationOnTypes.iterator(); i.hasNext();) {
726
 
                        DeclareAnnotation deca = i.next();
727
 
                        boolean didSomething = doDeclareAnnotations(deca, sourceType, true);
728
 
                        if (didSomething) {
729
 
                                anyNewAnnotations = true;
730
 
                        } else {
731
 
                                if (!deca.getTypePattern().isStar()) {
732
 
                                        decaToRepeat.add(deca);
733
 
                                }
734
 
                        }
735
 
                }
736
 
 
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;
 
754
 
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);
744
 
                                if (didSomething) {
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;
 
759
                                forRemoval.clear();
 
760
                                for (DeclareParents decp : decpToRepeat) {
 
761
                                        boolean didSomething = doDeclareParents(decp, sourceType);
 
762
                                        if (didSomething) {
 
763
                                                if (factory.pushinCollector != null) {
 
764
                                                        factory.pushinCollector.tagAsMunged(sourceType, decp.getParents().get(0));
 
765
                                                }
 
766
                                                anyNewParents = true;
 
767
                                                forRemoval.add(decp);
747
768
                                        }
748
 
                                        anyNewParents = true;
749
 
                                        forRemoval.add(decp);
750
769
                                }
751
 
                        }
752
 
                        decpToRepeat.removeAll(forRemoval);
 
770
                                decpToRepeat.removeAll(forRemoval);
753
771
 
754
 
                        forRemoval.clear();
755
 
                        for (Iterator i = declareAnnotationOnTypes.iterator(); i.hasNext();) {
756
 
                                DeclareAnnotation deca = (DeclareAnnotation) i.next();
757
 
                                boolean didSomething = doDeclareAnnotations(deca, sourceType, false);
758
 
                                if (didSomething) {
759
 
                                        if (factory.pushinCollector != null) {
760
 
                                                factory.pushinCollector.tagAsMunged(sourceType, deca.getAnnotationString());
 
772
                                forRemoval.clear();
 
773
                                for (DeclareAnnotation deca : decaToRepeat) {
 
774
                                        boolean didSomething = doDeclareAnnotations(deca, sourceType, false);
 
775
                                        if (didSomething) {
 
776
                                                if (factory.pushinCollector != null) {
 
777
                                                        factory.pushinCollector.tagAsMunged(sourceType, deca.getAnnotationString());
 
778
                                                }
 
779
                                                anyNewAnnotations = true;
 
780
                                                forRemoval.add(deca);
761
781
                                        }
762
 
                                        anyNewAnnotations = true;
763
 
                                        forRemoval.add(deca);
764
782
                                }
 
783
                                decaToRepeat.removeAll(forRemoval);
765
784
                        }
766
 
                        decaToRepeat.removeAll(forRemoval);
767
785
                }
 
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;
 
794
                                        // }
 
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());
 
803
                                                        }
 
804
                                                }
 
805
                                        }
 
806
                                }
 
807
                        }
768
808
 
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;
776
 
                                }
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());
788
819
                        }
789
820
                }
790
821
 
791
 
                onType.checkInterTypeMungers();
792
 
                for (Iterator i = onType.getInterTypeMungers().iterator(); i.hasNext();) {
793
 
                        EclipseTypeMunger munger = (EclipseTypeMunger) i.next();
794
 
                        if (munger.getMunger()==null || munger.getMunger().getKind() != ResolvedTypeMunger.InnerClass) {
795
 
                                if (munger.munge(sourceType, onType)) {
796
 
                                        if (factory.pushinCollector != null) {
797
 
                                                factory.pushinCollector.tagAsMunged(sourceType, munger.getSourceMethod());
798
 
                                        }
799
 
                                }
800
 
                        }
801
 
                }
802
 
 
803
822
                // Call if you would like to do source weaving of declare
804
823
                // @method/@constructor
805
824
                // at source time... no need to do this as it can't impact anything, but
824
843
                for (int i = 0, length = memberTypes.length; i < length; i++) {
825
844
                        if (memberTypes[i] instanceof SourceTypeBinding) {
826
845
                                weaveInterTypeDeclarations((SourceTypeBinding) memberTypes[i], typeMungers, declareParents,
827
 
                                                declareAnnotationOnTypes, false);
 
846
                                                declareAnnotationOnTypes, false, mode);
828
847
                        }
829
848
                }
830
849
                CompilationAndWeavingContext.leavingPhase(tok);
868
887
                                                        onType.getSourceLocation(), null);
869
888
                                }
870
889
                                if (Modifier.isFinal(parent.getModifiers())) {
871
 
                                        factory.showMessage(IMessage.ERROR, "cannot extend final class " + parent.getClassName(), declareParents
872
 
                                                        .getSourceLocation(), null);
 
890
                                        factory.showMessage(IMessage.ERROR, "cannot extend final class " + parent.getClassName(),
 
891
                                                        declareParents.getSourceLocation(), null);
873
892
                                } else {
874
893
                                        // do not actually do it if the type isn't exposed - this
875
894
                                        // will correctly reported as a problem elsewhere
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];
990
 
                                        break;
991
 
                                }
992
 
                        }
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();
1005
 
                                        }
1006
 
                                }
 
1002
                        toAdd = retrieveAnnotationFromBinaryTypeBinding(decA, stb);
 
1003
                        if (toAdd != null && toAdd.length > 0 && toAdd[0].resolvedType != null) {
 
1004
                                abits = toAdd[0].resolvedType.getAnnotationTagBits();
1007
1005
                        }
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();
1020
 
                                // }
 
1010
                        char[] declareSelector = decA.getAnnotationMethod().toCharArray();
 
1011
 
 
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();
 
1016
                        }
 
1017
                        MethodBinding[] mbs = rb.getMethods(declareSelector);
 
1018
 
 
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;
 
1023
                        }
 
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();
 
1028
                                }
 
1029
                        } else {
 
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();
 
1037
                                        // }
 
1038
                                }
1021
1039
                        }
1022
1040
                }
1023
1041
 
1163
1181
                return true;
1164
1182
        }
1165
1183
 
 
1184
        private Annotation[] retrieveAnnotationFromBinaryTypeBinding(DeclareAnnotation decA, ReferenceBinding declaringBinding) {
 
1185
                ReferenceType rt = (ReferenceType) factory.fromEclipse(declaringBinding);
 
1186
                ResolvedMember[] methods = rt.getDeclaredMethods();
 
1187
                ResolvedMember decaMethod = null;
 
1188
                String nameToLookFor = decA.getAnnotationMethod();
 
1189
                for (int i = 0; i < methods.length; i++) {
 
1190
                        if (methods[i].getName().equals(nameToLookFor)) {
 
1191
                                decaMethod = methods[i];
 
1192
                                break;
 
1193
                        }
 
1194
                }
 
1195
                if (decaMethod != null) { // could assert this ...
 
1196
                        AnnotationAJ[] axs = decaMethod.getAnnotations();
 
1197
                        if (axs != null) { // another error has occurred, dont crash here because of it
 
1198
                                Annotation[] toAdd = new Annotation[1];
 
1199
                                toAdd[0] = createAnnotationFromBcelAnnotation(axs[0], decaMethod.getSourceLocation().getOffset(), factory);
 
1200
                                // BUG BUG BUG - We dont test these abits are correct, in fact
 
1201
                                // we'll be very lucky if they are.
 
1202
                                // What does that mean? It means on an incremental compile you
 
1203
                                // might get away with an
 
1204
                                // annotation that isn't allowed on a type being put on a type.
 
1205
                                // if (toAdd[0].resolvedType != null) {
 
1206
                                // abits = toAdd[0].resolvedType.getAnnotationTagBits();
 
1207
                                // }
 
1208
                                return toAdd;
 
1209
                        }
 
1210
                }
 
1211
                return null;
 
1212
        }
 
1213
 
1166
1214
        /**
1167
1215
         * Transform an annotation from its AJ form to an eclipse form. We *DONT* care about the values of the annotation. that is
1168
1216
         * because it is only being stuck on a type during type completion to allow for other constructs (decps, decas) that might be
1244
1292
                        }
1245
1293
                        filename = filename.substring(takefrom + 1);
1246
1294
 
1247
 
                        factory.getWorld().getMessageHandler().handleMessage(
1248
 
                                        WeaveMessage.constructWeavingMessage(wmk, new String[] { CharOperation.toString(sourceType.compoundName),
1249
 
                                                        filename, parent.getClassName(), getShortname(parent.getSourceLocation().getSourceFile().getPath()) }));
 
1295
                        factory.getWorld()
 
1296
                                        .getMessageHandler()
 
1297
                                        .handleMessage(
 
1298
                                                        WeaveMessage.constructWeavingMessage(wmk,
 
1299
                                                                        new String[] { CharOperation.toString(sourceType.compoundName), filename,
 
1300
                                                                                        parent.getClassName(),
 
1301
                                                                                        getShortname(parent.getSourceLocation().getSourceFile().getPath()) }));
1250
1302
                }
1251
1303
        }
1252
1304
 
1389
1441
// System.err.println("Looking for anything that might match "+element+" on "+
1390
1442
// sourceType.debugName()+"  "+getType(sourceType.
1391
1443
// compoundName).debugName()+"  "+(sourceType instanceof BinaryTypeBinding));
1392
 
//              
 
1444
//
1393
1445
// ReferenceBinding rbb = getType(sourceType.compoundName);
1394
1446
// // fix me if we ever uncomment this code... should iterate the other way
1395
1447
// round, over the methods then over the decas
1401
1453
// ((SourceTypeBinding)rbb).getExactMethod(sourceMb.selector
1402
1454
// ,sourceMb.parameters);
1403
1455
// boolean isCtor = sourceMb.selector[0]=='<';
1404
 
//                      
 
1456
//
1405
1457
// if ((element.isDeclareAtConstuctor() ^ !isCtor)) {
1406
1458
// System.err.println("Checking "+sourceMb+" ... declaringclass="+sourceMb.
1407
1459
// declaringClass.debugName()+" rbb="+rbb.debugName()+"  "+
1408
1460
// sourceMb.declaringClass.equals(rbb));
1409
 
//                      
 
1461
//
1410
1462
// ResolvedMember rm = null;
1411
1463
// rm = EclipseFactory.makeResolvedMember(mbbbb);
1412
1464
// if (element.matches(rm,factory.getWorld())) {
1413
1465
// System.err.println("MATCH");
1414
 
//                              
 
1466
//
1415
1467
// // Determine the set of annotations that are currently on the method
1416
1468
// ReferenceBinding rb = getType(sourceType.compoundName);
1417
1469
// // TypeBinding tb = factory.makeTypeBinding(decA.getAspect());
1424
1476
// AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(sourceMb);
1425
1477
// Annotation[] currentlyHas = methodDecl.annotations; // this is what to add
1426
1478
// //abits = toAdd[0].resolvedType.getAnnotationTagBits();
1427
 
//                              
 
1479
//
1428
1480
// // Determine the annotations to add to that method
1429
1481
// TypeBinding tb = factory.makeTypeBinding(element.getAspect());
1430
1482
// MethodBinding[] aspectMbs =
1438
1490
// Annotation[] toAdd = methodDecl2.annotations; // this is what to add
1439
1491
// // abits = toAdd[0].resolvedType.getAnnotationTagBits();
1440
1492
// System.err.println("Has: "+currentlyHas+"    toAdd: "+toAdd);
1441
 
//                              
 
1493
//
1442
1494
// // fix me? should check if it already has the annotation
1443
1495
// //Annotation abefore[] = sourceType.scope.referenceContext.annotations;
1444
1496
// Annotation[] newset = new
1473
1525
// System.err.println("Processing deca "+element+" on "+sourceType.debugName()+
1474
1526
// "  "+getType(sourceType.compoundName).debugName()+"  "
1475
1527
// +(sourceType instanceof BinaryTypeBinding));
1476
 
//                              
 
1528
//
1477
1529
// ReferenceBinding rbb = getType(sourceType.compoundName);
1478
1530
// // fix me? should iterate the other way round, over the methods then over the
1479
1531
// decas
1484
1536
// //FieldBinding fbbbb =
1485
1537
// ((SourceTypeBinding)rbb).getgetExactMethod(sourceMb.selector
1486
1538
// ,sourceMb.parameters);
1487
 
//                                      
 
1539
//
1488
1540
// System.err.println("Checking "+sourceFb+" ... declaringclass="+sourceFb.
1489
1541
// declaringClass.debugName()+" rbb="+rbb.debugName());
1490
 
//                                      
 
1542
//
1491
1543
// ResolvedMember rm = null;
1492
1544
// rm = EclipseFactory.makeResolvedMember(sourceFb);
1493
1545
// if (element.matches(rm,factory.getWorld())) {
1494
1546
// System.err.println("MATCH");
1495
 
//                                              
 
1547
//
1496
1548
// // Determine the set of annotations that are currently on the field
1497
1549
// ReferenceBinding rb = getType(sourceType.compoundName);
1498
1550
// // TypeBinding tb = factory.makeTypeBinding(decA.getAspect());
1504
1556
// //AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(sourceMb);
1505
1557
// Annotation[] currentlyHas = fd.annotations; // this is what to add
1506
1558
// //abits = toAdd[0].resolvedType.getAnnotationTagBits();
1507
 
//                                              
 
1559
//
1508
1560
// // Determine the annotations to add to that method
1509
1561
// TypeBinding tb = factory.makeTypeBinding(element.getAspect());
1510
1562
// MethodBinding[] aspectMbs =
1518
1570
// Annotation[] toAdd = methodDecl2.annotations; // this is what to add
1519
1571
// // abits = toAdd[0].resolvedType.getAnnotationTagBits();
1520
1572
// System.err.println("Has: "+currentlyHas+"    toAdd: "+toAdd);
1521
 
//                                              
 
1573
//
1522
1574
// // fix me? check if it already has the annotation
1523
1575
//
1524
1576
//
1535
1587
// } else
1536
1588
// System.err.println("NO MATCH");
1537
1589
// }
1538
 
//                      
 
1590
//
1539
1591
// }
1540
1592
// }