From c236b590dc9716e1d578e4e43c5b0c1b8a7518de Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 3 Oct 2008 23:29:58 +0000 Subject: [PATCH] finally blocks to close zips/streams --- .../org/aspectj/weaver/bcel/BcelWeaver.java | 660 ++++++------------ 1 file changed, 228 insertions(+), 432 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java index e70694256..86f37053f 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java @@ -99,13 +99,12 @@ public class BcelWeaver { public static final String SYNTHETIC_CLASS_POSTFIX = "$ajc"; - private BcelWorld world; - private CrosscuttingMembersSet xcutSet; + private final BcelWorld world; + private final CrosscuttingMembersSet xcutSet; private boolean inReweavableMode = false; - private static Trace trace = TraceFactory.getTraceFactory().getTrace( - BcelWeaver.class); + private static Trace trace = TraceFactory.getTraceFactory().getTrace(BcelWeaver.class); public BcelWeaver(BcelWorld world) { super(); @@ -143,8 +142,7 @@ public class BcelWeaver { } /** - * Add the given aspect to the weaver. The type is resolved to support DOT - * for static inner classes as well as DOLLAR + * Add the given aspect to the weaver. The type is resolved to support DOT for static inner classes as well as DOLLAR * * @param aspectName * @return aspect @@ -185,15 +183,13 @@ public class BcelWeaver { if (wsi != null && wsi.isReweavable()) { BcelObjectType classType = getClassType(type.getName()); JavaClass wovenJavaClass = classType.getJavaClass(); - JavaClass unwovenJavaClass = Utility.makeJavaClass( - wovenJavaClass.getFileName(), wsi - .getUnwovenClassFileData(wovenJavaClass - .getBytes())); + JavaClass unwovenJavaClass = Utility.makeJavaClass(wovenJavaClass.getFileName(), wsi + .getUnwovenClassFileData(wovenJavaClass.getBytes())); world.storeClass(unwovenJavaClass); classType.setJavaClass(unwovenJavaClass); // classType.setJavaClass(Utility.makeJavaClass(classType. // getJavaClass().getFileName(), - //wsi.getUnwovenClassFileData(classType.getJavaClass().getBytes( + // wsi.getUnwovenClassFileData(classType.getJavaClass().getBytes( // )))); } @@ -219,9 +215,7 @@ public class BcelWeaver { return type; } else { // FIXME AV - better warning upon no such aspect from aop.xml - RuntimeException ex = new RuntimeException( - "Cannot register non aspect: " + type.getName() + " , " - + aspectName); + RuntimeException ex = new RuntimeException("Cannot register non aspect: " + type.getName() + " , " + aspectName); if (trace.isTraceEnabled()) trace.exit("addLibraryAspect", ex); throw ex; @@ -230,8 +224,7 @@ public class BcelWeaver { /** * - * @param inFile - * File path to class directory or zip/jar class archive + * @param inFile File path to class directory or zip/jar class archive * @throws IOException */ public void addLibraryJarFile(File inFile) throws IOException { @@ -248,41 +241,38 @@ public class BcelWeaver { } } - private List addAspectsFromJarFile(File inFile) - throws FileNotFoundException, IOException { - ZipInputStream inStream = new ZipInputStream( - new FileInputStream(inFile)); // ??? buffered + private List addAspectsFromJarFile(File inFile) throws FileNotFoundException, IOException { + ZipInputStream inStream = new ZipInputStream(new FileInputStream(inFile)); // ??? buffered List addedAspects = new ArrayList(); - while (true) { - ZipEntry entry = inStream.getNextEntry(); - if (entry == null) - break; + try { + while (true) { + ZipEntry entry = inStream.getNextEntry(); + if (entry == null) + break; - if (entry.isDirectory() || !entry.getName().endsWith(".class")) { - continue; - } + if (entry.isDirectory() || !entry.getName().endsWith(".class")) { + continue; + } - // FIXME ASC performance? of this alternative soln. - ClassParser parser = new ClassParser(new ByteArrayInputStream( - FileUtil.readAsByteArray(inStream)), entry.getName()); - JavaClass jc = parser.parse(); - inStream.closeEntry(); + // FIXME ASC performance? of this alternative soln. + ClassParser parser = new ClassParser(new ByteArrayInputStream(FileUtil.readAsByteArray(inStream)), entry.getName()); + JavaClass jc = parser.parse(); + inStream.closeEntry(); - ResolvedType type = world.addSourceObjectType(jc) - .getResolvedTypeX(); - type.setBinaryPath(inFile.getAbsolutePath()); - if (type.isAspect()) { - addedAspects.add(type); - } + ResolvedType type = world.addSourceObjectType(jc).getResolvedTypeX(); + type.setBinaryPath(inFile.getAbsolutePath()); + if (type.isAspect()) { + addedAspects.add(type); + } + } + } finally { + inStream.close(); } - - inStream.close(); return addedAspects; } - private List addAspectsFromDirectory(File dir) - throws FileNotFoundException, IOException { + private List addAspectsFromDirectory(File dir) throws FileNotFoundException, IOException { List addedAspects = new ArrayList(); File[] classFiles = FileUtil.listFiles(dir, new FileFilter() { @@ -294,17 +284,14 @@ public class BcelWeaver { for (int i = 0; i < classFiles.length; i++) { FileInputStream fis = new FileInputStream(classFiles[i]); byte[] bytes = FileUtil.readAsByteArray(fis); - addIfAspect(bytes, classFiles[i].getAbsolutePath(), addedAspects, - dir); + addIfAspect(bytes, classFiles[i].getAbsolutePath(), addedAspects, dir); fis.close(); } return addedAspects; } - private void addIfAspect(byte[] bytes, String name, List toList, File dir) - throws IOException { - ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes), - name); + private void addIfAspect(byte[] bytes, String name, List toList, File dir) throws IOException { + ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes), name); JavaClass jc = parser.parse(); ResolvedType type = world.addSourceObjectType(jc).getResolvedTypeX(); String typeName = type.getName().replace('.', File.separatorChar); @@ -329,13 +316,11 @@ public class BcelWeaver { // CopyResourcesFromInpathDirectoriesToOutput=false; /** - * Add any .class files in the directory to the outdir. Anything other than - * .class files in the directory (or its subdirectories) are considered - * resources and are also copied. + * Add any .class files in the directory to the outdir. Anything other than .class files in the directory (or its + * subdirectories) are considered resources and are also copied. * */ - public List addDirectoryContents(File inFile, File outDir) - throws IOException { + public List addDirectoryContents(File inFile, File outDir) throws IOException { List addedClassFiles = new ArrayList(); // Get a list of all files (i.e. everything that isnt a directory) @@ -370,42 +355,43 @@ public class BcelWeaver { } else { inJar = new JarFile(inFile); - addManifest(inJar.getManifest()); - Enumeration entries = inJar.entries(); - - while (entries.hasMoreElements()) { - JarEntry entry = (JarEntry) entries.nextElement(); - InputStream inStream = inJar.getInputStream(entry); - - byte[] bytes = FileUtil.readAsByteArray(inStream); - String filename = entry.getName(); - // System.out.println("? addJarFile() filename='" + filename - // + "'"); - UnwovenClassFile classFile = new UnwovenClassFile(new File( - outDir, filename).getAbsolutePath(), bytes); - - if (filename.endsWith(".class")) { - this.addClassFile(classFile); - addedClassFiles.add(classFile); - } - // else if (!entry.isDirectory()) { - // - // /* bug-44190 Copy meta-data */ - // addResource(filename,classFile); - // } + try { + addManifest(inJar.getManifest()); + Enumeration entries = inJar.entries(); + + while (entries.hasMoreElements()) { + JarEntry entry = (JarEntry) entries.nextElement(); + InputStream inStream = inJar.getInputStream(entry); + + byte[] bytes = FileUtil.readAsByteArray(inStream); + String filename = entry.getName(); + // System.out.println("? addJarFile() filename='" + filename + // + "'"); + UnwovenClassFile classFile = new UnwovenClassFile(new File(outDir, filename).getAbsolutePath(), bytes); + + if (filename.endsWith(".class")) { + this.addClassFile(classFile); + addedClassFiles.add(classFile); + } + // else if (!entry.isDirectory()) { + // + // /* bug-44190 Copy meta-data */ + // addResource(filename,classFile); + // } - inStream.close(); + inStream.close(); + } + } finally { + inJar.close(); } inJar.close(); } } catch (FileNotFoundException ex) { - IMessage message = new Message("Could not find input jar file " - + inFile.getPath() + ", ignoring", new SourceLocation( + IMessage message = new Message("Could not find input jar file " + inFile.getPath() + ", ignoring", new SourceLocation( inFile, 0), false); world.getMessageHandler().handleMessage(message); } catch (IOException ex) { - IMessage message = new Message("Could not read input jar file " - + inFile.getPath() + "(" + ex.getMessage() + ")", + IMessage message = new Message("Could not read input jar file " + inFile.getPath() + "(" + ex.getMessage() + ")", new SourceLocation(inFile, 0), true); world.getMessageHandler().handleMessage(message); } finally { @@ -413,10 +399,8 @@ public class BcelWeaver { try { inJar.close(); } catch (IOException ex) { - IMessage message = new Message( - "Could not close input jar file " - + inFile.getPath() + "(" + ex.getMessage() - + ")", new SourceLocation(inFile, 0), true); + IMessage message = new Message("Could not close input jar file " + inFile.getPath() + "(" + ex.getMessage() + + ")", new SourceLocation(inFile, 0), true); world.getMessageHandler().handleMessage(message); } } @@ -460,8 +444,7 @@ public class BcelWeaver { world.addSourceObjectType(classFile.getJavaClass()); } - public UnwovenClassFile addClassFile(File classFile, File inPathDir, - File outDir) throws IOException { + public UnwovenClassFile addClassFile(File classFile, File inPathDir, File outDir) throws IOException { FileInputStream fis = new FileInputStream(classFile); byte[] bytes = FileUtil.readAsByteArray(fis); // String relativePath = files[i].getPath(); @@ -469,10 +452,8 @@ public class BcelWeaver { // ASSERT: // files[i].getAbsolutePath().startsWith(inFile.getAbsolutePath() // or we are in trouble... - String filename = classFile.getAbsolutePath().substring( - inPathDir.getAbsolutePath().length() + 1); - UnwovenClassFile ucf = new UnwovenClassFile(new File(outDir, filename) - .getAbsolutePath(), bytes); + String filename = classFile.getAbsolutePath().substring(inPathDir.getAbsolutePath().length() + 1); + UnwovenClassFile ucf = new UnwovenClassFile(new File(outDir, filename).getAbsolutePath(), bytes); if (filename.endsWith(".class")) { // System.err.println( // "BCELWeaver: processing class from input directory "+classFile); @@ -566,14 +547,12 @@ public class BcelWeaver { if (sm2.getSourceLocation() == null) return -1; - return (sm2.getSourceLocation().getOffset() - sm1 - .getSourceLocation().getOffset()); + return (sm2.getSourceLocation().getOffset() - sm1.getSourceLocation().getOffset()); } }); if (inReweavableMode) - world.showMessage(IMessage.INFO, WeaverMessages - .format(WeaverMessages.REWEAVABLE_MODE), null, null); + world.showMessage(IMessage.INFO, WeaverMessages.format(WeaverMessages.REWEAVABLE_MODE), null, null); if (trace.isTraceEnabled()) trace.exit("prepareForWeave"); @@ -586,13 +565,11 @@ public class BcelWeaver { String name = jc.getClassName(); ResolvedType type = world.resolve(name); if (type.isAspect()) { - Collection/* ShadowMunger */shadowMungers = customMungerFactory - .createCustomShadowMungers(type); + Collection/* ShadowMunger */shadowMungers = customMungerFactory.createCustomShadowMungers(type); if (shadowMungers != null) { shadowMungerList.addAll(shadowMungers); } - Collection/* ConcreteTypeMunger */typeMungers = customMungerFactory - .createCustomTypeMungers(type); + Collection/* ConcreteTypeMunger */typeMungers = customMungerFactory.createCustomTypeMungers(type); if (typeMungers != null) typeMungerList.addAll(typeMungers); } @@ -605,13 +582,10 @@ public class BcelWeaver { } /* - * Rewrite all of the pointcuts in the world into their most efficient form - * for subsequent matching. Also ensure that if pc1.equals(pc2) then pc1 == - * pc2 (for non-binding pcds) by making references all point to the same - * instance. Since pointcuts remember their match decision on the last - * shadow, this makes matching faster when many pointcuts share common - * elements, or even when one single pointcut has one common element (which - * can be a side-effect of DNF rewriting). + * Rewrite all of the pointcuts in the world into their most efficient form for subsequent matching. Also ensure that if + * pc1.equals(pc2) then pc1 == pc2 (for non-binding pcds) by making references all point to the same instance. Since pointcuts + * remember their match decision on the last shadow, this makes matching faster when many pointcuts share common elements, or + * even when one single pointcut has one common element (which can be a side-effect of DNF rewriting). */ private void rewritePointcuts(List/* ShadowMunger */shadowMungers) { PointcutRewriter rewriter = new PointcutRewriter(); @@ -632,15 +606,12 @@ public class BcelWeaver { // an @AJ aspect (it could have been inherited from a code // style aspect) then // evaluate the alternative set of formals. pr125699 - if (advice.getConcreteAspect().isAnnotationStyleAspect() - && advice.getDeclaringAspect() != null - && advice.getDeclaringAspect().resolve(world) - .isAnnotationStyleAspect()) { + if (advice.getConcreteAspect().isAnnotationStyleAspect() && advice.getDeclaringAspect() != null + && advice.getDeclaringAspect().resolve(world).isAnnotationStyleAspect()) { numFormals = advice.getBaseParameterCount(); int numArgs = advice.getSignature().getParameterTypes().length; if (numFormals > 0) { - names = advice.getSignature().getParameterNames( - world); + names = advice.getSignature().getParameterNames(world); validateBindings(newP, p, numArgs, names); } } else { @@ -707,8 +678,7 @@ public class BcelWeaver { // in addition, the left and right branches of a disjunction must hold on // join point kinds in // common. - private void validateBindings(Pointcut dnfPointcut, Pointcut userPointcut, - int numFormals, String[] names) { + private void validateBindings(Pointcut dnfPointcut, Pointcut userPointcut, int numFormals, String[] names) { if (numFormals == 0) return; // nothing to check if (dnfPointcut.couldMatchKinds() == Shadow.NO_SHADOW_KINDS_BITS) @@ -717,41 +687,33 @@ public class BcelWeaver { OrPointcut orBasedDNFPointcut = (OrPointcut) dnfPointcut; Pointcut[] leftBindings = new Pointcut[numFormals]; Pointcut[] rightBindings = new Pointcut[numFormals]; - validateOrBranch(orBasedDNFPointcut, userPointcut, numFormals, - names, leftBindings, rightBindings); + validateOrBranch(orBasedDNFPointcut, userPointcut, numFormals, names, leftBindings, rightBindings); } else { Pointcut[] bindings = new Pointcut[numFormals]; - validateSingleBranch(dnfPointcut, userPointcut, numFormals, names, - bindings); + validateSingleBranch(dnfPointcut, userPointcut, numFormals, names, bindings); } } - private void validateOrBranch(OrPointcut pc, Pointcut userPointcut, - int numFormals, String[] names, Pointcut[] leftBindings, + private void validateOrBranch(OrPointcut pc, Pointcut userPointcut, int numFormals, String[] names, Pointcut[] leftBindings, Pointcut[] rightBindings) { Pointcut left = pc.getLeft(); Pointcut right = pc.getRight(); if (left instanceof OrPointcut) { Pointcut[] newRightBindings = new Pointcut[numFormals]; - validateOrBranch((OrPointcut) left, userPointcut, numFormals, - names, leftBindings, newRightBindings); + validateOrBranch((OrPointcut) left, userPointcut, numFormals, names, leftBindings, newRightBindings); } else { if (left.couldMatchKinds() != Shadow.NO_SHADOW_KINDS_BITS) - validateSingleBranch(left, userPointcut, numFormals, names, - leftBindings); + validateSingleBranch(left, userPointcut, numFormals, names, leftBindings); } if (right instanceof OrPointcut) { Pointcut[] newLeftBindings = new Pointcut[numFormals]; - validateOrBranch((OrPointcut) right, userPointcut, numFormals, - names, newLeftBindings, rightBindings); + validateOrBranch((OrPointcut) right, userPointcut, numFormals, names, newLeftBindings, rightBindings); } else { if (right.couldMatchKinds() != Shadow.NO_SHADOW_KINDS_BITS) - validateSingleBranch(right, userPointcut, numFormals, names, - rightBindings); + validateSingleBranch(right, userPointcut, numFormals, names, rightBindings); } int kindsInCommon = left.couldMatchKinds() & right.couldMatchKinds(); - if (kindsInCommon != Shadow.NO_SHADOW_KINDS_BITS - && couldEverMatchSameJoinPoints(left, right)) { + if (kindsInCommon != Shadow.NO_SHADOW_KINDS_BITS && couldEverMatchSameJoinPoints(left, right)) { // we know that every branch binds every formal, so there is no // ambiguity // if each branch binds it in exactly the same way... @@ -773,23 +735,19 @@ public class BcelWeaver { // pc is a pointcut that does not contain any disjunctions // check that every formal is bound (negation doesn't count). // we know that numFormals > 0 or else we would not be called - private void validateSingleBranch(Pointcut pc, Pointcut userPointcut, - int numFormals, String[] names, Pointcut[] bindings) { + private void validateSingleBranch(Pointcut pc, Pointcut userPointcut, int numFormals, String[] names, Pointcut[] bindings) { boolean[] foundFormals = new boolean[numFormals]; for (int i = 0; i < foundFormals.length; i++) { foundFormals[i] = false; } - validateSingleBranchRecursion(pc, userPointcut, foundFormals, names, - bindings); + validateSingleBranchRecursion(pc, userPointcut, foundFormals, names, bindings); for (int i = 0; i < foundFormals.length; i++) { if (!foundFormals[i]) { boolean ignore = false; // ATAJ soften the unbound error for implicit bindings like // JoinPoint in @AJ style for (int j = 0; j < userPointcut.m_ignoreUnboundBindingForNames.length; j++) { - if (names[i] != null - && names[i] - .equals(userPointcut.m_ignoreUnboundBindingForNames[j])) { + if (names[i] != null && names[i].equals(userPointcut.m_ignoreUnboundBindingForNames[j])) { ignore = true; break; } @@ -802,28 +760,22 @@ public class BcelWeaver { } // each formal must appear exactly once - private void validateSingleBranchRecursion(Pointcut pc, - Pointcut userPointcut, boolean[] foundFormals, String[] names, + private void validateSingleBranchRecursion(Pointcut pc, Pointcut userPointcut, boolean[] foundFormals, String[] names, Pointcut[] bindings) { if (pc instanceof NotPointcut) { // nots can only appear at leaves in DNF NotPointcut not = (NotPointcut) pc; if (not.getNegatedPointcut() instanceof NameBindingPointcut) { - NameBindingPointcut nnbp = (NameBindingPointcut) not - .getNegatedPointcut(); - if (!nnbp.getBindingAnnotationTypePatterns().isEmpty() - && !nnbp.getBindingTypePatterns().isEmpty()) + NameBindingPointcut nnbp = (NameBindingPointcut) not.getNegatedPointcut(); + if (!nnbp.getBindingAnnotationTypePatterns().isEmpty() && !nnbp.getBindingTypePatterns().isEmpty()) raiseNegationBindingError(userPointcut); } } else if (pc instanceof AndPointcut) { AndPointcut and = (AndPointcut) pc; - validateSingleBranchRecursion(and.getLeft(), userPointcut, - foundFormals, names, bindings); - validateSingleBranchRecursion(and.getRight(), userPointcut, - foundFormals, names, bindings); + validateSingleBranchRecursion(and.getLeft(), userPointcut, foundFormals, names, bindings); + validateSingleBranchRecursion(and.getRight(), userPointcut, foundFormals, names, bindings); } else if (pc instanceof NameBindingPointcut) { - List/* BindingTypePattern */btps = ((NameBindingPointcut) pc) - .getBindingTypePatterns(); + List/* BindingTypePattern */btps = ((NameBindingPointcut) pc).getBindingTypePatterns(); for (Iterator iter = btps.iterator(); iter.hasNext();) { BindingTypePattern btp = (BindingTypePattern) iter.next(); int index = btp.getFormalIndex(); @@ -834,8 +786,7 @@ public class BcelWeaver { foundFormals[index] = true; } } - List/* BindingPattern */baps = ((NameBindingPointcut) pc) - .getBindingAnnotationTypePatterns(); + List/* BindingPattern */baps = ((NameBindingPointcut) pc).getBindingAnnotationTypePatterns(); for (Iterator iter = baps.iterator(); iter.hasNext();) { BindingPattern bap = (BindingPattern) iter.next(); int index = bap.getFormalIndex(); @@ -886,19 +837,15 @@ public class BcelWeaver { } // look for withins - WithinPointcut leftWithin = (WithinPointcut) findFirstPointcutIn(left, - WithinPointcut.class); - WithinPointcut rightWithin = (WithinPointcut) findFirstPointcutIn( - right, WithinPointcut.class); + WithinPointcut leftWithin = (WithinPointcut) findFirstPointcutIn(left, WithinPointcut.class); + WithinPointcut rightWithin = (WithinPointcut) findFirstPointcutIn(right, WithinPointcut.class); if ((leftWithin != null) && (rightWithin != null)) { if (!leftWithin.couldEverMatchSameJoinPointsAs(rightWithin)) return false; } // look for kinded - KindedPointcut leftKind = (KindedPointcut) findFirstPointcutIn(left, - KindedPointcut.class); - KindedPointcut rightKind = (KindedPointcut) findFirstPointcutIn(right, - KindedPointcut.class); + KindedPointcut leftKind = (KindedPointcut) findFirstPointcutIn(left, KindedPointcut.class); + KindedPointcut rightKind = (KindedPointcut) findFirstPointcutIn(right, KindedPointcut.class); if ((leftKind != null) && (rightKind != null)) { if (!leftKind.couldEverMatchSameJoinPointsAs(rightKind)) return false; @@ -925,10 +872,8 @@ public class BcelWeaver { * @param userPointcut */ private void raiseNegationBindingError(Pointcut userPointcut) { - world.showMessage(IMessage.ERROR, WeaverMessages - .format(WeaverMessages.NEGATION_DOESNT_ALLOW_BINDING), - userPointcut.getSourceContext() - .makeSourceLocation(userPointcut), null); + world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.NEGATION_DOESNT_ALLOW_BINDING), userPointcut + .getSourceContext().makeSourceLocation(userPointcut), null); } /** @@ -936,25 +881,21 @@ public class BcelWeaver { * @param userPointcut */ private void raiseAmbiguousBindingError(String name, Pointcut userPointcut) { - world.showMessage(IMessage.ERROR, WeaverMessages.format( - WeaverMessages.AMBIGUOUS_BINDING, name), userPointcut + world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.AMBIGUOUS_BINDING, name), userPointcut .getSourceContext().makeSourceLocation(userPointcut), null); } /** * @param userPointcut */ - private void raiseAmbiguityInDisjunctionError(Pointcut userPointcut, - List names) { + private void raiseAmbiguityInDisjunctionError(Pointcut userPointcut, List names) { StringBuffer formalNames = new StringBuffer(names.get(0).toString()); for (int i = 1; i < names.size(); i++) { formalNames.append(", "); formalNames.append(names.get(i)); } - world.showMessage(IMessage.ERROR, WeaverMessages.format( - WeaverMessages.AMBIGUOUS_BINDING_IN_OR, formalNames), - userPointcut.getSourceContext() - .makeSourceLocation(userPointcut), null); + world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.AMBIGUOUS_BINDING_IN_OR, formalNames), userPointcut + .getSourceContext().makeSourceLocation(userPointcut), null); } /** @@ -962,8 +903,7 @@ public class BcelWeaver { * @param userPointcut */ private void raiseUnboundFormalError(String name, Pointcut userPointcut) { - world.showMessage(IMessage.ERROR, WeaverMessages.format( - WeaverMessages.UNBOUND_FORMAL, name), userPointcut + world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.UNBOUND_FORMAL, name), userPointcut .getSourceLocation(), null); } @@ -1168,8 +1108,7 @@ public class BcelWeaver { public Collection weave(IClassFileProvider input) throws IOException { if (trace.isTraceEnabled()) trace.enter("weave", this, input); - ContextToken weaveToken = CompilationAndWeavingContext.enteringPhase( - CompilationAndWeavingContext.WEAVING, ""); + ContextToken weaveToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING, ""); Collection wovenClassNames = new ArrayList(); IWeaveRequestor requestor = input.getRequestor(); @@ -1178,8 +1117,7 @@ public class BcelWeaver { if (AsmManager.isCreatingModel() && !isBatchWeave) { // remove all relationships where this file being woven is the // target of the relationship - AsmManager.getDefault().removeRelationshipsTargettingThisType( - classFile.getClassName()); + AsmManager.getDefault().removeRelationshipsTargettingThisType(classFile.getClassName()); } } @@ -1198,28 +1136,22 @@ public class BcelWeaver { // special case for AtAspectJMungerOnly - see #113587 if (input.isApplyAtAspectJMungersOnly()) { - ContextToken atAspectJMungersOnly = CompilationAndWeavingContext - .enteringPhase( - CompilationAndWeavingContext.PROCESSING_ATASPECTJTYPE_MUNGERS_ONLY, - ""); + ContextToken atAspectJMungersOnly = CompilationAndWeavingContext.enteringPhase( + CompilationAndWeavingContext.PROCESSING_ATASPECTJTYPE_MUNGERS_ONLY, ""); requestor.weavingAspects(); // ContextToken aspectToken = - CompilationAndWeavingContext.enteringPhase( - CompilationAndWeavingContext.WEAVING_ASPECTS, ""); + CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_ASPECTS, ""); for (Iterator i = input.getClassFileIterator(); i.hasNext();) { UnwovenClassFile classFile = (UnwovenClassFile) i.next(); String className = classFile.getClassName(); ResolvedType theType = world.resolve(className); if (theType.isAnnotationStyleAspect()) { - BcelObjectType classType = BcelWorld - .getBcelObjectType(theType); + BcelObjectType classType = BcelWorld.getBcelObjectType(theType); if (classType == null) { - 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()); } LazyClassGen clazz = classType.getLazyClassGen(); - BcelPerClauseAspectAdder selfMunger = new BcelPerClauseAspectAdder( - theType, theType.getPerClause().getKind()); + BcelPerClauseAspectAdder selfMunger = new BcelPerClauseAspectAdder(theType, theType.getPerClause().getKind()); selfMunger.forceMunge(clazz, true); classType.finishedWith(); UnwovenClassFile[] newClasses = getClassFilesFor(clazz); @@ -1248,10 +1180,8 @@ public class BcelWeaver { // source type - so // there *cant* be any reweavable state... (he bravely claimed...) if (classType != null) { - ContextToken tok = CompilationAndWeavingContext - .enteringPhase( - CompilationAndWeavingContext.PROCESSING_REWEAVABLE_STATE, - className); + ContextToken tok = CompilationAndWeavingContext.enteringPhase( + CompilationAndWeavingContext.PROCESSING_REWEAVABLE_STATE, className); processReweavableStateIfPresent(className, classType); CompilationAndWeavingContext.leavingPhase(tok); } @@ -1259,10 +1189,8 @@ public class BcelWeaver { CompilationAndWeavingContext.leavingPhase(reweaveToken); - ContextToken typeMungingToken = CompilationAndWeavingContext - .enteringPhase( - CompilationAndWeavingContext.PROCESSING_TYPE_MUNGERS, - ""); + ContextToken typeMungingToken = CompilationAndWeavingContext.enteringPhase( + CompilationAndWeavingContext.PROCESSING_TYPE_MUNGERS, ""); requestor.addingTypeMungers(); // We process type mungers in two groups, first mungers that change the @@ -1291,8 +1219,7 @@ public class BcelWeaver { CompilationAndWeavingContext.leavingPhase(typeMungingToken); requestor.weavingAspects(); - ContextToken aspectToken = CompilationAndWeavingContext.enteringPhase( - CompilationAndWeavingContext.WEAVING_ASPECTS, ""); + ContextToken aspectToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_ASPECTS, ""); // first weave into aspects for (Iterator i = input.getClassFileIterator(); i.hasNext();) { UnwovenClassFile classFile = (UnwovenClassFile) i.next(); @@ -1309,14 +1236,11 @@ public class BcelWeaver { // 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")) + 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); @@ -1326,8 +1250,7 @@ public class BcelWeaver { CompilationAndWeavingContext.leavingPhase(aspectToken); requestor.weavingClasses(); - ContextToken classToken = CompilationAndWeavingContext.enteringPhase( - CompilationAndWeavingContext.WEAVING_CLASSES, ""); + ContextToken classToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_CLASSES, ""); // then weave into non-aspects for (Iterator i = input.getClassFileIterator(); i.hasNext();) { UnwovenClassFile classFile = (UnwovenClassFile) i.next(); @@ -1338,17 +1261,14 @@ public class BcelWeaver { if (classType == null) { // bug 119882 - see above comment for bug 113531 - ReferenceTypeDelegate theDelegate = ((ReferenceType) theType) - .getDelegate(); + 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")) + 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); @@ -1371,14 +1291,13 @@ public class BcelWeaver { } /** - * In 1.5 mode and with XLint:adviceDidNotMatch enabled, put out messages - * for any mungers that did not match anything. + * In 1.5 mode and with XLint:adviceDidNotMatch enabled, put out messages for any mungers that did not match anything. */ private void warnOnUnmatchedAdvice() { class AdviceLocation { - private int lineNo; - private UnresolvedType inAspect; + private final int lineNo; + private final UnresolvedType inAspect; public AdviceLocation(BcelAdvice advice) { this.lineNo = advice.getSourceLocation().getLine(); @@ -1405,8 +1324,7 @@ public class BcelWeaver { // automatically for all xlint messages, ideally. // if a piece of advice hasn't matched anywhere and we are in -1.5 mode, // put out a warning - if (world.isInJava5Mode() - && world.getLint().adviceDidNotMatch.isEnabled()) { + if (world.isInJava5Mode() && world.getLint().adviceDidNotMatch.isEnabled()) { List l = world.getCrosscuttingMembersSet().getShadowMungers(); Set alreadyWarnedLocations = new HashSet(); @@ -1435,20 +1353,9 @@ public class BcelWeaver { } if (!(ba.getSignature() instanceof BcelMethod) - || !Utility.isSuppressing( - ba.getSignature(), - "adviceDidNotMatch")) { - world.getLint().adviceDidNotMatch - .signal( - ba.getDeclaringAspect() - .toString(), - new SourceLocation( - element - .getSourceLocation() - .getSourceFile(), - element - .getSourceLocation() - .getLine()));// element + || !Utility.isSuppressing(ba.getSignature(), "adviceDidNotMatch")) { + world.getLint().adviceDidNotMatch.signal(ba.getDeclaringAspect().toString(), new SourceLocation( + element.getSourceLocation().getSourceFile(), element.getSourceLocation().getLine()));// element // . // getSourceLocation // ( @@ -1464,16 +1371,13 @@ public class BcelWeaver { } /** - * 'typeToWeave' is one from the 'typesForWeaving' list. This routine - * ensures we process supertypes (classes/interfaces) of 'typeToWeave' that - * are in the 'typesForWeaving' list before 'typeToWeave' itself. - * 'typesToWeave' is then removed from the 'typesForWeaving' list. + * 'typeToWeave' is one from the 'typesForWeaving' list. This routine ensures we process supertypes (classes/interfaces) of + * 'typeToWeave' that are in the 'typesForWeaving' list before 'typeToWeave' itself. 'typesToWeave' is then removed from the + * 'typesForWeaving' list. * - * Note: Future gotcha in here ... when supplying partial hierarchies, this - * algorithm may break down. If you have a hierarchy A>B>C and only give A - * and C to the weaver, it may choose to weave them in either order - but - * you'll probably have other problems if you are supplying partial - * hierarchies like that ! + * Note: Future gotcha in here ... when supplying partial hierarchies, this algorithm may break down. If you have a hierarchy + * A>B>C and only give A and C to the weaver, it may choose to weave them in either order - but you'll probably have other + * problems if you are supplying partial hierarchies like that ! */ private void weaveParentsFor(List typesForWeaving, String typeToWeave) { // Look at the supertype first @@ -1492,9 +1396,8 @@ public class BcelWeaver { weaveParentsFor(typesForWeaving, rtxI.getName()); } } - ContextToken tok = CompilationAndWeavingContext.enteringPhase( - CompilationAndWeavingContext.PROCESSING_DECLARE_PARENTS, rtx - .getName()); + ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_DECLARE_PARENTS, rtx + .getName()); weaveParentTypeMungers(rtx); // Now do this type CompilationAndWeavingContext.leavingPhase(tok); typesForWeaving.remove(typeToWeave); // and remove it from the list of @@ -1504,39 +1407,27 @@ public class BcelWeaver { public void prepareToProcessReweavableState() { } - public void processReweavableStateIfPresent(String className, - BcelObjectType classType) { + public void processReweavableStateIfPresent(String className, BcelObjectType classType) { // If the class is marked reweavable, check any aspects around when it // was built are in this world WeaverStateInfo wsi = classType.getWeaverState(); if (wsi != null && wsi.isReweavable()) { // Check all necessary types // are around! - world.showMessage(IMessage.INFO, WeaverMessages.format( - WeaverMessages.PROCESSING_REWEAVABLE, className, classType - .getSourceLocation().getSourceFile()), null, null); + world.showMessage(IMessage.INFO, WeaverMessages.format(WeaverMessages.PROCESSING_REWEAVABLE, className, classType + .getSourceLocation().getSourceFile()), null, null); Set aspectsPreviouslyInWorld = wsi.getAspectsAffectingType(); if (aspectsPreviouslyInWorld != null) { // keep track of them just to ensure unique missing aspect error // reporting Set alreadyConfirmedReweavableState = new HashSet(); - for (Iterator iter = aspectsPreviouslyInWorld.iterator(); iter - .hasNext();) { + for (Iterator iter = aspectsPreviouslyInWorld.iterator(); iter.hasNext();) { String requiredTypeName = (String) iter.next(); - if (!alreadyConfirmedReweavableState - .contains(requiredTypeName)) { - ResolvedType rtx = world.resolve(UnresolvedType - .forName(requiredTypeName), true); + if (!alreadyConfirmedReweavableState.contains(requiredTypeName)) { + ResolvedType rtx = world.resolve(UnresolvedType.forName(requiredTypeName), true); boolean exists = !rtx.isMissing(); if (!exists) { - world - .showMessage( - IMessage.ERROR, - WeaverMessages - .format( - WeaverMessages.MISSING_REWEAVABLE_TYPE, - requiredTypeName, - className), - classType.getSourceLocation(), null); + world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.MISSING_REWEAVABLE_TYPE, + requiredTypeName, className), classType.getSourceLocation(), null); } else { // weaved in aspect that are not declared in aop.xml // trigger an error for now @@ -1544,56 +1435,32 @@ public class BcelWeaver { // without aop.xml in // see #104218 if (!xcutSet.containsAspect(rtx)) { - world - .showMessage( - IMessage.ERROR, - WeaverMessages - .format( - WeaverMessages.REWEAVABLE_ASPECT_NOT_REGISTERED, - requiredTypeName, - className), - null, null); - } else if (!world.getMessageHandler().isIgnoring( - IMessage.INFO)) - world - .showMessage( - IMessage.INFO, - WeaverMessages - .format( - WeaverMessages.VERIFIED_REWEAVABLE_TYPE, - requiredTypeName, - rtx - .getSourceLocation() - .getSourceFile()), - null, null); - alreadyConfirmedReweavableState - .add(requiredTypeName); + world.showMessage(IMessage.ERROR, WeaverMessages.format( + WeaverMessages.REWEAVABLE_ASPECT_NOT_REGISTERED, requiredTypeName, className), null, null); + } else if (!world.getMessageHandler().isIgnoring(IMessage.INFO)) + world.showMessage(IMessage.INFO, WeaverMessages.format(WeaverMessages.VERIFIED_REWEAVABLE_TYPE, + requiredTypeName, rtx.getSourceLocation().getSourceFile()), null, null); + alreadyConfirmedReweavableState.add(requiredTypeName); } } } } // old: - //classType.setJavaClass(Utility.makeJavaClass(classType.getJavaClass + // classType.setJavaClass(Utility.makeJavaClass(classType.getJavaClass // ().getFileName(), wsi.getUnwovenClassFileData())); // new: reweavable default with clever diff - classType.setJavaClass(Utility.makeJavaClass(classType - .getJavaClass().getFileName(), wsi - .getUnwovenClassFileData(classType.getJavaClass() - .getBytes()))); + classType.setJavaClass(Utility.makeJavaClass(classType.getJavaClass().getFileName(), wsi + .getUnwovenClassFileData(classType.getJavaClass().getBytes()))); // } else { // classType.resetState(); } } - private void weaveAndNotify(UnwovenClassFile classFile, - BcelObjectType classType, IWeaveRequestor requestor) - throws IOException { - trace.enter("weaveAndNotify", this, new Object[] { classFile, - classType, requestor }); + private void weaveAndNotify(UnwovenClassFile classFile, BcelObjectType classType, IWeaveRequestor requestor) throws IOException { + trace.enter("weaveAndNotify", this, new Object[] { classFile, classType, requestor }); - ContextToken tok = CompilationAndWeavingContext.enteringPhase( - CompilationAndWeavingContext.WEAVING_TYPE, classType - .getResolvedTypeX().getName()); + ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_TYPE, classType + .getResolvedTypeX().getName()); LazyClassGen clazz = weaveWithoutDump(classFile, classType); classType.finishedWith(); // clazz is null if the classfile was unchanged by weaving... @@ -1604,8 +1471,7 @@ public class BcelWeaver { // Copy the char[] across as it means the // WeaverAdapter.removeFromMap() can be fast! if (newClasses[0].getClassName().equals(classFile.getClassName())) { - newClasses[0].setClassNameAsChars(classFile - .getClassNameAsChars()); + newClasses[0].setClassNameAsChars(classFile.getClassNameAsChars()); } for (int i = 0; i < newClasses.length; i++) { requestor.acceptResult(newClasses[i]); @@ -1620,8 +1486,7 @@ public class BcelWeaver { } /** - * helper method - will return NULL if the underlying delegate is an - * EclipseSourceType and not a BcelObjectType + * helper method - will return NULL if the underlying delegate is an EclipseSourceType and not a BcelObjectType */ public BcelObjectType getClassType(String forClass) { return BcelWorld.getBcelObjectType(world.resolve(forClass)); @@ -1638,31 +1503,23 @@ public class BcelWeaver { public UnwovenClassFile[] getClassFilesFor(LazyClassGen clazz) { List childClasses = clazz.getChildClasses(world); UnwovenClassFile[] ret = new UnwovenClassFile[1 + childClasses.size()]; - ret[0] = new UnwovenClassFile(clazz.getFileName(), - clazz.getClassName(), clazz - .getJavaClassBytesIncludingReweavable(world)); + ret[0] = new UnwovenClassFile(clazz.getFileName(), clazz.getClassName(), clazz.getJavaClassBytesIncludingReweavable(world)); int index = 1; for (Iterator iter = childClasses.iterator(); iter.hasNext();) { - UnwovenClassFile.ChildClass element = (UnwovenClassFile.ChildClass) iter - .next(); - UnwovenClassFile childClass = new UnwovenClassFile(clazz - .getFileName() - + "$" + element.name, element.bytes); + UnwovenClassFile.ChildClass element = (UnwovenClassFile.ChildClass) iter.next(); + UnwovenClassFile childClass = new UnwovenClassFile(clazz.getFileName() + "$" + element.name, element.bytes); ret[index++] = childClass; } return ret; } /** - * Weaves new parents and annotations onto a type ("declare parents" and - * "declare @type") + * Weaves new parents and annotations onto a type ("declare parents" and "declare @type") * - * Algorithm: 1. First pass, do parents then do annotations. During this - * pass record: - any parent mungers that don't match but have a non-wild - * annotation type pattern - any annotation mungers that don't match 2. - * Multiple subsequent passes which go over the munger lists constructed in - * the first pass, repeatedly applying them until nothing changes. FIXME asc - * confirm that algorithm is optimal ?? + * Algorithm: 1. First pass, do parents then do annotations. During this pass record: - any parent mungers that don't match but + * have a non-wild annotation type pattern - any annotation mungers that don't match 2. Multiple subsequent passes which go over + * the munger lists constructed in the first pass, repeatedly applying them until nothing changes. FIXME asc confirm that + * algorithm is optimal ?? */ public void weaveParentTypeMungers(ResolvedType onType) { if (onType.isRawType()) @@ -1685,8 +1542,7 @@ public class BcelWeaver { } // Still first pass - apply all dec @type mungers - for (Iterator i = xcutSet.getDeclareAnnotationOnTypes().iterator(); i - .hasNext();) { + for (Iterator i = xcutSet.getDeclareAnnotationOnTypes().iterator(); i.hasNext();) { DeclareAnnotation decA = (DeclareAnnotation) i.next(); boolean typeChanged = applyDeclareAtType(decA, onType, true); if (typeChanged) { @@ -1694,8 +1550,7 @@ public class BcelWeaver { } } - while ((aParentChangeOccurred || anAnnotationChangeOccurred) - && !decpToRepeat.isEmpty()) { + while ((aParentChangeOccurred || anAnnotationChangeOccurred) && !decpToRepeat.isEmpty()) { anAnnotationChangeOccurred = aParentChangeOccurred = false; List decpToRepeatNextTime = new ArrayList(); for (Iterator iter = decpToRepeat.iterator(); iter.hasNext();) { @@ -1708,8 +1563,7 @@ public class BcelWeaver { } } - for (Iterator iter = xcutSet.getDeclareAnnotationOnTypes() - .iterator(); iter.hasNext();) { + for (Iterator iter = xcutSet.getDeclareAnnotationOnTypes().iterator(); iter.hasNext();) { DeclareAnnotation decA = (DeclareAnnotation) iter.next(); boolean typeChanged = applyDeclareAtType(decA, onType, false); if (typeChanged) { @@ -1723,8 +1577,7 @@ public class BcelWeaver { /** * Apply a declare @type - return true if we change the type */ - private boolean applyDeclareAtType(DeclareAnnotation decA, - ResolvedType onType, boolean reportProblems) { + private boolean applyDeclareAtType(DeclareAnnotation decA, ResolvedType onType, boolean reportProblems) { boolean didSomething = false; if (decA.matches(onType)) { @@ -1744,36 +1597,23 @@ public class BcelWeaver { AnnotationAJ annoX = decA.getAnnotationX(); // check the annotation is suitable for the target - boolean problemReported = verifyTargetIsOK(decA, onType, annoX, - reportProblems); + boolean problemReported = verifyTargetIsOK(decA, onType, annoX, reportProblems); if (!problemReported) { - AsmRelationshipProvider.getDefault() - .addDeclareAnnotationRelationship( - decA.getSourceLocation(), - onType.getSourceLocation()); + AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decA.getSourceLocation(), + onType.getSourceLocation()); // TAG: WeavingMessage - if (!getWorld().getMessageHandler().isIgnoring( - IMessage.WEAVEINFO)) { + if (!getWorld().getMessageHandler().isIgnoring(IMessage.WEAVEINFO)) { getWorld().getMessageHandler().handleMessage( - WeaveMessage.constructWeavingMessage( - WeaveMessage.WEAVEMESSAGE_ANNOTATES, - new String[] { - onType.toString(), - Utility.beautifyLocation(onType - .getSourceLocation()), - decA.getAnnotationString(), - "type", - decA.getAspect().toString(), - Utility.beautifyLocation(decA - .getSourceLocation()) })); + WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ANNOTATES, new String[] { + onType.toString(), Utility.beautifyLocation(onType.getSourceLocation()), + decA.getAnnotationString(), "type", decA.getAspect().toString(), + Utility.beautifyLocation(decA.getSourceLocation()) })); } didSomething = true; - ResolvedTypeMunger newAnnotationTM = new AnnotationOnTypeMunger( - annoX); + ResolvedTypeMunger newAnnotationTM = new AnnotationOnTypeMunger(annoX); newAnnotationTM.setSourceLocation(decA.getSourceLocation()); - onType.addInterTypeMunger(new BcelTypeMunger(newAnnotationTM, - decA.getAspect().resolve(world))); + onType.addInterTypeMunger(new BcelTypeMunger(newAnnotationTM, decA.getAspect().resolve(world))); decA.copyAnnotationTo(onType); } } @@ -1781,43 +1621,23 @@ public class BcelWeaver { } /** - * Checks for an @target() on the annotation and if found ensures it allows - * the annotation to be attached to the target type that matched. + * Checks for an @target() on the annotation and if found ensures it allows the annotation to be attached to the target type + * that matched. */ - private boolean verifyTargetIsOK(DeclareAnnotation decA, - ResolvedType onType, AnnotationAJ annoX, boolean outputProblems) { + private boolean verifyTargetIsOK(DeclareAnnotation decA, ResolvedType onType, AnnotationAJ annoX, boolean outputProblems) { boolean problemReported = false; if (annoX.specifiesTarget()) { - if ((onType.isAnnotation() && !annoX.allowedOnAnnotationType()) - || (!annoX.allowedOnRegularType())) { + if ((onType.isAnnotation() && !annoX.allowedOnAnnotationType()) || (!annoX.allowedOnRegularType())) { if (outputProblems) { - if (decA.isExactPattern()) { - world - .getMessageHandler() - .handleMessage( - MessageUtil - .error( - WeaverMessages - .format( - WeaverMessages.INCORRECT_TARGET_FOR_DECLARE_ANNOTATION, - onType - .getName(), - annoX - .getTypeName(), - annoX - .getValidTargets()), - decA - .getSourceLocation())); + if (decA.isExactPattern()) { + world.getMessageHandler().handleMessage( + MessageUtil.error(WeaverMessages.format(WeaverMessages.INCORRECT_TARGET_FOR_DECLARE_ANNOTATION, + onType.getName(), annoX.getTypeName(), annoX.getValidTargets()), decA.getSourceLocation())); } else { - if (world.getLint().invalidTargetForAnnotation - .isEnabled()) { - world.getLint().invalidTargetForAnnotation.signal( - new String[] { onType.getName(), - annoX.getTypeName(), - annoX.getValidTargets() }, decA - .getSourceLocation(), - new ISourceLocation[] { onType - .getSourceLocation() }); + if (world.getLint().invalidTargetForAnnotation.isEnabled()) { + world.getLint().invalidTargetForAnnotation.signal(new String[] { onType.getName(), annoX.getTypeName(), + annoX.getValidTargets() }, decA.getSourceLocation(), new ISourceLocation[] { onType + .getSourceLocation() }); } } } @@ -1847,20 +1667,17 @@ public class BcelWeaver { // (like transform super calls) - that is done in // BcelTypeMunger.mungeNewParent() classType.addParent(newParent); - ResolvedTypeMunger newParentMunger = new NewParentTypeMunger( - newParent); + ResolvedTypeMunger newParentMunger = new NewParentTypeMunger(newParent); newParentMunger.setSourceLocation(p.getSourceLocation()); - onType.addInterTypeMunger(new BcelTypeMunger(newParentMunger, - xcutSet.findAspectDeclaringParents(p))); + onType.addInterTypeMunger(new BcelTypeMunger(newParentMunger, xcutSet.findAspectDeclaringParents(p))); } } return didSomething; } public void weaveNormalTypeMungers(ResolvedType onType) { - ContextToken tok = CompilationAndWeavingContext.enteringPhase( - CompilationAndWeavingContext.PROCESSING_TYPE_MUNGERS, onType - .getName()); + ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_TYPE_MUNGERS, onType + .getName()); if (onType.isRawType() || onType.isParameterizedType()) onType = onType.getGenericType(); for (Iterator i = typeMungerList.iterator(); i.hasNext();) { @@ -1873,44 +1690,36 @@ public class BcelWeaver { } // exposed for ClassLoader dynamic weaving - public LazyClassGen weaveWithoutDump(UnwovenClassFile classFile, - BcelObjectType classType) throws IOException { + public LazyClassGen weaveWithoutDump(UnwovenClassFile classFile, BcelObjectType classType) throws IOException { return weave(classFile, classType, false); } // non-private for testing - LazyClassGen weave(UnwovenClassFile classFile, BcelObjectType classType) - throws IOException { + LazyClassGen weave(UnwovenClassFile classFile, BcelObjectType classType) throws IOException { LazyClassGen ret = weave(classFile, classType, true); return ret; } - private LazyClassGen weave(UnwovenClassFile classFile, - BcelObjectType classType, boolean dump) throws IOException { + 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; } - List shadowMungers = fastMatch(shadowMungerList, classType - .getResolvedTypeX()); + List shadowMungers = fastMatch(shadowMungerList, classType.getResolvedTypeX()); List typeMungers = classType.getResolvedTypeX().getInterTypeMungers(); classType.getResolvedTypeX().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; + 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() - && classType.getResolvedTypeX() - .getInterTypeMungersIncludingSupers().size() > 0; + boolean mightNeedBridgeMethods = world.isInJava5Mode() && !classType.isInterface() + && classType.getResolvedTypeX().getInterTypeMungersIncludingSupers().size() > 0; LazyClassGen clazz = null; if (mightNeedToWeave || mightNeedBridgeMethods) { @@ -1921,13 +1730,10 @@ public class BcelWeaver { boolean isChanged = false; if (mightNeedToWeave) - isChanged = BcelClassWeaver.weave(world, clazz, - shadowMungers, typeMungers, lateTypeMungerList); + isChanged = BcelClassWeaver.weave(world, clazz, shadowMungers, typeMungers, lateTypeMungerList); if (mightNeedBridgeMethods) - isChanged = BcelClassWeaver - .calculateAnyRequiredBridgeMethods(world, clazz) - || isChanged; + isChanged = BcelClassWeaver.calculateAnyRequiredBridgeMethods(world, clazz) || isChanged; if (isChanged) { if (dump) @@ -1943,8 +1749,7 @@ public class BcelWeaver { classDebugInfo = clazz.getClassName(); } String messageText = "trouble in: \n" + classDebugInfo; - getWorld().getMessageHandler().handleMessage( - new Message(messageText, IMessage.ABORT, re, null)); + getWorld().getMessageHandler().handleMessage(new Message(messageText, IMessage.ABORT, re, null)); } catch (Error re) { String classDebugInfo = null; try { @@ -1954,8 +1759,7 @@ public class BcelWeaver { classDebugInfo = clazz.getClassName(); } String messageText = "trouble in: \n" + classDebugInfo; - getWorld().getMessageHandler().handleMessage( - new Message(messageText, IMessage.ABORT, re, null)); + getWorld().getMessageHandler().handleMessage(new Message(messageText, IMessage.ABORT, re, null)); } } @@ -1981,9 +1785,7 @@ public class BcelWeaver { private void dumpUnchanged(UnwovenClassFile classFile) throws IOException { if (zipOutputStream != null) { - writeZipEntry( - getEntryName(classFile.getJavaClass().getClassName()), - classFile.getBytes()); + writeZipEntry(getEntryName(classFile.getJavaClass().getClassName()), classFile.getBytes()); } else { classFile.writeUnchangedBytes(); } @@ -1994,24 +1796,18 @@ public class BcelWeaver { return className.replace('.', '/') + ".class"; } - private void dump(UnwovenClassFile classFile, LazyClassGen clazz) - throws IOException { + private void dump(UnwovenClassFile classFile, LazyClassGen clazz) throws IOException { if (zipOutputStream != null) { String mainClassName = classFile.getJavaClass().getClassName(); - writeZipEntry(getEntryName(mainClassName), clazz - .getJavaClass(world).getBytes()); + writeZipEntry(getEntryName(mainClassName), clazz.getJavaClass(world).getBytes()); if (!clazz.getChildClasses(world).isEmpty()) { - for (Iterator i = clazz.getChildClasses(world).iterator(); i - .hasNext();) { - UnwovenClassFile.ChildClass c = (UnwovenClassFile.ChildClass) i - .next(); - writeZipEntry(getEntryName(mainClassName + "$" + c.name), - c.bytes); + for (Iterator i = clazz.getChildClasses(world).iterator(); i.hasNext();) { + UnwovenClassFile.ChildClass c = (UnwovenClassFile.ChildClass) i.next(); + writeZipEntry(getEntryName(mainClassName + "$" + c.name), c.bytes); } } } else { - classFile.writeWovenBytes(clazz.getJavaClass(world).getBytes(), - clazz.getChildClasses(world)); + classFile.writeWovenBytes(clazz.getJavaClass(world).getBytes(), clazz.getChildClasses(world)); } } -- 2.39.5