# HG changeset patch # User Jaroslav Tulach # Date 1348899212 -7200 # Node ID 4b334950499dbbc507c8842c7fc02008c13da997 # Parent 922ba77e0de0a23d97c01e50c497fba5b55b7f27 Removing references to classes that would create too big transitive dependencies diff -r 922ba77e0de0 -r 4b334950499d emul/src/main/java/java/lang/AbstractStringBuilder.java --- a/emul/src/main/java/java/lang/AbstractStringBuilder.java Sat Sep 29 07:50:39 2012 +0200 +++ b/emul/src/main/java/java/lang/AbstractStringBuilder.java Sat Sep 29 08:13:32 2012 +0200 @@ -124,7 +124,7 @@ throw new OutOfMemoryError(); newCapacity = Integer.MAX_VALUE; } - value = copyOf(value, newCapacity); + value = String.copyOf(value, newCapacity); } /** @@ -136,7 +136,7 @@ */ public void trimToSize() { if (count < value.length) { - value = copyOf(value, count); + value = String.copyOf(value, count); } } @@ -1399,10 +1399,4 @@ return value; } - private static char[] copyOf(char[] original, int newLength) { - char[] copy = new char[newLength]; - System.arraycopy(original, 0, copy, 0, - Math.min(original.length, newLength)); - return copy; - } } diff -r 922ba77e0de0 -r 4b334950499d emul/src/main/java/java/lang/String.java --- a/emul/src/main/java/java/lang/String.java Sat Sep 29 07:50:39 2012 +0200 +++ b/emul/src/main/java/java/lang/String.java Sat Sep 29 08:13:32 2012 +0200 @@ -27,12 +27,7 @@ import java.io.ObjectStreamField; import java.io.UnsupportedEncodingException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Comparator; -import java.util.Formatter; -import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -169,7 +164,7 @@ // String itself. Perhaps this constructor is being called // in order to trim the baggage, so make a copy of the array. int off = original.offset; - v = Arrays.copyOfRange(originalValue, off, off+size); + v = copyOfRange(originalValue, off, off+size); } else { // The array representing the String is the same // size as the String, so no point in making a copy. @@ -193,7 +188,7 @@ int size = value.length; this.offset = 0; this.count = size; - this.value = Arrays.copyOf(value, size); + this.value = copyOf(value, size); } /** @@ -230,7 +225,7 @@ } this.offset = 0; this.count = count; - this.value = Arrays.copyOfRange(value, offset, offset+count); + this.value = copyOfRange(value, offset, offset+count); } /** @@ -484,6 +479,7 @@ * * @since 1.6 */ + /* don't want dependnecy on Charset public String(byte bytes[], int offset, int length, Charset charset) { if (charset == null) throw new NullPointerException("charset"); @@ -493,6 +489,7 @@ this.count = v.length; this.value = v; } + */ /** * Constructs a new {@code String} by decoding the specified array of bytes @@ -543,9 +540,11 @@ * * @since 1.6 */ + /* don't want dep on Charset public String(byte bytes[], Charset charset) { this(bytes, 0, bytes.length, charset); } + */ /** * Constructs a new {@code String} by decoding the specified subarray of @@ -972,10 +971,12 @@ * * @since 1.6 */ + /* don't want dep on Charset public byte[] getBytes(Charset charset) { if (charset == null) throw new NullPointerException(); return StringCoding.encode(charset, value, offset, count); } + */ /** * Encodes this {@code String} into a sequence of bytes using the @@ -2325,7 +2326,7 @@ ((ch-'A')|('Z'-ch)) < 0)) && (ch < Character.MIN_HIGH_SURROGATE || ch > Character.MAX_LOW_SURROGATE)) - { + {/* int off = 0; int next = 0; boolean limited = limit > 0; @@ -2356,7 +2357,7 @@ resultSize--; String[] result = new String[resultSize]; return list.subList(0, resultSize).toArray(result); - } + */} return Pattern.compile(regex).split(this, limit); } @@ -2454,99 +2455,99 @@ * @see java.lang.String#toUpperCase(Locale) * @since 1.1 */ - public String toLowerCase(Locale locale) { - if (locale == null) { - throw new NullPointerException(); - } - - int firstUpper; - - /* Now check if there are any characters that need to be changed. */ - scan: { - for (firstUpper = 0 ; firstUpper < count; ) { - char c = value[offset+firstUpper]; - if ((c >= Character.MIN_HIGH_SURROGATE) && - (c <= Character.MAX_HIGH_SURROGATE)) { - int supplChar = codePointAt(firstUpper); - if (supplChar != Character.toLowerCase(supplChar)) { - break scan; - } - firstUpper += Character.charCount(supplChar); - } else { - if (c != Character.toLowerCase(c)) { - break scan; - } - firstUpper++; - } - } - return this; - } - - char[] result = new char[count]; - int resultOffset = 0; /* result may grow, so i+resultOffset - * is the write location in result */ - - /* Just copy the first few lowerCase characters. */ - System.arraycopy(value, offset, result, 0, firstUpper); - - String lang = locale.getLanguage(); - boolean localeDependent = - (lang == "tr" || lang == "az" || lang == "lt"); - char[] lowerCharArray; - int lowerChar; - int srcChar; - int srcCount; - for (int i = firstUpper; i < count; i += srcCount) { - srcChar = (int)value[offset+i]; - if ((char)srcChar >= Character.MIN_HIGH_SURROGATE && - (char)srcChar <= Character.MAX_HIGH_SURROGATE) { - srcChar = codePointAt(i); - srcCount = Character.charCount(srcChar); - } else { - srcCount = 1; - } - if (localeDependent || srcChar == '\u03A3') { // GREEK CAPITAL LETTER SIGMA - lowerChar = ConditionalSpecialCasing.toLowerCaseEx(this, i, locale); - } else if (srcChar == '\u0130') { // LATIN CAPITAL LETTER I DOT - lowerChar = Character.ERROR; - } else { - lowerChar = Character.toLowerCase(srcChar); - } - if ((lowerChar == Character.ERROR) || - (lowerChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) { - if (lowerChar == Character.ERROR) { - if (!localeDependent && srcChar == '\u0130') { - lowerCharArray = - ConditionalSpecialCasing.toLowerCaseCharArray(this, i, Locale.ENGLISH); - } else { - lowerCharArray = - ConditionalSpecialCasing.toLowerCaseCharArray(this, i, locale); - } - } else if (srcCount == 2) { - resultOffset += Character.toChars(lowerChar, result, i + resultOffset) - srcCount; - continue; - } else { - lowerCharArray = Character.toChars(lowerChar); - } - - /* Grow result if needed */ - int mapLen = lowerCharArray.length; - if (mapLen > srcCount) { - char[] result2 = new char[result.length + mapLen - srcCount]; - System.arraycopy(result, 0, result2, 0, - i + resultOffset); - result = result2; - } - for (int x=0; x= Character.MIN_HIGH_SURROGATE) && +// (c <= Character.MAX_HIGH_SURROGATE)) { +// int supplChar = codePointAt(firstUpper); +// if (supplChar != Character.toLowerCase(supplChar)) { +// break scan; +// } +// firstUpper += Character.charCount(supplChar); +// } else { +// if (c != Character.toLowerCase(c)) { +// break scan; +// } +// firstUpper++; +// } +// } +// return this; +// } +// +// char[] result = new char[count]; +// int resultOffset = 0; /* result may grow, so i+resultOffset +// * is the write location in result */ +// +// /* Just copy the first few lowerCase characters. */ +// System.arraycopy(value, offset, result, 0, firstUpper); +// +// String lang = locale.getLanguage(); +// boolean localeDependent = +// (lang == "tr" || lang == "az" || lang == "lt"); +// char[] lowerCharArray; +// int lowerChar; +// int srcChar; +// int srcCount; +// for (int i = firstUpper; i < count; i += srcCount) { +// srcChar = (int)value[offset+i]; +// if ((char)srcChar >= Character.MIN_HIGH_SURROGATE && +// (char)srcChar <= Character.MAX_HIGH_SURROGATE) { +// srcChar = codePointAt(i); +// srcCount = Character.charCount(srcChar); +// } else { +// srcCount = 1; +// } +// if (localeDependent || srcChar == '\u03A3') { // GREEK CAPITAL LETTER SIGMA +// lowerChar = ConditionalSpecialCasing.toLowerCaseEx(this, i, locale); +// } else if (srcChar == '\u0130') { // LATIN CAPITAL LETTER I DOT +// lowerChar = Character.ERROR; +// } else { +// lowerChar = Character.toLowerCase(srcChar); +// } +// if ((lowerChar == Character.ERROR) || +// (lowerChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) { +// if (lowerChar == Character.ERROR) { +// if (!localeDependent && srcChar == '\u0130') { +// lowerCharArray = +// ConditionalSpecialCasing.toLowerCaseCharArray(this, i, Locale.ENGLISH); +// } else { +// lowerCharArray = +// ConditionalSpecialCasing.toLowerCaseCharArray(this, i, locale); +// } +// } else if (srcCount == 2) { +// resultOffset += Character.toChars(lowerChar, result, i + resultOffset) - srcCount; +// continue; +// } else { +// lowerCharArray = Character.toChars(lowerChar); +// } +// +// /* Grow result if needed */ +// int mapLen = lowerCharArray.length; +// if (mapLen > srcCount) { +// char[] result2 = new char[result.length + mapLen - srcCount]; +// System.arraycopy(result, 0, result2, 0, +// i + resultOffset); +// result = result2; +// } +// for (int x=0; xString to lower @@ -2619,6 +2620,7 @@ * @see java.lang.String#toLowerCase(Locale) * @since 1.1 */ + /* not for javascript public String toUpperCase(Locale locale) { if (locale == null) { throw new NullPointerException(); @@ -2626,7 +2628,7 @@ int firstLower; - /* Now check if there are any characters that need to be changed. */ + // Now check if there are any characters that need to be changed. scan: { for (firstLower = 0 ; firstLower < count; ) { int c = (int)value[offset+firstLower]; @@ -2648,11 +2650,11 @@ return this; } - char[] result = new char[count]; /* may grow */ + char[] result = new char[count]; /* may grow * int resultOffset = 0; /* result may grow, so i+resultOffset - * is the write location in result */ + * is the write location in result * - /* Just copy the first few upperCase characters. */ + /* Just copy the first few upperCase characters. * System.arraycopy(value, offset, result, 0, firstLower); String lang = locale.getLanguage(); @@ -2692,7 +2694,7 @@ upperCharArray = Character.toChars(upperChar); } - /* Grow result if needed */ + /* Grow result if needed * int mapLen = upperCharArray.length; if (mapLen > srcCount) { char[] result2 = new char[result.length + mapLen - srcCount]; @@ -2710,6 +2712,7 @@ } return new String(0, count+resultOffset, result); } + */ /** * Converts all of the characters in this String to upper @@ -2731,7 +2734,7 @@ * @see java.lang.String#toUpperCase(Locale) */ public String toUpperCase() { - return toUpperCase(Locale.getDefault()); + throw new UnsupportedOperationException(); } /** @@ -2884,9 +2887,9 @@ * @see java.util.Formatter * @since 1.5 */ - public static String format(Locale l, String format, Object ... args) { - return new Formatter(l).format(format, args).toString(); - } +// public static String format(Locale l, String format, Object ... args) { +// return new Formatter(l).format(format, args).toString(); +// } /** * Returns the string representation of the Object argument. @@ -3073,4 +3076,21 @@ */ public native String intern(); + static char[] copyOfRange(char[] original, int from, int to) { + int newLength = to - from; + if (newLength < 0) { + throw new IllegalArgumentException(from + " > " + to); + } + char[] copy = new char[newLength]; + System.arraycopy(original, from, copy, 0, + Math.min(original.length - from, newLength)); + return copy; + } + static char[] copyOf(char[] original, int newLength) { + char[] copy = new char[newLength]; + System.arraycopy(original, 0, copy, 0, + Math.min(original.length, newLength)); + return copy; + } + } diff -r 922ba77e0de0 -r 4b334950499d emul/src/main/java/java/lang/Throwable.java --- a/emul/src/main/java/java/lang/Throwable.java Sat Sep 29 07:50:39 2012 +0200 +++ b/emul/src/main/java/java/lang/Throwable.java Sat Sep 29 08:13:32 2012 +0200 @@ -25,7 +25,6 @@ package java.lang; import java.io.*; -import java.util.*; /** * The {@code Throwable} class is the superclass of all errors and @@ -211,8 +210,9 @@ // Setting this static field introduces an acceptable // initialization dependency on a few java.util classes. - private static final List SUPPRESSED_SENTINEL = - Collections.unmodifiableList(new ArrayList(0)); +// I don't think this dependency is acceptable +// private static final List SUPPRESSED_SENTINEL = +// Collections.unmodifiableList(new ArrayList(0)); /** * The list of suppressed exceptions, as returned by {@link @@ -224,7 +224,7 @@ * @serial * @since 1.7 */ - private List suppressedExceptions = SUPPRESSED_SENTINEL; +// private List suppressedExceptions = SUPPRESSED_SENTINEL; /** Message for trying to suppress a null exception. */ private static final String NULL_CAUSE_MESSAGE = "Cannot suppress a null exception."; @@ -363,8 +363,8 @@ } detailMessage = message; this.cause = cause; - if (!enableSuppression) - suppressedExceptions = null; +// if (!enableSuppression) +// suppressedExceptions = null; } /** @@ -645,9 +645,9 @@ private void printStackTrace(PrintStreamOrWriter s) { // Guard against malicious overrides of Throwable.equals by // using a Set with identity equality semantics. - Set dejaVu = - Collections.newSetFromMap(new IdentityHashMap()); - dejaVu.add(this); +// Set dejaVu = +// Collections.newSetFromMap(new IdentityHashMap()); +// dejaVu.add(this); synchronized (s.lock()) { // Print our stack trace @@ -657,13 +657,13 @@ s.println("\tat " + traceElement); // Print suppressed exceptions, if any - for (Throwable se : getSuppressed()) - se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu); +// for (Throwable se : getSuppressed()) +// se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu); // Print cause, if any Throwable ourCause = getCause(); - if (ourCause != null) - ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu); +// if (ourCause != null) +// ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu); } } @@ -675,12 +675,9 @@ StackTraceElement[] enclosingTrace, String caption, String prefix, - Set dejaVu) { + Object dejaVu) { assert Thread.holdsLock(s.lock()); - if (dejaVu.contains(this)) { - s.println("\t[CIRCULAR REFERENCE:" + this + "]"); - } else { - dejaVu.add(this); + { // Compute number of frames in common between this and enclosing trace StackTraceElement[] trace = getOurStackTrace(); int m = trace.length - 1; @@ -911,25 +908,25 @@ private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); // read in all fields - if (suppressedExceptions != null) { - List suppressed = null; - if (suppressedExceptions.isEmpty()) { - // Use the sentinel for a zero-length list - suppressed = SUPPRESSED_SENTINEL; - } else { // Copy Throwables to new list - suppressed = new ArrayList(1); - for (Throwable t : suppressedExceptions) { - // Enforce constraints on suppressed exceptions in - // case of corrupt or malicious stream. - if (t == null) - throw new NullPointerException(NULL_CAUSE_MESSAGE); - if (t == this) - throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE); - suppressed.add(t); - } - } - suppressedExceptions = suppressed; - } // else a null suppressedExceptions field remains null +// if (suppressedExceptions != null) { +// List suppressed = null; +// if (suppressedExceptions.isEmpty()) { +// // Use the sentinel for a zero-length list +// suppressed = SUPPRESSED_SENTINEL; +// } else { // Copy Throwables to new list +// suppressed = new ArrayList(1); +// for (Throwable t : suppressedExceptions) { +// // Enforce constraints on suppressed exceptions in +// // case of corrupt or malicious stream. +// if (t == null) +// throw new NullPointerException(NULL_CAUSE_MESSAGE); +// if (t == this) +// throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE); +// suppressed.add(t); +// } +// } +// suppressedExceptions = suppressed; +// } // else a null suppressedExceptions field remains null /* * For zero-length stack traces, use a clone of @@ -1044,13 +1041,13 @@ if (exception == null) throw new NullPointerException(NULL_CAUSE_MESSAGE); - if (suppressedExceptions == null) // Suppressed exceptions not recorded - return; - - if (suppressedExceptions == SUPPRESSED_SENTINEL) - suppressedExceptions = new ArrayList(1); - - suppressedExceptions.add(exception); +// if (suppressedExceptions == null) // Suppressed exceptions not recorded +// return; +// +// if (suppressedExceptions == SUPPRESSED_SENTINEL) +// suppressedExceptions = new ArrayList(1); +// +// suppressedExceptions.add(exception); } private static final Throwable[] EMPTY_THROWABLE_ARRAY = new Throwable[0]; @@ -1071,10 +1068,11 @@ * @since 1.7 */ public final synchronized Throwable[] getSuppressed() { - if (suppressedExceptions == SUPPRESSED_SENTINEL || - suppressedExceptions == null) - return EMPTY_THROWABLE_ARRAY; - else - return suppressedExceptions.toArray(EMPTY_THROWABLE_ARRAY); + return new Throwable[0]; +// if (suppressedExceptions == SUPPRESSED_SENTINEL || +// suppressedExceptions == null) +// return EMPTY_THROWABLE_ARRAY; +// else +// return suppressedExceptions.toArray(EMPTY_THROWABLE_ARRAY); } }