From dbce4ca387fec90afb2f8044cdc48d0d4682edff Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Thu, 8 Feb 2024 11:58:49 +0700 Subject: [PATCH] Factor out some anonymous IWeaveRequestor classes to inner classes Drive-by cosmetics in the context of #279. Signed-off-by: Alexander Kriegisch --- .../org/aspectj/weaver/bcel/BcelWeaver.java | 43 ++++++----- .../aspectj/weaver/tools/WeavingAdaptor.java | 72 +++++++++---------- 2 files changed, 55 insertions(+), 60 deletions(-) diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelWeaver.java index d4f47cbe7..1df4e060f 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelWeaver.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelWeaver.java @@ -972,29 +972,7 @@ public class BcelWeaver { } public IWeaveRequestor getRequestor() { - return new IWeaveRequestor() { - public void acceptResult(IUnwovenClassFile result) { - try { - writeZipEntry(result.getFilename(), result.getBytes()); - } catch (IOException ex) { - } - } - - public void processingReweavableState() { - } - - public void addingTypeMungers() { - } - - public void weavingAspects() { - } - - public void weavingClasses() { - } - - public void weaveCompleted() { - } - }; + return new WeaveRequestor(); } }); // /* BUG 40943*/ @@ -1003,6 +981,25 @@ public class BcelWeaver { return c; } + private class WeaveRequestor implements IWeaveRequestor { + public void acceptResult(IUnwovenClassFile result) { + try { + writeZipEntry(result.getFilename(), result.getBytes()); + } catch (IOException ex) { + } + } + + public void processingReweavableState() {} + + public void addingTypeMungers() {} + + public void weavingAspects() {} + + public void weavingClasses() {} + + public void weaveCompleted() {} + } + private Set candidatesForRemoval = null; // variation of "weave" that sources class files from an external source. diff --git a/weaver/src/main/java/org/aspectj/weaver/tools/WeavingAdaptor.java b/weaver/src/main/java/org/aspectj/weaver/tools/WeavingAdaptor.java index ee9c82dd8..1617cb22b 100644 --- a/weaver/src/main/java/org/aspectj/weaver/tools/WeavingAdaptor.java +++ b/weaver/src/main/java/org/aspectj/weaver/tools/WeavingAdaptor.java @@ -916,52 +916,50 @@ public class WeavingAdaptor implements IMessageContext { } public IWeaveRequestor getRequestor() { - return new IWeaveRequestor() { - - public void acceptResult(IUnwovenClassFile result) { - if (wovenClass == null) { - wovenClass = result; - String name = result.getClassName(); - if (shouldDump(name.replace('/', '.'), false)) { - dump(name, result.getBytes(), false); - } - } else { - // Classes generated by weaver e.g. around closure advice - String className = result.getClassName(); - byte[] resultBytes = result.getBytes(); - - if (SimpleCacheFactory.isEnabled()) { - SimpleCache lacache=SimpleCacheFactory.createSimpleCache(); - lacache.put(result.getClassName(), wovenClass.getBytes(), result.getBytes()); - lacache.addGeneratedClassesNames(wovenClass.getClassName(), wovenClass.getBytes(), result.getClassName()); - } + return new WeaveRequestor(); + } - generatedClasses.put(wovenClass.getClassName(), wovenClass); - generatedClassHandler.acceptClass(className, null, resultBytes); + private class WeaveRequestor implements IWeaveRequestor { + @Override + public void acceptResult(IUnwovenClassFile result) { + if (wovenClass == null) { + wovenClass = result; + String name = result.getClassName(); + if (shouldDump(name.replace('/', '.'), false)) { + dump(name, result.getBytes(), false); + } + } else { + // Classes generated by weaver e.g. around closure advice + String className = result.getClassName(); + byte[] resultBytes = result.getBytes(); + + if (SimpleCacheFactory.isEnabled()) { + SimpleCache lacache=SimpleCacheFactory.createSimpleCache(); + lacache.put(result.getClassName(), wovenClass.getBytes(), result.getBytes()); + lacache.addGeneratedClassesNames(wovenClass.getClassName(), wovenClass.getBytes(), result.getClassName()); } - } - public void processingReweavableState() { + generatedClasses.put(wovenClass.getClassName(), wovenClass); + generatedClassHandler.acceptClass(className, null, resultBytes); } + } - public void addingTypeMungers() { - } + public void processingReweavableState() {} - public void weavingAspects() { - } + public void addingTypeMungers() {} - public void weavingClasses() { - } + public void weavingAspects() {} - public void weaveCompleted() { - // ResolvedType.resetPrimitives(); - if (delegateForCurrentClass != null) { - delegateForCurrentClass.weavingCompleted(); - } - // ResolvedType.resetPrimitives(); - // bcelWorld.discardType(typeBeingProcessed.getResolvedTypeX()); // work in progress + public void weavingClasses() {} + + public void weaveCompleted() { + // ResolvedType.resetPrimitives(); + if (delegateForCurrentClass != null) { + delegateForCurrentClass.weavingCompleted(); } - }; + // ResolvedType.resetPrimitives(); + // bcelWorld.discardType(typeBeingProcessed.getResolvedTypeX()); // work in progress + } } } -- 2.39.5