]> source.dussan.org Git - aspectj.git/commitdiff
bring refactoring up to date.
authoraclement <aclement>
Mon, 12 May 2008 19:29:22 +0000 (19:29 +0000)
committeraclement <aclement>
Mon, 12 May 2008 19:29:22 +0000 (19:29 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/ConfigParser.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java
org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java

index 4d8330af620e9de1272b1c4cda27c413dba41398..b63f6bf58c11391e4e0da1f56931c6063159f4b4 100644 (file)
 
 package org.aspectj.ajdt.ajc;
 
-import java.io.*;
-import java.util.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.StringTokenizer;
 
-import org.aspectj.ajdt.internal.core.builder.*;
-import org.aspectj.bridge.*;
-import org.aspectj.util.*;
-import org.aspectj.weaver.Constants;
-import org.aspectj.weaver.Dump;
-import org.aspectj.weaver.WeaverMessages;
+import org.aspectj.ajdt.internal.core.builder.AjBuildConfig;
+import org.aspectj.bridge.CountingMessageHandler;
+import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.IMessageHandler;
+import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.bridge.Message;
+import org.aspectj.bridge.MessageUtil;
+import org.aspectj.bridge.SourceLocation;
+import org.aspectj.bridge.Version;
 import org.aspectj.org.eclipse.jdt.core.compiler.InvalidInputException;
 import org.aspectj.org.eclipse.jdt.internal.compiler.batch.Main;
 import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+import org.aspectj.util.FileUtil;
+import org.aspectj.util.LangUtil;
+import org.aspectj.weaver.Constants;
+import org.aspectj.weaver.Dump;
+import org.aspectj.weaver.WeaverMessages;
 
 public class BuildArgParser extends Main {
 
index f113d25038e6fe35071cb406d621170db8d3ef3a..97aa9a8be79e5fe0f0df2927aaa23a6e80df547d 100644 (file)
 
 package org.aspectj.ajdt.ajc;
 
-import java.util.*;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
 
 public class ConfigParser {
     Location location;
index cf3938394dc9b32348e53e6580330fa23e47e8dc..744a39090d77b20fad78e659c2e8e9194a7e5ea3 100644 (file)
@@ -62,6 +62,7 @@ import org.aspectj.weaver.AsmRelationshipProvider;
 import org.aspectj.weaver.ConcreteTypeMunger;
 import org.aspectj.weaver.FakeAnnotation;
 import org.aspectj.weaver.ReferenceType;
+import org.aspectj.weaver.ReferenceTypeDelegate;
 import org.aspectj.weaver.ResolvedMember;
 import org.aspectj.weaver.ResolvedType;
 import org.aspectj.weaver.TypeVariable;
@@ -69,6 +70,7 @@ import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.WeaverMessages;
 import org.aspectj.weaver.WeaverStateInfo;
 import org.aspectj.weaver.World;
+import org.aspectj.weaver.bcel.BcelObjectType;
 import org.aspectj.weaver.bcel.LazyClassGen;
 import org.aspectj.weaver.patterns.DeclareAnnotation;
 import org.aspectj.weaver.patterns.DeclareParents;
@@ -140,6 +142,7 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
        
                for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
                        ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.BUILDING_FIELDS_AND_METHODS, units[i].compilationResult.fileName);
+//                     units[i].scope.checkParameterizedTypes(); do this check a little later, after ITDs applied to stbs
                        units[i].scope.buildFieldsAndMethods();
                        CompilationAndWeavingContext.leavingPhase(tok);
                }
@@ -221,7 +224,11 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
                                weaveInterTypeDeclarations(units[i].scope, typeMungers, declareParents,declareAnnotationOnTypes);
                        }
                }
