From: aclement Date: Tue, 6 Jul 2010 17:18:29 +0000 (+0000) Subject: 318884: incremental: member types X-Git-Tag: V1_6_10RC1~144 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4516c307d3f40f24120a872de1ccd471fd31694c;p=aspectj.git 318884: incremental: member types --- diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java index b193f4604..ba5de1b90 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java @@ -294,8 +294,8 @@ public class BuildArgParser extends Main { return Arrays.asList(FileUtil.listFiles(dir, FileUtil.aspectjSourceFileFilter)); } - public List getBootclasspath(AjcConfigParser parser) { - List ret = new ArrayList(); + public List getBootclasspath(AjcConfigParser parser) { + List ret = new ArrayList(); if (parser.bootclasspath == null) { addClasspath(System.getProperty("sun.boot.class.path", ""), ret); @@ -358,7 +358,7 @@ public class BuildArgParser extends Main { } } - private void addClasspath(String classpath, List classpathCollector) { + private void addClasspath(String classpath, List classpathCollector) { StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator); while (tokenizer.hasMoreTokens()) { classpathCollector.add(tokenizer.nextToken()); diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java index 40ab2ebc5..baa6d722d 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java @@ -44,18 +44,18 @@ public class AjBuildConfig implements CompilerConfigurationChangeFlags { private File outputJar; private String outxmlName; private CompilationResultDestinationManager compilationResultDestinationManager = null; - private List/* File */sourceRoots = new ArrayList(); - private List/* File */changedFiles; + private List sourceRoots = new ArrayList(); + private List changedFiles; private List files = new ArrayList(); private List xmlfiles = new ArrayList(); private List binaryFiles = new ArrayList(); // .class files in indirs... - private List/* File */inJars = new ArrayList(); - private List/* File */inPath = new ArrayList(); - private Map/* String->File */sourcePathResources = new HashMap(); - private List/* File */aspectpath = new ArrayList(); - private List/* String */classpath = new ArrayList(); - private List/* String */bootclasspath = new ArrayList(); - private List/* String */cpElementsWithModifiedContents = new ArrayList(); + private List inJars = new ArrayList(); + private List inPath = new ArrayList(); + private Map sourcePathResources = new HashMap(); + private List aspectpath = new ArrayList(); + private List classpath = new ArrayList(); + private List bootclasspath = new ArrayList(); + private List cpElementsWithModifiedContents = new ArrayList(); private File configFile; private String lintMode = AJLINT_DEFAULT; @@ -164,19 +164,19 @@ public class AjBuildConfig implements CompilerConfigurationChangeFlags { /** * This does not include -bootclasspath but includes -extdirs and -classpath */ - public List getClasspath() { // XXX setters don't respect javadoc contract... + public List getClasspath() { return classpath; } - public void setClasspath(List classpath) { + public void setClasspath(List classpath) { this.classpath = classpath; } - public List getBootclasspath() { + public List getBootclasspath() { return bootclasspath; } - public void setBootclasspath(List bootclasspath) { + public void setBootclasspath(List bootclasspath) { this.bootclasspath = bootclasspath; } @@ -188,16 +188,16 @@ public class AjBuildConfig implements CompilerConfigurationChangeFlags { return outxmlName; } - public List/* File */getInpath() { + public List getInpath() { // Elements of the list are either archives (jars/zips) or directories return inPath; } - public List/* File */getInJars() { + public List getInJars() { return inJars; } - public Map getSourcePathResources() { + public Map getSourcePathResources() { return sourcePathResources; } @@ -209,11 +209,11 @@ public class AjBuildConfig implements CompilerConfigurationChangeFlags { this.outxmlName = name; } - public void setInJars(List sourceJars) { + public void setInJars(List sourceJars) { this.inJars = sourceJars; } - public void setInPath(List dirsOrJars) { + public void setInPath(List dirsOrJars) { inPath = dirsOrJars; // remember all the class files in directories on the inpath @@ -223,8 +223,8 @@ public class AjBuildConfig implements CompilerConfigurationChangeFlags { return pathname.getPath().endsWith(".class"); } }; - for (Iterator iter = dirsOrJars.iterator(); iter.hasNext();) { - File inpathElement = (File) iter.next(); + for (Iterator iter = dirsOrJars.iterator(); iter.hasNext();) { + File inpathElement = iter.next(); if (inpathElement.isDirectory()) { File[] files = FileUtil.listFiles(inpathElement, filter); for (int i = 0; i < files.length; i++) { @@ -234,11 +234,11 @@ public class AjBuildConfig implements CompilerConfigurationChangeFlags { } } - public List getSourceRoots() { + public List getSourceRoots() { return sourceRoots; } - public void setSourceRoots(List sourceRootDir) { + public void setSourceRoots(List sourceRootDir) { this.sourceRoots = sourceRootDir; } @@ -270,17 +270,17 @@ public class AjBuildConfig implements CompilerConfigurationChangeFlags { * @return List (String) classpath of bootclasspath, injars, inpath, aspectpath entries, specified classpath (extdirs, and * classpath), and output dir or jar */ - public List getFullClasspath() { - List full = new ArrayList(); + public List getFullClasspath() { + List full = new ArrayList(); full.addAll(getBootclasspath()); // XXX Is it OK that boot classpath overrides inpath/injars/aspectpath? - for (Iterator i = inJars.iterator(); i.hasNext();) { - full.add(((File) i.next()).getAbsolutePath()); + for (Iterator i = inJars.iterator(); i.hasNext();) { + full.add((i.next()).getAbsolutePath()); } - for (Iterator i = inPath.iterator(); i.hasNext();) { - full.add(((File) i.next()).getAbsolutePath()); + for (Iterator i = inPath.iterator(); i.hasNext();) { + full.add((i.next()).getAbsolutePath()); } - for (Iterator i = aspectpath.iterator(); i.hasNext();) { - full.add(((File) i.next()).getAbsolutePath()); + for (Iterator i = aspectpath.iterator(); i.hasNext();) { + full.add((i.next()).getAbsolutePath()); } full.addAll(getClasspath()); // if (null != outputDir) { @@ -299,11 +299,11 @@ public class AjBuildConfig implements CompilerConfigurationChangeFlags { this.lintSpecFile = lintSpecFile; } - public List getAspectpath() { + public List getAspectpath() { return aspectpath; } - public void setAspectpath(List aspectpath) { + public void setAspectpath(List aspectpath) { this.aspectpath = aspectpath; } @@ -415,6 +415,7 @@ public class AjBuildConfig implements CompilerConfigurationChangeFlags { setMakeReflectable(global.isMakeReflectable()); } + @SuppressWarnings({ "rawtypes", "unchecked" }) void join(Collection local, Collection global) { for (Iterator iter = global.iterator(); iter.hasNext();) { Object next = iter.next(); @@ -424,25 +425,7 @@ public class AjBuildConfig implements CompilerConfigurationChangeFlags { } } - /** - * Join some global options into a local set of options - globals will override locals. - * - * @param local - * @param global - */ - void join(Map local, Map global) { - for (Iterator iter = global.keySet().iterator(); iter.hasNext();) { - Object key = iter.next(); - // if (override || (null == local.get(key))) { // - Object value = global.get(key); - if (null != value) { - local.put(key, value); - } - // } - } - } - - public void setSourcePathResources(Map map) { + public void setSourcePathResources(Map map) { sourcePathResources = map; } @@ -475,7 +458,7 @@ public class AjBuildConfig implements CompilerConfigurationChangeFlags { } if (lintValue != null) { - Map lintOptions = new HashMap(); + Map lintOptions = new HashMap(); lintOptions.put(AjCompilerOptions.OPTION_ReportInvalidAbsoluteTypeName, lintValue); lintOptions.put(AjCompilerOptions.OPTION_ReportInvalidWildcardTypeName, lintValue); lintOptions.put(AjCompilerOptions.OPTION_ReportUnresolvableMember, lintValue); @@ -692,19 +675,19 @@ public class AjBuildConfig implements CompilerConfigurationChangeFlags { return this.changes; } - public void setModifiedFiles(List projectSourceFilesChanged) { + public void setModifiedFiles(List projectSourceFilesChanged) { this.changedFiles = projectSourceFilesChanged; } - public List getModifiedFiles() { + public List getModifiedFiles() { return this.changedFiles; } - public void setClasspathElementsWithModifiedContents(List cpElementsWithModifiedContents) { + public void setClasspathElementsWithModifiedContents(List cpElementsWithModifiedContents) { this.cpElementsWithModifiedContents = cpElementsWithModifiedContents; } - public List getClasspathElementsWithModifiedContents() { + public List getClasspathElementsWithModifiedContents() { return this.cpElementsWithModifiedContents; } } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java index 5400948dd..68425ef0c 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java @@ -462,7 +462,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour if (buildConfig.getSourcePathResources() != null) { for (Iterator i = buildConfig.getSourcePathResources().keySet().iterator(); i.hasNext();) { String resource = (String) i.next(); - File from = (File) buildConfig.getSourcePathResources().get(resource); + File from = buildConfig.getSourcePathResources().get(resource); copyResourcesFromFile(from, resource, from); } } @@ -874,7 +874,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour // ??? incremental issues for (Iterator i = buildConfig.getInJars().iterator(); i.hasNext();) { File inJar = (File) i.next(); - List unwovenClasses = bcelWeaver.addJarFile(inJar, outputDir, false); + List unwovenClasses = bcelWeaver.addJarFile(inJar, outputDir, false); state.recordBinarySource(inJar.getPath(), unwovenClasses); } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjState.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjState.java index 9f3e873c4..e2bb43a9e 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjState.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjState.java @@ -14,7 +14,6 @@ package org.aspectj.ajdt.internal.core.builder; import java.io.File; -import java.io.FileFilter; import java.io.FilenameFilter; import java.io.IOException; import java.lang.ref.ReferenceQueue; @@ -46,6 +45,7 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFormatExcepti import org.aspectj.org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation; import org.aspectj.org.eclipse.jdt.internal.compiler.env.IBinaryField; import org.aspectj.org.eclipse.jdt.internal.compiler.env.IBinaryMethod; +import org.aspectj.org.eclipse.jdt.internal.compiler.env.IBinaryNestedType; import org.aspectj.org.eclipse.jdt.internal.compiler.env.IBinaryType; import org.aspectj.org.eclipse.jdt.internal.compiler.env.INameEnvironment; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; @@ -106,7 +106,7 @@ public class AjState implements CompilerConfigurationChangeFlags { private Set addedBinaryFiles; private Set deletedBinaryFiles; // For a particular build run, this set records the changes to classesFromName - public final Set deltaAddedClasses = new HashSet(); + public final Set deltaAddedClasses = new HashSet(); // --- non static, but transient state - no need to write out, DOES need reinitializing when read AjState instance reloaded @@ -121,7 +121,7 @@ public class AjState implements CompilerConfigurationChangeFlags { private AjBuildConfig buildConfig; private long lastSuccessfulFullBuildTime = -1; - private final Hashtable /* File, long */structuralChangesSinceLastFullBuild = new Hashtable(); + private final Hashtable structuralChangesSinceLastFullBuild = new Hashtable(); private long lastSuccessfulBuildTime = -1; private long currentBuildTime = -1; @@ -141,7 +141,7 @@ public class AjState implements CompilerConfigurationChangeFlags { * * Populated in noteResult and used in processDeletedFiles */ - private final Set/* */sourceFilesDefiningAspects = new HashSet(); + private final Set sourceFilesDefiningAspects = new HashSet(); /** * Populated in noteResult to record the set of types that should be recompiled if the given file is modified or deleted. @@ -180,13 +180,13 @@ public class AjState implements CompilerConfigurationChangeFlags { /** * A list of the .class files created by this state that contain aspects. */ - private final List/* */aspectClassFiles = new ArrayList(); + private final List aspectClassFiles = new ArrayList(); /** * Holds structure information on types as they were at the end of the last build. It would be nice to get rid of this too, but * can't see an easy way to do that right now. */ - private final Map/* FQN,CompactStructureRepresentation */resolvedTypeStructuresFromLastBuild = new HashMap(); + private final Map resolvedTypeStructuresFromLastBuild = new HashMap(); /** * Populated in noteResult to record the set of UnwovenClassFiles (intermediate results) that originated from compilation of the @@ -196,7 +196,7 @@ public class AjState implements CompilerConfigurationChangeFlags { * * Passed into StatefulNameEnvironment during incremental compilation to support findType lookups. */ - private final Map classesFromName = new HashMap(); + private final Map classesFromName = new HashMap(); /** * Populated by AjBuildManager to record the aspects with the file name in which they're contained. This is later used when @@ -206,7 +206,7 @@ public class AjState implements CompilerConfigurationChangeFlags { */ private Map aspectsFromFileNames; - private Set/* File */compiledSourceFiles = new HashSet(); + private Set compiledSourceFiles = new HashSet(); private final Map resources = new HashMap(); SoftHashMap/* > */fileToClassNameMap = new SoftHashMap(); @@ -355,21 +355,19 @@ public class AjState implements CompilerConfigurationChangeFlags { * * @return false if we discovered an aspect declaration */ - private boolean processDeletedFiles(Set deletedFiles) { - for (Iterator iter = deletedFiles.iterator(); iter.hasNext();) { - File aDeletedFile = (File) iter.next(); - if (this.sourceFilesDefiningAspects.contains(aDeletedFile)) { + private boolean processDeletedFiles(Set deletedFiles) { + for (File deletedFile : deletedFiles) { + if (this.sourceFilesDefiningAspects.contains(deletedFile)) { removeAllResultsOfLastBuild(); if (stateListener != null) { - stateListener.detectedAspectDeleted(aDeletedFile); + stateListener.detectedAspectDeleted(deletedFile); } return false; } - List/* ClassFile */classes = fullyQualifiedTypeNamesResultingFromCompilationUnit.get(aDeletedFile); + List classes = fullyQualifiedTypeNamesResultingFromCompilationUnit.get(deletedFile); if (classes != null) { - for (Iterator iterator = classes.iterator(); iterator.hasNext();) { - ClassFile element = (ClassFile) iterator.next(); - resolvedTypeStructuresFromLastBuild.remove(element.fullyQualifiedTypeName); + for (ClassFile cf : classes) { + resolvedTypeStructuresFromLastBuild.remove(cf.fullyQualifiedTypeName); } } } @@ -409,15 +407,15 @@ public class AjState implements CompilerConfigurationChangeFlags { return ret; } - private Collection getModifiedBinaryFiles() { + private Collection getModifiedBinaryFiles() { return getModifiedBinaryFiles(lastSuccessfulBuildTime); } - Collection getModifiedBinaryFiles(long lastBuildTime) { - List ret = new ArrayList(); + Collection getModifiedBinaryFiles(long lastBuildTime) { + List ret = new ArrayList(); // not our job to account for new and deleted files - for (Iterator i = buildConfig.getBinaryFiles().iterator(); i.hasNext();) { - AjBuildConfig.BinarySourceFile bsfile = (AjBuildConfig.BinarySourceFile) i.next(); + for (Iterator i = buildConfig.getBinaryFiles().iterator(); i.hasNext();) { + AjBuildConfig.BinarySourceFile bsfile = i.next(); File file = bsfile.binSrc; if (!file.exists()) { continue; @@ -433,12 +431,6 @@ public class AjState implements CompilerConfigurationChangeFlags { return ret; } - public static final FileFilter classFileFilter = new FileFilter() { - public boolean accept(File pathname) { - return pathname.getName().endsWith(".class"); - } - }; - private void recordDecision(String decision) { getListener().recordDecision(decision); } @@ -499,10 +491,10 @@ public class AjState implements CompilerConfigurationChangeFlags { } } - List classFiles = FileUtil.listClassFiles(dir); + List classFiles = FileUtil.listClassFiles(dir); - for (Iterator iterator = classFiles.iterator(); iterator.hasNext();) { - File classFile = (File) iterator.next(); + for (Iterator iterator = classFiles.iterator(); iterator.hasNext();) { + File classFile = iterator.next(); if (CHECK_STATE_FIRST && state != null) { // Next section reworked based on bug 270033: // if it is an aspect we may or may not be in trouble depending on whether (a) we depend on it (b) it is on the @@ -638,6 +630,7 @@ public class AjState implements CompilerConfigurationChangeFlags { return aspectClassFiles.contains(file.getAbsolutePath()); } + @SuppressWarnings("rawtypes") public static class SoftHashMap extends AbstractMap { private final Map map; @@ -660,6 +653,7 @@ public class AjState implements CompilerConfigurationChangeFlags { private final Object key; + @SuppressWarnings("unchecked") SoftReferenceKnownKey(Object k, Object v) { super(v, rq); this.key = k; @@ -823,7 +817,7 @@ public class AjState implements CompilerConfigurationChangeFlags { */ private boolean hasStructuralChangedSince(File file, long lastSuccessfulBuildTime) { // long lastModTime = file.lastModified(); - Long l = (Long) structuralChangesSinceLastFullBuild.get(file.getAbsolutePath()); + Long l = structuralChangesSinceLastFullBuild.get(file.getAbsolutePath()); long strucModTime = -1; if (l != null) { strucModTime = l.longValue(); @@ -839,10 +833,10 @@ public class AjState implements CompilerConfigurationChangeFlags { * Determine if anything has changed since a given time. */ private boolean hasAnyStructuralChangesSince(long lastSuccessfulBuildTime) { - Set entries = structuralChangesSinceLastFullBuild.entrySet(); - for (Iterator iterator = entries.iterator(); iterator.hasNext();) { - Map.Entry entry = (Map.Entry) iterator.next(); - Long l = (Long) entry.getValue(); + Set> entries = structuralChangesSinceLastFullBuild.entrySet(); + for (Iterator> iterator = entries.iterator(); iterator.hasNext();) { + Map.Entry entry = iterator.next(); + Long l = entry.getValue(); if (l != null) { long lvalue = l.longValue(); if (lvalue > lastSuccessfulBuildTime) { @@ -870,12 +864,12 @@ public class AjState implements CompilerConfigurationChangeFlags { int changes = newConfig.getChanged(); if ((changes & (CLASSPATH_CHANGED | ASPECTPATH_CHANGED | INPATH_CHANGED | OUTPUTDESTINATIONS_CHANGED | INJARS_CHANGED)) != 0) { - List oldOutputLocs = getOutputLocations(previousConfig); + List oldOutputLocs = getOutputLocations(previousConfig); - Set alreadyAnalysedPaths = new HashSet(); + Set alreadyAnalysedPaths = new HashSet(); - List oldClasspath = previousConfig.getClasspath(); - List newClasspath = newConfig.getClasspath(); + List oldClasspath = previousConfig.getClasspath(); + List newClasspath = newConfig.getClasspath(); if (stateListener != null) { stateListener.aboutToCompareClasspaths(oldClasspath, newClasspath); } @@ -883,20 +877,20 @@ public class AjState implements CompilerConfigurationChangeFlags { return true; } - List oldAspectpath = previousConfig.getAspectpath(); - List newAspectpath = newConfig.getAspectpath(); + List oldAspectpath = previousConfig.getAspectpath(); + List newAspectpath = newConfig.getAspectpath(); if (changedAndNeedsFullBuild(oldAspectpath, newAspectpath, true, oldOutputLocs, alreadyAnalysedPaths, PATHID_ASPECTPATH)) { return true; } - List oldInPath = previousConfig.getInpath(); - List newInPath = newConfig.getInpath(); + List oldInPath = previousConfig.getInpath(); + List newInPath = newConfig.getInpath(); if (changedAndNeedsFullBuild(oldInPath, newInPath, false, oldOutputLocs, alreadyAnalysedPaths, PATHID_INPATH)) { return true; } - List oldInJars = previousConfig.getInJars(); - List newInJars = newConfig.getInJars(); + List oldInJars = previousConfig.getInJars(); + List newInJars = newConfig.getInJars(); if (changedAndNeedsFullBuild(oldInJars, newInJars, false, oldOutputLocs, alreadyAnalysedPaths, PATHID_INPATH)) { return true; } @@ -906,9 +900,9 @@ public class AjState implements CompilerConfigurationChangeFlags { // the compiler configuration. This will allow for projects with long classpaths where classpaths // are also capturing project dependencies - when a project we depend on is rebuilt, we can just check // it as a standalone element on our classpath rather than going through them all - List/* String */modifiedCpElements = newConfig.getClasspathElementsWithModifiedContents(); - for (Iterator iterator = modifiedCpElements.iterator(); iterator.hasNext();) { - File cpElement = new File((String) iterator.next()); + List modifiedCpElements = newConfig.getClasspathElementsWithModifiedContents(); + for (Iterator iterator = modifiedCpElements.iterator(); iterator.hasNext();) { + File cpElement = new File(iterator.next()); if (cpElement.exists() && !cpElement.isDirectory()) { if (cpElement.lastModified() > lastSuccessfulBuildTime) { return true; @@ -958,7 +952,6 @@ public class AjState implements CompilerConfigurationChangeFlags { } private File getOutputLocationFor(AjBuildConfig config, File aResourceFile) { - new ArrayList(); if (config.getCompilationResultDestinationManager() != null) { File outputLoc = config.getCompilationResultDestinationManager().getOutputLocationForResource(aResourceFile); if (outputLoc != null) { @@ -983,8 +976,8 @@ public class AjState implements CompilerConfigurationChangeFlags { * @param outputLocs the output locations that should be ignored if they occur on the paths being compared * @return true if a change is detected that requires a full build */ - private boolean changedAndNeedsFullBuild(List oldPath, List newPath, boolean checkClassFiles, List outputLocs, - Set alreadyAnalysedPaths, int pathid) { + private boolean changedAndNeedsFullBuild(List oldPath, List newPath, boolean checkClassFiles, List outputLocs, + Set alreadyAnalysedPaths, int pathid) { if (oldPath.size() != newPath.size()) { return true; } @@ -1010,8 +1003,8 @@ public class AjState implements CompilerConfigurationChangeFlags { // that should save a massive amount of processing for incremental builds in a multi project scenario boolean foundMatch = false; - for (Iterator iterator = outputLocs.iterator(); !foundMatch && iterator.hasNext();) { - File dir = (File) iterator.next(); + for (Iterator iterator = outputLocs.iterator(); !foundMatch && iterator.hasNext();) { + File dir = iterator.next(); if (f.equals(dir)) { foundMatch = true; } @@ -1041,8 +1034,8 @@ public class AjState implements CompilerConfigurationChangeFlags { * @param outputLocs the output locations that should be ignored if they occur on the paths being compared * @return true if a change is detected that requires a full build */ - private boolean classpathChangedAndNeedsFullBuild(List oldPath, List newPath, boolean checkClassFiles, List outputLocs, - Set alreadyAnalysedPaths) { + private boolean classpathChangedAndNeedsFullBuild(List oldPath, List newPath, boolean checkClassFiles, + List outputLocs, Set alreadyAnalysedPaths) { if (oldPath.size() != newPath.size()) { return true; } @@ -1050,7 +1043,7 @@ public class AjState implements CompilerConfigurationChangeFlags { if (!oldPath.get(i).equals(newPath.get(i))) { return true; } - File f = new File((String) oldPath.get(i)); + File f = new File(oldPath.get(i)); if (f.exists() && !f.isDirectory() && (f.lastModified() >= lastSuccessfulBuildTime)) { return true; } @@ -1062,8 +1055,8 @@ public class AjState implements CompilerConfigurationChangeFlags { // that should save a massive amount of processing for incremental builds in a multi project scenario boolean foundMatch = false; - for (Iterator iterator = outputLocs.iterator(); !foundMatch && iterator.hasNext();) { - File dir = (File) iterator.next(); + for (Iterator iterator = outputLocs.iterator(); !foundMatch && iterator.hasNext();) { + File dir = iterator.next(); if (f.equals(dir)) { foundMatch = true; } @@ -1082,7 +1075,7 @@ public class AjState implements CompilerConfigurationChangeFlags { return false; } - public Set getFilesToCompile(boolean firstPass) { + public Set getFilesToCompile(boolean firstPass) { Set thisTime = new HashSet(); if (firstPass) { compiledSourceFiles = new HashSet(); @@ -1162,10 +1155,9 @@ public class AjState implements CompilerConfigurationChangeFlags { */ private void removeAllResultsOfLastBuild() { // remove all binarySourceFiles, and all classesFromName... - for (Iterator iter = this.inputClassFilesBySource.values().iterator(); iter.hasNext();) { - List cfs = (List) iter.next(); - for (Iterator iterator = cfs.iterator(); iterator.hasNext();) { - ClassFile cf = (ClassFile) iterator.next(); + for (Iterator> iter = this.inputClassFilesBySource.values().iterator(); iter.hasNext();) { + List cfs = iter.next(); + for (ClassFile cf : cfs) { cf.deleteFromFileSystem(buildConfig); } } @@ -1195,16 +1187,14 @@ public class AjState implements CompilerConfigurationChangeFlags { if (deletedFiles == null) { return; } - for (Iterator i = deletedFiles.iterator(); i.hasNext();) { - File deletedFile = (File) i.next(); + for (File deletedFile : deletedFiles) { addDependentsOf(deletedFile); - List cfs = this.fullyQualifiedTypeNamesResultingFromCompilationUnit.get(deletedFile); + List cfs = this.fullyQualifiedTypeNamesResultingFromCompilationUnit.get(deletedFile); this.fullyQualifiedTypeNamesResultingFromCompilationUnit.remove(deletedFile); if (cfs != null) { - for (Iterator iter = cfs.iterator(); iter.hasNext();) { - ClassFile cf = (ClassFile) iter.next(); + for (ClassFile cf : cfs) { deleteClassFile(cf); } } @@ -1386,24 +1376,22 @@ public class AjState implements CompilerConfigurationChangeFlags { */ private void deleteTypesThatWereInThisCompilationUnitLastTimeRoundButHaveBeenDeletedInThisIncrement(File sourceFile, UnwovenClassFile[] unwovenClassFiles) { - List classFiles = this.fullyQualifiedTypeNamesResultingFromCompilationUnit.get(sourceFile); + List classFiles = this.fullyQualifiedTypeNamesResultingFromCompilationUnit.get(sourceFile); if (classFiles != null) { for (int i = 0; i < unwovenClassFiles.length; i++) { // deleting also deletes types from the weaver... don't do this if they are // still present this time around... removeFromClassFilesIfPresent(unwovenClassFiles[i].getClassName(), classFiles); } - for (Iterator iter = classFiles.iterator(); iter.hasNext();) { - ClassFile cf = (ClassFile) iter.next(); + for (ClassFile cf : classFiles) { deleteClassFile(cf); } } } - private void removeFromClassFilesIfPresent(String className, List classFiles) { + private void removeFromClassFilesIfPresent(String className, List classFiles) { ClassFile victim = null; - for (Iterator iter = classFiles.iterator(); iter.hasNext();) { - ClassFile cf = (ClassFile) iter.next(); + for (ClassFile cf : classFiles) { if (cf.fullyQualifiedTypeName.equals(className)) { victim = cf; break; @@ -1441,8 +1429,8 @@ public class AjState implements CompilerConfigurationChangeFlags { if (cr != null) { Map compiledTypes = cr.compiledTypes; if (compiledTypes != null) { - for (Iterator iterator = compiledTypes.keySet().iterator(); iterator.hasNext();) { - char[] className = (char[]) iterator.next(); + for (Iterator iterator = compiledTypes.keySet().iterator(); iterator.hasNext();) { + char[] className = iterator.next(); String typeName = new String(className).replace('/', '.'); if (typeName.indexOf(BcelWeaver.SYNTHETIC_CLASS_POSTFIX) == -1) { ResolvedType rt = world.resolve(typeName); @@ -1494,7 +1482,7 @@ public class AjState implements CompilerConfigurationChangeFlags { return; } - CompactTypeStructureRepresentation existingStructure = (CompactTypeStructureRepresentation) this.resolvedTypeStructuresFromLastBuild + CompactTypeStructureRepresentation existingStructure = this.resolvedTypeStructuresFromLastBuild .get(thisTime.getClassName()); ResolvedType newResolvedType = world.resolve(thisTime.getClassName()); if (!newResolvedType.isMissing()) { @@ -1766,6 +1754,24 @@ public class AjState implements CompilerConfigurationChangeFlags { return true; // (no match found) } + // check for differences in inner types + // TODO could make order insensitive + IBinaryNestedType[] binaryNestedTypes = reader.getMemberTypes(); + IBinaryNestedType[] existingBinaryNestedTypes = existingType.getMemberTypes(); + if ((binaryNestedTypes == null && existingBinaryNestedTypes != null) + || (binaryNestedTypes != null && existingBinaryNestedTypes == null)) { + return true; + } + if (binaryNestedTypes != null) { + int bnLength = binaryNestedTypes.length; + for (int m = 0; m < bnLength; m++) { + IBinaryNestedType bnt = binaryNestedTypes[m]; + IBinaryNestedType existingBnt = existingBinaryNestedTypes[m]; + if (!CharOperation.equals(bnt.getName(), existingBnt.getName())) { + return true; + } + } + } return false; } @@ -1812,10 +1818,10 @@ public class AjState implements CompilerConfigurationChangeFlags { // return ret; // } - private String stringifyList(Set l) { + private String stringifySet(Set l) { StringBuffer sb = new StringBuffer(); sb.append("{"); - for (Iterator iter = l.iterator(); iter.hasNext();) { + for (Iterator iter = l.iterator(); iter.hasNext();) { Object el = iter.next(); sb.append(el); if (iter.hasNext()) { @@ -1826,14 +1832,14 @@ public class AjState implements CompilerConfigurationChangeFlags { return sb.toString(); } - protected void addAffectedSourceFiles(Set addTo, Set lastTimeSources) { + protected void addAffectedSourceFiles(Set addTo, Set lastTimeSources) { if (qualifiedStrings.elementSize == 0 && simpleStrings.elementSize == 0) { return; } if (listenerDefined()) { getListener().recordDecision( "Examining whether any other files now need compilation based on just compiling: '" - + stringifyList(lastTimeSources) + "'"); + + stringifySet(lastTimeSources) + "'"); } // the qualifiedStrings are of the form 'p1/p2' & the simpleStrings are just 'X' char[][][] qualifiedNames = ReferenceCollection.internQualifiedNames(qualifiedStrings); @@ -1850,11 +1856,11 @@ public class AjState implements CompilerConfigurationChangeFlags { // System.err.println("simple: " + simpleStrings); // System.err.println("qualif: " + qualifiedStrings); - for (Iterator i = references.entrySet().iterator(); i.hasNext();) { - Map.Entry entry = (Map.Entry) i.next(); - ReferenceCollection refs = (ReferenceCollection) entry.getValue(); + for (Iterator> i = references.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = i.next(); + ReferenceCollection refs = entry.getValue(); if (refs != null && refs.includes(qualifiedNames, simpleNames)) { - File file = (File) entry.getKey(); + File file = entry.getKey(); if (file.exists()) { if (!lastTimeSources.contains(file)) { // ??? O(n**2) if (listenerDefined()) { @@ -1909,15 +1915,12 @@ public class AjState implements CompilerConfigurationChangeFlags { } protected void addDependentsOf(File sourceFile) { - List cfs = this.fullyQualifiedTypeNamesResultingFromCompilationUnit.get(sourceFile); - + List cfs = this.fullyQualifiedTypeNamesResultingFromCompilationUnit.get(sourceFile); if (cfs != null) { - for (Iterator iter = cfs.iterator(); iter.hasNext();) { - ClassFile cf = (ClassFile) iter.next(); + for (ClassFile cf : cfs) { recordTypeChanged(cf.fullyQualifiedTypeName); } } - } public void setStructureModel(AsmManager structureModel) { @@ -1975,15 +1978,14 @@ public class AjState implements CompilerConfigurationChangeFlags { } public void clearBinarySourceFiles() { - this.binarySourceFiles = new HashMap(); + this.binarySourceFiles = new HashMap>(); } - public void recordBinarySource(String fromPathName, List unwovenClassFiles) { + public void recordBinarySource(String fromPathName, List unwovenClassFiles) { this.binarySourceFiles.put(fromPathName, unwovenClassFiles); if (this.maybeIncremental()) { - List simpleClassFiles = new LinkedList(); - for (Iterator iter = unwovenClassFiles.iterator(); iter.hasNext();) { - UnwovenClassFile ucf = (UnwovenClassFile) iter.next(); + List simpleClassFiles = new LinkedList(); + for (UnwovenClassFile ucf : unwovenClassFiles) { ClassFile cf = getClassFileFor(ucf); simpleClassFiles.add(cf); } @@ -1999,7 +2001,7 @@ public class AjState implements CompilerConfigurationChangeFlags { return new ClassFile(ucf.getClassName(), new File(ucf.getFilename())); } - public Map getBinarySourceMap() { + public Map> getBinarySourceMap() { return this.binarySourceFiles; } @@ -2018,14 +2020,14 @@ public class AjState implements CompilerConfigurationChangeFlags { /** * @return Returns the addedFiles. */ - public Set getAddedFiles() { + public Set getAddedFiles() { return this.addedFiles; } /** * @return Returns the deletedFiles. */ - public Set getDeletedFiles() { + public Set getDeletedFiles() { return this.deletedFiles; } @@ -2085,7 +2087,7 @@ public class AjState implements CompilerConfigurationChangeFlags { } public void initializeAspectNamesToFileNameMap() { - this.aspectsFromFileNames = new HashMap(); + this.aspectsFromFileNames = new HashMap(); } // Will allow us to record decisions made during incremental processing, hopefully aid in debugging @@ -2098,7 +2100,7 @@ public class AjState implements CompilerConfigurationChangeFlags { } public IBinaryType checkPreviousBuild(String name) { - return (IBinaryType) resolvedTypeStructuresFromLastBuild.get(name); + return resolvedTypeStructuresFromLastBuild.get(name); } public AjBuildManager getAjBuildManager() { diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AjStateTest.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AjStateTest.java index d333b9bfb..e574100aa 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AjStateTest.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AjStateTest.java @@ -16,111 +16,107 @@ import java.util.List; import junit.framework.TestCase; - public class AjStateTest extends TestCase { - private AjState aRightState; - private AjBuildConfig oldConfig; - private AjBuildConfig newConfig; - - public void testNoChange() { - aRightState.setCouldBeSubsequentIncrementalBuild(true); - assertTrue("Can do incremental",aRightState.prepareForNextBuild(newConfig)); - } - - public void testAddEntryToClasspath() { - newConfig.getClasspath().add("anotherEntry"); - assertFalse("Can do incremental",aRightState.prepareForNextBuild(newConfig)); - } - - public void testRemoveEntryFromClasspath() { - newConfig.getClasspath().remove(0); - assertFalse("Can do incremental",aRightState.prepareForNextBuild(newConfig)); - } - - public void testReorderClasspath() { - Object o = newConfig.getClasspath().remove(0); - newConfig.getClasspath().add(o); - assertFalse("Can do incremental",aRightState.prepareForNextBuild(newConfig)); - } - - public void testAddEntryToAspectpath() { - newConfig.getAspectpath().add(new File("anotherEntry.jar")); - assertFalse("Can do incremental",aRightState.prepareForNextBuild(newConfig)); - } - - public void testRemoveEntryFromAspectpath() { - newConfig.getAspectpath().remove(0); - assertFalse("Can do incremental",aRightState.prepareForNextBuild(newConfig)); - } - - public void testReorderAspectpath() { - Object o = newConfig.getClasspath().remove(0); - newConfig.getAspectpath().add(o); - assertFalse("Can do incremental",aRightState.prepareForNextBuild(newConfig)); - } - - public void testAddEntryToInpath() { - newConfig.getInpath().add(new File("anotherEntry")); - assertFalse("Can do incremental",aRightState.prepareForNextBuild(newConfig)); - } - - public void testRemoveEntryFromInpath() { - newConfig.getInpath().remove(0); - assertFalse("Can do incremental",aRightState.prepareForNextBuild(newConfig)); - } - - public void testReorderInpath() { - Object o = newConfig.getClasspath().remove(0); - newConfig.getInpath().add(o); - assertFalse("Can do incremental",aRightState.prepareForNextBuild(newConfig)); - } - - public void testAddEntryToInjars() { - newConfig.getInJars().add(new File("anotherEntry.jar")); - assertFalse("Can do incremental",aRightState.prepareForNextBuild(newConfig)); - } - - public void testRemoveEntryFromInjars() { - newConfig.getInJars().remove(0); - assertFalse("Can do incremental",aRightState.prepareForNextBuild(newConfig)); - } - - public void testReorderInjars() { - Object o = newConfig.getClasspath().remove(0); - newConfig.getInJars().add(o); - assertFalse("Can do incremental",aRightState.prepareForNextBuild(newConfig)); - } - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - aRightState = new AjState(null); - oldConfig = new AjBuildConfig(); - newConfig = new AjBuildConfig(); - List cp = new ArrayList(); - cp.add("adir"); - cp.add("ajar.jar"); - oldConfig.setClasspath(cp); - newConfig.setClasspath(new ArrayList(cp)); - List ap = new ArrayList(); - ap.add(new File("aLib.jar")); - ap.add(new File("anotherLib.jar")); - oldConfig.setAspectpath(ap); - newConfig.setAspectpath(new ArrayList(ap)); - List ip = new ArrayList(); - ip.add(new File("adir")); - ip.add(new File("ajar.jar")); - oldConfig.setInPath(ip); - newConfig.setInPath(new ArrayList(ip)); - List ij = new ArrayList(); - ij.add(new File("aLib.jar")); - ij.add(new File("anotherLib.jar")); - oldConfig.setInJars(ij); - newConfig.setInJars(new ArrayList(ij)); - aRightState.prepareForNextBuild(oldConfig); - aRightState.successfulCompile(oldConfig,true); - } + private AjState aRightState; + private AjBuildConfig oldConfig; + private AjBuildConfig newConfig; + + public void testNoChange() { + aRightState.setCouldBeSubsequentIncrementalBuild(true); + assertTrue("Can do incremental", aRightState.prepareForNextBuild(newConfig)); + } + + public void testAddEntryToClasspath() { + newConfig.getClasspath().add("anotherEntry"); + assertFalse("Can do incremental", aRightState.prepareForNextBuild(newConfig)); + } + + public void testRemoveEntryFromClasspath() { + newConfig.getClasspath().remove(0); + assertFalse("Can do incremental", aRightState.prepareForNextBuild(newConfig)); + } + + public void testReorderClasspath() { + String o = newConfig.getClasspath().remove(0); + newConfig.getClasspath().add(o); + assertFalse("Can do incremental", aRightState.prepareForNextBuild(newConfig)); + } + + public void testAddEntryToAspectpath() { + newConfig.getAspectpath().add(new File("anotherEntry.jar")); + assertFalse("Can do incremental", aRightState.prepareForNextBuild(newConfig)); + } + + public void testRemoveEntryFromAspectpath() { + newConfig.getAspectpath().remove(0); + assertFalse("Can do incremental", aRightState.prepareForNextBuild(newConfig)); + } + + public void testReorderAspectpath() { + String o = newConfig.getClasspath().remove(0); + newConfig.getAspectpath().add(new File(o)); + assertFalse("Can do incremental", aRightState.prepareForNextBuild(newConfig)); + } + + public void testAddEntryToInpath() { + newConfig.getInpath().add(new File("anotherEntry")); + assertFalse("Can do incremental", aRightState.prepareForNextBuild(newConfig)); + } + + public void testRemoveEntryFromInpath() { + newConfig.getInpath().remove(0); + assertFalse("Can do incremental", aRightState.prepareForNextBuild(newConfig)); + } + + public void testReorderInpath() { + String o = newConfig.getClasspath().remove(0); + newConfig.getInpath().add(new File(o)); + assertFalse("Can do incremental", aRightState.prepareForNextBuild(newConfig)); + } + + public void testAddEntryToInjars() { + newConfig.getInJars().add(new File("anotherEntry.jar")); + assertFalse("Can do incremental", aRightState.prepareForNextBuild(newConfig)); + } + + public void testRemoveEntryFromInjars() { + newConfig.getInJars().remove(0); + assertFalse("Can do incremental", aRightState.prepareForNextBuild(newConfig)); + } + + public void testReorderInjars() { + String o = newConfig.getClasspath().remove(0); + newConfig.getInJars().add(new File(o)); + assertFalse("Can do incremental", aRightState.prepareForNextBuild(newConfig)); + } + + protected void setUp() throws Exception { + super.setUp(); + aRightState = new AjState(null); + oldConfig = new AjBuildConfig(); + newConfig = new AjBuildConfig(); + List cp = new ArrayList(); + cp.add("adir"); + cp.add("ajar.jar"); + oldConfig.setClasspath(cp); + newConfig.setClasspath(new ArrayList(cp)); + List ap = new ArrayList(); + ap.add(new File("aLib.jar")); + ap.add(new File("anotherLib.jar")); + oldConfig.setAspectpath(ap); + newConfig.setAspectpath(new ArrayList(ap)); + List ip = new ArrayList(); + ip.add(new File("adir")); + ip.add(new File("ajar.jar")); + oldConfig.setInPath(ip); + newConfig.setInPath(new ArrayList(ip)); + List ij = new ArrayList(); + ij.add(new File("aLib.jar")); + ij.add(new File("anotherLib.jar")); + oldConfig.setInJars(ij); + newConfig.setInJars(new ArrayList(ij)); + aRightState.prepareForNextBuild(oldConfig); + aRightState.successfulCompile(oldConfig, true); + } }