From 8dda42d0272eb4fdc157282880caf915a9e33ea1 Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Fri, 20 Oct 2017 12:35:06 -0700 Subject: [PATCH] added support to avoid weaving module-info.class --- .../org/aspectj/weaver/bcel/BcelWeaver.java | 154 ++++++++++-------- .../aspectj/weaver/bcel/UnwovenClassFile.java | 8 + 2 files changed, 92 insertions(+), 70 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java index 1a66c72b3..4306602e7 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java @@ -1035,10 +1035,12 @@ public class BcelWeaver { // repaired prior to weaving for (Iterator i = input.getClassFileIterator(); i.hasNext();) { UnwovenClassFile classFile = i.next(); - String className = classFile.getClassName(); - ResolvedType theType = world.resolve(className); - if (theType != null) { - theType.ensureConsistent(); + if (classFile.shouldBeWoven()) { + String className = classFile.getClassName(); + ResolvedType theType = world.resolve(className); + if (theType != null) { + theType.ensureConsistent(); + } } } @@ -1051,22 +1053,24 @@ public class BcelWeaver { CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_ASPECTS, ""); for (Iterator i = input.getClassFileIterator(); i.hasNext();) { UnwovenClassFile classFile = i.next(); - String className = classFile.getClassName(); - ResolvedType theType = world.resolve(className); - if (theType.isAnnotationStyleAspect()) { - BcelObjectType classType = BcelWorld.getBcelObjectType(theType); - if (classType == null) { - throw new BCException("Can't find bcel delegate for " + className + " type=" + theType.getClass()); - } - LazyClassGen clazz = classType.getLazyClassGen(); - BcelPerClauseAspectAdder selfMunger = new BcelPerClauseAspectAdder(theType, theType.getPerClause().getKind()); - selfMunger.forceMunge(clazz, true); - classType.finishedWith(); - UnwovenClassFile[] newClasses = getClassFilesFor(clazz); - for (int news = 0; news < newClasses.length; news++) { - requestor.acceptResult(newClasses[news]); + if (classFile.shouldBeWoven()) { + String className = classFile.getClassName(); + ResolvedType theType = world.resolve(className); + if (theType.isAnnotationStyleAspect()) { + BcelObjectType classType = BcelWorld.getBcelObjectType(theType); + if (classType == null) { + throw new BCException("Can't find bcel delegate for " + className + " type=" + theType.getClass()); + } + LazyClassGen clazz = classType.getLazyClassGen(); + BcelPerClauseAspectAdder selfMunger = new BcelPerClauseAspectAdder(theType, theType.getPerClause().getKind()); + selfMunger.forceMunge(clazz, true); + classType.finishedWith(); + UnwovenClassFile[] newClasses = getClassFilesFor(clazz); + for (int news = 0; news < newClasses.length; news++) { + requestor.acceptResult(newClasses[news]); + } + wovenClassNames.add(classFile.getClassName()); } - wovenClassNames.add(classFile.getClassName()); } } requestor.weaveCompleted(); @@ -1081,17 +1085,19 @@ public class BcelWeaver { // clear all state from files we'll be reweaving for (Iterator i = input.getClassFileIterator(); i.hasNext();) { UnwovenClassFile classFile = i.next(); - String className = classFile.getClassName(); - BcelObjectType classType = getClassType(className); - - // null return from getClassType() means the delegate is an eclipse - // source type - so - // there *cant* be any reweavable state... (he bravely claimed...) - if (classType != null) { - ContextToken tok = CompilationAndWeavingContext.enteringPhase( - CompilationAndWeavingContext.PROCESSING_REWEAVABLE_STATE, className); - processReweavableStateIfPresent(className, classType); - CompilationAndWeavingContext.leavingPhase(tok); + if (classFile.shouldBeWoven()) { + String className = classFile.getClassName(); + BcelObjectType classType = getClassType(className); + + // null return from getClassType() means the delegate is an eclipse + // source type - so + // there *cant* be any reweavable state... (he bravely claimed...) + if (classType != null) { + ContextToken tok = CompilationAndWeavingContext.enteringPhase( + CompilationAndWeavingContext.PROCESSING_REWEAVABLE_STATE, className); + processReweavableStateIfPresent(className, classType); + CompilationAndWeavingContext.leavingPhase(tok); + } } } @@ -1112,7 +1118,9 @@ public class BcelWeaver { List typesToProcess = new ArrayList(); for (Iterator iter = input.getClassFileIterator(); iter.hasNext();) { UnwovenClassFile clf = iter.next(); - typesToProcess.add(clf.getClassName()); + if (clf.shouldBeWoven()) { + typesToProcess.add(clf.getClassName()); + } } while (typesToProcess.size() > 0) { weaveParentsFor(typesToProcess, typesToProcess.get(0), null); @@ -1120,8 +1128,10 @@ public class BcelWeaver { for (Iterator i = input.getClassFileIterator(); i.hasNext();) { UnwovenClassFile classFile = i.next(); - String className = classFile.getClassName(); - addNormalTypeMungers(className); + if (classFile.shouldBeWoven()) { + String className = classFile.getClassName(); + addNormalTypeMungers(className); + } } CompilationAndWeavingContext.leavingPhase(typeMungingToken); @@ -1131,28 +1141,30 @@ public class BcelWeaver { // first weave into aspects for (Iterator i = input.getClassFileIterator(); i.hasNext();) { UnwovenClassFile classFile = i.next(); - String className = classFile.getClassName(); - ResolvedType theType = world.resolve(className); - if (theType.isAspect()) { - BcelObjectType classType = BcelWorld.getBcelObjectType(theType); - if (classType == null) { - - // Sometimes.. if the Bcel Delegate couldn't be found then a - // problem occurred at compile time - on - // a previous compiler run. In this case I assert the - // delegate will still be an EclipseSourceType - // and we can ignore the problem here (the original compile - // error will be reported again from - // the eclipse source type) - pr113531 - ReferenceTypeDelegate theDelegate = ((ReferenceType) theType).getDelegate(); - if (theDelegate.getClass().getName().endsWith("EclipseSourceType")) { - continue; + if (classFile.shouldBeWoven()) { + String className = classFile.getClassName(); + ResolvedType theType = world.resolve(className); + if (theType.isAspect()) { + BcelObjectType classType = BcelWorld.getBcelObjectType(theType); + if (classType == null) { + + // Sometimes.. if the Bcel Delegate couldn't be found then a + // problem occurred at compile time - on + // a previous compiler run. In this case I assert the + // delegate will still be an EclipseSourceType + // and we can ignore the problem here (the original compile + // error will be reported again from + // the eclipse source type) - pr113531 + ReferenceTypeDelegate theDelegate = ((ReferenceType) theType).getDelegate(); + if (theDelegate.getClass().getName().endsWith("EclipseSourceType")) { + continue; + } + + throw new BCException("Can't find bcel delegate for " + className + " type=" + theType.getClass()); } - - throw new BCException("Can't find bcel delegate for " + className + " type=" + theType.getClass()); + weaveAndNotify(classFile, classType, requestor); + wovenClassNames.add(className); } - weaveAndNotify(classFile, classType, requestor); - wovenClassNames.add(className); } } @@ -1163,25 +1175,27 @@ public class BcelWeaver { // then weave into non-aspects for (Iterator i = input.getClassFileIterator(); i.hasNext();) { UnwovenClassFile classFile = i.next(); - String className = classFile.getClassName(); - ResolvedType theType = world.resolve(className); - if (!theType.isAspect()) { - BcelObjectType classType = BcelWorld.getBcelObjectType(theType); - if (classType == null) { - - // bug 119882 - see above comment for bug 113531 - ReferenceTypeDelegate theDelegate = ((ReferenceType) theType).getDelegate(); - - // TODO urgh - put a method on the interface to check this, - // string compare is hideous - if (theDelegate.getClass().getName().endsWith("EclipseSourceType")) { - continue; + if (classFile.shouldBeWoven()) { + String className = classFile.getClassName(); + ResolvedType theType = world.resolve(className); + if (!theType.isAspect()) { + BcelObjectType classType = BcelWorld.getBcelObjectType(theType); + if (classType == null) { + + // bug 119882 - see above comment for bug 113531 + ReferenceTypeDelegate theDelegate = ((ReferenceType) theType).getDelegate(); + + // TODO urgh - put a method on the interface to check this, + // string compare is hideous + if (theDelegate.getClass().getName().endsWith("EclipseSourceType")) { + continue; + } + + throw new BCException("Can't find bcel delegate for " + className + " type=" + theType.getClass()); } - - throw new BCException("Can't find bcel delegate for " + className + " type=" + theType.getClass()); + weaveAndNotify(classFile, classType, requestor); + wovenClassNames.add(className); } - weaveAndNotify(classFile, classType, requestor); - wovenClassNames.add(className); } } CompilationAndWeavingContext.leavingPhase(classToken); diff --git a/weaver/src/org/aspectj/weaver/bcel/UnwovenClassFile.java b/weaver/src/org/aspectj/weaver/bcel/UnwovenClassFile.java index d02c90130..7076316f7 100644 --- a/weaver/src/org/aspectj/weaver/bcel/UnwovenClassFile.java +++ b/weaver/src/org/aspectj/weaver/bcel/UnwovenClassFile.java @@ -30,19 +30,27 @@ public class UnwovenClassFile implements IUnwovenClassFile { // protected byte[] writtenBytes = null; protected List writtenChildClasses = Collections.emptyList(); protected String className = null; + protected boolean isModule = false; public UnwovenClassFile(String filename, byte[] bytes) { this.filename = filename; + this.isModule = filename.toLowerCase().endsWith("module-info.java"); this.bytes = bytes; } /** Use if the classname is known, saves a bytecode parse */ public UnwovenClassFile(String filename, String classname, byte[] bytes) { this.filename = filename; + this.isModule = filename.toLowerCase().endsWith("module-info.class"); this.className = classname; this.bytes = bytes; } + public boolean shouldBeWoven() { + // Skip module-info files for now, they aren't really types + return !isModule; + } + public String getFilename() { return filename; } -- 2.39.5