]> source.dussan.org Git - aspectj.git/commitdiff
fixed bug #29186, much better handling of structure generation
authorjhugunin <jhugunin>
Tue, 14 Jan 2003 21:36:18 +0000 (21:36 +0000)
committerjhugunin <jhugunin>
Tue, 14 Jan 2003 21:36:18 +0000 (21:36 +0000)
added an Xlint flag for warnings when join points don't have structure nodes

asm/src/org/aspectj/asm/StructureModel.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmBuilder.java
weaver/src/org/aspectj/weaver/AsmAdaptor.java
weaver/src/org/aspectj/weaver/Lint.java
weaver/src/org/aspectj/weaver/ResolvedTypeX.java
weaver/src/org/aspectj/weaver/Shadow.java
weaver/src/org/aspectj/weaver/XlintDefault.properties
weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java

index 18f464b4fa9fe455567b7e5f6dcf964698812a74..831f90f84a4fbdd7c609ebd680d3711c2daee79c 100644 (file)
@@ -70,14 +70,39 @@ public class StructureModel implements Serializable {
                        }
                        if (packageNode == null) return null;
                }
-               // !!! this searches each file for a class
+               
+               // this searches each file for a class
                for (Iterator it = packageNode.getChildren().iterator(); it.hasNext(); ) {
                        ProgramElementNode fileNode = (ProgramElementNode)it.next();
-                       for (Iterator j = fileNode.getChildren().iterator(); j.hasNext(); ) {
-                               ProgramElementNode classNode = (ProgramElementNode)j.next();    
-                               if (classNode instanceof ProgramElementNode && className.equals(classNode.getName())) {
-                                       return (ProgramElementNode)classNode;
-                               }
+                       ProgramElementNode ret = findClassInNodes(fileNode.getChildren(), className);
+                       if (ret != null) return ret;
+               }
+               
+               return null;
+       }
+       
+       private ProgramElementNode findClassInNodes(Collection nodes, String name) {
+               String baseName;
+               String innerName;
+               int dollar = name.indexOf('$');
+               if (dollar == -1) {
+                       baseName = name;
+                       innerName = null;
+               } else {
+                       baseName = name.substring(0, dollar);
+                       innerName = name.substring(dollar+1);
+               }
+               
+               
+               for (Iterator j = nodes.iterator(); j.hasNext(); ) {
+                       ProgramElementNode classNode = (ProgramElementNode)j.next();
+//                     System.err.println("checking: " + classNode + " for " + baseName);      
+//                     System.err.println("children: " + classNode.getChildren());
+                       if (baseName.equals(classNode.getName())) {
+                               if (innerName == null) return classNode;
+                               else return findClassInNodes(classNode.getChildren(), innerName);
+                       } else if (name.equals(classNode.getName())) {
+                               return classNode;
                        }
                }
                return null;
index 7a42f7c2a5bfda4ee284370394b868fc604c22da..c894d128b85b1597d2edda01ab4c7475ed1942a5 100644 (file)
@@ -101,6 +101,7 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
 
        public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) {
                String name = new String(typeDeclaration.name);
+               //System.err.println("type with name: " + name);
                ProgramElementNode.Kind kind = ProgramElementNode.Kind.CLASS;
                if (typeDeclaration instanceof AspectDeclaration) kind = ProgramElementNode.Kind.ASPECT;
                else if (typeDeclaration.isInterface()) kind = ProgramElementNode.Kind.INTERFACE;
@@ -124,6 +125,8 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
        // ??? share impl with visit(TypeDeclaration, ..) ?
        public boolean visit(MemberTypeDeclaration memberTypeDeclaration, ClassScope scope) {
                String name = new String(memberTypeDeclaration.name);
+               //System.err.println("member type with name: " + name);
+               
                ProgramElementNode.Kind kind = ProgramElementNode.Kind.CLASS;
                if (memberTypeDeclaration instanceof AspectDeclaration) kind = ProgramElementNode.Kind.ASPECT;
                else if (memberTypeDeclaration.isInterface()) kind = ProgramElementNode.Kind.INTERFACE;
@@ -144,6 +147,54 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
                stack.pop();
        }
        
+       public boolean visit(LocalTypeDeclaration memberTypeDeclaration, BlockScope scope) {
+               String name = new String(memberTypeDeclaration.name);
+               String fullName = new String(memberTypeDeclaration.binding.constantPoolName());
+               int dollar = fullName.indexOf('$');
+               fullName = fullName.substring(dollar+1);
+//             
+//             System.err.println("member type with name: " + name + ", " + 
+//                             new String(fullName));
+               
+               ProgramElementNode.Kind kind = ProgramElementNode.Kind.CLASS;
+               if (memberTypeDeclaration.isInterface()) kind = ProgramElementNode.Kind.INTERFACE;
+
+               ProgramElementNode peNode = new ProgramElementNode(
+                       fullName,
+                       kind,
+                       makeLocation(memberTypeDeclaration),
+                       memberTypeDeclaration.modifiers,
+                       "",
+                       new ArrayList());
+               
+               //??? we add this to the compilation unit
+               findEnclosingClass(stack).addChild(peNode);
+               stack.push(peNode);
+               return true;
+       }
+       public void endVisit(LocalTypeDeclaration memberTypeDeclaration, BlockScope scope) {
+               stack.pop();
+       }
+       
+       public boolean visit(AnonymousLocalTypeDeclaration memberTypeDeclaration, BlockScope scope) {
+               return visit((LocalTypeDeclaration)memberTypeDeclaration, scope);
+       }
+
+       public void endVisit(AnonymousLocalTypeDeclaration memberTypeDeclaration, BlockScope scope) {
+               stack.pop();
+       }
+       
+       private StructureNode findEnclosingClass(Stack stack) {
+               for (int i = stack.size()-1; i >= 0; i--) {
+                       ProgramElementNode pe = (ProgramElementNode)stack.get(i);
+                       if (pe.getProgramElementKind() == ProgramElementNode.Kind.CLASS) {
+                               return pe;
+                       }
+                       
+               }
+               return (StructureNode)stack.peek();
+       }       
+       
        // !!! improve name and type generation
        public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
                ProgramElementNode.Kind kind = ProgramElementNode.Kind.METHOD;
@@ -171,10 +222,11 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
                        methodDeclaration.modifiers,
                        "",
                        new ArrayList());
