]> source.dussan.org Git - aspectj.git/commitdiff
incremental and working with binaries improved
authorjhugunin <jhugunin>
Fri, 3 Jan 2003 23:21:30 +0000 (23:21 +0000)
committerjhugunin <jhugunin>
Fri, 3 Jan 2003 23:21:30 +0000 (23:21 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseObjectType.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseTypeMunger.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/InterTypeScope.java

index cbd1e13678ffcab73648153b703718f86cc022f0..937ffd4a94b2cbeb6875ddebc713ff14a1613151 100644 (file)
@@ -20,6 +20,7 @@ import org.aspectj.bridge.MessageUtil;
 import org.aspectj.weaver.*;
 import org.aspectj.weaver.patterns.*;
 import org.eclipse.jdt.internal.compiler.ast.*;
+import org.eclipse.jdt.internal.compiler.env.*;
 import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
 import org.eclipse.jdt.internal.compiler.impl.*;
 import org.eclipse.jdt.internal.compiler.lookup.*;
@@ -28,6 +29,9 @@ import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
 public class AjLookupEnvironment extends LookupEnvironment {
        public EclipseWorld world = null;
        
+       private boolean builtInterTypesAndPerClauses = false;
+       private List pendingTypesToWeave = new ArrayList();
+       
        public AjLookupEnvironment(
                ITypeRequestor typeRequestor,
                CompilerOptions options,
@@ -36,9 +40,10 @@ public class AjLookupEnvironment extends LookupEnvironment {
                super(typeRequestor, options, problemReporter, nameEnvironment);
        }
        
-       //XXX figure out if we can do this through super or not
-       //XXX otherwise duplicates some of super's code
+       //??? duplicates some of super's code
        public void completeTypeBindings() {
+               builtInterTypesAndPerClauses = false;
+               //pendingTypesToWeave = new ArrayList();
                stepCompleted = BUILD_TYPE_HIERARCHY;
                
                for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
@@ -62,8 +67,9 @@ public class AjLookupEnvironment extends LookupEnvironment {
                        for (int j = 0; j < b.length; j++) {
                                buildInterTypeAndPerClause(b[j].scope);
                        }
-               }               
-               //??? do we need a new stepCompleted
+               }
+               builtInterTypesAndPerClauses = true;
+               doPendingWeaves();
        
                // now do weaving
                Collection typeMungers = world.getTypeMungers();
@@ -76,6 +82,15 @@ public class AjLookupEnvironment extends LookupEnvironment {
                stepCompleted = BUILD_FIELDS_AND_METHODS;
                lastCompletedUnitIndex = lastUnitIndex;
        }
+
+       private void doPendingWeaves() {
+               for (Iterator i = pendingTypesToWeave.iterator(); i.hasNext(); ) {
+                       SourceTypeBinding t = (SourceTypeBinding)i.next();
+                       weaveInterTypeDeclarations(t);
+               }
+               pendingTypesToWeave.clear();
+       }
+
        
        private void buildInterTypeAndPerClause(ClassScope s) {
                TypeDeclaration dec = s.referenceContext;
@@ -91,20 +106,33 @@ public class AjLookupEnvironment extends LookupEnvironment {
                }
        }
        
+       
+       
                
        private void weaveInterTypeDeclarations(CompilationUnitScope unit, Collection typeMungers, Collection declareParents) {
                for (int i = 0, length = unit.topLevelTypes.length; i < length; i++)
-                   weaveInterTypeDeclarations(unit.topLevelTypes[i].scope, typeMungers, declareParents);
+                   weaveInterTypeDeclarations(unit.topLevelTypes[i], typeMungers, declareParents);
        
                //System.err.println("done with inter types");
        }
        
-       private void weaveInterTypeDeclarations(ClassScope scope, Collection typeMungers, Collection declareParents) {
-               //System.err.println("weaving: " + scope);
-               SourceTypeBinding sourceType = scope.referenceContext.binding;
+       
+       private void weaveInterTypeDeclarations(SourceTypeBinding sourceType) {
+               if (!builtInterTypesAndPerClauses) {
+                       pendingTypesToWeave.add(sourceType);
+               } else {
+                       //System.err.println("weaving: " + new String(sourceType.sourceName()) + ", " + world.getTypeMungers());
+                       weaveInterTypeDeclarations(sourceType, world.getTypeMungers(), world.getDeclareParents());
+               }
+       }
+       
+       
+       private void weaveInterTypeDeclarations(SourceTypeBinding sourceType, Collection typeMungers, Collection declareParents) {
                ResolvedTypeX onType = world.fromEclipse(sourceType);
+               onType.clearInterTypeMungers();
+               
                for (Iterator i = declareParents.iterator(); i.hasNext();) {
-                       doDeclareParents((DeclareParents)i.next(), scope);
+                       doDeclareParents((DeclareParents)i.next(), sourceType);
                }
                
                for (Iterator i = typeMungers.iterator(); i.hasNext();) {
@@ -118,28 +146,29 @@ public class AjLookupEnvironment extends LookupEnvironment {
                
                for (Iterator i = onType.getInterTypeMungers().iterator(); i.hasNext();) {
                        EclipseTypeMunger munger = (EclipseTypeMunger) i.next();
-                       munger.munge(scope);
+                       munger.munge(sourceType);
                }
                
                
 
                ReferenceBinding[] memberTypes = sourceType.memberTypes;
                for (int i = 0, length = memberTypes.length; i < length; i++) {
-                       weaveInterTypeDeclarations(((SourceTypeBinding) memberTypes[i]).scope, typeMungers, declareParents);
+                       if (memberTypes[i] instanceof SourceTypeBinding) {
+                               weaveInterTypeDeclarations((SourceTypeBinding) memberTypes[i], typeMungers, declareParents);
+                       }
                }
        }
 
-       private void doDeclareParents(DeclareParents declareParents, ClassScope scope) {
-               if (declareParents.match(world.fromEclipse(scope.referenceContext.binding))) {
+       private void doDeclareParents(DeclareParents declareParents, SourceTypeBinding sourceType) {
+               if (declareParents.match(world.fromEclipse(sourceType))) {
                        TypePatternList l = declareParents.getParents();
                        for (int i=0, len=l.size(); i < len; i++) {
-                               addParent(declareParents, scope, l.get(i));
+                               addParent(declareParents, sourceType, l.get(i));
                        }
                }
        }
 
-       private void addParent(DeclareParents declareParents, ClassScope scope, TypePattern typePattern) {
-               SourceTypeBinding sourceType = scope.referenceContext.binding;
+       private void addParent(DeclareParents declareParents, SourceTypeBinding sourceType, TypePattern typePattern) {
                //if (!typePattern.assertExactType(world.getMessageHandler())) return;
                if (typePattern == TypePattern.NO) return;  // already had an error here
                TypeX iType = typePattern.getExactType();
@@ -192,11 +221,43 @@ public class AjLookupEnvironment extends LookupEnvironment {
                }
                
        }
-
-       private TypeReference makeReference(ExactTypePattern e) {
-               return new SingleTypeReference(e.getType().getName().toCharArray(),
-                       AstUtil.makeLongPos(e.getStart(), e.getEnd()));
+       
+       
+       
+       private List pendingTypesToFinish = new ArrayList();
+       boolean inBinaryTypeCreation = false;
+       public BinaryTypeBinding createBinaryTypeFrom(
+               IBinaryType binaryType,
+               PackageBinding packageBinding,
+               boolean needFieldsAndMethods)
+       {
+               if (inBinaryTypeCreation) {
+                       BinaryTypeBinding ret = super.createBinaryTypeFrom(
+                               binaryType,
+                               packageBinding,
+                               needFieldsAndMethods);
+                       pendingTypesToFinish.add(ret);
+                       return ret;
+               }
+               
+               
+               inBinaryTypeCreation = true;
+               try {
+                       BinaryTypeBinding ret = super.createBinaryTypeFrom(
+                               binaryType,
+                               packageBinding,
+                               needFieldsAndMethods);
+                       weaveInterTypeDeclarations(ret);
+                       
+                       return ret;
+               } finally {
+                       inBinaryTypeCreation = false;
+                       if (!pendingTypesToFinish.isEmpty()) {
+                               for (Iterator i = pendingTypesToFinish.iterator(); i.hasNext(); ) {
+                                       weaveInterTypeDeclarations((BinaryTypeBinding)i.next());
+                               }
+                               pendingTypesToFinish.clear();
+                       }
+               }               
        }
-
-
 }
index 4167cecaa1f501c159f4f1f93f491ab6b69d84f0..911f43ece2da0096ba8516d58a3141f7f2f277bc 100644 (file)
@@ -33,7 +33,7 @@ public class EclipseObjectType extends ResolvedTypeX.Name {
        
 
        public EclipseObjectType(String signature, EclipseWorld world, ReferenceBinding binding) {
-               super(signature, world);
+               super(signature, world, !(binding instanceof BinaryTypeBinding));  //XXX
                this.binding = binding;
        }
        
@@ -169,7 +169,7 @@ public class EclipseObjectType extends ResolvedTypeX.Name {
        }
 
        public ISourceLocation getSourceLocation() {
-               if (!(binding instanceof SourceTypeBinding)) return null;
+               if (!(binding instanceof SourceTypeBinding) || (binding instanceof BinaryTypeBinding)) return null;
                SourceTypeBinding sourceType = (SourceTypeBinding)binding;
                TypeDeclaration dec = sourceType.scope.referenceContext;
                return new EclipseSourceLocation(dec.compilationResult, dec.sourceStart, dec.sourceEnd);
index 2610a56c0aa8291587f2645bfabc030a0c5f987e..796e834112a9e95f6e6722b9ed800ed858509269 100644 (file)
@@ -27,26 +27,27 @@ import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
 public class EclipseTypeMunger extends ConcreteTypeMunger {
        protected ReferenceBinding targetBinding = null;
        private AbstractMethodDeclaration sourceMethod;
+       private EclipseWorld world;
 
        public EclipseTypeMunger(ResolvedTypeMunger munger, ResolvedTypeX aspectType,
                                                                AbstractMethodDeclaration sourceMethod)
        {
                super(munger, aspectType);
                this.sourceMethod = sourceMethod;
+               this.world = (EclipseWorld)aspectType.getWorld();
        }
 
        public String toString() {
                return "(EclipseTypeMunger " + getMunger() + ")";
        }
        
-       private boolean match(ClassScope scope) {
+       private boolean match(SourceTypeBinding sourceType) {
                if (targetBinding == null) {
                        TypeX targetTypeX = munger.getSignature().getDeclaringType();
-                       targetBinding =
-                               (ReferenceBinding)EclipseWorld.fromScopeLookupEnvironment(scope).makeTypeBinding(targetTypeX);
+                       targetBinding = (ReferenceBinding)world.makeTypeBinding(targetTypeX);
                }
                //??? assumes instance uniqueness for ReferenceBindings
-               return targetBinding == scope.referenceContext.binding;
+               return targetBinding == sourceType;
                
        }
        
@@ -54,15 +55,15 @@ public class EclipseTypeMunger extends ConcreteTypeMunger {
         * Modifies signatures of a TypeBinding through its ClassScope,
         * i.e. adds Method|FieldBindings, plays with inheritance, ...
         */
-       public boolean munge(ClassScope classScope) {
-               if (!match(classScope)) return false;
+       public boolean munge(SourceTypeBinding sourceType) {
+               if (!match(sourceType)) return false;
                
                if (munger.getKind() == ResolvedTypeMunger.Field) {
-                       mungeNewField(classScope, (NewFieldTypeMunger)munger);
+                       mungeNewField(sourceType, (NewFieldTypeMunger)munger);
                } else if (munger.getKind() == ResolvedTypeMunger.Method) {
-                       mungeNewMethod(classScope, (NewMethodTypeMunger)munger);
+                       mungeNewMethod(sourceType, (NewMethodTypeMunger)munger);
                } else if (munger.getKind() == ResolvedTypeMunger.Constructor) {
-                       mungeNewConstructor(classScope, (NewConstructorTypeMunger)munger);
+                       mungeNewConstructor(sourceType, (NewConstructorTypeMunger)munger);
                } else {
                        throw new RuntimeException("unimplemented");
                }
@@ -70,9 +71,7 @@ public class EclipseTypeMunger extends ConcreteTypeMunger {
        }
        
 
-       private void mungeNewMethod(ClassScope classScope, NewMethodTypeMunger munger) {
-               EclipseWorld world = EclipseWorld.fromScopeLookupEnvironment(classScope);
-               
+       private void mungeNewMethod(SourceTypeBinding sourceType, NewMethodTypeMunger munger) {
 //             if (shouldTreatAsPublic()) {
 //                     MethodBinding binding = world.makeMethodBinding(munger.getSignature());
 //                     findOrCreateInterTypeMemberFinder(classScope).addInterTypeMethod(binding);
@@ -80,36 +79,32 @@ public class EclipseTypeMunger extends ConcreteTypeMunger {
 //             } else {
                        InterTypeMethodBinding binding =
                                new InterTypeMethodBinding(world, munger.getSignature(), aspectType, sourceMethod);
-                       findOrCreateInterTypeMemberFinder(classScope).addInterTypeMethod(binding);
+                       findOrCreateInterTypeMemberFinder(sourceType).addInterTypeMethod(binding);
 //             }
 
        }
-       private void mungeNewConstructor(ClassScope classScope, NewConstructorTypeMunger munger) {
-               EclipseWorld world = EclipseWorld.fromScopeLookupEnvironment(classScope);
-               
+       private void mungeNewConstructor(SourceTypeBinding sourceType, NewConstructorTypeMunger munger) {               
                if (shouldTreatAsPublic()) {
                        MethodBinding binding = world.makeMethodBinding(munger.getSignature());
-                       findOrCreateInterTypeMemberFinder(classScope).addInterTypeMethod(binding);
+                       findOrCreateInterTypeMemberFinder(sourceType).addInterTypeMethod(binding);
                        //classScope.referenceContext.binding.addMethod(binding);
                } else {
                        InterTypeMethodBinding binding =
                                new InterTypeMethodBinding(world, munger.getSignature(), aspectType, sourceMethod);
-                       findOrCreateInterTypeMemberFinder(classScope).addInterTypeMethod(binding);
+                       findOrCreateInterTypeMemberFinder(sourceType).addInterTypeMethod(binding);
                }
 
        }
 
-       private void mungeNewField(ClassScope classScope, NewFieldTypeMunger munger) {
-               EclipseWorld world = EclipseWorld.fromScopeLookupEnvironment(classScope);
-               
+       private void mungeNewField(SourceTypeBinding sourceType, NewFieldTypeMunger munger) {           
                if (shouldTreatAsPublic() && !targetBinding.isInterface()) {
                        FieldBinding binding = world.makeFieldBinding(munger.getSignature());
-                       findOrCreateInterTypeMemberFinder(classScope).addInterTypeField(binding);
+                       findOrCreateInterTypeMemberFinder(sourceType).addInterTypeField(binding);
                        //classScope.referenceContext.binding.addField(binding);
                } else {
                        InterTypeFieldBinding binding =
                                new InterTypeFieldBinding(world, munger.getSignature(), aspectType, sourceMethod);
-                       findOrCreateInterTypeMemberFinder(classScope).addInterTypeField(binding);
+                       findOrCreateInterTypeMemberFinder(sourceType).addInterTypeField(binding);
                }
        }
        
@@ -122,13 +117,13 @@ public class EclipseTypeMunger extends ConcreteTypeMunger {
        }
        
        
-       private InterTypeMemberFinder findOrCreateInterTypeMemberFinder(ClassScope classScope) {
+       private InterTypeMemberFinder findOrCreateInterTypeMemberFinder(SourceTypeBinding sourceType) {
                InterTypeMemberFinder finder = 
-                       (InterTypeMemberFinder)classScope.referenceContext.binding.memberFinder;
+                       (InterTypeMemberFinder)sourceType.memberFinder;
                if (finder == null) {
                        finder = new InterTypeMemberFinder();
-                       classScope.referenceContext.binding.memberFinder = finder;
-                       finder.sourceTypeBinding = classScope.referenceContext.binding;
+                       sourceType.memberFinder = finder;
+                       finder.sourceTypeBinding = sourceType;
                }
                return finder;
        }
index 2a70e641e866099a47d96c1e92346a15b30698ea..12566bdcd480f1ffd07ad4229f67fe7914db33b7 100644 (file)
@@ -26,29 +26,16 @@ public class InterTypeScope extends ClassScope {
                this.onType = onType;
        }
 
+       // this method depends on the fact that BinaryTypeBinding extends SourceTypeBinding
        private SourceTypeBinding makeSourceTypeBinding(ReferenceBinding onType) {
                if (onType instanceof SourceTypeBinding) return (SourceTypeBinding)onType;
                else throw new RuntimeException("can't handle: " + onType);
-               //return new FakeSourceTypeBinding(onType);
-       }
-
-       public FieldBinding findField(
-               TypeBinding receiverType,
-               char[] fieldName,
-               InvocationSite invocationSite)
-       {
-               //System.out.println("find: " + new String(fieldName));
-               return super.findField(receiverType, fieldName, invocationSite);
        }
 
        public SourceTypeBinding invocationType() {
                return parent.enclosingSourceType();
        }
        
-       public ReferenceBinding effectiveThisType() {
-               return onType;
-       }
-       
        public int addDepth() {
                return 0;
        }