From c478a53fee1518aec9a057c317df1fcc666d36bc Mon Sep 17 00:00:00 2001 From: aclement Date: Wed, 27 Aug 2008 00:38:45 +0000 Subject: [PATCH] findbugs/eclipse warnings fixed --- util/src/org/aspectj/util/FileUtil.java | 9 +- util/src/org/aspectj/util/FuzzyBoolean.java | 7 +- util/src/org/aspectj/util/LangUtil.java | 678 +++++++++--------- util/src/org/aspectj/util/LineReader.java | 212 ------ util/src/org/aspectj/util/Reflection.java | 24 - .../org/aspectj/util/FileUtilTest.java | 1 - .../org/aspectj/util/LangUtilTest.java | 276 +++---- 7 files changed, 482 insertions(+), 725 deletions(-) delete mode 100644 util/src/org/aspectj/util/LineReader.java diff --git a/util/src/org/aspectj/util/FileUtil.java b/util/src/org/aspectj/util/FileUtil.java index ce84d4147..cfea7e533 100644 --- a/util/src/org/aspectj/util/FileUtil.java +++ b/util/src/org/aspectj/util/FileUtil.java @@ -673,13 +673,12 @@ public class FileUtil { if (!LangUtil.isEmpty(suffixes)) { ArrayList list = new ArrayList(); for (int i = 0; i < paths.length; i++) { - boolean listed = false; String path = paths[i]; - for (int j = 0; !listed && (j < suffixes.length); j++) { - String suffix = suffixes[j]; - if (listed = path.endsWith(suffix)) { + for (int j = 0; j < suffixes.length; j++) { + if (path.endsWith(suffixes[j])) { list.add(new File(basedir, paths[i])); - } + break; + } } } result = (File[]) list.toArray(new File[0]); diff --git a/util/src/org/aspectj/util/FuzzyBoolean.java b/util/src/org/aspectj/util/FuzzyBoolean.java index 0817af893..f47de92a0 100644 --- a/util/src/org/aspectj/util/FuzzyBoolean.java +++ b/util/src/org/aspectj/util/FuzzyBoolean.java @@ -10,14 +10,11 @@ * Contributors: * Xerox/PARC initial implementation * ******************************************************************/ - - package org.aspectj.util; - -/** This class implements boolean that include a "maybe" +/** + * This class implements boolean that include a "maybe" */ - public abstract class FuzzyBoolean { public abstract boolean alwaysTrue(); public abstract boolean alwaysFalse(); diff --git a/util/src/org/aspectj/util/LangUtil.java b/util/src/org/aspectj/util/LangUtil.java index 849f3187b..4bcac4198 100644 --- a/util/src/org/aspectj/util/LangUtil.java +++ b/util/src/org/aspectj/util/LangUtil.java @@ -10,11 +10,8 @@ * Contributors: * Xerox/PARC initial implementation * ******************************************************************/ - package org.aspectj.util; - -//import java.awt.event.InvocationEvent; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -29,19 +26,18 @@ import java.util.Arrays; import java.util.BitSet; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.StringTokenizer; /** * */ public class LangUtil { - /** map from String version to String class implemented in that version or later */ - private static final Map VM_CLASSES; + +// /** map from String version to String class implemented in that version or later */ +// private static final Map VM_CLASSES; public static final String EOL; static { @@ -52,40 +48,40 @@ public class LangUtil { try { buf.close(); StringBuffer sb = buf.getBuffer(); - if ((null != sb) || (0 < sb.length())) { + if (sb!=null) { eol = buf.toString(); } } catch (Throwable t) { } EOL = eol; - HashMap map = new HashMap(); - map.put("1.2", "java.lang.ref.Reference"); - map.put("1.3", "java.lang.reflect.Proxy"); - map.put("1.4", "java.nio.Buffer"); - map.put("1.5", "java.lang.annotation.Annotation"); - - VM_CLASSES = Collections.unmodifiableMap(map); +// HashMap map = new HashMap(); +// map.put("1.2", "java.lang.ref.Reference"); +// map.put("1.3", "java.lang.reflect.Proxy"); +// map.put("1.4", "java.nio.Buffer"); +// map.put("1.5", "java.lang.annotation.Annotation"); +// +// VM_CLASSES = Collections.unmodifiableMap(map); } - /** - * Detect whether Java version is supported. - * @param version String "1.2" or "1.3" or "1.4" - * @return true if the currently-running VM supports the version - * @throws IllegalArgumentException if version is not known - */ - public static final boolean supportsJava(String version) { - LangUtil.throwIaxIfNull(version, "version"); - String className = (String) VM_CLASSES.get(version); - if (null == className) { - throw new IllegalArgumentException("unknown version: " + version); - } - try { - Class.forName(className); - return true; - } catch (Throwable t) { - return false; - } - } +// /** +// * Detect whether Java version is supported. +// * @param version String "1.2" or "1.3" or "1.4" +// * @return true if the currently-running VM supports the version +// * @throws IllegalArgumentException if version is not known +// */ +// public static final boolean supportsJava(String version) { +// LangUtil.throwIaxIfNull(version, "version"); +// String className = (String) VM_CLASSES.get(version); +// if (null == className) { +// throw new IllegalArgumentException("unknown version: " + version); +// } +// try { +// Class.forName(className); +// return true; +// } catch (Throwable t) { +// return false; +// } +// } private static boolean is13VMOrGreater = true; private static boolean is14VMOrGreater = true; @@ -156,20 +152,20 @@ public class LangUtil { } } - /** - * Shorthand for "if any not null or not assignable, throw IllegalArgumentException" - * @throws IllegalArgumentException "{name} is not assignable to {c}" - */ - public static final void throwIaxIfNotAllAssignable(final Collection collection, - final Class c, final String name) { - throwIaxIfNull(collection, name); - if (null != c) { - for (Iterator iter = collection.iterator(); iter.hasNext();) { - throwIaxIfNotAssignable(iter.next(), c, name); - - } - } - } +// /** +// * Shorthand for "if any not null or not assignable, throw IllegalArgumentException" +// * @throws IllegalArgumentException "{name} is not assignable to {c}" +// */ +// public static final void throwIaxIfNotAllAssignable(final Collection collection, +// final Class c, final String name) { +// throwIaxIfNull(collection, name); +// if (null != c) { +// for (Iterator iter = collection.iterator(); iter.hasNext();) { +// throwIaxIfNotAssignable(iter.next(), c, name); +// +// } +// } +// } /** * Shorthand for "if false, throw IllegalArgumentException" * @throws IllegalArgumentException "{message}" if test is false @@ -180,11 +176,11 @@ public class LangUtil { } } - /** @return ((null == s) || (0 == s.trim().length())); */ - public static boolean isEmptyTrimmed(String s) { - return ((null == s) || (0 == s.length()) - || (0 == s.trim().length())); - } +// /** @return ((null == s) || (0 == s.trim().length())); */ +// public static boolean isEmptyTrimmed(String s) { +// return ((null == s) || (0 == s.length()) +// || (0 == s.trim().length())); +// } /** @return ((null == s) || (0 == s.length())); */ public static boolean isEmpty(String s) { @@ -318,71 +314,71 @@ public class LangUtil { : Collections.unmodifiableList(list)); } - /** - * Select from input String[] based on suffix-matching - * @param inputs String[] of input - null ignored - * @param suffixes String[] of suffix selectors - null ignored - * @param ignoreCase if true, ignore case - * @return String[] of input that end with any input - */ - public static String[] endsWith(String[] inputs, String[] suffixes, boolean ignoreCase) { - if (LangUtil.isEmpty(inputs) || LangUtil.isEmpty(suffixes)) { - return new String[0]; - } - if (ignoreCase) { - String[] temp = new String[suffixes.length]; - for (int i = 0; i < temp.length; i++) { - String suff = suffixes[i]; - temp[i] = (null == suff ? null : suff.toLowerCase()); - } - suffixes = temp; - } - ArrayList result = new ArrayList(); - for (int i = 0; i < inputs.length; i++) { - String input = inputs[i]; - if (null == input) { - continue; - } - if (!ignoreCase) { - input = input.toLowerCase(); - } - for (int j = 0; j < suffixes.length; j++) { - String suffix = suffixes[j]; - if (null == suffix) { - continue; - } - if (input.endsWith(suffix)) { - result.add(input); - break; - } - } - } - return (String[]) result.toArray(new String[0]); - } - - /** - * Select from input String[] if readable directories - * @param inputs String[] of input - null ignored - * @param baseDir the base directory of the input - * @return String[] of input that end with any input - */ - public static String[] selectDirectories(String[] inputs, File baseDir) { - if (LangUtil.isEmpty(inputs)) { - return new String[0]; - } - ArrayList result = new ArrayList(); - for (int i = 0; i < inputs.length; i++) { - String input = inputs[i]; - if (null == input) { - continue; - } - File inputFile = new File(baseDir, input); - if (inputFile.canRead() && inputFile.isDirectory()) { - result.add(input); - } - } - return (String[]) result.toArray(new String[0]); - } +// /** +// * Select from input String[] based on suffix-matching +// * @param inputs String[] of input - null ignored +// * @param suffixes String[] of suffix selectors - null ignored +// * @param ignoreCase if true, ignore case +// * @return String[] of input that end with any input +// */ +// public static String[] endsWith(String[] inputs, String[] suffixes, boolean ignoreCase) { +// if (LangUtil.isEmpty(inputs) || LangUtil.isEmpty(suffixes)) { +// return new String[0]; +// } +// if (ignoreCase) { +// String[] temp = new String[suffixes.length]; +// for (int i = 0; i < temp.length; i++) { +// String suff = suffixes[i]; +// temp[i] = (null == suff ? null : suff.toLowerCase()); +// } +// suffixes = temp; +// } +// ArrayList result = new ArrayList(); +// for (int i = 0; i < inputs.length; i++) { +// String input = inputs[i]; +// if (null == input) { +// continue; +// } +// if (!ignoreCase) { +// input = input.toLowerCase(); +// } +// for (int j = 0; j < suffixes.length; j++) { +// String suffix = suffixes[j]; +// if (null == suffix) { +// continue; +// } +// if (input.endsWith(suffix)) { +// result.add(input); +// break; +// } +// } +// } +// return (String[]) result.toArray(new String[0]); +// } +// +// /** +// * Select from input String[] if readable directories +// * @param inputs String[] of input - null ignored +// * @param baseDir the base directory of the input +// * @return String[] of input that end with any input +// */ +// public static String[] selectDirectories(String[] inputs, File baseDir) { +// if (LangUtil.isEmpty(inputs)) { +// return new String[0]; +// } +// ArrayList result = new ArrayList(); +// for (int i = 0; i < inputs.length; i++) { +// String input = inputs[i]; +// if (null == input) { +// continue; +// } +// File inputFile = new File(baseDir, input); +// if (inputFile.canRead() && inputFile.isDirectory()) { +// result.add(input); +// } +// } +// return (String[]) result.toArray(new String[0]); +// } /** * copy non-null two-dimensional String[][] @@ -424,7 +420,8 @@ public class LangUtil { String[] option = options[i]; LangUtil.throwIaxIfFalse(!LangUtil.isEmpty(option), "options"); String sought = option[0]; - if (found = sought.equals(args[j])) { + found = sought.equals(args[j]); + if (found) { foundSet.set(i); int doMore = option.length-1; if (0 < doMore) { @@ -459,185 +456,186 @@ public class LangUtil { return args; } - - /** - * Extract options and arguments to input parameter list, returning remainder. - * @param args the String[] input options - * @param validOptions the String[] options to find in the input args - not null - * @param optionArgs the int[] number of arguments for each option in validOptions - * (if null, then no arguments for any option) - * @param extracted the List for the matched options - * @return String[] of args remaining after extracting options to extracted - */ - public static String[] extractOptions(String[] args, String[] validOptions, - int[] optionArgs, List extracted) { - if (LangUtil.isEmpty(args) - || LangUtil.isEmpty(validOptions) ) { - return args; - } - if (null != optionArgs) { - if (optionArgs.length != validOptions.length) { - throw new IllegalArgumentException("args must match options"); - } - } - String[] result = new String[args.length]; - int resultIndex = 0; - for (int j = 0; j < args.length; j++) { - boolean found = false; - for (int i = 0; !found && (i < validOptions.length); i++) { - String sought = validOptions[i]; - int doMore = (null == optionArgs ? 0 : optionArgs[i]); - if (LangUtil.isEmpty(sought)) { - continue; - } - if (found = sought.equals(args[j])) { - if (null != extracted) { - extracted.add(sought); - } - if (0 < doMore) { - final int MAX = j + doMore; - if (MAX >= args.length) { - String s = "expecting " + doMore + " args after "; - throw new IllegalArgumentException(s + args[j]); - } - if (null != extracted) { - while (j < MAX) { - extracted.add(args[++j]); - } - } else { - j = MAX; - } - } - break; - } - } - if (!found) { - result[resultIndex++] = args[j]; - } - } - if (resultIndex < args.length) { - String[] temp = new String[resultIndex]; - System.arraycopy(result, 0, temp, 0, resultIndex); - args = temp; - } - return args; - } +// +// /** +// * Extract options and arguments to input parameter list, returning remainder. +// * @param args the String[] input options +// * @param validOptions the String[] options to find in the input args - not null +// * @param optionArgs the int[] number of arguments for each option in validOptions +// * (if null, then no arguments for any option) +// * @param extracted the List for the matched options +// * @return String[] of args remaining after extracting options to extracted +// */ +// public static String[] extractOptions(String[] args, String[] validOptions, +// int[] optionArgs, List extracted) { +// if (LangUtil.isEmpty(args) +// || LangUtil.isEmpty(validOptions) ) { +// return args; +// } +// if (null != optionArgs) { +// if (optionArgs.length != validOptions.length) { +// throw new IllegalArgumentException("args must match options"); +// } +// } +// String[] result = new String[args.length]; +// int resultIndex = 0; +// for (int j = 0; j < args.length; j++) { +// boolean found = false; +// for (int i = 0; !found && (i < validOptions.length); i++) { +// String sought = validOptions[i]; +// int doMore = (null == optionArgs ? 0 : optionArgs[i]); +// if (LangUtil.isEmpty(sought)) { +// continue; +// } +// found = sought.equals(args[j]); +// if (found) { +// if (null != extracted) { +// extracted.add(sought); +// } +// if (0 < doMore) { +// final int MAX = j + doMore; +// if (MAX >= args.length) { +// String s = "expecting " + doMore + " args after "; +// throw new IllegalArgumentException(s + args[j]); +// } +// if (null != extracted) { +// while (j < MAX) { +// extracted.add(args[++j]); +// } +// } else { +// j = MAX; +// } +// } +// break; +// } +// } +// if (!found) { +// result[resultIndex++] = args[j]; +// } +// } +// if (resultIndex < args.length) { +// String[] temp = new String[resultIndex]; +// System.arraycopy(result, 0, temp, 0, resultIndex); +// args = temp; +// } +// return args; +// } - /** @return String[] of entries in validOptions found in args */ - public static String[] selectOptions(String[] args, String[] validOptions) { - if (LangUtil.isEmpty(args) || LangUtil.isEmpty(validOptions)) { - return new String[0]; - } - ArrayList result = new ArrayList(); - for (int i = 0; i < validOptions.length; i++) { - String sought = validOptions[i]; - if (LangUtil.isEmpty(sought)) { - continue; - } - for (int j = 0; j < args.length; j++) { - if (sought.equals(args[j])) { - result.add(sought); - break; - } - } - } - return (String[]) result.toArray(new String[0]); - } +// /** @return String[] of entries in validOptions found in args */ +// public static String[] selectOptions(String[] args, String[] validOptions) { +// if (LangUtil.isEmpty(args) || LangUtil.isEmpty(validOptions)) { +// return new String[0]; +// } +// ArrayList result = new ArrayList(); +// for (int i = 0; i < validOptions.length; i++) { +// String sought = validOptions[i]; +// if (LangUtil.isEmpty(sought)) { +// continue; +// } +// for (int j = 0; j < args.length; j++) { +// if (sought.equals(args[j])) { +// result.add(sought); +// break; +// } +// } +// } +// return (String[]) result.toArray(new String[0]); +// } - /** @return String[] of entries in validOptions found in args */ - public static String[] selectOptions(List args, String[] validOptions) { - if (LangUtil.isEmpty(args) || LangUtil.isEmpty(validOptions)) { - return new String[0]; - } - ArrayList result = new ArrayList(); - for (int i = 0; i < validOptions.length; i++) { - String sought = validOptions[i]; - if (LangUtil.isEmpty(sought)) { - continue; - } - for (Iterator iter = args.iterator(); iter.hasNext();) { - String arg = (String) iter.next(); - if (sought.equals(arg)) { - result.add(sought); - break; - } - } - } - return (String[]) result.toArray(new String[0]); - } +// /** @return String[] of entries in validOptions found in args */ +// public static String[] selectOptions(List args, String[] validOptions) { +// if (LangUtil.isEmpty(args) || LangUtil.isEmpty(validOptions)) { +// return new String[0]; +// } +// ArrayList result = new ArrayList(); +// for (int i = 0; i < validOptions.length; i++) { +// String sought = validOptions[i]; +// if (LangUtil.isEmpty(sought)) { +// continue; +// } +// for (Iterator iter = args.iterator(); iter.hasNext();) { +// String arg = (String) iter.next(); +// if (sought.equals(arg)) { +// result.add(sought); +// break; +// } +// } +// } +// return (String[]) result.toArray(new String[0]); +// } - /** - * Generate variants of String[] options by creating an extra set for - * each option that ends with "-". If none end with "-", then an - * array equal to new String[][] { options } is returned; - * if one ends with "-", then two sets are returned, - * three causes eight sets, etc. - * @return String[][] with each option set. - * @throws IllegalArgumentException if any option is null or empty. - */ - public static String[][] optionVariants(String[] options) { - if ((null == options) || (0 == options.length)) { - return new String[][] { new String[0]}; - } - // be nice, don't stomp input - String[] temp = new String[options.length]; - System.arraycopy(options, 0, temp, 0, temp.length); - options = temp; - boolean[] dup = new boolean[options.length]; - int numDups = 0; - - for (int i = 0; i < options.length; i++) { - String option = options[i]; - if (LangUtil.isEmpty(option)) { - throw new IllegalArgumentException("empty option at " + i); - } - if (option.endsWith("-")) { - options[i] = option.substring(0, option.length()-1); - dup[i] = true; - numDups++; - } - } - final String[] NONE = new String[0]; - final int variants = exp(2, numDups); - final String[][] result = new String[variants][]; - // variant is a bitmap wrt doing extra value when dup[k]=true - for (int variant = 0; variant < variants; variant++) { - ArrayList next = new ArrayList(); - int nextOption = 0; - for (int k = 0; k < options.length; k++) { - if (!dup[k] || (0 != (variant & (1 << (nextOption++))))) { - next.add(options[k]); - } - } - result[variant] = (String[]) next.toArray(NONE); - } - return result; - } - - private static int exp(int base, int power) { // not in Math? - if (0 > power) { - throw new IllegalArgumentException("negative power: " + power); - } - int result = 1; - while (0 < power--) { - result *= base; - } - return result; - } +// /** +// * Generate variants of String[] options by creating an extra set for +// * each option that ends with "-". If none end with "-", then an +// * array equal to new String[][] { options } is returned; +// * if one ends with "-", then two sets are returned, +// * three causes eight sets, etc. +// * @return String[][] with each option set. +// * @throws IllegalArgumentException if any option is null or empty. +// */ +// public static String[][] optionVariants(String[] options) { +// if ((null == options) || (0 == options.length)) { +// return new String[][] { new String[0]}; +// } +// // be nice, don't stomp input +// String[] temp = new String[options.length]; +// System.arraycopy(options, 0, temp, 0, temp.length); +// options = temp; +// boolean[] dup = new boolean[options.length]; +// int numDups = 0; +// +// for (int i = 0; i < options.length; i++) { +// String option = options[i]; +// if (LangUtil.isEmpty(option)) { +// throw new IllegalArgumentException("empty option at " + i); +// } +// if (option.endsWith("-")) { +// options[i] = option.substring(0, option.length()-1); +// dup[i] = true; +// numDups++; +// } +// } +// final String[] NONE = new String[0]; +// final int variants = exp(2, numDups); +// final String[][] result = new String[variants][]; +// // variant is a bitmap wrt doing extra value when dup[k]=true +// for (int variant = 0; variant < variants; variant++) { +// ArrayList next = new ArrayList(); +// int nextOption = 0; +// for (int k = 0; k < options.length; k++) { +// if (!dup[k] || (0 != (variant & (1 << (nextOption++))))) { +// next.add(options[k]); +// } +// } +// result[variant] = (String[]) next.toArray(NONE); +// } +// return result; +// } +// +// private static int exp(int base, int power) { // not in Math? +// if (0 > power) { +// throw new IllegalArgumentException("negative power: " + power); +// } +// int result = 1; +// while (0 < power--) { +// result *= base; +// } +// return result; +// } - /** - * Make a copy of the array. - * @return an array with the same component type as source - * containing same elements, even if null. - * @throws IllegalArgumentException if source is null - */ - public static final Object[] copy(Object[] source) { - LangUtil.throwIaxIfNull(source, "source"); - final Class c = source.getClass().getComponentType(); - Object[] result = (Object[]) Array.newInstance(c, source.length); - System.arraycopy(source, 0, result, 0, result.length); - return result; - } +// /** +// * Make a copy of the array. +// * @return an array with the same component type as source +// * containing same elements, even if null. +// * @throws IllegalArgumentException if source is null +// */ +// public static final Object[] copy(Object[] source) { +// LangUtil.throwIaxIfNull(source, "source"); +// final Class c = source.getClass().getComponentType(); +// Object[] result = (Object[]) Array.newInstance(c, source.length); +// System.arraycopy(source, 0, result, 0, result.length); +// return result; +// } /** @@ -737,36 +735,36 @@ public class LangUtil { return result; } - /** clip StringBuffer to maximum number of lines */ - static String clipBuffer(StringBuffer buffer, int maxLines) { - if ((null == buffer) || (1 > buffer.length())) return ""; - StringBuffer result = new StringBuffer(); - int j = 0; - final int MAX = maxLines; - final int N = buffer.length(); - for (int i = 0, srcBegin = 0; i < MAX; srcBegin += j) { - // todo: replace with String variant if/since getting char? - char[] chars = new char[128]; - int srcEnd = srcBegin+chars.length; - if (srcEnd >= N) { - srcEnd = N-1; - } - if (srcBegin == srcEnd) break; - //log("srcBegin:" + srcBegin + ":srcEnd:" + srcEnd); - buffer.getChars(srcBegin, srcEnd, chars, 0); - for (j = 0; j < srcEnd-srcBegin/*chars.length*/; j++) { - char c = chars[j]; - if (c == '\n') { - i++; - j++; - break; - } - } - try { result.append(chars, 0, j); } - catch (Throwable t) { } - } - return result.toString(); - } +// /** clip StringBuffer to maximum number of lines */ +// static String clipBuffer(StringBuffer buffer, int maxLines) { +// if ((null == buffer) || (1 > buffer.length())) return ""; +// StringBuffer result = new StringBuffer(); +// int j = 0; +// final int MAX = maxLines; +// final int N = buffer.length(); +// for (int i = 0, srcBegin = 0; i < MAX; srcBegin += j) { +// // todo: replace with String variant if/since getting char? +// char[] chars = new char[128]; +// int srcEnd = srcBegin+chars.length; +// if (srcEnd >= N) { +// srcEnd = N-1; +// } +// if (srcBegin == srcEnd) break; +// //log("srcBegin:" + srcBegin + ":srcEnd:" + srcEnd); +// buffer.getChars(srcBegin, srcEnd, chars, 0); +// for (j = 0; j < srcEnd-srcBegin/*chars.length*/; j++) { +// char c = chars[j]; +// if (c == '\n') { +// i++; +// j++; +// break; +// } +// } +// try { result.append(chars, 0, j); } +// catch (Throwable t) { } +// } +// return result.toString(); +// } /** * @return "({UnqualifiedExceptionClass}) {message}" @@ -1021,22 +1019,22 @@ public class LangUtil { return controller; } - /** - * Create a process to run asynchronously. - * @param controller if not null, initialize this one - * @param command the String[] command to run - * @param controller the ProcessControl for streams and results - */ - public static ProcessController makeProcess( // not needed? - ProcessController controller, - String[] command, - String label) { - if (null == controller) { - controller = new ProcessController(); - } - controller.init(command, label); - return controller; - } +// /** +// * Create a process to run asynchronously. +// * @param controller if not null, initialize this one +// * @param command the String[] command to run +// * @param controller the ProcessControl for streams and results +// */ +// public static ProcessController makeProcess( // not needed? +// ProcessController controller, +// String[] command, +// String label) { +// if (null == controller) { +// controller = new ProcessController(); +// } +// controller.init(command, label); +// return controller; +// } /** * Find java executable File path from java.home system property. diff --git a/util/src/org/aspectj/util/LineReader.java b/util/src/org/aspectj/util/LineReader.java deleted file mode 100644 index 223ca0566..000000000 --- a/util/src/org/aspectj/util/LineReader.java +++ /dev/null @@ -1,212 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - - -package org.aspectj.util; - -import java.io.*; -import java.util.ArrayList; - -/** - * LineNumberReader which absorbs comments and blank lines - * and renders as file:line - */ -public class LineReader extends LineNumberReader { - /** delimited multi-line output of readToBlankLine */ - public static final String RETURN= "\n\r"; - - private static final String[] NONE = new String[0]; - private static final String cSCRIPT = "#"; - private static final String cJAVA = "//"; - private static final String[] TESTER_LEAD = new String[] {cSCRIPT, cJAVA}; - - /** - * Convenience factory for tester suite files - * @return null if IOException or IllegalArgumentException thrown - */ - public static final LineReader createTester(File file) { - return create(file, TESTER_LEAD, null); - } - - /** - * convenience factory - * @return null if IOException or IllegalArgumentException thrown - */ - public static final LineReader create(File file, - String[] leadComments, String[] eolComments) { - try { - FileReader reader = new FileReader(file); - return new LineReader(reader, file, leadComments, eolComments); - } catch (IllegalArgumentException e) { - } catch (IOException e) { - } - return null; - } - - final private File file; - final private String[] eolComments; - final private String[] leadComments; - transient String lastLine; - - /** - * @param file the File used to open the FileReader - * @param leadComments the String[] to be taken as the start of - * comments when they are the first non-blank text on a line - - * pass null to signal none. - * @param leadComments the String[] to be taken as the start of - * comment anywhere on a line - pass null to signal none. - *@throws IllegalArgumentException if any String in - * leadComments or eolComments is null. - */ - public LineReader(FileReader reader, File file, - String[] leadComments, String[] eolComments) { - super(reader); - this.file = file; - this.eolComments = normalize(eolComments); - this.leadComments = normalize(leadComments); - } - public LineReader(FileReader reader, File file) { - this(reader, file, null, null); - } - - /** @return file:line */ - public String toString() { - return file.getPath() + ":" + getLineNumber(); - } - - /** @return underlying file */ - public File getFile() { return file; } - - /** - * Reader first..last (inclusive) and return in String[]. - * This will return (1+(last-first)) elements only if this - * reader has not read past the first line and there are last lines - * and there are no IOExceptions during reads. - * @param first the first line to read - if negative, use 0 - * @param last the last line to read (inclusive) - * - if less than first, use first - * @return String[] of first..last (inclusive) lines read or - */ - public String[] readLines(int first, int last) { - if (0 > first) first = 0; - if (first > last) last = first; - ArrayList list = new ArrayList(); - try { - String line = null; - while (getLineNumber() < first) { - line = readLine(); - if (null == line) { - break; - } - } - if (getLineNumber() > first) { - // XXX warn? something else read past line - } - if ((null != line) && (first == getLineNumber())) { - list.add(line); - while (last >= getLineNumber()) { - line = readLine(); - if (null == line) { - break; - } - list.add(line); - } - } - } catch (IOException e) { - return NONE; - } - return (String[]) list.toArray(NONE); - } - - /** Skip to next blank line - * @return the String containing all lines skipped (delimited with RETURN) - */ - public String readToBlankLine() throws IOException { - StringBuffer sb = new StringBuffer(); - String input; - while (null != (input = nextLine(false))) { // get next empty line to restart - sb.append(input); - sb.append(RETURN);// XXX verify/ignore/correct - } - return sb.toString(); - } - - /** - * lastLine is set only by readClippedLine, not readLine. - * @return the last line read, after clipping - */ - public String lastLine() { - return lastLine; - } - - /** - * Get the next line from the input stream, stripping eol and - * leading comments. - * If emptyLinesOk is true, then this reads past lines which are - * empty after omitting comments and trimming until the next non-empty line. - * Otherwise, this returns null on reading an empty line. - * (The input stream is not exhausted until this - * returns null when emptyLines is true.) - * @param skipEmpties if true, run to next non-empty line; if false, return next line - * @return null if no more lines or got an empty line when they are not ok, - * or next non-null, non-empty line in reader, - * ignoring comments - */ - public String nextLine(boolean skipEmpties) throws IOException { - String result; - do { - result = readClippedLine(); - if ((null != result) && skipEmpties && (0 == result.length())) { - continue; - } - return result; - } while (true); - } - - /** @return null if no more lines or a clipped line otherwise */ - protected String readClippedLine() throws IOException { - String result = readLine(); - if (result != null) { - result = result.trim(); - int len = result.length(); - for (int i = 0; ((0 < len) && (i < leadComments.length)); i++) { - if (result.startsWith(leadComments[i])) { - result = ""; - len = 0; - } - } - for (int i = 0; ((0 < len) && (i < eolComments.length)); i++) { - int loc = result.indexOf(eolComments[i]); - if (-1 != loc) { - result = result.substring(0, loc); - len = result.length(); - } - } - } - lastLine = result; - return result; - } - - private String[] normalize(String[] input) { - if ((null == input) || (0 == input.length)) return NONE; - String[] result = new String[input.length]; - System.arraycopy(input, 0, result, 0, result.length); - for (int i = 0; i < result.length; i++) { - if ((null == result[i]) || (0 == result[i].length())) { - throw new IllegalArgumentException("empty input at [" + i + "]"); - } - } - return result; - } -} - diff --git a/util/src/org/aspectj/util/Reflection.java b/util/src/org/aspectj/util/Reflection.java index 2ea5eb6f8..575caa665 100644 --- a/util/src/org/aspectj/util/Reflection.java +++ b/util/src/org/aspectj/util/Reflection.java @@ -26,32 +26,10 @@ public class Reflection { private Reflection() { } - public static Object invokestatic(Class class_, String name) { - return invokestaticN(class_, name, new Object[0]); - } - - public static Object invokestatic(Class class_, String name, Object arg1) { - return invokestaticN(class_, name, new Object[] { arg1 }); - } - - public static Object invokestatic(Class class_, String name, Object arg1, Object arg2) { - return invokestaticN(class_, name, new Object[] { arg1, arg2 }); - } - - public static Object invokestatic(Class class_, String name, Object arg1, Object arg2, Object arg3) { - return invokestaticN(class_, name, new Object[] { arg1, arg2, arg3 }); - } - - public static Object invokestaticN(Class class_, String name, Object[] args) { return invokeN(class_, name, null, args); } - - public static Object invoke(Class class_, Object target, String name, Object arg1) { - return invokeN(class_, name, target, new Object[] { arg1 }); - } - public static Object invoke(Class class_, Object target, String name, Object arg1, Object arg2) { return invokeN(class_, name, target, new Object[] { arg1, arg2 }); } @@ -60,8 +38,6 @@ public class Reflection { return invokeN(class_, name, target, new Object[] { arg1, arg2, arg3 }); } - - public static Object invokeN(Class class_, String name, Object target, Object[] args) { Method meth = getMatchingMethod(class_, name, args); diff --git a/util/testsrc/org/aspectj/util/FileUtilTest.java b/util/testsrc/org/aspectj/util/FileUtilTest.java index 23ac0e31f..d3ae6b502 100644 --- a/util/testsrc/org/aspectj/util/FileUtilTest.java +++ b/util/testsrc/org/aspectj/util/FileUtilTest.java @@ -340,7 +340,6 @@ public class FileUtilTest extends TestCase { private void checkGetURL(String arg) { assertTrue(null != arg); File f = new File(arg); - assertTrue(null != f); URL url = FileUtil.getFileURL(f); assertTrue(null != url); log("url " + url); diff --git a/util/testsrc/org/aspectj/util/LangUtilTest.java b/util/testsrc/org/aspectj/util/LangUtilTest.java index b28e17f36..cee1c5f11 100644 --- a/util/testsrc/org/aspectj/util/LangUtilTest.java +++ b/util/testsrc/org/aspectj/util/LangUtilTest.java @@ -28,78 +28,78 @@ public class LangUtilTest extends TestCase { super(name); } - /** @see LangUtil.extractOptions(String[], String[], int[], List) */ - public void testExtractOptions() { - ArrayList extracted = new ArrayList(); - String[] args = new String[] { "-d", "classes", "-classpath", "foo.jar", "-verbose", "Bar.java" }; - String[] validOptions = new String[] { "-classpath", "-d", "-verbose", "-help" }; - int[] optionArgs = new int[] { 1, 1, 0, 0 }; - String[] result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted); - String resultString = "" + Arrays.asList(result); - String EXP = "[Bar.java]"; - assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); - EXP = "[-d, classes, -classpath, foo.jar, -verbose]"; - resultString = "" + extracted; - assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); - - // no input, no output - extracted.clear(); - args = new String[] {}; - result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted); - resultString = "" + Arrays.asList(result); - EXP = "[]"; - assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); - resultString = "" + extracted; - assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); - - // one input, nothing extracted - extracted.clear(); - args = new String[] {"Bar.java"}; - result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted); - resultString = "" + Arrays.asList(result); - EXP = "[Bar.java]"; - assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); - EXP = "[]"; - resultString = "" + extracted; - assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); - - // one input, extracted - extracted.clear(); - args = new String[] {"-verbose"}; - result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted); - resultString = "" + Arrays.asList(result); - EXP = "[]"; - assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); - EXP = "[-verbose]"; - resultString = "" + extracted; - assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); - - // ------- booleans - validOptions = new String[] { "-help", "-verbose" }; - optionArgs = null; - - // one input, extracted - extracted.clear(); - args = new String[] {"-verbose"}; - result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted); - resultString = "" + Arrays.asList(result); - EXP = "[]"; - assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); - EXP = "[-verbose]"; - resultString = "" + extracted; - assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); - - // one input, not extracted - extracted.clear(); - args = new String[] {"Bar.java"}; - result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted); - resultString = "" + Arrays.asList(result); - EXP = "[Bar.java]"; - assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); - EXP = "[]"; - resultString = "" + extracted; - assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); - } +// /** @see LangUtil.extractOptions(String[], String[], int[], List) */ +// public void testExtractOptions() { +// ArrayList extracted = new ArrayList(); +// String[] args = new String[] { "-d", "classes", "-classpath", "foo.jar", "-verbose", "Bar.java" }; +// String[] validOptions = new String[] { "-classpath", "-d", "-verbose", "-help" }; +// int[] optionArgs = new int[] { 1, 1, 0, 0 }; +// String[] result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted); +// String resultString = "" + Arrays.asList(result); +// String EXP = "[Bar.java]"; +// assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); +// EXP = "[-d, classes, -classpath, foo.jar, -verbose]"; +// resultString = "" + extracted; +// assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); +// +// // no input, no output +// extracted.clear(); +// args = new String[] {}; +// result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted); +// resultString = "" + Arrays.asList(result); +// EXP = "[]"; +// assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); +// resultString = "" + extracted; +// assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); +// +// // one input, nothing extracted +// extracted.clear(); +// args = new String[] {"Bar.java"}; +// result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted); +// resultString = "" + Arrays.asList(result); +// EXP = "[Bar.java]"; +// assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); +// EXP = "[]"; +// resultString = "" + extracted; +// assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); +// +// // one input, extracted +// extracted.clear(); +// args = new String[] {"-verbose"}; +// result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted); +// resultString = "" + Arrays.asList(result); +// EXP = "[]"; +// assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); +// EXP = "[-verbose]"; +// resultString = "" + extracted; +// assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); +// +// // ------- booleans +// validOptions = new String[] { "-help", "-verbose" }; +// optionArgs = null; +// +// // one input, extracted +// extracted.clear(); +// args = new String[] {"-verbose"}; +// result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted); +// resultString = "" + Arrays.asList(result); +// EXP = "[]"; +// assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); +// EXP = "[-verbose]"; +// resultString = "" + extracted; +// assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); +// +// // one input, not extracted +// extracted.clear(); +// args = new String[] {"Bar.java"}; +// result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted); +// resultString = "" + Arrays.asList(result); +// EXP = "[Bar.java]"; +// assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); +// EXP = "[]"; +// resultString = "" + extracted; +// assertTrue(resultString + " != " + EXP, resultString.equals(EXP)); +// } public void testVersion() { assertTrue(LangUtil.is13VMOrGreater()); // min vm now - floor may change @@ -144,73 +144,73 @@ public class LangUtilTest extends TestCase { assertTrue(null == options[3][0]); } - public void testOptionVariants() { - String[] NONE = new String[0]; - String[] one = new String[] {"-1"}; - String[] two = new String[] {"-2"}; - String[] three= new String[] {"-3"}; - String[] both = new String[] {"-1", "-2" }; - String[] oneB = new String[] {"-1-"}; - String[] bothB = new String[] {"-1-", "-2-" }; - String[] onetwoB = new String[] {"-1", "-2-" }; - String[] oneBtwo = new String[] {"-1-", "-2" }; - String[] threeB = new String[] {"-1-", "-2-", "-3-"}; - String[] athreeB = new String[] {"a", "-1-", "-2-", "-3-"}; - String[] threeaB = new String[] {"-1-", "a", "-2-", "-3-"}; - - checkOptionVariants(NONE, new String[][] { NONE }); - checkOptionVariants(one, new String[][] { one }); - checkOptionVariants(both, new String[][] { both }); - checkOptionVariants(oneB, new String[][] { NONE, one }); - checkOptionVariants(bothB, new String[][] { NONE, one, new String[] {"-2"}, both }); - checkOptionVariants(onetwoB, new String[][] { one, new String[] {"-1", "-2"}}); - checkOptionVariants(oneBtwo, new String[][] { two, new String[] {"-1", "-2"}}); - checkOptionVariants(threeB, new String[][] - { - NONE, - one, - two, - new String[] {"-1", "-2"}, - three, - new String[] {"-1", "-3"}, - new String[] {"-2", "-3"}, - new String[] {"-1", "-2", "-3"} - }); - checkOptionVariants(athreeB, new String[][] - { - new String[] {"a"}, - new String[] {"a", "-1"}, - new String[] {"a", "-2"}, - new String[] {"a", "-1", "-2"}, - new String[] {"a", "-3"}, - new String[] {"a", "-1", "-3"}, - new String[] {"a", "-2", "-3"}, - new String[] {"a", "-1", "-2", "-3"} - }); - checkOptionVariants(threeaB, new String[][] - { - new String[] {"a"}, - new String[] {"-1", "a"}, - new String[] {"a", "-2"}, - new String[] {"-1", "a", "-2"}, - new String[] {"a", "-3"}, - new String[] {"-1", "a", "-3"}, - new String[] {"a", "-2", "-3"}, - new String[] {"-1", "a", "-2", "-3"} - }); - } +// public void testOptionVariants() { +// String[] NONE = new String[0]; +// String[] one = new String[] {"-1"}; +// String[] two = new String[] {"-2"}; +// String[] three= new String[] {"-3"}; +// String[] both = new String[] {"-1", "-2" }; +// String[] oneB = new String[] {"-1-"}; +// String[] bothB = new String[] {"-1-", "-2-" }; +// String[] onetwoB = new String[] {"-1", "-2-" }; +// String[] oneBtwo = new String[] {"-1-", "-2" }; +// String[] threeB = new String[] {"-1-", "-2-", "-3-"}; +// String[] athreeB = new String[] {"a", "-1-", "-2-", "-3-"}; +// String[] threeaB = new String[] {"-1-", "a", "-2-", "-3-"}; +// +// checkOptionVariants(NONE, new String[][] { NONE }); +// checkOptionVariants(one, new String[][] { one }); +// checkOptionVariants(both, new String[][] { both }); +// checkOptionVariants(oneB, new String[][] { NONE, one }); +// checkOptionVariants(bothB, new String[][] { NONE, one, new String[] {"-2"}, both }); +// checkOptionVariants(onetwoB, new String[][] { one, new String[] {"-1", "-2"}}); +// checkOptionVariants(oneBtwo, new String[][] { two, new String[] {"-1", "-2"}}); +// checkOptionVariants(threeB, new String[][] +// { +// NONE, +// one, +// two, +// new String[] {"-1", "-2"}, +// three, +// new String[] {"-1", "-3"}, +// new String[] {"-2", "-3"}, +// new String[] {"-1", "-2", "-3"} +// }); +// checkOptionVariants(athreeB, new String[][] +// { +// new String[] {"a"}, +// new String[] {"a", "-1"}, +// new String[] {"a", "-2"}, +// new String[] {"a", "-1", "-2"}, +// new String[] {"a", "-3"}, +// new String[] {"a", "-1", "-3"}, +// new String[] {"a", "-2", "-3"}, +// new String[] {"a", "-1", "-2", "-3"} +// }); +// checkOptionVariants(threeaB, new String[][] +// { +// new String[] {"a"}, +// new String[] {"-1", "a"}, +// new String[] {"a", "-2"}, +// new String[] {"-1", "a", "-2"}, +// new String[] {"a", "-3"}, +// new String[] {"-1", "a", "-3"}, +// new String[] {"a", "-2", "-3"}, +// new String[] {"-1", "a", "-2", "-3"} +// }); +// } - void checkOptionVariants(String[] options, String[][] expected) { - String[][] result = LangUtil.optionVariants(options); - if (expected.length != result.length) { - assertTrue("exp=" + expected.length + " actual=" + result.length, false); - } - for (int i = 0; i < expected.length; i++) { - assertEquals(""+i, - "" + Arrays.asList(expected[i]), - "" + Arrays.asList(result[i])); - } - } +// void checkOptionVariants(String[] options, String[][] expected) { +// String[][] result = LangUtil.optionVariants(options); +// if (expected.length != result.length) { +// assertTrue("exp=" + expected.length + " actual=" + result.length, false); +// } +// for (int i = 0; i < expected.length; i++) { +// assertEquals(""+i, +// "" + Arrays.asList(expected[i]), +// "" + Arrays.asList(result[i])); +// } +// } /** @see XMLWriterTest#testUnflattenList() */ public void testCommaSplit() { -- 2.39.5