View | Details | Raw Unified | Return to bug 98901 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/aspectj/weaver/AjcMemberMaker.java (-1 / +3 lines)
Lines 603-609 Link Here
603
603
604
	/**
604
	/**
605
	 * This method goes on the target type of the inter-type method. (and possibly the topmost-implemeters,
605
	 * This method goes on the target type of the inter-type method. (and possibly the topmost-implemeters,
606
	 * if the target type is an interface) 
606
-	 * if the target type is an interface). It calls the interMethodDispatcher on the aspect.
607
	 */
607
	 */
608
	public static ResolvedMember interMethod(ResolvedMember meth, TypeX aspectType, boolean onInterface) 
608
	public static ResolvedMember interMethod(ResolvedMember meth, TypeX aspectType, boolean onInterface) 
609
	{
609
	{
Lines 621-626 Link Here
621
621
622
	/**
622
	/**
623
	 * This static method goes on the declaring aspect of the inter-type method.
623
	 * This static method goes on the declaring aspect of the inter-type method.
624
	 * It calls the interMethodBody.
624
	 */
625
	 */
625
	public static ResolvedMember interMethodDispatcher(ResolvedMember meth, TypeX aspectType) 
626
	public static ResolvedMember interMethodDispatcher(ResolvedMember meth, TypeX aspectType) 
626
	{
627
	{
Lines 637-642 Link Here
637
638
638
	/**
639
	/**
639
	 * This static method goes on the declaring aspect of the inter-type method.
640
	 * This static method goes on the declaring aspect of the inter-type method.
641
	 * It contains the body of the ITD method.
640
	 */
642
	 */
641
	public static ResolvedMember interMethodBody(ResolvedMember meth, TypeX aspectType) 
643
	public static ResolvedMember interMethodBody(ResolvedMember meth, TypeX aspectType) 
642
	{
644
	{
(-)src/org/aspectj/weaver/NewConstructorTypeMunger.java (-2 / +1 lines)
Lines 38-45 Link Here
38
38
39
	}
39
	}
40
	
40
	
41
	//XXX horrible name clash here
41
	public ResolvedMember getInterMethodBody(TypeX aspectType) {
42
	public ResolvedMember getDispatchMethod(TypeX aspectType) {
43
		return AjcMemberMaker.interMethodBody(signature, aspectType);
42
		return AjcMemberMaker.interMethodBody(signature, aspectType);
44
	}
43
	}
45
44
(-)src/org/aspectj/weaver/NewMethodTypeMunger.java (-2 / +5 lines)
Lines 28-37 Link Here
28
28
29
	}
29
	}
30
	
30
	
31
	//XXX horrible name clash here
31
	public ResolvedMember getInterMethodBody(TypeX aspectType) {
32
	public ResolvedMember getDispatchMethod(TypeX aspectType) {
33
		return AjcMemberMaker.interMethodBody(signature, aspectType);
32
		return AjcMemberMaker.interMethodBody(signature, aspectType);
34
	}
33
	}
34
	
35
	public ResolvedMember getInterMethodDispatcher(TypeX aspectType) {
36
		return AjcMemberMaker.interMethodDispatcher(signature, aspectType);
37
	}
35
38
36
	public void write(DataOutputStream s) throws IOException {
39
	public void write(DataOutputStream s) throws IOException {
37
		kind.write(s);
40
		kind.write(s);
(-)src/org/aspectj/weaver/bcel/BcelClassWeaver.java (-57 / +149 lines)
Lines 27-35 Link Here
27
27
28
import org.aspectj.apache.bcel.Constants;
28
import org.aspectj.apache.bcel.Constants;
29
import org.aspectj.apache.bcel.classfile.Field;
29
import org.aspectj.apache.bcel.classfile.Field;
30
import org.aspectj.apache.bcel.classfile.annotation.Annotation;
30
import org.aspectj.apache.bcel.generic.BranchInstruction;
31
import org.aspectj.apache.bcel.generic.BranchInstruction;
31
import org.aspectj.apache.bcel.generic.CPInstruction;
32
import org.aspectj.apache.bcel.generic.CPInstruction;
32
import org.aspectj.apache.bcel.generic.ConstantPoolGen;
33
import org.aspectj.apache.bcel.generic.ConstantPoolGen;
34
import org.aspectj.apache.bcel.generic.FieldGen;
33
import org.aspectj.apache.bcel.generic.FieldInstruction;
35
import org.aspectj.apache.bcel.generic.FieldInstruction;
34
import org.aspectj.apache.bcel.generic.INVOKESPECIAL;
36
import org.aspectj.apache.bcel.generic.INVOKESPECIAL;
35
import org.aspectj.apache.bcel.generic.IndexedInstruction;
37
import org.aspectj.apache.bcel.generic.IndexedInstruction;
Lines 49-54 Link Here
49
import org.aspectj.apache.bcel.generic.ReturnInstruction;
51
import org.aspectj.apache.bcel.generic.ReturnInstruction;
50
import org.aspectj.apache.bcel.generic.Select;
52
import org.aspectj.apache.bcel.generic.Select;
51
import org.aspectj.apache.bcel.generic.Type;
53
import org.aspectj.apache.bcel.generic.Type;
54
import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
52
import org.aspectj.bridge.IMessage;
55
import org.aspectj.bridge.IMessage;
53
import org.aspectj.bridge.ISourceLocation;
56
import org.aspectj.bridge.ISourceLocation;
54
import org.aspectj.bridge.WeaveMessage;
57
import org.aspectj.bridge.WeaveMessage;
Lines 78-83 Link Here
78
import org.aspectj.weaver.Shadow.Kind;
81
import org.aspectj.weaver.Shadow.Kind;
79
import org.aspectj.weaver.patterns.DeclareAnnotation;
82
import org.aspectj.weaver.patterns.DeclareAnnotation;
80
import org.aspectj.weaver.patterns.FastMatchInfo;
83
import org.aspectj.weaver.patterns.FastMatchInfo;
84
import org.aspectj.apache.bcel.classfile.Method;
85
import org.aspectj.apache.bcel.generic.MethodGen;
81
86
82
class BcelClassWeaver implements IClassWeaver {
87
class BcelClassWeaver implements IClassWeaver {
83
    
88
    
Lines 465-513 Link Here
465
          for (int memberCounter = 0;memberCounter<members.size();memberCounter++) {
470
          for (int memberCounter = 0;memberCounter<members.size();memberCounter++) {
466
            LazyMethodGen mg = (LazyMethodGen)members.get(memberCounter);
471
            LazyMethodGen mg = (LazyMethodGen)members.get(memberCounter);
467
            if (!mg.getName().startsWith(NameMangler.PREFIX)) {
472
            if (!mg.getName().startsWith(NameMangler.PREFIX)) {
468
473
            	
469
            // Single first pass
474
            	// Single first pass
470
            List worthRetrying = new ArrayList();
475
            	List worthRetrying = new ArrayList();
471
            boolean modificationOccured = false;
476
            	boolean modificationOccured = false;
472
            
477
            	
473
            for (Iterator iter = decaMs.iterator(); iter.hasNext();) {
478
            	for (Iterator iter = decaMs.iterator(); iter.hasNext();) {
474
				DeclareAnnotation decaM = (DeclareAnnotation) iter.next();
479
            		DeclareAnnotation decaM = (DeclareAnnotation) iter.next();
475
				
480
            		
476
				if (decaM.matches(mg.getMemberView(),world)) {
481
            		if (decaM.matches(mg.getMemberView(),world)) {
477
	  				if (doesAlreadyHaveAnnotation(mg.getMemberView(),decaM,reportedProblems)) continue; // skip this one...
482
            			if (doesAlreadyHaveAnnotation(mg.getMemberView(),decaM,reportedProblems)) continue; // skip this one...
478
					mg.addAnnotation(decaM.getAnnotationX());
483
            			
479
					AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaM.getSourceLocation(),clazz.getName(),mg.getMethod());
484
            			Annotation a = decaM.getAnnotationX().getBcelAnnotation();
480
                    
485
            			AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPoolGen(),true);
481
					reportMethodCtorWeavingMessage(clazz, mg, decaM);
486
            			Method oldMethod = mg.getMethod();
482
					isChanged = true;
487
            			MethodGen myGen = new MethodGen(oldMethod,clazz.getClassName(),clazz.getConstantPoolGen());
483
					modificationOccured = true;
488
            			myGen.addAnnotation(ag);
484
				} else {
489
            			Method newMethod = myGen.getMethod();
485
					if (!decaM.isStarredAnnotationPattern()) 
490
            			mg.addAnnotation(decaM.getAnnotationX());
486
						worthRetrying.add(decaM); // an annotation is specified that might be put on by a subsequent decaf
491
            			members.set(memberCounter,new LazyMethodGen(newMethod,clazz));
487
				}
492
            			
488
			}
493
            			AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaM.getSourceLocation(),clazz.getName(),mg.getMethod());
489
			
494
            			
490
            // Multiple secondary passes
495
            			reportMethodCtorWeavingMessage(clazz, mg, decaM);
491
            while (!worthRetrying.isEmpty() && modificationOccured) {
496
            			isChanged = true;
492
              modificationOccured = false;
497
            			modificationOccured = true;
493
              // lets have another go
498
            		} else {
494
              List forRemoval = new ArrayList();
499
            			if (!decaM.isStarredAnnotationPattern()) 
495
              for (Iterator iter = worthRetrying.iterator(); iter.hasNext();) {
500
            				worthRetrying.add(decaM); // an annotation is specified that might be put on by a subsequent decaf
496
				DeclareAnnotation decaM = (DeclareAnnotation) iter.next();
501
            		}
497
				if (decaM.matches(mg.getMemberView(),world)) {
502
            	}
498
					if (doesAlreadyHaveAnnotation(mg.getMemberView(),decaM,reportedProblems)) continue; // skip this one...
503
            	
499
					mg.addAnnotation(decaM.getAnnotationX());
504
            	// Multiple secondary passes
500
					AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaM.getSourceLocation(),clazz.getName(),mg.getMethod());
505
            	while (!worthRetrying.isEmpty() && modificationOccured) {
501
					isChanged = true;
506
            		modificationOccured = false;
502
					modificationOccured = true;
507
            		// lets have another go
503
					forRemoval.add(decaM);
508
            		List forRemoval = new ArrayList();
504
				}
509
            		for (Iterator iter = worthRetrying.iterator(); iter.hasNext();) {
505
			  }
510
            			DeclareAnnotation decaM = (DeclareAnnotation) iter.next();
506
			  worthRetrying.removeAll(forRemoval);
511
            			if (decaM.matches(mg.getMemberView(),world)) {
507
            }
512
            				if (doesAlreadyHaveAnnotation(mg.getMemberView(),decaM,reportedProblems)) continue; // skip this one...
513
            				mg.addAnnotation(decaM.getAnnotationX());
514
            				AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaM.getSourceLocation(),clazz.getName(),mg.getMethod());
515
            				isChanged = true;
516
            				modificationOccured = true;
517
            				forRemoval.add(decaM);
518
            			}
519
            		}
520
            		worthRetrying.removeAll(forRemoval);
521
            	}
508
            }
522
            }
509
          }
523
          }
510
        }
