]> source.dussan.org Git - aspectj.git/commitdiff
try to ensure demotion happens
authoraclement <aclement>
Fri, 4 Dec 2009 07:04:00 +0000 (07:04 +0000)
committeraclement <aclement>
Fri, 4 Dec 2009 07:04:00 +0000 (07:04 +0000)
weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java

index 37b37b0ab770ef2f7b65e7386fa06f868e4e8dd6..3c64e2a02a91f78735b8b76893de14ba4e188f5f 100644 (file)
@@ -1780,115 +1780,118 @@ public class BcelWeaver {
 
        private LazyClassGen weave(UnwovenClassFile classFile, BcelObjectType classType, boolean dump) throws IOException {
 
-               if (classType.isSynthetic()) { // Don't touch synthetic classes
-                       if (dump) {
-                               dumpUnchanged(classFile);
-                       }
-                       return null;
-               }
-               ReferenceType resolvedClassType = classType.getResolvedTypeX();
-
-               if (world.isXmlConfigured() && world.getXmlConfiguration().excludesType(resolvedClassType)) {
-                       if (!world.getMessageHandler().isIgnoring(IMessage.INFO)) {
-                               world.getMessageHandler().handleMessage(
-                                               MessageUtil.info("Type '" + resolvedClassType.getName()
-                                                               + "' not woven due to exclusion via XML weaver exclude section"));
-
-                       }
-                       if (dump) {
-                               dumpUnchanged(classFile);
-                       }
-                       return null;
-               }
-
-               List<ShadowMunger> shadowMungers = fastMatch(shadowMungerList, resolvedClassType);
-               List<ConcreteTypeMunger> typeMungers = classType.getResolvedTypeX().getInterTypeMungers();
-
-               resolvedClassType.checkInterTypeMungers();
-
-               // Decide if we need to do actual weaving for this class
-               boolean mightNeedToWeave = shadowMungers.size() > 0 || typeMungers.size() > 0 || classType.isAspect()
-                               || world.getDeclareAnnotationOnMethods().size() > 0 || world.getDeclareAnnotationOnFields().size() > 0;
-
-               // May need bridge methods if on 1.5 and something in our hierarchy is
-               // affected by ITDs
-               boolean mightNeedBridgeMethods = world.isInJava5Mode() && !classType.isInterface()
-                               && resolvedClassType.getInterTypeMungersIncludingSupers().size() > 0;
-
-               LazyClassGen clazz = null;
-               if (mightNeedToWeave || mightNeedBridgeMethods) {
-                       clazz = classType.getLazyClassGen();
-                       // System.err.println("got lazy gen: " + clazz + ", " +
-                       // clazz.getWeaverState());
-                       try {
-                               boolean isChanged = false;
-
-                               if (mightNeedToWeave) {
-                                       isChanged = BcelClassWeaver.weave(world, clazz, shadowMungers, typeMungers, lateTypeMungerList,
-                                                       inReweavableMode);
-                               }
-
-                               if (mightNeedBridgeMethods) {
-                                       isChanged = BcelClassWeaver.calculateAnyRequiredBridgeMethods(world, clazz) || isChanged;
+               try {
+                       if (classType.isSynthetic()) { // Don't touch synthetic classes
+                               if (dump) {
+                                       dumpUnchanged(classFile);
                                }
-
-                               if (isChanged) {
-                                       if (dump) {
-                                               dump(classFile, clazz);
-                                       }
-                                       return clazz;
+                               return null;
+                       }
+                       ReferenceType resolvedClassType = classType.getResolvedTypeX();
+       
+                       if (world.isXmlConfigured() && world.getXmlConfiguration().excludesType(resolvedClassType)) {
+                               if (!world.getMessageHandler().isIgnoring(IMessage.INFO)) {
+                                       world.getMessageHandler().handleMessage(
+                                                       MessageUtil.info("Type '" + resolvedClassType.getName()
+                                                                       + "' not woven due to exclusion via XML weaver exclude section"));
+       
                                }
-                       } catch (RuntimeException re) {
-                               String classDebugInfo = null;
-                               try {
-                                       classDebugInfo = clazz.toLongString();
-                               } catch (Exception e) {
-                                       // recover from crash whilst producing debug string
-                                       classDebugInfo = clazz.getClassName();
+                               if (dump) {
+                                       dumpUnchanged(classFile);
                                }
-                               String messageText = "trouble in: \n" + classDebugInfo;
-                               getWorld().getMessageHandler().handleMessage(new Message(messageText, IMessage.ABORT, re, null));
-                       } catch (Error re) {
-                               String classDebugInfo = null;
+                               return null;
+                       }
+       
+                       List<ShadowMunger> shadowMungers = fastMatch(shadowMungerList, resolvedClassType);
+                       List<ConcreteTypeMunger> typeMungers = classType.getResolvedTypeX().getInterTypeMungers();
+       
+                       resolvedClassType.checkInterTypeMungers();
+       
+                       // Decide if we need to do actual weaving for this class
+                       boolean mightNeedToWeave = shadowMungers.size() > 0 || typeMungers.size() > 0 || classType.isAspect()
+                                       || world.getDeclareAnnotationOnMethods().size() > 0 || world.getDeclareAnnotationOnFields().size() > 0;
+       
+                       // May need bridge methods if on 1.5 and something in our hierarchy is
+                       // affected by ITDs
+                       boolean mightNeedBridgeMethods = world.isInJava5Mode() && !classType.isInterface()
+                                       && resolvedClassType.getInterTypeMungersIncludingSupers().size() > 0;
+       
+                       LazyClassGen clazz = null;
+                       if (mightNeedToWeave || mightNeedBridgeMethods) {
+                               clazz = classType.getLazyClassGen();
+                               // System.err.println("got lazy gen: " + clazz + ", " +
+                               // clazz.getWeaverState());
                                try {
-                                       classDebugInfo = clazz.toLongString();
-                               } catch (Exception e) {
-                                       // recover from crash whilst producing debug string
-                                       classDebugInfo = clazz.getClassName();
+                                       boolean isChanged = false;
+       
+                                       if (mightNeedToWeave) {
+                                               isChanged = BcelClassWeaver.weave(world, clazz, shadowMungers, typeMungers, lateTypeMungerList,
+                                                               inReweavableMode);
+                                       }
+       
+                                       if (mightNeedBridgeMethods) {
+                                               isChanged = BcelClassWeaver.calculateAnyRequiredBridgeMethods(world, clazz) || isChanged;
+                                       }
+       
+                                       if (isChanged) {
+                                               if (dump) {
+                                                       dump(classFile, clazz);
+                                               }
+                                               return clazz;
+                                       }
+                               } catch (RuntimeException re) {
+                                       String classDebugInfo = null;
+                                       try {
+                                               classDebugInfo = clazz.toLongString();
+                                       } catch (Exception e) {
+                                               // recover from crash whilst producing debug string
+                                               classDebugInfo = clazz.getClassName();
+                                       }
+                                       String messageText = "trouble in: \n" + classDebugInfo;
+                                       getWorld().getMessageHandler().handleMessage(new Message(messageText, IMessage.ABORT, re, null));
+                               } catch (Error re) {
+                                       String classDebugInfo = null;
+                                       try {
+                                               classDebugInfo = clazz.toLongString();
+                                       } catch (Exception e) {
+                                               // recover from crash whilst producing debug string
+                                               classDebugInfo = clazz.getClassName();
+                                       }
+                                       String messageText = "trouble in: \n" + classDebugInfo;
+                                       getWorld().getMessageHandler().handleMessage(new Message(messageText, IMessage.ABORT, re, null));
                                }
-                               String messageText = "trouble in: \n" + classDebugInfo;
-                               getWorld().getMessageHandler().handleMessage(new Message(messageText, IMessage.ABORT, re, null));
-                       }
-               }
-               world.demote();
-               // this is very odd return behavior trying to keep everyone happy
-               /*
-                * // can we remove it from the model now? we know it contains no relationship endpoints... AsmManager asm =
-                * world.getModelAsAsmManager(); if (asm != null) { IHierarchy model = asm.getHierarchy(); if (!classType.isAspect()) {
-                * 
-                * String pkgname = classType.getResolvedTypeX().getPackageName(); String tname =
-                * classType.getResolvedTypeX().getSimpleBaseName(); IProgramElement typeElement = model.findElementForType(pkgname, tname);
-                * if (typeElement != null) { Set deleted = new HashSet();
-                * deleted.add(asm.getCanonicalFilePath(typeElement.getSourceLocation().getSourceFile()));
-                * 
-                * model.updateHandleMap(deleted); IProgramElement parent = typeElement.getParent(); // parent may have children: PACKAGE
-                * DECL, IMPORT-REFEFERENCE, TYPE_DECL if (parent != null) { typeElement.getParent().removeChild(typeElement); //
-                * System.out.println("Removing " + classType.getResolvedTypeX().getName() + "? " // + ); } } } }
-                */
-               if (dump) {
-                       dumpUnchanged(classFile);
-                       return clazz;
-               } else {
-                       // ATAJ: the class was not weaved, but since it gets there early it
-                       // may have new generated inner classes
-                       // attached to it to support LTW perX aspectOf support (see
-                       // BcelPerClauseAspectAdder)
-                       // that aggressively defines the inner <aspect>$mayHaveAspect
-                       // interface.
-                       if (clazz != null && !clazz.getChildClasses(world).isEmpty()) {
+                       }
+                       // this is very odd return behavior trying to keep everyone happy
+                       /*
+                        * // can we remove it from the model now? we know it contains no relationship endpoints... AsmManager asm =
+                        * world.getModelAsAsmManager(); if (asm != null) { IHierarchy model = asm.getHierarchy(); if (!classType.isAspect()) {
+                        * 
+                        * String pkgname = classType.getResolvedTypeX().getPackageName(); String tname =
+                        * classType.getResolvedTypeX().getSimpleBaseName(); IProgramElement typeElement = model.findElementForType(pkgname, tname);
+                        * if (typeElement != null) { Set deleted = new HashSet();
+                        * deleted.add(asm.getCanonicalFilePath(typeElement.getSourceLocation().getSourceFile()));
+                        * 
+                        * model.updateHandleMap(deleted); IProgramElement parent = typeElement.getParent(); // parent may have children: PACKAGE
+                        * DECL, IMPORT-REFEFERENCE, TYPE_DECL if (parent != null) { typeElement.getParent().removeChild(typeElement); //
+                        * System.out.println("Removing " + classType.getResolvedTypeX().getName() + "? " // + ); } } } }
+                        */
+                       if (dump) {
+                               dumpUnchanged(classFile);
                                return clazz;
+                       } else {
+                               // ATAJ: the class was not weaved, but since it gets there early it
+                               // may have new generated inner classes
+                               // attached to it to support LTW perX aspectOf support (see
+                               // BcelPerClauseAspectAdder)
+                               // that aggressively defines the inner <aspect>$mayHaveAspect
+                               // interface.
+                               if (clazz != null && !clazz.getChildClasses(world).isEmpty()) {
+                                       return clazz;
+                               }
+                               return null;
                        }
-                       return null;
+               } finally {
+                       world.demote();
                }
        }