add classes and methods needed for GNU Classpath compatibility

Most of these methods are stubs which throw
UnsupportedOperationExceptions for now.
This commit is contained in:
Joel Dice 2009-06-02 17:14:38 -06:00
parent 70bd2d908f
commit 0615b8a09f
18 changed files with 416 additions and 17 deletions

View File

@ -0,0 +1,22 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.lang;
import java.io.IOException;
public interface Appendable {
public Appendable append(char c) throws IOException;
public Appendable append(CharSequence sequence) throws IOException;
public Appendable append(CharSequence sequence, int start, int end)
throws IOException;
}

View File

@ -187,4 +187,40 @@ public final class Character implements Comparable<Character> {
return isHighSurrogate(high) && isLowSurrogate(low);
}
public static int codePointAt(CharSequence sequence, int offset) {
int length = sequence.length();
if (offset < 0 || offset >= length) {
throw new IndexOutOfBoundsException();
}
char high = sequence.charAt(offset);
if (! isHighSurrogate(high) || offset >= length) {
return high;
}
char low = sequence.charAt(offset + 1);
if (! isLowSurrogate(low)) {
return high;
}
return toCodePoint(high, low);
}
public static int codePointCount(CharSequence sequence, int start, int end) {
int length = sequence.length();
if (start < 0 || start > end || end >= length) {
throw new IndexOutOfBoundsException();
}
int count = 0;
for (int i = start; i < end; ++i) {
if (isHighSurrogate(sequence.charAt(i))
&& (i + 1) < end
&& isLowSurrogate(sequence.charAt(i + 1)))
{
++ i;
}
++ count;
}
return count;
}
}

View File

@ -14,12 +14,17 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.GenericDeclaration;
import java.lang.annotation.Annotation;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
import java.security.ProtectionDomain;
public final class Class <T> {
public final class Class <T> implements Type, GenericDeclaration {
private static final int PrimitiveFlag = 1 << 4;
private short flags;
@ -434,8 +439,61 @@ public final class Class <T> {
return null;
}
}
public boolean desiredAssertionStatus() {
return false;
}
public T cast(Object o) {
return (T) o;
}
public Object[] getSigners() {
throw new UnsupportedOperationException();
}
public Annotation[] getDeclaredAnnotations() {
throw new UnsupportedOperationException();
}
public boolean isEnum() {
throw new UnsupportedOperationException();
}
public TypeVariable<Class<T>>[] getTypeParameters() {
throw new UnsupportedOperationException();
}
public String getSimpleName() {
throw new UnsupportedOperationException();
}
public Method getEnclosingMethod() {
throw new UnsupportedOperationException();
}
public Constructor getEnclosingConstructor() {
throw new UnsupportedOperationException();
}
public Class getEnclosingClass() {
throw new UnsupportedOperationException();
}
public Class[] getDeclaredClasses() {
throw new UnsupportedOperationException();
}
public <A extends Annotation> A getAnnotation(Class<A> c) {
throw new UnsupportedOperationException();
}
public ProtectionDomain getProtectionDomain() {
throw new UnsupportedOperationException();
}
// for GNU Classpath compatibility:
void setSigners(Object[] signers) {
throw new UnsupportedOperationException();
}
}

View File

@ -53,4 +53,12 @@ public abstract class Enum<E extends Enum<E>> implements Comparable<E> {
public String toString() {
return name;
}
public Class<E> getDeclaringClass() {
Class c = getClass();
while (c.getSuperclass() != Enum.class) {
c = c.getSuperclass();
}
return c;
}
}

View File

@ -25,7 +25,7 @@ public class Object {
return this == o;
}
protected void finalize() { }
protected void finalize() throws Throwable { }
public native final Class<? extends Object> getClass();
@ -41,5 +41,14 @@ public class Object {
wait(0);
}
public native final void wait(long timeout) throws InterruptedException;
public native final void wait(long milliseconds) throws InterruptedException;
public final void wait(long milliseconds, int nanoseconds)
throws InterruptedException
{
if (nanoseconds != 0) {
++ milliseconds;
}
wait(milliseconds);
}
}

View File