524
		}
511
		return isChanged;
525
		return isChanged;
512
    }
526
    }
513
527
Lines 581-588 Link Here
581
		Collection c = clazz.getBcelObjectType().getTypeMungers();
595
		Collection c = clazz.getBcelObjectType().getTypeMungers();
582
		for (Iterator iter = c.iterator();iter.hasNext();) {
596
		for (Iterator iter = c.iterator();iter.hasNext();) {
583
			BcelTypeMunger typeMunger = (BcelTypeMunger)iter.next();
597
			BcelTypeMunger typeMunger = (BcelTypeMunger)iter.next();
584
			if (typeMunger.getMunger().getKind()==wantedKind) 
598
			if (typeMunger.getMunger().getKind()==wantedKind) {
585
				subset.add(typeMunger);
599
				subset.add(typeMunger);
600
			}
586
		}
601
		}
587
		return subset;
602
		return subset;
588
	}
603
	}
Lines 601-614 Link Here
601
	// FIXME asc refactor this to neaten it up
616
	// FIXME asc refactor this to neaten it up
602
	public LazyMethodGen locateAnnotationHolderForMethodCtorMunger(LazyClassGen clazz,BcelTypeMunger methodCtorMunger) {
617
	public LazyMethodGen locateAnnotationHolderForMethodCtorMunger(LazyClassGen clazz,BcelTypeMunger methodCtorMunger) {
603
		if (methodCtorMunger.getMunger() instanceof NewMethodTypeMunger) {
618
		if (methodCtorMunger.getMunger() instanceof NewMethodTypeMunger) {
604
		NewMethodTypeMunger nftm = (NewMethodTypeMunger)methodCtorMunger.getMunger();
619
			NewMethodTypeMunger nftm = (NewMethodTypeMunger)methodCtorMunger.getMunger();
605
		ResolvedMember lookingFor =AjcMemberMaker.interMethodBody(nftm.getSignature(),methodCtorMunger.getAspectType());
620
			
606
		List meths = clazz.getMethodGens();
621
			ResolvedMember lookingFor =AjcMemberMaker.interMethodDispatcher(nftm.getSignature(),methodCtorMunger.getAspectType());
607
		for (Iterator iter = meths.iterator(); iter.hasNext();) {
622
			
608
			LazyMethodGen element = (LazyMethodGen) iter.next();
623
			List meths = clazz.getMethodGens();
609
			if (element.getName().equals(lookingFor.getName()) && element.getParameterSignature().equals(lookingFor.getParameterSignature())) return element;
624
			for (Iterator iter = meths.iterator(); iter.hasNext();) {
625
				LazyMethodGen element = (LazyMethodGen) iter.next();
626
				if (element.getName().equals(lookingFor.getName()) && element.getParameterSignature().equals(lookingFor.getParameterSignature())) return element;
627
			}
628
			return null;
629
		} else if (methodCtorMunger.getMunger() instanceof NewConstructorTypeMunger) {
630
			NewConstructorTypeMunger nftm = (NewConstructorTypeMunger)methodCtorMunger.getMunger();
631
			ResolvedMember lookingFor =AjcMemberMaker.postIntroducedConstructor(methodCtorMunger.getAspectType(),nftm.getSignature().getDeclaringType(),nftm.getSignature().getParameterTypes());
632
			List meths = clazz.getMethodGens();
633
			for (Iterator iter = meths.iterator(); iter.hasNext();) {
634
				LazyMethodGen element = (LazyMethodGen) iter.next();
635
				if (element.getName().equals(lookingFor.getName()) && element.getParameterSignature().equals(lookingFor.getParameterSignature())) return element;
636
			}
637
			return null;
638
		} else {
639
			throw new RuntimeException("Not sure what this is: "+methodCtorMunger);
610
		}
640
		}
611
		return null;
641
	}
642
	
643
	public LazyMethodGen locateOldAnnotationHolderForMethodCtorMunger(LazyClassGen clazz,BcelTypeMunger methodCtorMunger) {
644
        // ajh02: stupid method added.
645
		// this method is only needed because it's still looking on the old annotation holder
646
		// (the interMethodBody) when doing pointcut matching for annotated methods.
647
		if (methodCtorMunger.getMunger() instanceof NewMethodTypeMunger) {
648
			NewMethodTypeMunger nftm = (NewMethodTypeMunger)methodCtorMunger.getMunger();
649
			
650
			ResolvedMember lookingFor =AjcMemberMaker.interMethodBody(nftm.getSignature(),methodCtorMunger.getAspectType());
651
			
652
			List meths = clazz.getMethodGens();
653
			for (Iterator iter = meths.iterator(); iter.hasNext();) {
654
				LazyMethodGen element = (LazyMethodGen) iter.next();
655
				if (element.getName().equals(lookingFor.getName()) && element.getParameterSignature().equals(lookingFor.getParameterSignature())) return element;
656
			}
657
			return null;
612
		} else if (methodCtorMunger.getMunger() instanceof NewConstructorTypeMunger) {
658
		} else if (methodCtorMunger.getMunger() instanceof NewConstructorTypeMunger) {
613
			NewConstructorTypeMunger nftm = (NewConstructorTypeMunger)methodCtorMunger.getMunger();
659
			NewConstructorTypeMunger nftm = (NewConstructorTypeMunger)methodCtorMunger.getMunger();
614
			ResolvedMember lookingFor =AjcMemberMaker.postIntroducedConstructor(methodCtorMunger.getAspectType(),nftm.getSignature().getDeclaringType(),nftm.getSignature().getParameterTypes());
660
			ResolvedMember lookingFor =AjcMemberMaker.postIntroducedConstructor(methodCtorMunger.getAspectType(),nftm.getSignature().getDeclaringType(),nftm.getSignature().getParameterTypes());
Lines 694-702 Link Here
694
				
740
				
695
				if (decaMC.matches(itdIsActually,world)) {
741
				if (decaMC.matches(itdIsActually,world)) {
696
					LazyMethodGen annotationHolder = locateAnnotationHolderForMethodCtorMunger(clazz,methodctorMunger);
742
					LazyMethodGen annotationHolder = locateAnnotationHolderForMethodCtorMunger(clazz,methodctorMunger);
697
					if (doesAlreadyHaveAnnotation(annotationHolder,itdIsActually,decaMC,reportedErrors)) continue; // skip this one...
743
					if (annotationHolder == null || doesAlreadyHaveAnnotation(annotationHolder,itdIsActually,decaMC,reportedErrors)) continue; // skip this one...
744
						
698
					annotationHolder.addAnnotation(decaMC.getAnnotationX());
745
					annotationHolder.addAnnotation(decaMC.getAnnotationX());
699
					itdIsActually.addAnnotation(decaMC.getAnnotationX());
746
					
747
					// ajh02: this is kind of stupid. Because we still need the annotations on the
748
					// interMethodBody for pointcut matching to work we have to put them there as
749
					// well as on the interMethodDispatch. Really the code should be changed so
750
					// that the pointcut matching code looks at the intermethod dispatch
751
					// rather than the intermethodbody
752
					LazyMethodGen oldAnnotationHolder = locateOldAnnotationHolderForMethodCtorMunger(clazz,methodctorMunger);
753
					if (oldAnnotationHolder != null && !oldAnnotationHolder.hasAnnotation(decaMC.getAnnotationTypeX())){
754
						oldAnnotationHolder.addAnnotation(decaMC.getAnnotationX());
755
					}
756
					
700
					isChanged=true;
757
					isChanged=true;
701
					AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaMC.getSourceLocation(),itdIsActually.getSourceLocation());
758
					AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaMC.getSourceLocation(),itdIsActually.getSourceLocation());
702
					modificationOccured = true;					
759
					modificationOccured = true;					
Lines 728-733 Link Here
728
	      return isChanged;
785
	      return isChanged;
729
	}
786
	}
730
	
787
	
788
	private boolean dontAddTwice(DeclareAnnotation decaF, Annotation [] dontAddMeTwice){
789
		for (int i = 0; i < dontAddMeTwice.length; i++){
790
			Annotation ann = dontAddMeTwice[i];
791
			if (ann != null && decaF.getAnnotationX().getTypeName().equals(ann.getTypeName())){
792
				dontAddMeTwice[i] = null; // incase it really has been added twice!
793
				return true;
794
			}
795
		}
796
		return false;
797
	}
731
	
798
	
732
	/**
799
	/**
733
	 * Weave any declare @field statements into the fields of the supplied class
800
	 * Weave any declare @field statements into the fields of the supplied class
Lines 753-759 Link Here
753
		List allDecafs = world.getDeclareAnnotationOnFields();
820
		List allDecafs = world.getDeclareAnnotationOnFields();
754
		if (allDecafs.isEmpty()) return false; // nothing to do
821
		if (allDecafs.isEmpty()) return false; // nothing to do
755
		
822
		
756
		
757
		boolean isChanged = false;
823
		boolean isChanged = false;
758
		List itdFields = getITDSubset(clazz,ResolvedTypeMunger.Field);
824
		List itdFields = getITDSubset(clazz,ResolvedTypeMunger.Field);
759
		if (itdFields!=null) {
825
		if (itdFields!=null) {
Lines 771-786 Link Here
771
            // Single first pass
837
            // Single first pass
772
            List worthRetrying = new ArrayList();
838
            List worthRetrying = new ArrayList();
773
            boolean modificationOccured = false;
839
            boolean modificationOccured = false;
840
            
841
            Annotation [] dontAddMeTwice = fields[fieldCounter].getAnnotations();
842
            
774
            // go through all the declare @field statements
843
            // go through all the declare @field statements
775
            for (Iterator iter = decaFs.iterator(); iter.hasNext();) {
844
            for (Iterator iter = decaFs.iterator(); iter.hasNext();) {
776
				DeclareAnnotation decaF = (DeclareAnnotation) iter.next();
845
				DeclareAnnotation decaF = (DeclareAnnotation) iter.next();
777
				if (decaF.matches(aBcelField,world)) {
846
				if (decaF.matches(aBcelField,world)) {
778
					if (doesAlreadyHaveAnnotation(aBcelField,decaF,reportedProblems)) continue; // skip this one...
847
					
779
					aBcelField.addAnnotation(decaF.getAnnotationX());
848
					if (!dontAddTwice(decaF,dontAddMeTwice)){
849
						if (doesAlreadyHaveAnnotation(aBcelField,decaF,reportedProblems)){
850
							continue;
851
						}
852
						if(decaF.getAnnotationTypeX().isAnnotationWithRuntimeRetention(world)){						
853
							// it should be runtime visible, so put it on the Field
854
							Annotation a = decaF.getAnnotationX().getBcelAnnotation();
855
							AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPoolGen(),true);
856
							FieldGen myGen = new FieldGen(fields[fieldCounter],clazz.getConstantPoolGen());
857
							myGen.addAnnotation(ag);
858
							Field newField = myGen.getField();
859
							
860
							aBcelField.addAnnotation(decaF.getAnnotationX());
861
							clazz.replaceField(fields[fieldCounter],newField);
862
							fields[fieldCounter]=newField;
863
							
864
						} else{
865
							aBcelField.addAnnotation(decaF.getAnnotationX());
866
						}
867
					}
868
					
780
					AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),clazz.getName(),fields[fieldCounter]);
869
					AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),clazz.getName(),fields[fieldCounter]);
781
					reportFieldAnnotationWeavingMessage(clazz, fields, fieldCounter, decaF);		
870
					reportFieldAnnotationWeavingMessage(clazz, fields, fieldCounter, decaF);		
782
					isChanged = true;
871
					isChanged = true;
783
					modificationOccured = true;
872
					modificationOccured = true;
873
					
784
				} else {
874
				} else {
785
					if (!decaF.isStarredAnnotationPattern()) 
875
					if (!decaF.isStarredAnnotationPattern()) 
786
						worthRetrying.add(decaF); // an annotation is specified that might be put on by a subsequent decaf
876
						worthRetrying.add(decaF); // an annotation is specified that might be put on by a subsequent decaf
Lines 795-800 Link Here
795
              for (Iterator iter = worthRetrying.iterator(); iter.hasNext();) {
885
              for (Iterator iter = worthRetrying.iterator(); iter.hasNext();) {
796
				DeclareAnnotation decaF = (DeclareAnnotation) iter.next();
886
				DeclareAnnotation decaF = (DeclareAnnotation) iter.next();
797
				if (decaF.matches(aBcelField,world)) {
887
				if (decaF.matches(aBcelField,world)) {
888
					// below code is for recursive things
798
					if (doesAlreadyHaveAnnotation(aBcelField,decaF,reportedProblems)) continue; // skip this one...
889
					if (doesAlreadyHaveAnnotation(aBcelField,decaF,reportedProblems)) continue; // skip this one...
799
					aBcelField.addAnnotation(decaF.getAnnotationX());
890
					aBcelField.addAnnotation(decaF.getAnnotationX());
800
					AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),clazz.getName(),fields[fieldCounter]);
891
					AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),clazz.getName(),fields[fieldCounter]);
Lines 848-854 Link Here
848
	}
939
	}
849
	
940
	
850
	private boolean doesAlreadyHaveAnnotation(LazyMethodGen rm,ResolvedMember itdfieldsig,DeclareAnnotation deca,List reportedProblems) {
941
	private boolean doesAlreadyHaveAnnotation(LazyMethodGen rm,ResolvedMember itdfieldsig,DeclareAnnotation deca,List reportedProblems) {
851
		  if (rm.hasAnnotation(deca.getAnnotationTypeX())) {
942
		  if (rm != null && rm.hasAnnotation(deca.getAnnotationTypeX())) {
852
			  if (world.getLint().elementAlreadyAnnotated.isEnabled()) {
943
			  if (world.getLint().elementAlreadyAnnotated.isEnabled()) {
853
				  Integer uniqueID = new Integer(rm.hashCode()*deca.hashCode());
944
				  Integer uniqueID = new Integer(rm.hashCode()*deca.hashCode());
854
				  if (!reportedProblems.contains(uniqueID)) {
945
				  if (!reportedProblems.contains(uniqueID)) {
Lines 1263-1268 Link Here
1263
	// ----
1354
	// ----
1264
	
1355
	
1265
	private boolean match(LazyMethodGen mg) {
1356
	private boolean match(LazyMethodGen mg) {
1357
		
1266
		BcelShadow enclosingShadow;
1358
		BcelShadow enclosingShadow;
1267
1359
1268
		List shadowAccumulator = new ArrayList();
1360
		List shadowAccumulator = new ArrayList();
Lines 1287-1293 Link Here
1287
				  // Annotations for things with effective signatures are never stored in the effective 
1379
				  // Annotations for things with effective signatures are never stored in the effective 
1288
				  // signature itself -  we have to hunt for them.  Storing them in the effective signature
1380
				  // signature itself -  we have to hunt for them.  Storing them in the effective signature
1289
				  // would mean keeping two sets up to date (no way!!)
1381
				  // would mean keeping two sets up to date (no way!!)
1290
				  
1382
                  
1291
				  fixAnnotationsForResolvedMember(rm,mg.getMemberView());
1383
				  fixAnnotationsForResolvedMember(rm,mg.getMemberView());
1292
				  				  
1384
				  				  
1293
				  enclosingShadow =
1385
				  enclosingShadow =
Lines 1594-1600 Link Here
1594
					ResolvedMember resolvedDooberry = world.resolve(declaredSig);
1686
					ResolvedMember resolvedDooberry = world.resolve(declaredSig);
1595
					annotations = resolvedDooberry.getAnnotationTypes();
1687
					annotations = resolvedDooberry.getAnnotationTypes();
1596
				} else {
1688
				} else {
1597
					ResolvedMember realthing = AjcMemberMaker.interMethodBody(rm,memberHostType);
1689
					ResolvedMember realthing = AjcMemberMaker.interMethodDispatcher(rm,memberHostType); // 
1598
					ResolvedMember resolvedDooberry = world.resolve(realthing);
1690
					ResolvedMember resolvedDooberry = world.resolve(realthing);
1599
					annotations = resolvedDooberry.getAnnotationTypes();
1691
					annotations = resolvedDooberry.getAnnotationTypes();
1600
				}
1692
				}
(-)src/org/aspectj/weaver/bcel/BcelTypeMunger.java (-27 / +69 lines)
Lines 55-63 Link Here
55
import org.aspectj.weaver.TypeX;
55
import org.aspectj.weaver.TypeX;
56
import org.aspectj.weaver.WeaverMessages;
56
import org.aspectj.weaver.WeaverMessages;
57
import org.aspectj.weaver.WeaverStateInfo;
57
import org.aspectj.weaver.WeaverStateInfo;
58
import org.aspectj.weaver.patterns.DeclareAnnotation;
58
import org.aspectj.weaver.patterns.Pointcut;
59
import org.aspectj.weaver.patterns.Pointcut;
59
60
60
61
//XXX addLazyMethodGen is probably bad everywhere
61
//XXX addLazyMethodGen is probably bad everywhere
62
public class BcelTypeMunger extends ConcreteTypeMunger {
62
public class BcelTypeMunger extends ConcreteTypeMunger {
63
63
Lines 707-714 Link Here
707
	
707
	
708
	private boolean mungeNewMethod(BcelClassWeaver weaver, NewMethodTypeMunger munger) {
708
	private boolean mungeNewMethod(BcelClassWeaver weaver, NewMethodTypeMunger munger) {
709
		ResolvedMember signature = munger.getSignature();
709
		ResolvedMember signature = munger.getSignature();
710
		ResolvedMember dispatchMethod = munger.getDispatchMethod(aspectType);
710
		ResolvedMember interMethodBody = munger.getInterMethodBody(aspectType);
711
711
		ResolvedMember interMethodDispatcher = munger.getInterMethodDispatcher(aspectType);
712
		
712
		LazyClassGen gen = weaver.getLazyClassGen();
713
		LazyClassGen gen = weaver.getLazyClassGen();
713
		
714
		
714
		ResolvedTypeX onType = weaver.getWorld().resolve(signature.getDeclaringType(),munger.getSourceLocation());
715
		ResolvedTypeX onType = weaver.getWorld().resolve(signature.getDeclaringType(),munger.getSourceLocation());
Lines 725-756 Link Here
725
		}
726
		}
726
		
727
		
727
		if (onType.equals(gen.getType())) {
728
		if (onType.equals(gen.getType())) {
728
			ResolvedMember introMethod = 
729
			ResolvedMember interMethod = 
729
					AjcMemberMaker.interMethod(signature, aspectType, onInterface);
730
					AjcMemberMaker.interMethod(signature, aspectType, onInterface);
730
            
731
            
731
			AnnotationX annotationsOnRealMember[] = null;
732
			
733
			LazyMethodGen mg = makeMethodGen(gen, interMethod);
734
			
732
			// pr98901
735
			// pr98901
733
		    // For copying the annotations across, we have to discover the real member in the aspect
736
		    // For copying the annotations across, we have to discover the real member in the aspect
734
		    // which is holding them.
737
		    // which is holding them.
735
			if (weaver.getWorld().behaveInJava5Way && !onInterface && munger.getSignature().isPublic() && !munger.getSignature().isAbstract()) {
738
			if (weaver.getWorld().behaveInJava5Way){
736
				ResolvedMember realMember = getRealMemberForITDFromAspect(aspectType,dispatchMethod);
739
				if (munger.getSignature().isPublic()){
737
				if (realMember==null) throw new BCException("Couldn't find ITD holder member '"+
740
					AnnotationX annotationsOnRealMember[] = null;
738
						                                    dispatchMethod+"' on aspect "+aspectType);
741
					ResolvedMember realMember = getRealMemberForITDFromAspect(aspectType,interMethodDispatcher);
739
				annotationsOnRealMember = realMember.getAnnotations();
742
					if (realMember==null) throw new BCException("Couldn't find ITD holder member '"+
740
			}
743
							interMethodDispatcher+"' on aspect "+aspectType);
741
744
					annotationsOnRealMember = realMember.getAnnotations();
742
			LazyMethodGen mg = makeMethodGen(gen, introMethod);
745
					System.err.println("anns on " + realMember + ":");
743
			
746
					if (annotationsOnRealMember.length > 0)
744
			if (annotationsOnRealMember!=null) {
747
						System.err.println(annotationsOnRealMember[0].getTypeName());
745
				for (int i = 0; i < annotationsOnRealMember.length; i++) {
748
					if (annotationsOnRealMember!=null) {
746
					AnnotationX annotationX = annotationsOnRealMember[i];
749
						for (int i = 0; i < annotationsOnRealMember.length; i++) {
747
					Annotation a = annotationX.getBcelAnnotation();
750
							AnnotationX annotationX = annotationsOnRealMember[i];
748
					AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true);
751
							Annotation a = annotationX.getBcelAnnotation();
749
					mg.addAnnotation(new AnnotationX(ag.getAnnotation(),weaver.getWorld()));
752
							AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true);
753
							mg.addAnnotation(new AnnotationX(ag.getAnnotation(),weaver.getWorld()));
754
						}
755
					}
756
				}
757
				// the below loop fixes the very special (and very stupid)
758
				// case where an aspect declares an annotation
759
				// on an ITD it declared on itself.
760
				List allDecams = weaver.getWorld().getDeclareAnnotationOnMethods();
761
				for (Iterator i = allDecams.iterator(); i.hasNext();){
762
					DeclareAnnotation decaMC = (DeclareAnnotation) i.next();	
763
					if (decaMC.matches(interMethod,weaver.getWorld())
764
						 && mg.getEnclosingClass().getType() == aspectType) {
765
						mg.addAnnotation(decaMC.getAnnotationX());
766
					}
750
				}
767
				}
751
			}
768
			}
752
769
753
			if (!onInterface && !Modifier.isAbstract(introMethod.getModifiers())) {
770
			if (!onInterface && !Modifier.isAbstract(interMethod.getModifiers())) {
754
				InstructionList body = mg.getBody();
771
				InstructionList body = mg.getBody();
755
				InstructionFactory fact = gen.getFactory();
772
				InstructionFactory fact = gen.getFactory();
756
				int pos = 0;
773
				int pos = 0;
Lines 759-780 Link Here
759
					body.append(InstructionFactory.createThis());
776
					body.append(InstructionFactory.createThis());
760
					pos++;
777
					pos++;
761
				}
778
				}
762
				Type[] paramTypes = BcelWorld.makeBcelTypes(introMethod.getParameterTypes());
779
				Type[] paramTypes = BcelWorld.makeBcelTypes(interMethod.getParameterTypes());
763
				for (int i = 0, len = paramTypes.length; i < len; i++) {
780
				for (int i = 0, len = paramTypes.length; i < len; i++) {
764
					Type paramType = paramTypes[i];
781
					Type paramType = paramTypes[i];
765
					body.append(InstructionFactory.createLoad(paramType, pos));
782
					body.append(InstructionFactory.createLoad(paramType, pos));
766
					pos+=paramType.getSize();
783
					pos+=paramType.getSize();
767
				}
784
				}
768
				body.append(Utility.createInvoke(fact, weaver.getWorld(), dispatchMethod));
785
				body.append(Utility.createInvoke(fact, weaver.getWorld(), interMethodBody));
769
				body.append(
786
				body.append(
770
					InstructionFactory.createReturn(
787
					InstructionFactory.createReturn(
771
						BcelWorld.makeBcelType(introMethod.getReturnType())));
788
						BcelWorld.makeBcelType(interMethod.getReturnType())));
772
			} else {
789
			} else {
773
				//??? this is okay
790
				//??? this is okay
774
				//if (!(mg.getBody() == null)) throw new RuntimeException("bas");
791
				//if (!(mg.getBody() == null)) throw new RuntimeException("bas");
775
			}
792
			}
776
			
793
			
777
778
			// XXX make sure to check that we set exceptions properly on this guy.
794
			// XXX make sure to check that we set exceptions properly on this guy.
779
			weaver.addLazyMethodGen(mg);
795
			weaver.addLazyMethodGen(mg);
780
			weaver.getLazyClassGen().warnOnAddedMethod(mg.getMethod(),getSignature().getSourceLocation());
796
			weaver.getLazyClassGen().warnOnAddedMethod(mg.getMethod(),getSignature().getSourceLocation());
Lines 824-830 Link Here
824
				body.append(InstructionFactory.createLoad(paramType, pos));
840
				body.append(InstructionFactory.createLoad(paramType, pos));
825
				pos+=paramType.getSize();
841
				pos+=paramType.getSize();
826
			  }
842
			  }
827
			  body.append(Utility.createInvoke(fact, weaver.getWorld(), dispatchMethod));
843
			  body.append(Utility.createInvoke(fact, weaver.getWorld(), interMethodBody));
828
			  body.append(InstructionFactory.createReturn(returnType));
844
			  body.append(InstructionFactory.createReturn(returnType));
829
			  mg.definingType = onType;
845
			  mg.definingType = onType;
830
			
846
			
Lines 1055-1060 Link Here
1055
			return false;
1071
			return false;
1056
		}
1072
		}
1057
		
1073
		
1074
		
1075
		ResolvedMember interMethodBody = munger.getInitMethod(aspectType);
1076
		
1077
		AnnotationX annotationsOnRealMember[] = null;
1078
		// pr98901
1079
	    // For copying the annotations across, we have to discover the real member in the aspect
1080
	    // which is holding them.
1081
		if (weaver.getWorld().behaveInJava5Way && munger.getSignature().isPublic()){
1082
				// the below line just gets the method with the same name in aspectType.getDeclaredMethods();
1083
				ResolvedMember realMember = getRealMemberForITDFromAspect(aspectType,interMethodBody);
1084
				if (realMember==null) throw new BCException("Couldn't find ITD init member '"+
1085
						interMethodBody+"' on aspect "+aspectType);
1086
				annotationsOnRealMember = realMember.getAnnotations();
1087
		}
1088
		
1058
		if (onType.equals(gen.getType())) {
1089
		if (onType.equals(gen.getType())) {
1059
			if (onInterface) {
1090
			if (onInterface) {
1060
				LazyMethodGen mg = makeMethodGen(gen, 
1091
				LazyMethodGen mg = makeMethodGen(gen, 
Lines 1068-1074 Link Here
1068
				weaver.addInitializer(this);
1099
				weaver.addInitializer(this);
1069
				FieldGen fg = makeFieldGen(gen,
1100
				FieldGen fg = makeFieldGen(gen,
1070
					AjcMemberMaker.interFieldClassField(field, aspectType));
1101
					AjcMemberMaker.interFieldClassField(field, aspectType));
1071
	    		gen.addField(fg.getField(),getSourceLocation());
1102
				
1103
				if (annotationsOnRealMember!=null) {
1104
					for (int i = 0; i < annotationsOnRealMember.length; i++) {
1105
						AnnotationX annotationX = annotationsOnRealMember[i];
1106
						Annotation a = annotationX.getBcelAnnotation();
1107
						AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true);	
1108
						fg.addAnnotation(ag);
1109
					}
1110
				}
1111
				
1112
				gen.addField(fg.getField(),getSourceLocation());
1113
	    		
1072
			}
1114
			}
1073
    		return true;
1115
    		return true;
1074
		} else if (onInterface && gen.getType().isTopmostImplementor(onType)) {
1116
		} else if (onInterface && gen.getType().isTopmostImplementor(onType)) {
(-)src/org/aspectj/weaver/bcel/LazyClassGen.java (+5 lines)
Lines 886-891 Link Here
886
		myGen.addField(field);
886
		myGen.addField(field);
887
	}
887
	}
888
	
888
	
889
	public void replaceField(Field oldF, Field newF){
890
		myGen.removeField(oldF);
891
		myGen.addField(newF);
892
	}
893
	
889
	public void addField(Field field, ISourceLocation sourceLocation) {
894
	public void addField(Field field, ISourceLocation sourceLocation) {
890
		addField(field);
895
		addField(field);
891
		if (!(field.isPrivate() 
896
		if (!(field.isPrivate() 

Return to bug 98901