aboutsummaryrefslogtreecommitdiffstats
path: root/util/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'util/src/main')
-rw-r--r--util/src/main/java/org/aspectj/util/FileUtil.java215
-rw-r--r--util/src/main/java/org/aspectj/util/GenericSignature.java24
-rw-r--r--util/src/main/java/org/aspectj/util/GenericSignatureParser.java4
-rw-r--r--util/src/main/java/org/aspectj/util/PartialOrder.java7
-rw-r--r--util/src/main/java/org/aspectj/util/Reflection.java32
-rw-r--r--util/src/main/java/org/aspectj/util/UtilClassLoader.java12
6 files changed, 144 insertions, 150 deletions
diff --git a/util/src/main/java/org/aspectj/util/FileUtil.java b/util/src/main/java/org/aspectj/util/FileUtil.java
index fef580e83..6e55742b1 100644
--- a/util/src/main/java/org/aspectj/util/FileUtil.java
+++ b/util/src/main/java/org/aspectj/util/FileUtil.java
@@ -147,12 +147,11 @@ public class FileUtil {
return 0;
}
- for (Iterator<String> iter = SOURCE_SUFFIXES.iterator(); iter.hasNext();) {
- String suffix = iter.next();
- if (path.endsWith(suffix) || path.toLowerCase().endsWith(suffix)) {
- return suffix.length();
- }
- }
+ for (String suffix : SOURCE_SUFFIXES) {
+ if (path.endsWith(suffix) || path.toLowerCase().endsWith(suffix)) {
+ return suffix.length();
+ }
+ }
return 0;
}
@@ -335,18 +334,18 @@ public class FileUtil {
}
StringBuffer result = new StringBuffer();
boolean first = true;
- for (int i = 0; i < paths.length; i++) {
- String path = paths[i];
- if (null == path) {
- continue;
- }
- if (first) {
- first = false;
- } else {
- result.append(infix);
- }
- result.append(path);
- }
+ for (String path : paths) {
+ if (null == path) {
+ continue;
+ }
+ if (first) {
+ first = false;
+ }
+ else {
+ result.append(infix);
+ }
+ result.append(path);
+ }
return result.toString();
}
@@ -540,24 +539,24 @@ public class FileUtil {
return 0;
}
int result = 0;
- for (int i = 0; i < fromFiles.length; i++) {
- String string = fromFiles[i];
- File file = new File(dir, string);
- if ((null == filter) || filter.accept(file)) {
- if (file.isDirectory()) {
- result += deleteContents(file, filter, deleteEmptyDirs);
- String[] fileContent = file.list();
- if (deleteEmptyDirs && fileContent != null
- && 0 == fileContent.length) {
- file.delete();
- }
- } else {
- /* boolean ret = */
- file.delete();
- result++;
- }
- }
- }
+ for (String string : fromFiles) {
+ File file = new File(dir, string);
+ if ((null == filter) || filter.accept(file)) {
+ if (file.isDirectory()) {
+ result += deleteContents(file, filter, deleteEmptyDirs);
+ String[] fileContent = file.list();
+ if (deleteEmptyDirs && fileContent != null
+ && 0 == fileContent.length) {
+ file.delete();
+ }
+ }
+ else {
+ /* boolean ret = */
+ file.delete();
+ result++;
+ }
+ }
+ }
return result;
}
@@ -752,15 +751,14 @@ public class FileUtil {
File[] result = null;
if (!LangUtil.isEmpty(suffixes)) {
ArrayList<File> list = new ArrayList<File>();
- for (int i = 0; i < paths.length; i++) {
- String path = paths[i];
- for (int j = 0; j < suffixes.length; j++) {
- if (path.endsWith(suffixes[j])) {
- list.add(new File(basedir, paths[i]));
- break;
- }
- }
- }
+ for (String path : paths) {
+ for (String suffix : suffixes) {
+ if (path.endsWith(suffix)) {
+ list.add(new File(basedir, path));
+ break;
+ }
+ }
+ }
result = list.toArray(new File[0]);
} else {
result = new File[paths.length];
@@ -1080,9 +1078,9 @@ public class FileUtil {
public static void writeBooleanArray(boolean[] a, DataOutputStream s) throws IOException {
int len = a.length;
s.writeInt(len);
- for (int i = 0; i < len; i++) {
- s.writeBoolean(a[i]);
- }
+ for (boolean b : a) {
+ s.writeBoolean(b);
+ }
}
/**
@@ -1103,9 +1101,9 @@ public class FileUtil {
public static void writeIntArray(int[] a, DataOutputStream s) throws IOException {
int len = a.length;
s.writeInt(len);
- for (int i = 0; i < len; i++) {
- s.writeInt(a[i]);
- }
+ for (int j : a) {
+ s.writeInt(j);
+ }
}
/**
@@ -1130,9 +1128,9 @@ public class FileUtil {
}
int len = a.length;
s.writeInt(len);
- for (int i = 0; i < len; i++) {
- s.writeUTF(a[i]);
- }
+ for (String value : a) {
+ s.writeUTF(value);
+ }
}
/**
@@ -1276,13 +1274,12 @@ public class FileUtil {
return Collections.emptyList();
}
ArrayList<String> result = new ArrayList<String>();
- for (Iterator<String> iter = sources.iterator(); iter.hasNext();) {
- String path = iter.next();
- String error = lineSeek(sought, path, listAll, result);
- if ((null != error) && (null != errorSink)) {
- errorSink.println(error);
- }
- }
+ for (String path : sources) {
+ String error = lineSeek(sought, path, listAll, result);
+ if ((null != error) && (null != errorSink)) {
+ errorSink.println(error);
+ }
+ }
return result;
}
@@ -1357,53 +1354,52 @@ public class FileUtil {
return true;
}
long delayUntil = System.currentTimeMillis();
- for (int i = 0; i < files.length; i++) {
- File file = files[i];
- if ((null == file) || !file.exists()) {
- continue;
- }
- long nextModTime = file.lastModified();
- if (nextModTime > delayUntil) {
- delayUntil = nextModTime;
- }
- }
+ for (File file : files) {
+ if ((null == file) || !file.exists()) {
+ continue;
+ }
+ long nextModTime = file.lastModified();
+ if (nextModTime > delayUntil) {
+ delayUntil = nextModTime;
+ }
+ }
return LangUtil.sleepUntil(++delayUntil);
}
private static void listClassFiles(final File baseDir, ArrayList<File> result) {
File[] files = baseDir.listFiles();
- for (int i = 0; i < files.length; i++) {
- File f = files[i];
- if (f.isDirectory()) {
- listClassFiles(f, result);
- } else {
- if (f.getName().endsWith(".class")) {
- result.add(f);
- }
- }
- }
+ for (File f : files) {
+ if (f.isDirectory()) {
+ listClassFiles(f, result);
+ }
+ else {
+ if (f.getName().endsWith(".class")) {
+ result.add(f);
+ }
+ }
+ }
}
private static void listFiles(final File baseDir, ArrayList<File> result, FileFilter filter) {
File[] files = baseDir.listFiles();
// hack https://bugs.eclipse.org/bugs/show_bug.cgi?id=48650
final boolean skipCVS = (!PERMIT_CVS && (filter == aspectjSourceFileFilter));
- for (int i = 0; i < files.length; i++) {
- File f = files[i];
- if (f.isDirectory()) {
- if (skipCVS) {
- String name = f.getName().toLowerCase();
- if ("cvs".equals(name) || "sccs".equals(name)) {
- continue;
- }
- }
- listFiles(f, result, filter);
- } else {
- if (filter.accept(f)) {
- result.add(f);
- }
- }
- }
+ for (File f : files) {
+ if (f.isDirectory()) {
+ if (skipCVS) {
+ String name = f.getName().toLowerCase();
+ if ("cvs".equals(name) || "sccs".equals(name)) {
+ continue;
+ }
+ }
+ listFiles(f, result, filter);
+ }
+ else {
+ if (filter.accept(f)) {
+ result.add(f);
+ }
+ }
+ }
}
/** @return true if input is not null and contains no path separator */
@@ -1415,15 +1411,16 @@ public class FileUtil {
final String dirPrefix = (null == dir ? "" : dir + "/");
final File dirFile = (null == dir ? baseDir : new File(baseDir.getPath() + "/" + dir));
final String[] files = dirFile.list();
- for (int i = 0; i < files.length; i++) {
- File f = new File(dirFile, files[i]);
- String path = dirPrefix + files[i];
- if (f.isDirectory()) {
- listFiles(baseDir, path, result);
- } else {
- result.add(path);
- }
- }
+ for (String file : files) {
+ File f = new File(dirFile, file);
+ String path = dirPrefix + file;
+ if (f.isDirectory()) {
+ listFiles(baseDir, path, result);
+ }
+ else {
+ result.add(path);
+ }
+ }
}
private FileUtil() {
@@ -1432,9 +1429,9 @@ public class FileUtil {
public static List<String> makeClasspath(URL[] urls) {
List<String> ret = new LinkedList<String>();
if (urls != null) {
- for (int i = 0; i < urls.length; i++) {
- ret.add(toPathString(urls[i]));
- }
+ for (URL url : urls) {
+ ret.add(toPathString(url));
+ }
}
return ret;
}
diff --git a/util/src/main/java/org/aspectj/util/GenericSignature.java b/util/src/main/java/org/aspectj/util/GenericSignature.java
index bfefc007e..5fa7ac632 100644
--- a/util/src/main/java/org/aspectj/util/GenericSignature.java
+++ b/util/src/main/java/org/aspectj/util/GenericSignature.java
@@ -30,8 +30,8 @@ public class GenericSignature {
StringBuffer ret = new StringBuffer();
ret.append(formalTypeParameters.toString());
ret.append(superclassSignature.toString());
- for (int i = 0; i < superInterfaceSignatures.length; i++) {
- ret.append(superInterfaceSignatures[i].toString());
+ for (ClassTypeSignature superInterfaceSignature : superInterfaceSignatures) {
+ ret.append(superInterfaceSignature.toString());
}
return ret.toString();
}
@@ -55,20 +55,20 @@ public class GenericSignature {
StringBuffer sb = new StringBuffer();
if (formalTypeParameters.length > 0) {
sb.append("<");
- for (int i = 0; i < formalTypeParameters.length; i++) {
- sb.append(formalTypeParameters[i].toString());
+ for (FormalTypeParameter formalTypeParameter : formalTypeParameters) {
+ sb.append(formalTypeParameter.toString());
}
sb.append(">");
}
sb.append("(");
- for (int i = 0; i < parameters.length; i++) {
- sb.append(parameters[i].toString());
+ for (TypeSignature parameter : parameters) {
+ sb.append(parameter.toString());
}
sb.append(")");
sb.append(returnType.toString());
- for (int i = 0; i < throwsSignatures.length; i++) {
+ for (FieldTypeSignature throwsSignature : throwsSignatures) {
sb.append("^");
- sb.append(throwsSignatures[i].toString());
+ sb.append(throwsSignature.toString());
}
return sb.toString();
}
@@ -89,9 +89,9 @@ public class GenericSignature {
ret.append(identifier);
ret.append(":");
ret.append(classBound.toString());
- for (int i = 0; i < interfaceBounds.length; i++) {
+ for (FieldTypeSignature interfaceBound : interfaceBounds) {
ret.append(":");
- ret.append(interfaceBounds[i].toString());
+ ret.append(interfaceBound.toString());
}
return ret.toString();
}
@@ -212,8 +212,8 @@ public class GenericSignature {
sb.append(identifier);
if (typeArguments.length > 0) {
sb.append("<");
- for (int i = 0; i < typeArguments.length; i++) {
- sb.append(typeArguments[i].toString());
+ for (TypeArgument typeArgument : typeArguments) {
+ sb.append(typeArgument.toString());
}
sb.append(">");
}
diff --git a/util/src/main/java/org/aspectj/util/GenericSignatureParser.java b/util/src/main/java/org/aspectj/util/GenericSignatureParser.java
index 28c8db83d..27670cc00 100644
--- a/util/src/main/java/org/aspectj/util/GenericSignatureParser.java
+++ b/util/src/main/java/org/aspectj/util/GenericSignatureParser.java
@@ -194,8 +194,8 @@ public class GenericSignatureParser {
} else if (tokenStream[tokenIndex].equals("<")) {
ret.append("<");
TypeArgument[] tArgs = maybeParseTypeArguments();
- for (int i = 0; i < tArgs.length; i++) {
- ret.append(tArgs[i].toString());
+ for (TypeArgument tArg : tArgs) {
+ ret.append(tArg.toString());
}
ret.append(">");
outerType = new SimpleClassTypeSignature(identifier, tArgs);
diff --git a/util/src/main/java/org/aspectj/util/PartialOrder.java b/util/src/main/java/org/aspectj/util/PartialOrder.java
index 8bb9f3b77..14f23b0d6 100644
--- a/util/src/main/java/org/aspectj/util/PartialOrder.java
+++ b/util/src/main/java/org/aspectj/util/PartialOrder.java
@@ -88,8 +88,7 @@ public class PartialOrder {
private static <T extends PartialComparable> void addNewPartialComparable(List<SortObject<T>> graph, T o) {
SortObject<T> so = new SortObject<T>(o);
- for (Iterator<SortObject<T>> i = graph.iterator(); i.hasNext();) {
- SortObject<T> other = i.next();
+ for (SortObject<T> other : graph) {
so.addDirectedLinks(other);
}
graph.add(so);
@@ -125,8 +124,8 @@ public class PartialOrder {
// ??? I don't like creating this data structure, but it does give good
// ??? separation of concerns.
List<SortObject<T>> sortList = new LinkedList<SortObject<T>>();
- for (Iterator<T> i = objects.iterator(); i.hasNext();) {
- addNewPartialComparable(sortList, i.next());
+ for (T object : objects) {
+ addNewPartialComparable(sortList, object);
}
// System.out.println(sortList);
diff --git a/util/src/main/java/org/aspectj/util/Reflection.java b/util/src/main/java/org/aspectj/util/Reflection.java
index 3650962cc..d78f67101 100644
--- a/util/src/main/java/org/aspectj/util/Reflection.java
+++ b/util/src/main/java/org/aspectj/util/Reflection.java
@@ -57,8 +57,7 @@ public class Reflection {
public static Method getMatchingMethod(Class<?> class_, String name, Object[] args) {
Method[] meths = class_.getMethods();
- for (int i=0; i < meths.length; i++) {
- Method meth = meths[i];
+ for (Method meth : meths) {
if (meth.getName().equals(name) && isCompatible(meth, args)) {
return meth;
}
@@ -101,25 +100,24 @@ public class Reflection {
ArrayList<File> libs = new ArrayList<File>();
ArrayList<URL> urls = new ArrayList<URL>();
String[] entries = LangUtil.splitClasspath(classpath);
- for (int i = 0; i < entries.length; i++) {
- String entry = entries[i];
- URL url = makeURL(entry);
- if (null != url) {
- urls.add(url);
- }
- File file = new File(entries[i]);
+ for (String entry : entries) {
+ URL url = makeURL(entry);
+ if (null != url) {
+ urls.add(url);
+ }
+ File file = new File(entry);
// tolerate bad entries b/c bootclasspath sometimes has them
// if (!file.canRead()) {
// throw new IllegalArgumentException("cannot read " + file);
// }
- if (FileUtil.isZipFile(file)) {
- libs.add(file);
- } else if (file.isDirectory()) {
- dirs.add(file);
- } else {
- // not URL, zip, or dir - unsure what to do
- }
- }
+ if (FileUtil.isZipFile(file)) {
+ libs.add(file);
+ } else if (file.isDirectory()) {
+ dirs.add(file);
+ } else {
+ // not URL, zip, or dir - unsure what to do
+ }
+ }
File[] dirRa = (File[]) dirs.toArray(new File[0]);
File[] libRa = (File[]) libs.toArray(new File[0]);
URL[] urlRa = (URL[]) urls.toArray(new URL[0]);
diff --git a/util/src/main/java/org/aspectj/util/UtilClassLoader.java b/util/src/main/java/org/aspectj/util/UtilClassLoader.java
index 091e022a3..4704bfcc9 100644
--- a/util/src/main/java/org/aspectj/util/UtilClassLoader.java
+++ b/util/src/main/java/org/aspectj/util/UtilClassLoader.java
@@ -102,12 +102,12 @@ public class UtilClassLoader extends URLClassLoader {
/** @return null if class not found or byte[] of class otherwise */
private byte[] readClass(String className) throws ClassNotFoundException {
final String fileName = className.replace('.', '/')+".class";
- for (Iterator<File> iter = dirs.iterator(); iter.hasNext();) {
- File file = new File(iter.next(), fileName);
- if (file.canRead()) {
- return getClassData(file);
- }
- }
+ for (File dir : dirs) {
+ File file = new File(dir, fileName);
+ if (file.canRead()) {
+ return getClassData(file);
+ }
+ }
return null;
}