diff options
author | Elliott Hughes <enh@google.com> | 2013-07-25 17:24:20 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2013-07-25 18:06:34 -0700 |
commit | 07e1d1125c11b8e037a31e9ebb6b64332a394a9f (patch) | |
tree | 683c7207e0b4b52e263380a4f4ba81f7845d1ee6 /libdvm | |
parent | b8f93421684a6292496804ca30d8428d2602ce7a (diff) | |
download | libcore-07e1d1125c11b8e037a31e9ebb6b64332a394a9f.zip libcore-07e1d1125c11b8e037a31e9ebb6b64332a394a9f.tar.gz libcore-07e1d1125c11b8e037a31e9ebb6b64332a394a9f.tar.bz2 |
Use the libcore.reflect implementation.
Change-Id: I3cb180d3c1912b9362c5a2e8dbedc1e80fb0c14f
Diffstat (limited to 'libdvm')
12 files changed, 82 insertions, 1009 deletions
diff --git a/libdvm/src/main/java/java/lang/Class.java b/libdvm/src/main/java/java/lang/Class.java index 47addea..2f26688 100644 --- a/libdvm/src/main/java/java/lang/Class.java +++ b/libdvm/src/main/java/java/lang/Class.java @@ -32,6 +32,7 @@ package java.lang; +import com.android.dex.Dex; import dalvik.system.VMStack; import java.io.InputStream; import java.io.Serializable; @@ -56,8 +57,9 @@ import java.util.List; import libcore.util.CollectionUtils; import libcore.util.EmptyArray; import org.apache.harmony.kernel.vm.StringUtils; -import org.apache.harmony.luni.lang.reflect.GenericSignatureParser; -import org.apache.harmony.luni.lang.reflect.Types; +import libcore.reflect.AnnotationAccess; +import libcore.reflect.GenericSignatureParser; +import libcore.reflect.Types; /** * The in-memory representation of a Java class. This representation serves as @@ -123,12 +125,39 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe */ private transient String name; + private transient int dexTypeIndex; + private Class() { // Prevent this class to be instantiated, instance // should be created by JVM only } /** + * Returns the dex file from which this class was loaded. + * @hide + */ + public native Dex getDex(); + + /** + * The type index of this class in its own Dex, or 0 if it is unknown. If a + * class is referenced by multiple Dex files, it will have a different type + * index in each. Dex files support 65534 type indices, with 65535 + * representing no index. + * + * TODO: 0 is a valid index; this should be -1 if it is unknown + * + * @hide + */ + public int getTypeIndex() { + int result = dexTypeIndex; + if (result == 0) { // uncomputed => Dalvik + result = AnnotationAccess.computeTypeIndex(getDex(), this); + dexTypeIndex = result; + } + return result; + } + + /** * Get the Signature attribute for this class. Returns null if not found. */ private String getSignatureAttribute() { @@ -1220,4 +1249,17 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe System.arraycopy(tail, 0, result, head.length, tail.length); return result; } + + /** + * The annotation directory offset of this class in its own Dex, or 0 if it + * is unknown. + * + * TODO: 0 is a sentinel that means 'no annotations directory'; this should be -1 if unknown + * + * @hide + */ + public int getAnnotationDirectoryOffset() { + return AnnotationAccess.typeIndexToAnnotationDirectoryOffset(getDex(), getTypeIndex()); + } + } diff --git a/libdvm/src/main/java/java/lang/reflect/Constructor.java b/libdvm/src/main/java/java/lang/reflect/Constructor.java index 9a0e03c..23e26a9 100644 --- a/libdvm/src/main/java/java/lang/reflect/Constructor.java +++ b/libdvm/src/main/java/java/lang/reflect/Constructor.java @@ -35,9 +35,9 @@ package java.lang.reflect; import java.lang.annotation.Annotation; import libcore.util.EmptyArray; import org.apache.harmony.kernel.vm.StringUtils; -import org.apache.harmony.luni.lang.reflect.GenericSignatureParser; -import org.apache.harmony.luni.lang.reflect.ListOfTypes; -import org.apache.harmony.luni.lang.reflect.Types; +import libcore.reflect.GenericSignatureParser; +import libcore.reflect.ListOfTypes; +import libcore.reflect.Types; /** * This class represents a constructor. Information about the constructor can be @@ -74,6 +74,8 @@ public final class Constructor<T> extends AccessibleObject implements GenericDec int slot; + private int methodDexIndex; + /** * Prevent this class from being instantiated. */ @@ -94,11 +96,16 @@ public final class Constructor<T> extends AccessibleObject implements GenericDec * @param slot * the slot of the constructor inside the VM class structure */ - private Constructor (Class<T> declaringClass, Class<?>[] ptypes, Class<?>[] extypes, int slot){ + private Constructor (Class<T> declaringClass, Class<?>[] ptypes, Class<?>[] extypes, int slot, int methodDexIndex) { this.declaringClass = declaringClass; this.parameterTypes = ptypes; this.exceptionTypes = extypes; // may be null this.slot = slot; + this.methodDexIndex = methodDexIndex; + } + + public int getDexMethodIndex() { + return methodDexIndex; } @Override /*package*/ String getSignatureAttribute() { diff --git a/libdvm/src/main/java/java/lang/reflect/Field.java b/libdvm/src/main/java/java/lang/reflect/Field.java index 0aacb11..dcafaf7 100644 --- a/libdvm/src/main/java/java/lang/reflect/Field.java +++ b/libdvm/src/main/java/java/lang/reflect/Field.java @@ -35,8 +35,8 @@ package java.lang.reflect; import java.lang.annotation.Annotation; import java.util.Comparator; import org.apache.harmony.kernel.vm.StringUtils; -import org.apache.harmony.luni.lang.reflect.GenericSignatureParser; -import org.apache.harmony.luni.lang.reflect.Types; +import libcore.reflect.GenericSignatureParser; +import libcore.reflect.Types; /** * This class represents a field. Information about the field can be accessed, @@ -73,6 +73,8 @@ public final class Field extends AccessibleObject implements Member { private int slot; + private final int fieldDexIndex; + private static final char TYPE_BOOLEAN = 'Z'; private static final char TYPE_BYTE = 'B'; @@ -95,7 +97,7 @@ public final class Field extends AccessibleObject implements Member { * @param orig non-null; the original instance to clone */ /*package*/ Field(Field orig) { - this(orig.declaringClass, orig.type, orig.name, orig.slot); + this(orig.declaringClass, orig.type, orig.name, orig.slot, orig.fieldDexIndex); // Copy the accessible flag. if (orig.flag) { @@ -103,11 +105,20 @@ public final class Field extends AccessibleObject implements Member { } } - private Field(Class<?> declaringClass, Class<?> type, String name, int slot) { + private Field(Class<?> declaringClass, Class<?> type, String name, int slot, int fieldDexIndex) { this.declaringClass = declaringClass; this.type = type; this.name = name; this.slot = slot; + this.fieldDexIndex = fieldDexIndex; + } + + /** + * Returns the index of this field's ID in its dex file. + * @hide + */ + public int getDexFieldIndex() { + return fieldDexIndex; } private synchronized void initGenericType() { diff --git a/libdvm/src/main/java/java/lang/reflect/Method.java b/libdvm/src/main/java/java/lang/reflect/Method.java index b2f970a..80d0c90 100644 --- a/libdvm/src/main/java/java/lang/reflect/Method.java +++ b/libdvm/src/main/java/java/lang/reflect/Method.java @@ -37,9 +37,9 @@ import java.util.Arrays; import java.util.Comparator; import libcore.util.EmptyArray; import org.apache.harmony.kernel.vm.StringUtils; -import org.apache.harmony.luni.lang.reflect.GenericSignatureParser; -import org.apache.harmony.luni.lang.reflect.ListOfTypes; -import org.apache.harmony.luni.lang.reflect.Types; +import libcore.reflect.GenericSignatureParser; +import libcore.reflect.ListOfTypes; +import libcore.reflect.Types; /** * This class represents a method. Information about the method can be accessed, @@ -80,6 +80,8 @@ public final class Method extends AccessibleObject implements GenericDeclaration private int slot; + private final int methodDexIndex; + private Class<?> declaringClass; private String name; @@ -117,7 +119,7 @@ public final class Method extends AccessibleObject implements GenericDeclaration */ /*package*/ Method(Method orig) { this(orig.declaringClass, orig.parameterTypes, orig.exceptionTypes, - orig.returnType, orig.name, orig.slot); + orig.returnType, orig.name, orig.slot, orig.methodDexIndex); // Copy the accessible flag. if (orig.flag) { @@ -125,14 +127,18 @@ public final class Method extends AccessibleObject implements GenericDeclaration } } - private Method(Class<?> declaring, Class<?>[] paramTypes, Class<?>[] exceptTypes, Class<?> returnType, String name, int slot) - { + private Method(Class<?> declaring, Class<?>[] paramTypes, Class<?>[] exceptTypes, Class<?> returnType, String name, int slot, int methodDexIndex) { this.declaringClass = declaring; this.name = name; this.slot = slot; this.parameterTypes = paramTypes; this.exceptionTypes = exceptTypes; // may be null this.returnType = returnType; + this.methodDexIndex = methodDexIndex; + } + + public int getDexMethodIndex() { + return methodDexIndex; } public TypeVariable<Method>[] getTypeParameters() { diff --git a/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/GenericSignatureParser.java b/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/GenericSignatureParser.java deleted file mode 100644 index 490daaf..0000000 --- a/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/GenericSignatureParser.java +++ /dev/null @@ -1,508 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.harmony.luni.lang.reflect; - -import java.lang.reflect.Constructor; -import java.lang.reflect.GenericDeclaration; -import java.lang.reflect.GenericSignatureFormatError; -import java.lang.reflect.Method; -import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; - -/** - * Implements a parser for the generics signature attribute. - * Uses a top-down, recursive descent parsing approach for the following grammar: - * <pre> - * ClassSignature ::= - * OptFormalTypeParams SuperclassSignature {SuperinterfaceSignature}. - * SuperclassSignature ::= ClassTypeSignature. - * SuperinterfaceSignature ::= ClassTypeSignature. - * - * OptFormalTypeParams ::= - * ["<" FormalTypeParameter {FormalTypeParameter} ">"]. - * - * FormalTypeParameter ::= Ident ClassBound {InterfaceBound}. - * ClassBound ::= ":" [FieldTypeSignature]. - * InterfaceBound ::= ":" FieldTypeSignature. - * - * FieldTypeSignature ::= - * ClassTypeSignature | ArrayTypeSignature | TypeVariableSignature. - * ArrayTypeSignature ::= "[" TypSignature. - * - * ClassTypeSignature ::= - * "L" {Ident "/"} Ident OptTypeArguments {"." Ident OptTypeArguments} ";". - * - * OptTypeArguments ::= "<" TypeArgument {TypeArgument} ">". - * - * TypeArgument ::= ([WildcardIndicator] FieldTypeSignature) | "*". - * WildcardIndicator ::= "+" | "-". - * - * TypeVariableSignature ::= "T" Ident ";". - * - * TypSignature ::= FieldTypeSignature | BaseType. - * BaseType ::= "B" | "C" | "D" | "F" | "I" | "J" | "S" | "Z". - * - * MethodTypeSignature ::= - * OptFormalTypeParams "(" {TypeSignature} ")" ReturnType {ThrowsSignature}. - * ThrowsSignature ::= ("^" ClassTypeSignature) | ("^" TypeVariableSignature). - * - * ReturnType ::= TypSignature | VoidDescriptor. - * VoidDescriptor ::= "V". - * </pre> - */ -public class GenericSignatureParser { - - public ListOfTypes exceptionTypes; - public ListOfTypes parameterTypes; - public TypeVariable[] formalTypeParameters; - public Type returnType; - public Type fieldType; - public ListOfTypes interfaceTypes; - public Type superclassType; - public ClassLoader loader; - - GenericDeclaration genericDecl; - - /* - * Parser: - */ - char symbol; // 0: eof; else valid term symbol or first char of identifier. - String identifier; - - - /* - * Scanner: - * eof is private to the scan methods - * and it's set only when a scan is issued at the end of the buffer. - */ - private boolean eof; - - char[] buffer; - int pos; - - public GenericSignatureParser(ClassLoader loader) { - this.loader = loader; - } - - void setInput(GenericDeclaration genericDecl, String input) { - if (input != null) { - this.genericDecl = genericDecl; - this.buffer = input.toCharArray(); - this.eof = false; - scanSymbol(); - } - else { - this.eof = true; - } - } - - /** - * Parses the generic signature of a class and creates the data structure - * representing the signature. - * - * @param genericDecl the GenericDeclaration calling this method - * @param signature the generic signature of the class - */ - public void parseForClass(GenericDeclaration genericDecl, - String signature) { - setInput(genericDecl, signature); - if (!eof) { - parseClassSignature(); - } else { - if(genericDecl instanceof Class) { - Class c = (Class) genericDecl; - this.formalTypeParameters = ListOfVariables.EMPTY; - this.superclassType = c.getSuperclass(); - this.interfaceTypes = new ListOfTypes(c.getInterfaces()); - } else { - this.formalTypeParameters = ListOfVariables.EMPTY; - this.superclassType = Object.class; - this.interfaceTypes = ListOfTypes.EMPTY; - } - } - } - - /** - * Parses the generic signature of a method and creates the data structure - * representing the signature. - * - * @param genericDecl the GenericDeclaration calling this method - * @param signature the generic signature of the class - */ - public void parseForMethod(GenericDeclaration genericDecl, - String signature, Class<?>[] rawExceptionTypes) { - setInput(genericDecl, signature); - if (!eof) { - parseMethodTypeSignature(rawExceptionTypes); - } else { - if(genericDecl instanceof Method) { - Method m = (Method) genericDecl; - this.formalTypeParameters = ListOfVariables.EMPTY; - this.parameterTypes = new ListOfTypes(m.getParameterTypes()); - this.exceptionTypes = new ListOfTypes(m.getExceptionTypes()); - this.returnType = m.getReturnType(); - } else { - this.formalTypeParameters = ListOfVariables.EMPTY; - this.parameterTypes = ListOfTypes.EMPTY; - this.exceptionTypes = ListOfTypes.EMPTY; - this.returnType = void.class; - } - } - } - - /** - * Parses the generic signature of a constructor and creates the data - * structure representing the signature. - * - * @param genericDecl the GenericDeclaration calling this method - * @param signature the generic signature of the class - */ - public void parseForConstructor(GenericDeclaration genericDecl, - String signature, Class<?>[] rawExceptionTypes) { - setInput(genericDecl, signature); - if (!eof) { - parseMethodTypeSignature(rawExceptionTypes); - } else { - if(genericDecl instanceof Constructor) { - Constructor c = (Constructor) genericDecl; - this.formalTypeParameters = ListOfVariables.EMPTY; - this.parameterTypes = new ListOfTypes(c.getParameterTypes()); - this.exceptionTypes = new ListOfTypes(c.getExceptionTypes()); - } else { - this.formalTypeParameters = ListOfVariables.EMPTY; - this.parameterTypes = ListOfTypes.EMPTY; - this.exceptionTypes = ListOfTypes.EMPTY; - } - } - } - - /** - * Parses the generic signature of a field and creates the data structure - * representing the signature. - * - * @param genericDecl the GenericDeclaration calling this method - * @param signature the generic signature of the class - */ - public void parseForField(GenericDeclaration genericDecl, - String signature) { - setInput(genericDecl, signature); - if (!eof) { - this.fieldType = parseFieldTypeSignature(); - } - } - - - // - // Parser: - // - - void parseClassSignature() { - // ClassSignature ::= - // OptFormalTypeParameters SuperclassSignature {SuperinterfaceSignature}. - - parseOptFormalTypeParameters(); - - // SuperclassSignature ::= ClassTypeSignature. - this.superclassType = parseClassTypeSignature(); - - interfaceTypes = new ListOfTypes(16); - while (symbol > 0) { - // SuperinterfaceSignature ::= ClassTypeSignature. - interfaceTypes.add(parseClassTypeSignature()); - } - } - - void parseOptFormalTypeParameters() { - // OptFormalTypeParameters ::= - // ["<" FormalTypeParameter {FormalTypeParameter} ">"]. - - ListOfVariables typeParams = new ListOfVariables(); - - if (symbol == '<') { - scanSymbol(); - typeParams.add(parseFormalTypeParameter()); - while ((symbol != '>') && (symbol > 0)) { - typeParams.add(parseFormalTypeParameter()); - } - expect('>'); - } - this.formalTypeParameters = typeParams.getArray(); - } - - ImplForVariable<GenericDeclaration> parseFormalTypeParameter() { - // FormalTypeParameter ::= Ident ClassBound {InterfaceBound}. - - scanIdentifier(); - String name = identifier.intern(); // FIXME: is this o.k.? - - ListOfTypes bounds = new ListOfTypes(8); - - // ClassBound ::= ":" [FieldTypeSignature]. - expect(':'); - if (symbol == 'L' || symbol == '[' || symbol == 'T') { - bounds.add(parseFieldTypeSignature()); - } - - while (symbol == ':') { - // InterfaceBound ::= ":" FieldTypeSignature. - scanSymbol(); - bounds.add(parseFieldTypeSignature()); - } - - return new ImplForVariable<GenericDeclaration>(genericDecl, name, bounds); - } - - Type parseFieldTypeSignature() { - // FieldTypeSignature ::= ClassTypeSignature | ArrayTypeSignature - // | TypeVariableSignature. - - switch (symbol) { - case 'L': - return parseClassTypeSignature(); - case '[': - // ArrayTypeSignature ::= "[" TypSignature. - scanSymbol(); - return new ImplForArray(parseTypeSignature()); - case 'T': - return parseTypeVariableSignature(); - default: - throw new GenericSignatureFormatError(); - } - } - - Type parseClassTypeSignature() { - // ClassTypeSignature ::= "L" {Ident "/"} Ident - // OptTypeArguments {"." Ident OptTypeArguments} ";". - - expect('L'); - - StringBuilder qualIdent = new StringBuilder(); - scanIdentifier(); - while (symbol == '/') { - scanSymbol(); - qualIdent.append(identifier).append("."); - scanIdentifier(); - } - - qualIdent.append(this.identifier); - - ListOfTypes typeArgs = parseOptTypeArguments(); - ImplForType parentType = - new ImplForType(null, qualIdent.toString(), typeArgs, loader); - ImplForType type = parentType; - - while (symbol == '.') { - // Deal with Member Classes: - scanSymbol(); - scanIdentifier(); - qualIdent.append("$").append(identifier); // FIXME: is "$" correct? - typeArgs = parseOptTypeArguments(); - type = new ImplForType(parentType, qualIdent.toString(), typeArgs, - loader); - } - - expect(';'); - - return type; - } - - ListOfTypes parseOptTypeArguments() { - // OptTypeArguments ::= "<" TypeArgument {TypeArgument} ">". - - ListOfTypes typeArgs = new ListOfTypes(8); - if (symbol == '<') { - scanSymbol(); - - typeArgs.add(parseTypeArgument()); - while ((symbol != '>') && (symbol > 0)) { - typeArgs.add(parseTypeArgument()); - } - expect('>'); - } - return typeArgs; - } - - Type parseTypeArgument() { - // TypeArgument ::= (["+" | "-"] FieldTypeSignature) | "*". - ListOfTypes extendsBound = new ListOfTypes(1); - ListOfTypes superBound = new ListOfTypes(1); - if (symbol == '*') { - scanSymbol(); - extendsBound.add(Object.class); - return new ImplForWildcard(extendsBound, superBound); - } - else if (symbol == '+') { - scanSymbol(); - extendsBound.add(parseFieldTypeSignature()); - return new ImplForWildcard(extendsBound, superBound); - } - else if (symbol == '-') { - scanSymbol(); - superBound.add(parseFieldTypeSignature()); - extendsBound.add(Object.class); - return new ImplForWildcard(extendsBound, superBound); - } - else { - return parseFieldTypeSignature(); - } - } - - ImplForVariable<GenericDeclaration> parseTypeVariableSignature() { - // TypeVariableSignature ::= "T" Ident ";". - expect('T'); - scanIdentifier(); - expect(';'); - // Reference to type variable: - // Note: we don't know the declaring GenericDeclaration yet. - return new ImplForVariable<GenericDeclaration>(genericDecl, identifier); - } - - Type parseTypeSignature() { - switch (symbol) { - case 'B': scanSymbol(); return byte.class; - case 'C': scanSymbol(); return char.class; - case 'D': scanSymbol(); return double.class; - case 'F': scanSymbol(); return float.class; - case 'I': scanSymbol(); return int.class; - case 'J': scanSymbol(); return long.class; - case 'S': scanSymbol(); return short.class; - case 'Z': scanSymbol(); return boolean.class; - default: - // Not an elementary type, but a FieldTypeSignature. - return parseFieldTypeSignature(); - } - } - - /** - * @param rawExceptionTypes the non-generic exceptions. This is necessary - * because the signature may omit the exceptions when none are generic. - * May be null for methods that declare no exceptions. - */ - void parseMethodTypeSignature(Class<?>[] rawExceptionTypes) { - // MethodTypeSignature ::= [FormalTypeParameters] - // "(" {TypeSignature} ")" ReturnType {ThrowsSignature}. - - parseOptFormalTypeParameters(); - - parameterTypes = new ListOfTypes(16); - expect('('); - while (symbol != ')' && (symbol > 0)) { - parameterTypes.add(parseTypeSignature()); - } - expect(')'); - - returnType = parseReturnType(); - - if (symbol == '^') { - exceptionTypes = new ListOfTypes(8); - do { - scanSymbol(); - - // ThrowsSignature ::= ("^" ClassTypeSignature) | - // ("^" TypeVariableSignature). - if (symbol == 'T') { - exceptionTypes.add(parseTypeVariableSignature()); - } else { - exceptionTypes.add(parseClassTypeSignature()); - } - } while (symbol == '^'); - } else if (rawExceptionTypes != null) { - exceptionTypes = new ListOfTypes(rawExceptionTypes); - } else { - exceptionTypes = new ListOfTypes(0); - } - } - - Type parseReturnType() { - // ReturnType ::= TypeSignature | "V". - if (symbol != 'V') { return parseTypeSignature(); } - else { scanSymbol(); return void.class; } - } - - - // - // Scanner: - // - - void scanSymbol() { - if (!eof) { - if (pos < buffer.length) { - symbol = buffer[pos]; - pos++; - } else { - symbol = 0; - eof = true; - } - } else { - throw new GenericSignatureFormatError(); - } - } - - void expect(char c) { - if (symbol == c) { - scanSymbol(); - } else { - throw new GenericSignatureFormatError(); - } - } - - boolean isStopSymbol(char ch) { - switch (ch) { - case ':': - case '/': - case ';': - case '<': - case '.': - return true; - } - return false; - } - - // PRE: symbol is the first char of the identifier. - // POST: symbol = the next symbol AFTER the identifier. - void scanIdentifier() { - if (!eof) { - StringBuilder identBuf = new StringBuilder(32); - if (!isStopSymbol(symbol)) { - identBuf.append(symbol); - do { - char ch = buffer[pos]; - if ((ch >= 'a') && (ch <= 'z') || (ch >= 'A') && (ch <= 'Z') - || !isStopSymbol(ch)) { - identBuf.append(buffer[pos]); - pos++; - } else { - identifier = identBuf.toString(); - scanSymbol(); - return; - } - } while (pos != buffer.length); - identifier = identBuf.toString(); - symbol = 0; - eof = true; - } else { - // Ident starts with incorrect char. - symbol = 0; - eof = true; - throw new GenericSignatureFormatError(); - } - } else { - throw new GenericSignatureFormatError(); - } - } - -} diff --git a/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForArray.java b/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForArray.java deleted file mode 100644 index c9b76b1..0000000 --- a/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForArray.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.harmony.luni.lang.reflect; - -import java.lang.reflect.GenericArrayType; -import java.lang.reflect.Type; - -public final class ImplForArray implements GenericArrayType { - private final Type componentType; - - public ImplForArray(Type componentType) { - this.componentType = componentType; - } - - public Type getGenericComponentType() { - try { - return ((ImplForType)componentType).getResolvedType(); - } catch (ClassCastException e) { - return componentType; - } - } - - public String toString() { - return componentType.toString() + "[]"; - } -} diff --git a/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForType.java b/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForType.java deleted file mode 100644 index b1f05d4..0000000 --- a/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForType.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.harmony.luni.lang.reflect; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; - -public final class ImplForType implements ParameterizedType { - private final ListOfTypes args; - private final ImplForType ownerType0; // Potentially unresolved. - private Type ownerTypeRes; - private Class rawType; // Already resolved. - private final String rawTypeName; - private ClassLoader loader; - - - public ImplForType(ImplForType ownerType, String rawTypeName, - ListOfTypes args, ClassLoader loader) { - this.ownerType0 = ownerType; - this.rawTypeName = rawTypeName; - this.args = args; - this.loader = loader; - } - - - public Type[] getActualTypeArguments() { - // ASSUMPTION: args is never null!!! - return args.getResolvedTypes().clone(); - } - - public Type getOwnerType() { - if (ownerTypeRes == null) { - if (ownerType0 != null) { - ownerTypeRes = ownerType0.getResolvedType(); - } else { - ownerTypeRes = getRawType().getDeclaringClass(); - } - } - return ownerTypeRes; - } - - public Class getRawType() { - if (rawType == null) { - // Here the actual loading of the class has to be performed and the - // Exceptions have to be re-thrown TypeNotPresent... - // How to deal with member (nested) classes? - try { - rawType = Class.forName(rawTypeName, false, loader); - } catch (ClassNotFoundException e) { - throw new TypeNotPresentException(rawTypeName, e); - } - } - return rawType; - } - - - Type getResolvedType() { - if (args.getResolvedTypes().length == 0) { - return getRawType(); - } else { - return this; - } - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(rawTypeName); - if (args.length() > 0) { - sb.append("<").append(args).append(">"); - } - return sb.toString(); - } -} diff --git a/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForVariable.java b/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForVariable.java deleted file mode 100644 index 783d223..0000000 --- a/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForVariable.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.harmony.luni.lang.reflect; - -import java.lang.reflect.Constructor; -import java.lang.reflect.GenericDeclaration; -import java.lang.reflect.Method; -import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; - - -public final class ImplForVariable<D extends GenericDeclaration> implements TypeVariable<D> { - private ImplForVariable<D> formalVar; - private final GenericDeclaration declOfVarUser; - private final String name; - private D genericDeclaration; - private ListOfTypes bounds; - - @Override - public boolean equals(Object o) { - if(!(o instanceof TypeVariable)) { - return false; - } - TypeVariable<?> that = (TypeVariable<?>) o; - return getName().equals(that.getName()) && - getGenericDeclaration().equals(that.getGenericDeclaration()); - } - - - @Override - public int hashCode() { - return 31 * getName().hashCode() + getGenericDeclaration().hashCode(); - } - - /** - * @param genericDecl declaration where a type variable is declared - * @param name type variable name - * @param bounds class and interface bounds - */ - ImplForVariable(D genericDecl, String name, ListOfTypes bounds) { - this.genericDeclaration = genericDecl; - this.name = name; - this.bounds = bounds; - this.formalVar = this; - this.declOfVarUser = null; - } - - /** - * @param genericDecl declaration where a type variable is used - * @param name type variable name - */ - ImplForVariable(D genericDecl, String name) { - this.name = name; - this.declOfVarUser = genericDecl; - } - - static TypeVariable findFormalVar(GenericDeclaration layer, String name) { - TypeVariable[] formalVars = layer.getTypeParameters(); - for (TypeVariable var : formalVars) { - if (name.equals(var.getName())) { - return var; - } - } - // resolve() looks up the next level only, if null is returned - return null; - } - - private static GenericDeclaration nextLayer(GenericDeclaration decl) { - if (decl instanceof Class) { - // FIXME: Is the following hierarchy correct?: - Class cl = (Class)decl; - decl = cl.getEnclosingMethod(); - if (decl != null) { - return decl; - } - decl = cl.getEnclosingConstructor(); - if (decl != null) { - return decl; - } - return cl.getEnclosingClass(); - } else if (decl instanceof Method) { - return ((Method)decl).getDeclaringClass(); - } else if (decl instanceof Constructor) { - return ((Constructor)decl).getDeclaringClass(); - } else { - throw new AssertionError(); - } - } - - void resolve() { - if (formalVar != null) { - return; - } - GenericDeclaration curLayer = declOfVarUser; - TypeVariable var; - while ((var = findFormalVar(curLayer, name)) == null) { - curLayer = nextLayer(curLayer); - if (curLayer == null) { - throw new AssertionError("illegal type variable reference"); - } - } - formalVar = (ImplForVariable<D>) var; - this.genericDeclaration = formalVar.genericDeclaration; - this.bounds = formalVar.bounds; - } - - public Type[] getBounds() { - resolve(); - return bounds.getResolvedTypes().clone(); - } - - public D getGenericDeclaration() { - resolve(); - return genericDeclaration; - } - - public String getName() { - return name; - } - - @Override - public String toString() { - return name; - } -} diff --git a/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForWildcard.java b/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForWildcard.java deleted file mode 100644 index b0605f2..0000000 --- a/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForWildcard.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.harmony.luni.lang.reflect; - -import java.lang.reflect.MalformedParameterizedTypeException; -import java.lang.reflect.Type; -import java.lang.reflect.WildcardType; -import java.util.Arrays; - -public final class ImplForWildcard implements WildcardType { - - private final ListOfTypes extendsBound, superBound; - - public ImplForWildcard(ListOfTypes extendsBound, ListOfTypes superBound) { - this.extendsBound = extendsBound; - this.superBound = superBound; - } - - public Type[] getLowerBounds() throws TypeNotPresentException, - MalformedParameterizedTypeException { - return superBound.getResolvedTypes().clone(); - } - - public Type[] getUpperBounds() throws TypeNotPresentException, - MalformedParameterizedTypeException { - return extendsBound.getResolvedTypes().clone(); - } - - @Override - public boolean equals(Object o) { - if(!(o instanceof WildcardType)) { - return false; - } - WildcardType that = (WildcardType) o; - return Arrays.equals(getLowerBounds(), that.getLowerBounds()) && - Arrays.equals(getUpperBounds(), that.getUpperBounds()); - } - - @Override - public int hashCode() { - return 31 * Arrays.hashCode(getLowerBounds()) + - Arrays.hashCode(getUpperBounds()); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("?"); - if ((extendsBound.length() == 1 && extendsBound.getResolvedTypes()[0] != Object.class) - || extendsBound.length() > 1) { - sb.append(" extends ").append(extendsBound); - } else if (superBound.length() > 0) { - sb.append(" super ").append(superBound); - } - return sb.toString(); - } -} diff --git a/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ListOfTypes.java b/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ListOfTypes.java deleted file mode 100644 index 59470f5..0000000 --- a/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ListOfTypes.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.harmony.luni.lang.reflect; - -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; - -public final class ListOfTypes { - public static final ListOfTypes EMPTY = new ListOfTypes(0); - - private final ArrayList<Type> types; - private Type[] resolvedTypes; - - ListOfTypes(int capacity) { - types = new ArrayList<Type>(capacity); - } - - ListOfTypes(Type[] types) { - this.types = new ArrayList<Type>(types.length); - for (Type type : types) { - this.types.add(type); - } - } - - void add(Type type) { - if (type == null) { - throw new NullPointerException("type == null"); - } - types.add(type); - } - - int length() { - return types.size(); - } - - public Type[] getResolvedTypes() { - Type[] result = resolvedTypes; - return result != null ? result : (resolvedTypes = resolveTypes(types)); - } - - private Type[] resolveTypes(List<Type> unresolved) { - Type[] result = new Type[unresolved.size()]; - for (int i = 0; i < unresolved.size(); i++) { - Type type = unresolved.get(i); - try { - result[i] = ((ImplForType) type).getResolvedType(); - } catch (ClassCastException e) { - result[i] = type; - } - } - return result; - } - - @Override public String toString() { - StringBuilder result = new StringBuilder(); - for (int i = 0; i < types.size(); i++) { - if (i > 0) { - result.append(", "); - } - result.append(types.get(i)); - } - return result.toString(); - } -} diff --git a/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ListOfVariables.java b/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ListOfVariables.java deleted file mode 100644 index 0e757ac..0000000 --- a/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/ListOfVariables.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.harmony.luni.lang.reflect; - -import java.lang.reflect.TypeVariable; -import java.util.ArrayList; - -class ListOfVariables { - public static final TypeVariable[] EMPTY = new ImplForVariable[0]; - - ArrayList<TypeVariable<?>> array = new ArrayList<TypeVariable<?>>(); - - void add (TypeVariable<?> elem) { - array.add(elem); - } - - TypeVariable<?>[] getArray() { - TypeVariable<?>[] a = new TypeVariable[array.size()]; - return array.toArray(a); - } -} diff --git a/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/Types.java b/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/Types.java deleted file mode 100644 index bd700fc..0000000 --- a/libdvm/src/main/java/org/apache/harmony/luni/lang/reflect/Types.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.harmony.luni.lang.reflect; - -import java.lang.reflect.Type; - -public class Types { - - public static Type[] getClonedTypeArray(ListOfTypes types) { - return types.getResolvedTypes().clone(); - } - - public static Type getType(Type type) { - if (type instanceof ImplForType) { - return ((ImplForType)type).getResolvedType(); - } else { - return type; - } - } -} |