public interface Displayable {
String displayString(Object o);
}
-
- public static String LINE_SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$
- public static char[] LINE_SEPARATOR_CHARS = LINE_SEPARATOR.toCharArray();
-
- private final static char[] DOUBLE_QUOTES = "''".toCharArray(); //$NON-NLS-1$
- private final static char[] SINGLE_QUOTE = "'".toCharArray(); //$NON-NLS-1$
- private static final int DEFAULT_READING_SIZE = 8192;
+ static {
+ relocalize();
+ }
/* Bundle containing messages */
protected static ResourceBundle bundle;
private final static String bundleName =
"org.eclipse.jdt.internal.compiler.util.messages"; //$NON-NLS-1$
- static {
- relocalize();
+ private static final int DEFAULT_READING_SIZE = 8192;
+
+ private final static char[] DOUBLE_QUOTES = "''".toCharArray(); //$NON-NLS-1$
+
+ public static String LINE_SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$
+ public static char[] LINE_SEPARATOR_CHARS = LINE_SEPARATOR.toCharArray();
+ private final static char[] SINGLE_QUOTE = "'".toCharArray(); //$NON-NLS-1$
+
+ /**
+ * Lookup the message with the given ID in this catalog
+ */
+ public static String bind(String id) {
+ return bind(id, (String[]) null);
}
/**
* Lookup the message with the given ID in this catalog and bind its
- * substitution locations with the given strings.
+ * substitution locations with the given string.
*/
- public static String bind(String id, String binding1, String binding2) {
- return bind(id, new String[] { binding1, binding2 });
+ public static String bind(String id, String argument) {
+ return bind(id, new String[] { argument });
}
/**
* Lookup the message with the given ID in this catalog and bind its
- * substitution locations with the given string.
+ * substitution locations with the given strings.
*/
- public static String bind(String id, String binding) {
- return bind(id, new String[] { binding });
+ public static String bind(String id, String argument1, String argument2) {
+ return bind(id, new String[] { argument1, argument2 });
}
/**
* Lookup the message with the given ID in this catalog and bind its
* substitution locations with the given string values.
*/
- public static String bind(String id, String[] bindings) {
+ public static String bind(String id, String[] arguments) {
if (id == null)
return "No message available"; //$NON-NLS-1$
String message = null;
// the id we were looking for. In most cases this is semi-informative so is not too bad.
return "Missing message: " + id + " in: " + bundleName; //$NON-NLS-2$ //$NON-NLS-1$
}
+ return bindMessage(message, arguments);
+ }
+ /**
+ * Bind some message with given string values.
+ */
+ public static String bindMessage(String message, String[] arguments) {
// for compatibility with MessageFormat which eliminates double quotes in original message
char[] messageWithNoDoubleQuotes =
CharOperation.replace(message.toCharArray(), DOUBLE_QUOTES, SINGLE_QUOTE);
- if (bindings == null) return new String(messageWithNoDoubleQuotes);
+ if (arguments == null) return new String(messageWithNoDoubleQuotes);
int length = messageWithNoDoubleQuotes.length;
int start = 0;
StringBuffer output = null;
while (true) {
if ((end = CharOperation.indexOf('{', messageWithNoDoubleQuotes, start)) > -1) {
- if (output == null) output = new StringBuffer(length+bindings.length*20);
+ if (output == null) output = new StringBuffer(length+arguments.length*20);
output.append(messageWithNoDoubleQuotes, start, end - start);
if ((start = CharOperation.indexOf('}', messageWithNoDoubleQuotes, end + 1)) > -1) {
int index = -1;
String argId = new String(messageWithNoDoubleQuotes, end + 1, start - end - 1);
try {
index = Integer.parseInt(argId);
- output.append(bindings[index]);
+ if (arguments[index] == null) {
+ output.append('{').append(argId).append('}'); // leave parameter in since no better arg '{0}'
+ } else {
+ output.append(arguments[index]);
+ }
} catch (NumberFormatException nfe) { // could be nested message ID {compiler.name}
boolean done = false;
- if (!id.equals(argId)) {
- String argMessage = null;
- try {
- argMessage = bundle.getString(argId);
- output.append(argMessage);
- done = true;
- } catch (MissingResourceException e) {
- // unable to bind argument, ignore (will leave argument in)
- }
+ String argMessage = null;
+ try {
+ argMessage = bundle.getString(argId);
+ output.append(argMessage);
+ done = true;
+ } catch (MissingResourceException e) {
+ // unable to bind argument, ignore (will leave argument in)
}
if (!done) output.append(messageWithNoDoubleQuotes, end + 1, start - end);
} catch (ArrayIndexOutOfBoundsException e) {
return output.toString();
}
/**
- * Lookup the message with the given ID in this catalog
- */
- public static String bind(String id) {
- return bind(id, (String[]) null);
- }
- /**
- * Creates a NLS catalog for the given locale.
- */
- public static void relocalize() {
- try {
- bundle = ResourceBundle.getBundle(bundleName, Locale.getDefault());
- } catch(MissingResourceException e) {
- System.out.println("Missing resource : " + bundleName.replace('.', '/') + ".properties for locale " + Locale.getDefault()); //$NON-NLS-1$//$NON-NLS-2$
- throw e;
- }
- }
- /**
* Returns the given bytes as a char array using a given encoding (null means platform default).
*/
public static char[] bytesToChar(byte[] bytes, String encoding) throws IOException {
* Returns true iff str.toLowerCase().endsWith(".class")
* implementation is not creating extra strings.
*/
+ public final static boolean isClassFileName(char[] name) {
+ int nameLength = name == null ? 0 : name.length;
+ int suffixLength = SUFFIX_CLASS.length;
+ if (nameLength < suffixLength) return false;
+
+ for (int i = 0, offset = nameLength - suffixLength; i < suffixLength; i++) {
+ char c = name[offset + i];
+ if (c != SUFFIX_class[i] && c != SUFFIX_CLASS[i]) return false;
+ }
+ return true;
+ }
+ /**
+ * Returns true iff str.toLowerCase().endsWith(".class")
+ * implementation is not creating extra strings.
+ */
public final static boolean isClassFileName(String name) {
int nameLength = name == null ? 0 : name.length();
int suffixLength = SUFFIX_CLASS.length;
}
return true;
}
+ /* TODO (philippe) should consider promoting it to CharOperation
+ * Returns whether the given resource path matches one of the inclusion/exclusion
+ * patterns.
+ * NOTE: should not be asked directly using pkg root pathes
+ * @see IClasspathEntry#getInclusionPatterns
+ * @see IClasspathEntry#getExclusionPatterns
+ */
+ public final static boolean isExcluded(char[] path, char[][] inclusionPatterns, char[][] exclusionPatterns, boolean isFolderPath) {
+ if (inclusionPatterns == null && exclusionPatterns == null) return false;
+
+ inclusionCheck: if (inclusionPatterns != null) {
+ for (int i = 0, length = inclusionPatterns.length; i < length; i++) {
+ char[] pattern = inclusionPatterns[i];
+ char[] folderPattern = pattern;
+ if (isFolderPath) {
+ int lastSlash = CharOperation.lastIndexOf('/', pattern);
+ if (lastSlash != -1 && lastSlash != pattern.length-1){ // trailing slash -> adds '**' for free (see http://ant.apache.org/manual/dirtasks.html)
+ int star = CharOperation.indexOf('*', pattern, lastSlash);
+ if ((star == -1
+ || star >= pattern.length-1
+ || pattern[star+1] != '*')) {
+ folderPattern = CharOperation.subarray(pattern, 0, lastSlash);
+ }
+ }
+ }
+ if (CharOperation.pathMatch(folderPattern, path, true, '/')) {
+ break inclusionCheck;
+ }
+ }
+ return true; // never included
+ }
+ if (isFolderPath) {
+ path = CharOperation.concat(path, new char[] {'*'}, '/');
+ }
+ exclusionCheck: if (exclusionPatterns != null) {
+ for (int i = 0, length = exclusionPatterns.length; i < length; i++) {
+ if (CharOperation.pathMatch(exclusionPatterns[i], path, true, '/')) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
/**
- * Returns true iff str.toLowerCase().endsWith(".class")
+ * Returns true iff str.toLowerCase().endsWith(".java")
* implementation is not creating extra strings.
*/
- public final static boolean isClassFileName(char[] name) {
+ public final static boolean isJavaFileName(char[] name) {
int nameLength = name == null ? 0 : name.length;
- int suffixLength = SUFFIX_CLASS.length;
+ int suffixLength = SUFFIX_JAVA.length;
if (nameLength < suffixLength) return false;
for (int i = 0, offset = nameLength - suffixLength; i < suffixLength; i++) {
char c = name[offset + i];
- if (c != SUFFIX_class[i] && c != SUFFIX_CLASS[i]) return false;
+ if (c != SUFFIX_java[i] && c != SUFFIX_JAVA[i]) return false;
}
return true;
- }
+ }
/**
* Returns true iff str.toLowerCase().endsWith(".java")
* implementation is not creating extra strings.
return true;
}
/**
- * Returns true iff str.toLowerCase().endsWith(".java")
- * implementation is not creating extra strings.
+ * Creates a NLS catalog for the given locale.
*/
- public final static boolean isJavaFileName(char[] name) {
- int nameLength = name == null ? 0 : name.length;
- int suffixLength = SUFFIX_JAVA.length;
- if (nameLength < suffixLength) return false;
+ public static void relocalize() {
+ try {
+ bundle = ResourceBundle.getBundle(bundleName, Locale.getDefault());
+ } catch(MissingResourceException e) {
+ System.out.println("Missing resource : " + bundleName.replace('.', '/') + ".properties for locale " + Locale.getDefault()); //$NON-NLS-1$//$NON-NLS-2$
+ throw e;
+ }
+ }
- for (int i = 0, offset = nameLength - suffixLength; i < suffixLength; i++) {
- char c = name[offset + i];
- if (c != SUFFIX_java[i] && c != SUFFIX_JAVA[i]) return false;
+ /**
+ * Converts a boolean value into Boolean.
+ * @param bool The boolean to convert
+ * @return The corresponding Boolean object (TRUE or FALSE).
+ */
+ public static Boolean toBoolean(boolean bool) {
+ if (bool) {
+ return Boolean.TRUE;
+ } else {
+ return Boolean.FALSE;
}
- return true;
}
/**
* Converts an array of Objects into String.
}
return buffer.toString();
}
-
- /**
- * Converts a boolean value into Boolean.
- * @param bool The boolean to convert
- * @return The corresponding Boolean object (TRUE or FALSE).
- */
- public static Boolean toBoolean(boolean bool) {
- if (bool) {
- return Boolean.TRUE;
- } else {
- return Boolean.FALSE;
- }
- }
}