-               
+
+        for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
+            units[i].scope.checkParameterizedTypes();
+        }
+        
                for (int i = lastCompletedUnitIndex +1; i<=lastUnitIndex; i++) {
                        SourceTypeBinding[] b = units[i].scope.topLevelTypes;
             for (int j = 0; j < b.length; j++) {
@@ -699,7 +706,8 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
        
        private boolean doDeclareParents(DeclareParents declareParents, SourceTypeBinding sourceType) {
                ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_DECLARE_PARENTS, sourceType.sourceName);
-               List newParents = declareParents.findMatchingNewParents(factory.fromEclipse(sourceType),false);
+               ResolvedType resolvedSourceType = factory.fromEclipse(sourceType);
+               List newParents = declareParents.findMatchingNewParents(resolvedSourceType,false);
                if (!newParents.isEmpty()) {
                        for (Iterator i = newParents.iterator(); i.hasNext(); ) {
                                ResolvedType parent = (ResolvedType)i.next();
@@ -712,6 +720,8 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
                                if (Modifier.isFinal(parent.getModifiers())) {
                                        factory.showMessage(IMessage.ERROR,"cannot extend final class " + parent.getClassName(),declareParents.getSourceLocation(),null);
                                } else {
+                                   // do not actually do it if the type isn't exposed - this will correctly reported as a problem elsewhere
+                                       if (!resolvedSourceType.isExposedToWeaver()) return false;
                                        AsmRelationshipProvider.getDefault().addDeclareParentsRelationship(declareParents.getSourceLocation(),factory.fromEclipse(sourceType), newParents);
                                        addParent(sourceType, parent);
                                }
@@ -794,7 +804,8 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
                                // BUG BUG BUG - We dont test these abits are correct, in fact we'll be very lucky if they are.
                                // What does that mean?  It means on an incremental compile you might get away with an
                                // annotation that isn't allowed on a type being put on a type.
-                               abits = toAdd[0].resolvedType.getAnnotationTagBits(); 
+                               if (toAdd[0].resolvedType != null) // pr184447
+                                   abits = toAdd[0].resolvedType.getAnnotationTagBits(); 
                        }               
                } else {
                        // much nicer, its a real SourceTypeBinding so we can stay in eclipse land
@@ -803,6 +814,7 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
                        TypeDeclaration typeDecl = ((SourceTypeBinding)mbs[0].declaringClass).scope.referenceContext;
                        AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(mbs[0]);
                        toAdd = methodDecl.annotations; // this is what to add
+                       toAdd[0] = createAnnotationCopy(toAdd[0]);
                        if (toAdd[0].resolvedType!=null) // pr148536
                          abits = toAdd[0].resolvedType.getAnnotationTagBits();
                }
@@ -812,9 +824,10 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
                        // on the weaver type temporarily
                        ResolvedType theTargetType = factory.fromEclipse(sourceType);
                        TypeBinding theAnnotationType = toAdd[0].resolvedType;
-                       String name = new String(theAnnotationType.qualifiedPackageName())+"."+new String(theAnnotationType.sourceName());
                        String sig = new String(theAnnotationType.signature());
-                       if (theTargetType.hasAnnotation(UnresolvedType.forSignature(sig))) {
+                       UnresolvedType bcelAnnotationType = UnresolvedType.forSignature(sig);
+                       String name = bcelAnnotationType.getName();
+                       if (theTargetType.hasAnnotation(bcelAnnotationType)) {
                                CompilationAndWeavingContext.leavingPhase(tok);
                                return false;
                        }
@@ -940,6 +953,32 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
 //             ann.memberValuePairs = mvps;
                return ann;
        }
+       
+       /** Create a copy of an annotation, not deep but deep enough so we don't copy across fields that will get us into trouble like 'recipient' */
+       private static Annotation createAnnotationCopy(Annotation ann) {
+               NormalAnnotation ann2 = new NormalAnnotation(ann.type,ann.sourceStart);
+               ann2.memberValuePairs = ann.memberValuePairs();
+               ann2.resolvedType = ann.resolvedType;
+               ann2.bits = ann.bits;
+               return ann2;
+//             String name = annX.getTypeName();
+//             TypeBinding tb = factory.makeTypeBinding(annX.getSignature());
+//             String theName = annX.getSignature().getBaseName();
+//             char[][] typeName = CharOperation.splitOn('.',name.replace('$','.').toCharArray()); //pr149293 - not bulletproof...
+//             long[] positions = new long[typeName.length];
+//             for (int i = 0; i < positions.length; i++) positions[i]=pos;
+//             TypeReference annType = new QualifiedTypeReference(typeName,positions);
+//             NormalAnnotation ann = new NormalAnnotation(annType,pos);
+//             ann.resolvedType=tb; // yuck - is this OK in all cases?
+//             // We don't need membervalues...
+////           Expression pcExpr = new StringLiteral(pointcutExpression.toCharArray(),pos,pos);
+////           MemberValuePair[] mvps = new MemberValuePair[2];
+////           mvps[0] = new MemberValuePair("value".toCharArray(),pos,pos,pcExpr);
+////           Expression argNamesExpr = new StringLiteral(argNames.toCharArray(),pos,pos);
+////           mvps[1] = new MemberValuePair("argNames".toCharArray(),pos,pos,argNamesExpr);
+////           ann.memberValuePairs = mvps;
+//             return ann;
+       }
 
        private boolean isAnnotationTargettingSomethingOtherThanAnnotationOrNormal(long abits) {
                return (abits & (TagBits.AnnotationForAnnotationType | TagBits.AnnotationForType))==0;
@@ -1006,7 +1045,17 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
                // reportDeclareParentsMessage(WeaveMessage.WEAVEMESSAGE_DECLAREPARENTSIMPLEMENTS,sourceType,parent);
                        
                }
-               
+        
+        // also add it to the bcel delegate if there is one
+        if (sourceType instanceof BinaryTypeBinding) {
+               ResolvedType onType = factory.fromEclipse(sourceType);
+               ReferenceType rt = (ReferenceType)onType;
+               ReferenceTypeDelegate rtd = rt.getDelegate();
+               if (rtd instanceof BcelObjectType) {
+                       ((BcelObjectType)rtd).addParent(parent);
+                   }
+        }
+        
        }
 
        public void warnOnAddedInterface (ResolvedType type, ResolvedType parent) {
index f2328311c3bfdd11dff1eadefc14d3acf71b613c..77d8bc0dd81649fa001a4bfe956d4027f6c32548 100644 (file)
@@ -19,8 +19,8 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.PrintStream;
 import java.util.Arrays;
-import java.util.List;
 import java.util.Date;
+import java.util.List;
 
 import org.aspectj.ajdt.internal.core.builder.AjBuildManager;
 import org.aspectj.bridge.AbortException;
@@ -254,7 +254,7 @@ public class Main {
                run(args, holder);
                long etime = System.currentTimeMillis();
                if (timers) {
-                       System.out.println("Compiler took "+(etime-stime)+"ms");
+                   System.out.println("Compiler took "+(etime-stime)+"ms");
                }
                holder.handleMessage(MessageUtil.info("Compiler took "+(etime-stime)+"ms"));
                // uncomment next line to pause at end (keeps jconsole alive!)