From 5498d0a84762c437b6bff443d6cc1e1e5c914dce Mon Sep 17 00:00:00 2001 From: aclement Date: Thu, 28 Aug 2008 02:28:48 +0000 Subject: [PATCH] formatter chewed on it --- .../ajdt/internal/compiler/WeaverAdapter.java | 160 +++++++++--------- 1 file changed, 83 insertions(+), 77 deletions(-) diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/WeaverAdapter.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/WeaverAdapter.java index 6d1e267d6..485d18eec 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/WeaverAdapter.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/WeaverAdapter.java @@ -24,13 +24,11 @@ import org.aspectj.weaver.bcel.UnwovenClassFile; import org.eclipse.core.runtime.OperationCanceledException; /** - * @author colyer - * This class provides the weaver with a source of class files to weave (via the - * iterator and IClassFileProvider interfaces). It receives results back from the - * weaver via the IWeaveRequestor interface. + * @author colyer This class provides the weaver with a source of class files to weave (via the iterator and IClassFileProvider + * interfaces). It receives results back from the weaver via the IWeaveRequestor interface. */ public class WeaverAdapter implements IClassFileProvider, IWeaveRequestor, Iterator { - + private AbstractCompilerAdapter compilerAdapter; private Iterator resultIterator; private int classFileIndex = 0; @@ -40,7 +38,7 @@ public class WeaverAdapter implements IClassFileProvider, IWeaveRequestor, Itera private IProgressListener progressListener; private boolean finalPhase = false; private int localIteratorCounter; - + // Fields related to progress monitoring private int progressMaxTypes; private String progressPhasePrefix; @@ -48,16 +46,16 @@ public class WeaverAdapter implements IClassFileProvider, IWeaveRequestor, Itera private double toPercent = 100.0; private int progressCompletionCount; - - public WeaverAdapter(AbstractCompilerAdapter forCompiler, - WeaverMessageHandler weaverMessageHandler, - IProgressListener progressListener) { + public WeaverAdapter(AbstractCompilerAdapter forCompiler, WeaverMessageHandler weaverMessageHandler, + IProgressListener progressListener) { this.compilerAdapter = forCompiler; this.weaverMessageHandler = weaverMessageHandler; this.progressListener = progressListener; } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.aspectj.weaver.IClassFileProvider#getClassFileIterator() */ public Iterator getClassFileIterator() { @@ -68,51 +66,64 @@ public class WeaverAdapter implements IClassFileProvider, IWeaveRequestor, Itera resultIterator = compilerAdapter.getResultsPendingWeave().iterator(); return this; } - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.aspectj.weaver.IClassFileProvider#getRequestor() */ public IWeaveRequestor getRequestor() { return this; } - public boolean isApplyAtAspectJMungersOnly() { - return false; - } + public boolean isApplyAtAspectJMungersOnly() { + return false; + } - // Iteration + // Iteration // ================================================================ - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see java.util.Iterator#hasNext() */ public boolean hasNext() { if (nowProcessing == null) { - if (!resultIterator.hasNext()) return false; + if (!resultIterator.hasNext()) + return false; nowProcessing = (InterimCompilationResult) resultIterator.next(); classFileIndex = 0; } - while (nowProcessing.unwovenClassFiles().length == 0 ) { - if (!resultIterator.hasNext()) return false; + while (nowProcessing.unwovenClassFiles().length == 0) { + if (!resultIterator.hasNext()) + return false; nowProcessing = (InterimCompilationResult) resultIterator.next(); } if (classFileIndex < nowProcessing.unwovenClassFiles().length) { return true; } else { classFileIndex = 0; - if (!resultIterator.hasNext()) return false; + if (!resultIterator.hasNext()) + return false; nowProcessing = (InterimCompilationResult) resultIterator.next(); - while (nowProcessing.unwovenClassFiles().length == 0 ) { - if (!resultIterator.hasNext()) return false; + while (nowProcessing.unwovenClassFiles().length == 0) { + if (!resultIterator.hasNext()) + return false; nowProcessing = (InterimCompilationResult) resultIterator.next(); - } + } } return true; } - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see java.util.Iterator#next() */ public Object next() { - if (!hasNext()) return null; // sets up indices correctly + if (!hasNext()) + return null; // sets up indices correctly if (finalPhase) { if ((lastReturnedResult != null) && (lastReturnedResult != nowProcessing)) { // we're done with the lastReturnedResult @@ -125,107 +136,108 @@ public class WeaverAdapter implements IClassFileProvider, IWeaveRequestor, Itera // weaverMessageHandler.handleMessage(new Message("weaving " + nowProcessing.fileName(),IMessage.INFO, null, null)); return nowProcessing.unwovenClassFiles()[classFileIndex++]; } - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see java.util.Iterator#remove() */ public void remove() { throw new UnsupportedOperationException(); } - // IWeaveRequestor // ===================================================================================== // weave phases as indicated by bcelWeaver... public void processingReweavableState() { - + // progress reporting logic fromPercent = 50.0; // Assume weaving takes 50% of the progress bar... - // recordProgress("processing reweavable state"); + // recordProgress("processing reweavable state"); } - + public void addingTypeMungers() { - + // progress reporting logic - // At this point we have completed one iteration through all the classes/aspects + // At this point we have completed one iteration through all the classes/aspects // we'll be dealing with, so let us remember this max value for localIteratorCounter // (for accurate progress reporting) // recordProgress("adding type mungers"); progressMaxTypes = localIteratorCounter; } - + public void weavingAspects() { - + // progress reporting logic - progressPhasePrefix="woven aspect "; - progressCompletionCount=0; // Start counting from *now* + progressPhasePrefix = "woven aspect "; + progressCompletionCount = 0; // Start counting from *now* } - + public void weavingClasses() { finalPhase = true; - + // progress reporting logic - progressPhasePrefix="woven class "; + progressPhasePrefix = "woven class "; } - + public void weaveCompleted() { if ((lastReturnedResult != null) && (!lastReturnedResult.result().hasBeenAccepted)) { finishedWith(lastReturnedResult); } - lastReturnedResult=null; + lastReturnedResult = null; } - - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.aspectj.weaver.IWeaveRequestor#acceptResult(org.aspectj.weaver.bcel.UnwovenClassFile) */ public void acceptResult(UnwovenClassFile result) { char[] key = result.getClassNameAsChars(); removeFromMap(lastReturnedResult.result().compiledTypes, key); AjClassFile ajcf = new AjClassFile(key, result.getBytes()); - lastReturnedResult.result().record(ajcf.fileName(),ajcf); - if (!weaverMessageHandler.isIgnoring(IMessage.INFO) || progressListener!=null) { - StringBuffer msg = new StringBuffer(); - msg.append(progressPhasePrefix).append(result.getClassName()).append(" (from ").append(nowProcessing.fileName()).append(")"); - weaverMessageHandler.handleMessage(MessageUtil.info(msg.toString())); + lastReturnedResult.result().record(ajcf.fileName(), ajcf); + if (!weaverMessageHandler.isIgnoring(IMessage.INFO) || progressListener != null) { + StringBuffer msg = new StringBuffer(); + msg.append(progressPhasePrefix).append(result.getClassName()).append(" (from ").append(nowProcessing.fileName()) + .append(")"); + weaverMessageHandler.handleMessage(MessageUtil.info(msg.toString())); if (progressListener != null) { progressCompletionCount++; - + // Smoothly take progress from 'fromPercent' to 'toPercent' - recordProgress( - fromPercent - +((progressCompletionCount/(double)progressMaxTypes)*(toPercent-fromPercent)), - msg.toString()); - // progressPhasePrefix+result.getClassName()+" (from "+nowProcessing.fileName()+")"); - + recordProgress(fromPercent + ((progressCompletionCount / (double) progressMaxTypes) * (toPercent - fromPercent)), + msg.toString()); + // progressPhasePrefix+result.getClassName()+" (from "+nowProcessing.fileName()+")"); + if (progressListener.isCancelledRequested()) { - throw new AbortCompilation(true,new OperationCanceledException("Weaving cancelled as requested")); + throw new AbortCompilation(true, new OperationCanceledException("Weaving cancelled as requested")); } } - } + } } // helpers... // ================================================================= - + private void finishedWith(InterimCompilationResult result) { compilerAdapter.acceptResult(result.result()); } - + private boolean removeFromMap(Map aMap, char[] key) { // jdt uses char[] as a key in the hashtable, which is not very useful as equality is based on being // the same array, not having the same content. -// String skey = new String(key); + // String skey = new String(key); // OPTIMIZE what is this code for? - if (aMap.remove(key)!=null) { + if (aMap.remove(key) != null) { return true; } char[] victim = null; for (Iterator iter = aMap.keySet().iterator(); iter.hasNext();) { char[] thisKey = (char[]) iter.next(); - if (CharOperation.equals(thisKey,key)) { -// if (skey.equals(new String(thisKey))) { + if (CharOperation.equals(thisKey, key)) { + // if (skey.equals(new String(thisKey))) { victim = thisKey; break; } @@ -236,16 +248,10 @@ public class WeaverAdapter implements IClassFileProvider, IWeaveRequestor, Itera } return false; } - - private void recordProgress(String message) { - if (progressListener!=null) { - progressListener.setText(message); - } - } - - private void recordProgress(double percentage,String message) { - if (progressListener!=null) { - progressListener.setProgress(percentage/100); + + private void recordProgress(double percentage, String message) { + if (progressListener != null) { + progressListener.setProgress(percentage / 100); progressListener.setText(message); } } -- 2.39.5