-                       
-               Member member = EclipseWorld.makeResolvedMember(methodDeclaration.binding);
-               peNode.setBytecodeName(member.getName());
-               peNode.setBytecodeSignature(member.getSignature());
+               if (methodDeclaration.binding != null) {
+                       Member member = EclipseWorld.makeResolvedMember(methodDeclaration.binding);
+                       peNode.setBytecodeName(member.getName());
+                       peNode.setBytecodeSignature(member.getSignature());
+               }
                ((StructureNode)stack.peek()).addChild(peNode);
                stack.push(peNode);
                
index 256f7c470fe390d8a308ddb49195d0a791710aaf..c9c0e52c0ab31260a6819d764afda3095c46d27d 100644 (file)
@@ -77,6 +77,7 @@ public class AsmAdaptor {
        private static ProgramElementNode getNode(StructureModel model, Advice a) {
                //ResolvedTypeX inAspect = a.getConcreteAspect();
                Member member = a.getSignature();
+               if (a.getSignature() == null) return null;
                return lookupMember(model, member);
        }
        
@@ -84,6 +85,13 @@ public class AsmAdaptor {
                Member enclosingMember = shadow.getEnclosingCodeSignature();
                
                ProgramElementNode enclosingNode = lookupMember(model, enclosingMember);
+               if (enclosingNode == null) {
+                       Lint.Kind err = shadow.getIWorld().getLint().shadowNotInStructure;
+                       if (err.isEnabled()) {
+                               err.signal(shadow.toString(), shadow.getSourceLocation());
+                       }
+                       return null;
+               }
                
                Member shadowSig = shadow.getSignature();
                if (!shadowSig.equals(enclosingMember)) {
@@ -117,7 +125,7 @@ public class AsmAdaptor {
                        "",
                        new ArrayList());
                        
-               System.err.println(peNode.getSourceLocation());
+               //System.err.println(peNode.getSourceLocation());
                peNode.setBytecodeName(shadowSig.getName());
                peNode.setBytecodeSignature(shadowSig.getSignature());
                enclosingNode.addChild(peNode);
@@ -142,13 +150,16 @@ public class AsmAdaptor {
                if (classNode == null) return null; // XXX remove this check
                for (Iterator it = classNode.getChildren().iterator(); it.hasNext(); ) {
                        ProgramElementNode node = (ProgramElementNode)it.next();
+                       //System.err.println("checking: " + member.getName() + " with " + node.getBytecodeName() + ", " + node.getBytecodeSignature());
                        if (member.getName().equals(node.getBytecodeName()) &&
                                member.getSignature().equals(node.getBytecodeSignature()))
                        {
                                return node;
                        }
                }
-               return null;
+               // if we can't find the member, we'll just put it in the class
+               //??? is this what the IDEs want
+               return classNode;
        }
 
 
index eeef10f10b17429575ab65d465660021c4ea809b..80163d951823838629cbcaf9ce3fe4d8620708da 100644 (file)
@@ -37,6 +37,9 @@ public class Lint {
        public final Kind typeNotExposedToWeaver = 
                new Kind("typeNotExposedToWeaver", "this affected type is not exposed to the weaver: {0}");
                
+       public final Kind shadowNotInStructure = 
+               new Kind("shadowNotInStructure", "the shadow for this join point is not exposed in the structure model: {0}");
+               
        public Lint(World world) {
                this.world = world;
        }
index b220875439acb48832148e75555b5ec3ad27166c..b6b0a4fe32870ffb5f3f70ab8b392efa2f417c43 100644 (file)
@@ -436,6 +436,10 @@ public abstract class ResolvedTypeX extends TypeX {
     }
     
     
+    public boolean isSynthetic() {
+       return signature.indexOf("$ajc") != -1;
+    }
+    
     public final boolean isFinal() {
         return Modifier.isFinal(getModifiers());
     }
index 505006ccc2b289361a93287ccc5212ac880a3138..fe58a5672359700898d98a3aa87ae435b7e6e698 100644 (file)
@@ -305,7 +305,7 @@ public abstract class Shadow {
                        ShadowMunger munger = (ShadowMunger) iter.next();
                        munger.implementOn(this);
                        if (world.getModel() != null) {
-                               System.err.println("munger: " + munger + " on " + this);
+                               //System.err.println("munger: " + munger + " on " + this);
                                AsmAdaptor.noteMunger(world.getModel(), this, munger);
                        }
                }
index 25e48c76e8f476375c5d9dd79e451bba0aee8cdc..59d6d2f28d389a37af51b55c18674ce6855423e0 100644 (file)
@@ -3,4 +3,6 @@ invalidWildcardTypeName = ignore
 
 unresolvableMember = warning
 
-typeNotExposedToWeaver = warning
\ No newline at end of file
+typeNotExposedToWeaver = warning
+
+shadowNotInStructure = ignore
\ No newline at end of file
index 1d62b92cba9379a519d6b463c8623f49d18e0844..53ccfd7056dd9d0a052ffd6230c2e1db7ef97b96 100644 (file)
@@ -294,6 +294,11 @@ public class BcelWeaver implements IWeaver {
 
        // non-private for testing
        LazyClassGen weave(UnwovenClassFile classFile, BcelObjectType classType) throws IOException {
+               if (classType.isSynthetic()) {
+                       dumpUnchanged(classFile);
+                       return null;
+               }
+               
                JavaClass javaClass = classType.getJavaClass();
                List shadowMungers = fastMatch(shadowMungerList, javaClass);
                List typeMungers = fastMatch(classType.getInterTypeMungers(), javaClass);