@ -18,8 +18,8 @@ public class StackTraceElement {
private String file;
private int line;
private StackTraceElement(String class_, String method, String file,
int line)
public StackTraceElement(String class_, String method, String file,
int line)
{
this.class_ = class_;
this.method = method;

View File

@ -12,14 +12,30 @@ package java.lang;
import java.io.UnsupportedEncodingException;
import java.util.regex.Pattern;
import java.util.Comparator;
import java.util.Locale;
import java.io.ByteArrayOutputStream;
import java.io.Serializable;
public final class String
implements Comparable<String>, CharSequence, Serializable
{
public static Comparator<String> CASE_INSENSITIVE_ORDER
= new Comparator<String>() {
public int compare(String a, String b) {
return a.compareToIgnoreCase(b);
}
};
public final class String implements Comparable<String>, CharSequence {
private final Object data;
private final int offset;
private final int length;
private int hashCode;
public String() {
this(new char[0], 0, 0);
}
public String(char[] data, int offset, int length, boolean copy) {
this((Object) data, offset, length, copy);
}
@ -32,7 +48,9 @@ public final class String implements Comparable<String>, CharSequence {
this(data, 0, data.length);
}
public String(byte bytes[], int offset, int length, String charsetName) throws UnsupportedEncodingException {
public String(byte bytes[], int offset, int length, String charsetName)
throws UnsupportedEncodingException
{
this(bytes, offset, length);
if (!charsetName.equals("UTF-8")) {
throw new UnsupportedEncodingException(charsetName);
@ -57,12 +75,29 @@ public final class String implements Comparable<String>, CharSequence {
public String(byte[] data, String charset)
throws UnsupportedEncodingException
{
this(data);
if (! charset.equals("UTF-8")) {
throw new UnsupportedEncodingException(charset);
}
{
this(data);
if (! charset.equals("UTF-8")) {
throw new UnsupportedEncodingException(charset);
}
}
public String(byte bytes[], int highByte, int offset, int length) {
if (offset < 0 || offset + length > bytes.length) {
throw new IndexOutOfBoundsException
(offset + " < 0 or " + offset + " + " + length + " > " + bytes.length);
}
char[] c = new char[length];
int mask = highByte << 8;
for (int i = 0; i < length; ++i) {
c[i] = (char) ((bytes[offset + i] & 0xFF) | mask);
}
this.data = c;
this.offset = 0;
this.length = length;
}
private String(Object data, int offset, int length, boolean copy) {
int l;
@ -534,6 +569,10 @@ public final class String implements Comparable<String>, CharSequence {
return Pattern.matches(regex, this);
}
public String replaceAll(String regex, String replacement) {
return Pattern.compile(regex).matcher(this).replaceAll(replacement);
}
public native String intern();
public static String valueOf(Object s) {
@ -572,6 +611,10 @@ public final class String implements Comparable<String>, CharSequence {
return Double.toString(v);
}
public static String valueOf(char[] data, int offset, int length) {
return new String(data, offset, length);
}
public int lastIndexOf(int ch, int lastIndex) {
for (int i = lastIndex ; i >= 0; --i) {
if (charAt(i) == ch) {
@ -581,4 +624,63 @@ public final class String implements Comparable<String>, CharSequence {
return -1;
}
public boolean regionMatches(int thisOffset, String match, int matchOffset,
int length)
{
return regionMatches(false, thisOffset, match, matchOffset, length);
}
public boolean regionMatches(boolean ignoreCase, int thisOffset,
String match, int matchOffset, int length)
{
String a = substring(thisOffset, length);
String b = match.substring(matchOffset, length);
if (ignoreCase) {
return a.equalsIgnoreCase(b);
} else {
return a.equals(b);
}
}
public boolean isEmpty() {
return length == 0;
}
public boolean contains(String match) {
return indexOf(match) != -1;
}
public int codePointAt(int offset) {
return Character.codePointAt(this, offset);
}
public int codePointCount(int start, int end) {
return Character.codePointCount(this, start, end);
}
public String replace(CharSequence match, CharSequence replacement) {
throw new UnsupportedOperationException();
}
public String toUpperCase(Locale locale) {
throw new UnsupportedOperationException();
}
public String toLowerCase(Locale locale) {
throw new UnsupportedOperationException();
}
// for GNU Classpath compatibility:
static char[] zeroBasedStringValue(String s) {
if (s.offset == 0) {
if (s.data instanceof char[]) {
char[] data = (char[]) s.data;
if (data.length == s.length) {
return data;
}
}
}
return s.toCharArray();
}
}

View File

@ -10,7 +10,7 @@
package java.lang;
public class StringBuilder implements CharSequence {
public class StringBuilder implements CharSequence, Appendable {
private static final int BufferSize = 32;
private Cell chain;
@ -54,6 +54,14 @@ public class StringBuilder implements CharSequence {
}
}
public StringBuilder append(CharSequence sequence) {
return append(sequence.toString());
}
public Appendable append(CharSequence sequence, int start, int end) {
return append(sequence.subSequence(start, end));
}
public StringBuilder append(char[] b, int offset, int length) {
return append(new String(b, offset, length));
}
@ -150,6 +158,10 @@ public class StringBuilder implements CharSequence {
return this;
}
public StringBuilder insert(int i, CharSequence s) {
return insert(i, s.toString());
}
public StringBuilder insert(int i, char c) {
return insert(i, new String(new char[] { c }, 0, 1, false));
}
@ -332,4 +344,8 @@ public class StringBuilder implements CharSequence {
deleteCharAt(index);
insert(index, ch);
}
public void ensureCapacity(int capacity) {
// ignore
}
}

View File

@ -13,8 +13,9 @@ package java.lang;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.Serializable;
public class Throwable {
public class Throwable implements Serializable {
private String message;
private Object trace;
private Throwable cause;
@ -109,4 +110,9 @@ public class Throwable {
cause.printStackTrace(sb, nl);
}
}
public Throwable fillInStackTrace() {
trace = trace(0);
return this;
}
}

View File

@ -22,6 +22,10 @@ public abstract class Reference<T> {
this.queue = queue;
}
protected Reference(T target) {
this(target, null);
}
public T get() {
return target;
}

View File

@ -10,7 +10,9 @@
package java.lang.reflect;
public class Constructor<T> extends AccessibleObject implements Member {
public class Constructor<T> extends AccessibleObject
implements Member, GenericDeclaration
{
private Method<T> method;
public Constructor(Method<T> method) {
@ -46,6 +48,18 @@ public class Constructor<T> extends AccessibleObject implements Member {
return method.getName();
}
public boolean isSynthetic() {
return method.isSynthetic();
}
public TypeVariable<Constructor<T>>[] getTypeParameters() {
throw new UnsupportedOperationException();
}
public Type[] getGenericParameterTypes() {
return method.getGenericParameterTypes();
}
private static native <T> T make(Class<T> c);
public T newInstance(Object ... arguments)

View File

@ -101,6 +101,38 @@ public class Field<T> extends AccessibleObject {
}
}
public boolean getBoolean(Object instance) throws IllegalAccessException {
return ((Boolean) get(instance)).booleanValue();
}
public byte getByte(Object instance) throws IllegalAccessException {
return ((Byte) get(instance)).byteValue();
}
public short getShort(Object instance) throws IllegalAccessException {
return ((Short) get(instance)).shortValue();
}
public char getChar(Object instance) throws IllegalAccessException {
return ((Character) get(instance)).charValue();
}
public int getInt(Object instance) throws IllegalAccessException {
return ((Integer) get(instance)).intValue();
}
public float getFloat(Object instance) throws IllegalAccessException {
return ((Float) get(instance)).floatValue();
}
public long getLong(Object instance) throws IllegalAccessException {
return ((Long) get(instance)).longValue();
}
public double getDouble(Object instance) throws IllegalAccessException {
return ((Double) get(instance)).doubleValue();
}
public void set(Object instance, Object value)
throws IllegalAccessException
{
@ -162,6 +194,10 @@ public class Field<T> extends AccessibleObject {
}
}
public boolean isEnumConstant() {
throw new UnsupportedOperationException();
}
private static native long getPrimitive
(Object instance, int code, int offset);

View File

@ -0,0 +1,15 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.lang.reflect;
public interface GenericDeclaration {
public TypeVariable<?>[] getTypeParameters();
}

View File

@ -19,4 +19,6 @@ public interface Member {
public int getModifiers();
public String getName();
public boolean isSynthetic();
}

View File

@ -10,7 +10,9 @@
package java.lang.reflect;
public class Method<T> extends AccessibleObject implements Member {
public class Method<T> extends AccessibleObject
implements Member, GenericDeclaration
{
private byte vmFlags;
private byte returnCode;
private byte parameterCount;
@ -124,4 +126,28 @@ public class Method<T> extends AccessibleObject implements Member {
}
throw new RuntimeException();
}
public boolean isSynthetic() {
throw new UnsupportedOperationException();
}
public Object getDefaultValue() {
throw new UnsupportedOperationException();
}
public Type[] getGenericParameterTypes() {
throw new UnsupportedOperationException();
}
public Type getGenericReturnType() {
throw new UnsupportedOperationException();
}
public Class[] getExceptionTypes() {
throw new UnsupportedOperationException();
}
public TypeVariable<Method<T>>[] getTypeParameters() {
throw new UnsupportedOperationException();
}
}

View File

@ -0,0 +1,13 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.lang.reflect;
public interface Type { }

View File

@ -0,0 +1,19 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.lang.reflect;
public interface TypeVariable<T extends GenericDeclaration>
extends Type
{
public Type[] getBounds();
public T getGenericDeclaration();
public String getName();
}

View File

@ -0,0 +1,13 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.security;
public class ProtectionDomain { }