mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-21 11:34:38 +02:00
8187443: Forest Consolidation: Move files to unified layout
Reviewed-by: darcy, ihse
This commit is contained in:
parent
270fe13182
commit
3789983e89
56923 changed files with 3 additions and 15727 deletions
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.factory;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.GenericDeclaration;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.lang.reflect.WildcardType;
|
||||
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.*;
|
||||
import sun.reflect.generics.scope.Scope;
|
||||
import sun.reflect.generics.tree.FieldTypeSignature;
|
||||
|
||||
|
||||
/**
|
||||
* Factory for reflective generic type objects for use by
|
||||
* core reflection (java.lang.reflect).
|
||||
*/
|
||||
public class CoreReflectionFactory implements GenericsFactory {
|
||||
private final GenericDeclaration decl;
|
||||
private final Scope scope;
|
||||
|
||||
private CoreReflectionFactory(GenericDeclaration d, Scope s) {
|
||||
decl = d;
|
||||
scope = s;
|
||||
}
|
||||
|
||||
private GenericDeclaration getDecl(){ return decl;}
|
||||
|
||||
private Scope getScope(){ return scope;}
|
||||
|
||||
|
||||
private ClassLoader getDeclsLoader() {
|
||||
if (decl instanceof Class) {return ((Class) decl).getClassLoader();}
|
||||
if (decl instanceof Method) {
|
||||
return ((Method) decl).getDeclaringClass().getClassLoader();
|
||||
}
|
||||
assert decl instanceof Constructor : "Constructor expected";
|
||||
return ((Constructor) decl).getDeclaringClass().getClassLoader();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory for this class. Returns an instance of
|
||||
* {@code CoreReflectionFactory} for the declaration and scope
|
||||
* provided.
|
||||
* This factory will produce reflective objects of the appropriate
|
||||
* kind. Classes produced will be those that would be loaded by the
|
||||
* defining class loader of the declaration {@code d} (if {@code d}
|
||||
* is a type declaration, or by the defining loader of the declaring
|
||||
* class of {@code d} otherwise.
|
||||
* <p> Type variables will be created or lookup as necessary in the
|
||||
* scope {@code s}.
|
||||
* @param d - the generic declaration (class, interface, method or
|
||||
* constructor) that this factory services
|
||||
* @param s the scope in which the factory will allocate and search for
|
||||
* type variables
|
||||
* @return an instance of {@code CoreReflectionFactory}
|
||||
*/
|
||||
public static CoreReflectionFactory make(GenericDeclaration d, Scope s) {
|
||||
return new CoreReflectionFactory(d, s);
|
||||
}
|
||||
|
||||
public TypeVariable<?> makeTypeVariable(String name,
|
||||
FieldTypeSignature[] bounds){
|
||||
return TypeVariableImpl.make(getDecl(), name, bounds, this);
|
||||
}
|
||||
|
||||
public WildcardType makeWildcard(FieldTypeSignature[] ubs,
|
||||
FieldTypeSignature[] lbs) {
|
||||
return WildcardTypeImpl.make(ubs, lbs, this);
|
||||
}
|
||||
|
||||
public ParameterizedType makeParameterizedType(Type declaration,
|
||||
Type[] typeArgs,
|
||||
Type owner) {
|
||||
return ParameterizedTypeImpl.make((Class<?>) declaration,
|
||||
typeArgs, owner);
|
||||
}
|
||||
|
||||
public TypeVariable<?> findTypeVariable(String name){
|
||||
return getScope().lookup(name);
|
||||
}
|
||||
|
||||
public Type makeNamedType(String name){
|
||||
try {return Class.forName(name, false, // don't initialize
|
||||
getDeclsLoader());}
|
||||
catch (ClassNotFoundException c) {
|
||||
throw new TypeNotPresentException(name, c);
|
||||
}
|
||||
}
|
||||
|
||||
public Type makeArrayType(Type componentType){
|
||||
if (componentType instanceof Class<?>)
|
||||
return Array.newInstance((Class<?>) componentType, 0).getClass();
|
||||
else
|
||||
return GenericArrayTypeImpl.make(componentType);
|
||||
}
|
||||
|
||||
public Type makeByte(){return byte.class;}
|
||||
public Type makeBool(){return boolean.class;}
|
||||
public Type makeShort(){return short.class;}
|
||||
public Type makeChar(){return char.class;}
|
||||
public Type makeInt(){return int.class;}
|
||||
public Type makeLong(){return long.class;}
|
||||
public Type makeFloat(){return float.class;}
|
||||
public Type makeDouble(){return double.class;}
|
||||
|
||||
public Type makeVoid(){return void.class;}
|
||||
}
|
|
@ -0,0 +1,190 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.factory;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.lang.reflect.WildcardType;
|
||||
import sun.reflect.generics.tree.FieldTypeSignature;
|
||||
|
||||
/**
|
||||
* A factory interface for reflective objects representing generic types.
|
||||
* Implementors (such as core reflection or JDI, or possibly javadoc
|
||||
* will manufacture instances of (potentially) different classes
|
||||
* in response to invocations of the methods described here.
|
||||
* <p> The intent is that reflective systems use these factories to
|
||||
* produce generic type information on demand.
|
||||
* Certain components of such reflective systems can be independent
|
||||
* of a specific implementation by using this interface. For example,
|
||||
* repositories of generic type information are initialized with a
|
||||
* factory conforming to this interface, and use it to generate the
|
||||
* type information they are required to provide. As a result, such
|
||||
* repository code can be shared across different reflective systems.
|
||||
*/
|
||||
public interface GenericsFactory {
|
||||
/**
|
||||
* Returns a new type variable declaration. Note that {@code name}
|
||||
* may be empty (but not {@code null}). If {@code bounds} is
|
||||
* empty, a bound of {@code java.lang.Object} is used.
|
||||
* @param name The name of the type variable
|
||||
* @param bounds An array of abstract syntax trees representing
|
||||
* the upper bound(s) on the type variable being declared
|
||||
* @return a new type variable declaration
|
||||
* @throws NullPointerException if any of the actual parameters
|
||||
* or any of the elements of {@code bounds} are {@code null}.
|
||||
*/
|
||||
TypeVariable<?> makeTypeVariable(String name,
|
||||
FieldTypeSignature[] bounds);
|
||||
/**
|
||||
* Returns an instance of the {@code ParameterizedType} interface
|
||||
* that corresponds to a generic type instantiation of the
|
||||
* generic declaration {@code declaration} with actual type arguments
|
||||
* {@code typeArgs}.
|
||||
* If {@code owner} is {@code null}, the declaring class of
|
||||
* {@code declaration} is used as the owner of this parameterized
|
||||
* type.
|
||||
* <p> This method throws a MalformedParameterizedTypeException
|
||||
* under the following circumstances:
|
||||
* If the type declaration does not represent a generic declaration
|
||||
* (i.e., it is not an instance of {@code GenericDeclaration}).
|
||||
* If the number of actual type arguments (i.e., the size of the
|
||||
* array {@code typeArgs}) does not correspond to the number of
|
||||
* formal type arguments.
|
||||
* If any of the actual type arguments is not an instance of the
|
||||
* bounds on the corresponding formal.
|
||||
* @param declaration - the generic type declaration that is to be
|
||||
* instantiated
|
||||
* @param typeArgs - the list of actual type arguments
|
||||
* @return - a parameterized type representing the instantiation
|
||||
* of the declaration with the actual type arguments
|
||||
* @throws MalformedParameterizedTypeException if the instantiation
|
||||
* is invalid
|
||||
* @throws NullPointerException if any of {@code declaration},
|
||||
* {@code typeArgs}
|
||||
* or any of the elements of {@code typeArgs} are {@code null}
|
||||
*/
|
||||
ParameterizedType makeParameterizedType(Type declaration,
|
||||
Type[] typeArgs,
|
||||
Type owner);
|
||||
|
||||
/**
|
||||
* Returns the type variable with name {@code name}, if such
|
||||
* a type variable is declared in the
|
||||
* scope used to create this factory.
|
||||
* Returns {@code null} otherwise.
|
||||
* @param name - the name of the type variable to search for
|
||||
* @return - the type variable with name {@code name}, or {@code null}
|
||||
* @throws NullPointerException if any of actual parameters are
|
||||
* {@code null}
|
||||
*/
|
||||
TypeVariable<?> findTypeVariable(String name);
|
||||
|
||||
/**
|
||||
* Returns a new wildcard type variable. If
|
||||
* {@code ubs} is empty, a bound of {@code java.lang.Object} is used.
|
||||
* @param ubs An array of abstract syntax trees representing
|
||||
* the upper bound(s) on the type variable being declared
|
||||
* @param lbs An array of abstract syntax trees representing
|
||||
* the lower bound(s) on the type variable being declared
|
||||
* @return a new wildcard type variable
|
||||
* @throws NullPointerException if any of the actual parameters
|
||||
* or any of the elements of {@code ubs} or {@code lbs} are
|
||||
* {@code null}
|
||||
*/
|
||||
WildcardType makeWildcard(FieldTypeSignature[] ubs,
|
||||
FieldTypeSignature[] lbs);
|
||||
|
||||
Type makeNamedType(String name);
|
||||
|
||||
/**
|
||||
* Returns a (possibly generic) array type.
|
||||
* If the component type is a parameterized type, it must
|
||||
* only have unbounded wildcard arguments, otherwise
|
||||
* a MalformedParameterizedTypeException is thrown.
|
||||
* @param componentType - the component type of the array
|
||||
* @return a (possibly generic) array type.
|
||||
* @throws MalformedParameterizedTypeException if {@code componentType}
|
||||
* is a parameterized type with non-wildcard type arguments
|
||||
* @throws NullPointerException if any of the actual parameters
|
||||
* are {@code null}
|
||||
*/
|
||||
Type makeArrayType(Type componentType);
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of type {@code byte}.
|
||||
* @return the reflective representation of type {@code byte}.
|
||||
*/
|
||||
Type makeByte();
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of type {@code boolean}.
|
||||
* @return the reflective representation of type {@code boolean}.
|
||||
*/
|
||||
Type makeBool();
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of type {@code short}.
|
||||
* @return the reflective representation of type {@code short}.
|
||||
*/
|
||||
Type makeShort();
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of type {@code char}.
|
||||
* @return the reflective representation of type {@code char}.
|
||||
*/
|
||||
Type makeChar();
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of type {@code int}.
|
||||
* @return the reflective representation of type {@code int}.
|
||||
*/
|
||||
Type makeInt();
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of type {@code long}.
|
||||
* @return the reflective representation of type {@code long}.
|
||||
*/
|
||||
Type makeLong();
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of type {@code float}.
|
||||
* @return the reflective representation of type {@code float}.
|
||||
*/
|
||||
Type makeFloat();
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of type {@code double}.
|
||||
* @return the reflective representation of type {@code double}.
|
||||
*/
|
||||
Type makeDouble();
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of {@code void}.
|
||||
* @return the reflective representation of {@code void}.
|
||||
*/
|
||||
Type makeVoid();
|
||||
}
|
|
@ -0,0 +1,634 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.parser;
|
||||
|
||||
import java.lang.reflect.GenericSignatureFormatError;
|
||||
import java.util.*;
|
||||
import sun.reflect.generics.tree.*;
|
||||
|
||||
/**
|
||||
* Parser for type signatures, as defined in the Java Virtual
|
||||
* Machine Specification (JVMS) chapter 4.
|
||||
* Converts the signatures into an abstract syntax tree (AST) representation.
|
||||
* See the package sun.reflect.generics.tree for details of the AST.
|
||||
*/
|
||||
public class SignatureParser {
|
||||
// The input is conceptually a character stream (though currently it's
|
||||
// a string). This is slightly different than traditional parsers,
|
||||
// because there is no lexical scanner performing tokenization.
|
||||
// Having a separate tokenizer does not fit with the nature of the
|
||||
// input format.
|
||||
// Other than the absence of a tokenizer, this parser is a classic
|
||||
// recursive descent parser. Its structure corresponds as closely
|
||||
// as possible to the grammar in the JVMS.
|
||||
//
|
||||
// A note on asserts vs. errors: The code contains assertions
|
||||
// in situations that should never occur. An assertion failure
|
||||
// indicates a failure of the parser logic. A common pattern
|
||||
// is an assertion that the current input is a particular
|
||||
// character. This is often paired with a separate check
|
||||
// that this is the case, which seems redundant. For example:
|
||||
//
|
||||
// assert(current() != x);
|
||||
// if (current != x {error("expected an x");
|
||||
//
|
||||
// where x is some character constant.
|
||||
// The assertion indicates, that, as currently written,
|
||||
// the code should never reach this point unless the input is an
|
||||
// x. On the other hand, the test is there to check the legality
|
||||
// of the input wrt to a given production. It may be that at a later
|
||||
// time the code might be called directly, and if the input is
|
||||
// invalid, the parser should flag an error in accordance
|
||||
// with its logic.
|
||||
|
||||
private String input; // the input signature
|
||||
private int index; // index into the input
|
||||
private int mark; // index of mark
|
||||
// used to mark end of input
|
||||
private static final char EOI = ':';
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
// private constructor - enforces use of static factory
|
||||
private SignatureParser(){}
|
||||
|
||||
// prepares parser for new parsing session
|
||||
private void init(String s) {
|
||||
input = s;
|
||||
mark = index = 0;
|
||||
}
|
||||
|
||||
// Utility methods.
|
||||
|
||||
// Most parsing routines use the following routines to access the
|
||||
// input stream, and advance it as necessary.
|
||||
// This makes it easy to adapt the parser to operate on streams
|
||||
// of various kinds as well as strings.
|
||||
|
||||
// returns current element of the input
|
||||
private char current(){
|
||||
assert(index <= input.length());
|
||||
return index < input.length() ? input.charAt(index) : EOI;
|
||||
}
|
||||
|
||||
// advance the input
|
||||
private void advance(){
|
||||
assert(index <= input.length());
|
||||
if (index < input.length()) index++;
|
||||
}
|
||||
|
||||
// mark current position
|
||||
private void mark() {
|
||||
mark = index;
|
||||
}
|
||||
|
||||
// For debugging, prints current character to the end of the input.
|
||||
private String remainder() {
|
||||
return input.substring(index);
|
||||
}
|
||||
|
||||
// returns a substring of input from mark (inclusive)
|
||||
// to current position (exclusive)
|
||||
private String markToCurrent() {
|
||||
return input.substring(mark, index);
|
||||
}
|
||||
|
||||
// Error handling routine. Encapsulates error handling.
|
||||
// Takes a string error message as argument.
|
||||
// Currently throws a GenericSignatureFormatError.
|
||||
|
||||
private Error error(String errorMsg) {
|
||||
return new GenericSignatureFormatError("Signature Parse error: " + errorMsg +
|
||||
"\n\tRemaining input: " + remainder());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the parse has made forward progress; throw an exception
|
||||
* if no progress.
|
||||
*/
|
||||
private void progress(int startingPosition) {
|
||||
if (index <= startingPosition)
|
||||
throw error("Failure to make progress!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Static factory method. Produces a parser instance.
|
||||
* @return an instance of {@code SignatureParser}
|
||||
*/
|
||||
public static SignatureParser make() {
|
||||
return new SignatureParser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a class signature (as defined in the JVMS, chapter 4)
|
||||
* and produces an abstract syntax tree representing it.
|
||||
* @param s a string representing the input class signature
|
||||
* @return An abstract syntax tree for a class signature
|
||||
* corresponding to the input string
|
||||
* @throws GenericSignatureFormatError if the input is not a valid
|
||||
* class signature
|
||||
*/
|
||||
public ClassSignature parseClassSig(String s) {
|
||||
if (DEBUG) System.out.println("Parsing class sig:" + s);
|
||||
init(s);
|
||||
return parseClassSignature();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a method signature (as defined in the JVMS, chapter 4)
|
||||
* and produces an abstract syntax tree representing it.
|
||||
* @param s a string representing the input method signature
|
||||
* @return An abstract syntax tree for a method signature
|
||||
* corresponding to the input string
|
||||
* @throws GenericSignatureFormatError if the input is not a valid
|
||||
* method signature
|
||||
*/
|
||||
public MethodTypeSignature parseMethodSig(String s) {
|
||||
if (DEBUG) System.out.println("Parsing method sig:" + s);
|
||||
init(s);
|
||||
return parseMethodTypeSignature();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses a type signature
|
||||
* and produces an abstract syntax tree representing it.
|
||||
*
|
||||
* @param s a string representing the input type signature
|
||||
* @return An abstract syntax tree for a type signature
|
||||
* corresponding to the input string
|
||||
* @throws GenericSignatureFormatError if the input is not a valid
|
||||
* type signature
|
||||
*/
|
||||
public TypeSignature parseTypeSig(String s) {
|
||||
if (DEBUG) System.out.println("Parsing type sig:" + s);
|
||||
init(s);
|
||||
return parseTypeSignature();
|
||||
}
|
||||
|
||||
// Parsing routines.
|
||||
// As a rule, the parsing routines access the input using the
|
||||
// utilities current() and advance().
|
||||
// The convention is that when a parsing routine is invoked
|
||||
// it expects the current input to be the first character it should parse
|
||||
// and when it completes parsing, it leaves the input at the first
|
||||
// character after the input parses.
|
||||
|
||||
/*
|
||||
* Note on grammar conventions: a trailing "*" matches zero or
|
||||
* more occurrences, a trailing "+" matches one or more occurrences,
|
||||
* "_opt" indicates an optional component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* ClassSignature:
|
||||
* FormalTypeParameters_opt SuperclassSignature SuperinterfaceSignature*
|
||||
*/
|
||||
private ClassSignature parseClassSignature() {
|
||||
// parse a class signature based on the implicit input.
|
||||
assert(index == 0);
|
||||
return ClassSignature.make(parseZeroOrMoreFormalTypeParameters(),
|
||||
parseClassTypeSignature(), // Only rule for SuperclassSignature
|
||||
parseSuperInterfaces());
|
||||
}
|
||||
|
||||
private FormalTypeParameter[] parseZeroOrMoreFormalTypeParameters(){
|
||||
if (current() == '<') {
|
||||
return parseFormalTypeParameters();
|
||||
} else {
|
||||
return new FormalTypeParameter[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* FormalTypeParameters:
|
||||
* "<" FormalTypeParameter+ ">"
|
||||
*/
|
||||
private FormalTypeParameter[] parseFormalTypeParameters(){
|
||||
List<FormalTypeParameter> ftps = new ArrayList<>(3);
|
||||
assert(current() == '<'); // should not have been called at all
|
||||
if (current() != '<') { throw error("expected '<'");}
|
||||
advance();
|
||||
ftps.add(parseFormalTypeParameter());
|
||||
while (current() != '>') {
|
||||
int startingPosition = index;
|
||||
ftps.add(parseFormalTypeParameter());
|
||||
progress(startingPosition);
|
||||
}
|
||||
advance();
|
||||
return ftps.toArray(new FormalTypeParameter[ftps.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* FormalTypeParameter:
|
||||
* Identifier ClassBound InterfaceBound*
|
||||
*/
|
||||
private FormalTypeParameter parseFormalTypeParameter(){
|
||||
String id = parseIdentifier();
|
||||
FieldTypeSignature[] bs = parseBounds();
|
||||
return FormalTypeParameter.make(id, bs);
|
||||
}
|
||||
|
||||
private String parseIdentifier() {
|
||||
mark();
|
||||
skipIdentifier();
|
||||
return markToCurrent();
|
||||
}
|
||||
|
||||
private void skipIdentifier() {
|
||||
char c = current();
|
||||
while (c != ';' && c != '.' && c != '/' &&
|
||||
c != '[' && c != ':' && c != '>' &&
|
||||
c != '<' && !Character.isWhitespace(c)) {
|
||||
advance();
|
||||
c = current();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* FieldTypeSignature:
|
||||
* ClassTypeSignature
|
||||
* ArrayTypeSignature
|
||||
* TypeVariableSignature
|
||||
*/
|
||||
private FieldTypeSignature parseFieldTypeSignature() {
|
||||
return parseFieldTypeSignature(true);
|
||||
}
|
||||
|
||||
private FieldTypeSignature parseFieldTypeSignature(boolean allowArrays) {
|
||||
switch(current()) {
|
||||
case 'L':
|
||||
return parseClassTypeSignature();
|
||||
case 'T':
|
||||
return parseTypeVariableSignature();
|
||||
case '[':
|
||||
if (allowArrays)
|
||||
return parseArrayTypeSignature();
|
||||
else
|
||||
throw error("Array signature not allowed here.");
|
||||
default: throw error("Expected Field Type Signature");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ClassTypeSignature:
|
||||
* "L" PackageSpecifier_opt SimpleClassTypeSignature ClassTypeSignatureSuffix* ";"
|
||||
*/
|
||||
private ClassTypeSignature parseClassTypeSignature(){
|
||||
assert(current() == 'L');
|
||||
if (current() != 'L') { throw error("expected a class type");}
|
||||
advance();
|
||||
List<SimpleClassTypeSignature> scts = new ArrayList<>(5);
|
||||
scts.add(parsePackageNameAndSimpleClassTypeSignature());
|
||||
|
||||
parseClassTypeSignatureSuffix(scts);
|
||||
if (current() != ';')
|
||||
throw error("expected ';' got '" + current() + "'");
|
||||
|
||||
advance();
|
||||
return ClassTypeSignature.make(scts);
|
||||
}
|
||||
|
||||
/**
|
||||
* PackageSpecifier:
|
||||
* Identifier "/" PackageSpecifier*
|
||||
*/
|
||||
private SimpleClassTypeSignature parsePackageNameAndSimpleClassTypeSignature() {
|
||||
// Parse both any optional leading PackageSpecifier as well as
|
||||
// the following SimpleClassTypeSignature.
|
||||
|
||||
mark();
|
||||
skipIdentifier();
|
||||
while (current() == '/') {
|
||||
advance();
|
||||
skipIdentifier();
|
||||
}
|
||||
String id = markToCurrent().replace('/', '.');
|
||||
|
||||
switch (current()) {
|
||||
case ';':
|
||||
return SimpleClassTypeSignature.make(id, false, new TypeArgument[0]); // all done!
|
||||
case '<':
|
||||
if (DEBUG) System.out.println("\t remainder: " + remainder());
|
||||
return SimpleClassTypeSignature.make(id, false, parseTypeArguments());
|
||||
default:
|
||||
throw error("expected '<' or ';' but got " + current());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SimpleClassTypeSignature:
|
||||
* Identifier TypeArguments_opt
|
||||
*/
|
||||
private SimpleClassTypeSignature parseSimpleClassTypeSignature(boolean dollar){
|
||||
String id = parseIdentifier();
|
||||
char c = current();
|
||||
|
||||
switch (c) {
|
||||
case ';':
|
||||
case '.':
|
||||
return SimpleClassTypeSignature.make(id, dollar, new TypeArgument[0]) ;
|
||||
case '<':
|
||||
return SimpleClassTypeSignature.make(id, dollar, parseTypeArguments());
|
||||
default:
|
||||
throw error("expected '<' or ';' or '.', got '" + c + "'.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ClassTypeSignatureSuffix:
|
||||
* "." SimpleClassTypeSignature
|
||||
*/
|
||||
private void parseClassTypeSignatureSuffix(List<SimpleClassTypeSignature> scts) {
|
||||
while (current() == '.') {
|
||||
advance();
|
||||
scts.add(parseSimpleClassTypeSignature(true));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TypeArguments:
|
||||
* "<" TypeArgument+ ">"
|
||||
*/
|
||||
private TypeArgument[] parseTypeArguments() {
|
||||
List<TypeArgument> tas = new ArrayList<>(3);
|
||||
assert(current() == '<');
|
||||
if (current() != '<') { throw error("expected '<'");}
|
||||
advance();
|
||||
tas.add(parseTypeArgument());
|
||||
while (current() != '>') {
|
||||
//(matches(current(), '+', '-', 'L', '[', 'T', '*')) {
|
||||
tas.add(parseTypeArgument());
|
||||
}
|
||||
advance();
|
||||
return tas.toArray(new TypeArgument[tas.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* TypeArgument:
|
||||
* WildcardIndicator_opt FieldTypeSignature
|
||||
* "*"
|
||||
*/
|
||||
private TypeArgument parseTypeArgument() {
|
||||
FieldTypeSignature[] ub, lb;
|
||||
ub = new FieldTypeSignature[1];
|
||||
lb = new FieldTypeSignature[1];
|
||||
TypeArgument[] ta = new TypeArgument[0];
|
||||
char c = current();
|
||||
switch (c) {
|
||||
case '+': {
|
||||
advance();
|
||||
ub[0] = parseFieldTypeSignature();
|
||||
lb[0] = BottomSignature.make(); // bottom
|
||||
return Wildcard.make(ub, lb);
|
||||
}
|
||||
case '*':{
|
||||
advance();
|
||||
ub[0] = SimpleClassTypeSignature.make("java.lang.Object", false, ta);
|
||||
lb[0] = BottomSignature.make(); // bottom
|
||||
return Wildcard.make(ub, lb);
|
||||
}
|
||||
case '-': {
|
||||
advance();
|
||||
lb[0] = parseFieldTypeSignature();
|
||||
ub[0] = SimpleClassTypeSignature.make("java.lang.Object", false, ta);
|
||||
return Wildcard.make(ub, lb);
|
||||
}
|
||||
default:
|
||||
return parseFieldTypeSignature();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TypeVariableSignature:
|
||||
* "T" Identifier ";"
|
||||
*/
|
||||
private TypeVariableSignature parseTypeVariableSignature() {
|
||||
assert(current() == 'T');
|
||||
if (current() != 'T') { throw error("expected a type variable usage");}
|
||||
advance();
|
||||
TypeVariableSignature ts = TypeVariableSignature.make(parseIdentifier());
|
||||
if (current() != ';') {
|
||||
throw error("; expected in signature of type variable named" +
|
||||
ts.getIdentifier());
|
||||
}
|
||||
advance();
|
||||
return ts;
|
||||
}
|
||||
|
||||
/**
|
||||
* ArrayTypeSignature:
|
||||
* "[" TypeSignature
|
||||
*/
|
||||
private ArrayTypeSignature parseArrayTypeSignature() {
|
||||
if (current() != '[') {throw error("expected array type signature");}
|
||||
advance();
|
||||
return ArrayTypeSignature.make(parseTypeSignature());
|
||||
}
|
||||
|
||||
/**
|
||||
* TypeSignature:
|
||||
* FieldTypeSignature
|
||||
* BaseType
|
||||
*/
|
||||
private TypeSignature parseTypeSignature() {
|
||||
switch (current()) {
|
||||
case 'B':
|
||||
case 'C':
|
||||
case 'D':
|
||||
case 'F':
|
||||
case 'I':
|
||||
case 'J':
|
||||
case 'S':
|
||||
case 'Z':
|
||||
return parseBaseType();
|
||||
|
||||
default:
|
||||
return parseFieldTypeSignature();
|
||||
}
|
||||
}
|
||||
|
||||
private BaseType parseBaseType() {
|
||||
switch(current()) {
|
||||
case 'B':
|
||||
advance();
|
||||
return ByteSignature.make();
|
||||
case 'C':
|
||||
advance();
|
||||
return CharSignature.make();
|
||||
case 'D':
|
||||
advance();
|
||||
return DoubleSignature.make();
|
||||
case 'F':
|
||||
advance();
|
||||
return FloatSignature.make();
|
||||
case 'I':
|
||||
advance();
|
||||
return IntSignature.make();
|
||||
case 'J':
|
||||
advance();
|
||||
return LongSignature.make();
|
||||
case 'S':
|
||||
advance();
|
||||
return ShortSignature.make();
|
||||
case 'Z':
|
||||
advance();
|
||||
return BooleanSignature.make();
|
||||
default: {
|
||||
assert(false);
|
||||
throw error("expected primitive type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ClassBound:
|
||||
* ":" FieldTypeSignature_opt
|
||||
*
|
||||
* InterfaceBound:
|
||||
* ":" FieldTypeSignature
|
||||
*/
|
||||
private FieldTypeSignature[] parseBounds() {
|
||||
List<FieldTypeSignature> fts = new ArrayList<>(3);
|
||||
|
||||
if (current() == ':') {
|
||||
advance();
|
||||
switch(current()) {
|
||||
case ':': // empty class bound
|
||||
break;
|
||||
|
||||
default: // parse class bound
|
||||
fts.add(parseFieldTypeSignature());
|
||||
}
|
||||
|
||||
// zero or more interface bounds
|
||||
while (current() == ':') {
|
||||
advance();
|
||||
fts.add(parseFieldTypeSignature());
|
||||
}
|
||||
} else
|
||||
error("Bound expected");
|
||||
|
||||
return fts.toArray(new FieldTypeSignature[fts.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* SuperclassSignature:
|
||||
* ClassTypeSignature
|
||||
*/
|
||||
private ClassTypeSignature[] parseSuperInterfaces() {
|
||||
List<ClassTypeSignature> cts = new ArrayList<>(5);
|
||||
while(current() == 'L') {
|
||||
cts.add(parseClassTypeSignature());
|
||||
}
|
||||
return cts.toArray(new ClassTypeSignature[cts.size()]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* MethodTypeSignature:
|
||||
* FormalTypeParameters_opt "(" TypeSignature* ")" ReturnType ThrowsSignature*
|
||||
*/
|
||||
private MethodTypeSignature parseMethodTypeSignature() {
|
||||
// Parse a method signature based on the implicit input.
|
||||
FieldTypeSignature[] ets;
|
||||
|
||||
assert(index == 0);
|
||||
return MethodTypeSignature.make(parseZeroOrMoreFormalTypeParameters(),
|
||||
parseFormalParameters(),
|
||||
parseReturnType(),
|
||||
parseZeroOrMoreThrowsSignatures());
|
||||
}
|
||||
|
||||
// "(" TypeSignature* ")"
|
||||
private TypeSignature[] parseFormalParameters() {
|
||||
if (current() != '(') {throw error("expected '('");}
|
||||
advance();
|
||||
TypeSignature[] pts = parseZeroOrMoreTypeSignatures();
|
||||
if (current() != ')') {throw error("expected ')'");}
|
||||
advance();
|
||||
return pts;
|
||||
}
|
||||
|
||||
// TypeSignature*
|
||||
private TypeSignature[] parseZeroOrMoreTypeSignatures() {
|
||||
List<TypeSignature> ts = new ArrayList<>();
|
||||
boolean stop = false;
|
||||
while (!stop) {
|
||||
switch(current()) {
|
||||
case 'B':
|
||||
case 'C':
|
||||
case 'D':
|
||||
case 'F':
|
||||
case 'I':
|
||||
case 'J':
|
||||
case 'S':
|
||||
case 'Z':
|
||||
case 'L':
|
||||
case 'T':
|
||||
case '[': {
|
||||
ts.add(parseTypeSignature());
|
||||
break;
|
||||
}
|
||||
default: stop = true;
|
||||
}
|
||||
}
|
||||
return ts.toArray(new TypeSignature[ts.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* ReturnType:
|
||||
* TypeSignature
|
||||
* VoidDescriptor
|
||||
*/
|
||||
private ReturnType parseReturnType(){
|
||||
if (current() == 'V') {
|
||||
advance();
|
||||
return VoidDescriptor.make();
|
||||
} else
|
||||
return parseTypeSignature();
|
||||
}
|
||||
|
||||
// ThrowSignature*
|
||||
private FieldTypeSignature[] parseZeroOrMoreThrowsSignatures(){
|
||||
List<FieldTypeSignature> ets = new ArrayList<>(3);
|
||||
while( current() == '^') {
|
||||
ets.add(parseThrowsSignature());
|
||||
}
|
||||
return ets.toArray(new FieldTypeSignature[ets.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* ThrowsSignature:
|
||||
* "^" ClassTypeSignature
|
||||
* "^" TypeVariableSignature
|
||||
*/
|
||||
private FieldTypeSignature parseThrowsSignature() {
|
||||
assert(current() == '^');
|
||||
if (current() != '^') { throw error("expected throws signature");}
|
||||
advance();
|
||||
return parseFieldTypeSignature(false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.reflectiveObjects;
|
||||
|
||||
import java.lang.reflect.GenericArrayType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Implementation of GenericArrayType interface for core reflection.
|
||||
*/
|
||||
public class GenericArrayTypeImpl
|
||||
implements GenericArrayType {
|
||||
private final Type genericComponentType;
|
||||
|
||||
// private constructor enforces use of static factory
|
||||
private GenericArrayTypeImpl(Type ct) {
|
||||
genericComponentType = ct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method.
|
||||
* @param ct - the desired component type of the generic array type
|
||||
* being created
|
||||
* @return a generic array type with the desired component type
|
||||
*/
|
||||
public static GenericArrayTypeImpl make(Type ct) {
|
||||
return new GenericArrayTypeImpl(ct);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a {@code Type} object representing the component type
|
||||
* of this array.
|
||||
*
|
||||
* @return a {@code Type} object representing the component type
|
||||
* of this array
|
||||
* @since 1.5
|
||||
*/
|
||||
public Type getGenericComponentType() {
|
||||
return genericComponentType; // return cached component type
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getGenericComponentType().getTypeName() + "[]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof GenericArrayType) {
|
||||
GenericArrayType that = (GenericArrayType) o;
|
||||
|
||||
return Objects.equals(genericComponentType, that.getGenericComponentType());
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(genericComponentType);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.reflectiveObjects;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.tree.FieldTypeSignature;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
|
||||
|
||||
/**
|
||||
* Common infrastructure for things that lazily generate reflective generics
|
||||
* objects.
|
||||
* <p> In all these cases, one needs produce a visitor that will, on demand,
|
||||
* traverse the stored AST(s) and reify them into reflective objects.
|
||||
* The visitor needs to be initialized with a factory, which will be
|
||||
* provided when the instance is initialized.
|
||||
* The factory should be cached.
|
||||
*
|
||||
*/
|
||||
public abstract class LazyReflectiveObjectGenerator {
|
||||
private final GenericsFactory factory; // cached factory
|
||||
|
||||
protected LazyReflectiveObjectGenerator(GenericsFactory f) {
|
||||
factory = f;
|
||||
}
|
||||
|
||||
// accessor for factory
|
||||
private GenericsFactory getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
// produce a reifying visitor (could this be typed as a TypeTreeVisitor?
|
||||
protected Reifier getReifier(){return Reifier.make(getFactory());}
|
||||
|
||||
Type[] reifyBounds(FieldTypeSignature[] boundASTs) {
|
||||
final int length = boundASTs.length;
|
||||
final Type[] bounds = new Type[length];
|
||||
// iterate over bound trees, reifying each in turn
|
||||
for (int i = 0; i < length; i++) {
|
||||
Reifier r = getReifier();
|
||||
boundASTs[i].accept(r);
|
||||
bounds[i] = r.getResult();
|
||||
}
|
||||
return bounds;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.reflectiveObjects;
|
||||
|
||||
/** Temporary class used to indicate missing functionality */
|
||||
public class NotImplementedException extends RuntimeException {
|
||||
private static final long serialVersionUID = -9177857708926624790L;
|
||||
}
|
|
@ -0,0 +1,236 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.reflectiveObjects;
|
||||
|
||||
import sun.reflect.generics.tree.FieldTypeSignature;
|
||||
|
||||
import java.lang.reflect.MalformedParameterizedTypeException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.Arrays;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.Objects;
|
||||
|
||||
/** Implementing class for ParameterizedType interface. */
|
||||
|
||||
public class ParameterizedTypeImpl implements ParameterizedType {
|
||||
private final Type[] actualTypeArguments;
|
||||
private final Class<?> rawType;
|
||||
private final Type ownerType;
|
||||
|
||||
private ParameterizedTypeImpl(Class<?> rawType,
|
||||
Type[] actualTypeArguments,
|
||||
Type ownerType) {
|
||||
this.actualTypeArguments = actualTypeArguments;
|
||||
this.rawType = rawType;
|
||||
this.ownerType = (ownerType != null) ? ownerType : rawType.getDeclaringClass();
|
||||
validateConstructorArguments();
|
||||
}
|
||||
|
||||
private void validateConstructorArguments() {
|
||||
TypeVariable<?>[] formals = rawType.getTypeParameters();
|
||||
// check correct arity of actual type args
|
||||
if (formals.length != actualTypeArguments.length){
|
||||
throw new MalformedParameterizedTypeException();
|
||||
}
|
||||
for (int i = 0; i < actualTypeArguments.length; i++) {
|
||||
// check actuals against formals' bounds
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Static factory. Given a (generic) class, actual type arguments
|
||||
* and an owner type, creates a parameterized type.
|
||||
* This class can be instantiated with a a raw type that does not
|
||||
* represent a generic type, provided the list of actual type
|
||||
* arguments is empty.
|
||||
* If the ownerType argument is null, the declaring class of the
|
||||
* raw type is used as the owner type.
|
||||
* <p> This method throws a MalformedParameterizedTypeException
|
||||
* under the following circumstances:
|
||||
* If the number of actual type arguments (i.e., the size of the
|
||||
* array {@code typeArgs}) does not correspond to the number of
|
||||
* formal type arguments.
|
||||
* If any of the actual type arguments is not an instance of the
|
||||
* bounds on the corresponding formal.
|
||||
* @param rawType the Class representing the generic type declaration being
|
||||
* instantiated
|
||||
* @param actualTypeArguments a (possibly empty) array of types
|
||||
* representing the actual type arguments to the parameterized type
|
||||
* @param ownerType the enclosing type, if known.
|
||||
* @return An instance of {@code ParameterizedType}
|
||||
* @throws MalformedParameterizedTypeException if the instantiation
|
||||
* is invalid
|
||||
*/
|
||||
public static ParameterizedTypeImpl make(Class<?> rawType,
|
||||
Type[] actualTypeArguments,
|
||||
Type ownerType) {
|
||||
return new ParameterizedTypeImpl(rawType, actualTypeArguments,
|
||||
ownerType);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of {@code Type} objects representing the actual type
|
||||
* arguments to this type.
|
||||
*
|
||||
* <p>Note that in some cases, the returned array be empty. This can occur
|
||||
* if this type represents a non-parameterized type nested within
|
||||
* a parameterized type.
|
||||
*
|
||||
* @return an array of {@code Type} objects representing the actual type
|
||||
* arguments to this type
|
||||
* @throws TypeNotPresentException if any of the
|
||||
* actual type arguments refers to a non-existent type declaration
|
||||
* @throws MalformedParameterizedTypeException if any of the
|
||||
* actual type parameters refer to a parameterized type that cannot
|
||||
* be instantiated for any reason
|
||||
* @since 1.5
|
||||
*/
|
||||
public Type[] getActualTypeArguments() {
|
||||
return actualTypeArguments.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@code Type} object representing the class or interface
|
||||
* that declared this type.
|
||||
*
|
||||
* @return the {@code Type} object representing the class or interface
|
||||
* that declared this type
|
||||
*/
|
||||
public Class<?> getRawType() {
|
||||
return rawType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a {@code Type} object representing the type that this type
|
||||
* is a member of. For example, if this type is {@code O<T>.I<S>},
|
||||
* return a representation of {@code O<T>}.
|
||||
*
|
||||
* <p>If this type is a top-level type, {@code null} is returned.
|
||||
*
|
||||
* @return a {@code Type} object representing the type that
|
||||
* this type is a member of. If this type is a top-level type,
|
||||
* {@code null} is returned
|
||||
* @throws TypeNotPresentException if the owner type
|
||||
* refers to a non-existent type declaration
|
||||
* @throws MalformedParameterizedTypeException if the owner type
|
||||
* refers to a parameterized type that cannot be instantiated
|
||||
* for any reason
|
||||
*
|
||||
*/
|
||||
public Type getOwnerType() {
|
||||
return ownerType;
|
||||
}
|
||||
|
||||
/*
|
||||
* From the JavaDoc for java.lang.reflect.ParameterizedType
|
||||
* "Instances of classes that implement this interface must
|
||||
* implement an equals() method that equates any two instances
|
||||
* that share the same generic type declaration and have equal
|
||||
* type parameters."
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof ParameterizedType) {
|
||||
// Check that information is equivalent
|
||||
ParameterizedType that = (ParameterizedType) o;
|
||||
|
||||
if (this == that)
|
||||
return true;
|
||||
|
||||
Type thatOwner = that.getOwnerType();
|
||||
Type thatRawType = that.getRawType();
|
||||
|
||||
if (false) { // Debugging
|
||||
boolean ownerEquality = (ownerType == null ?
|
||||
thatOwner == null :
|
||||
ownerType.equals(thatOwner));
|
||||
boolean rawEquality = (rawType == null ?
|
||||
thatRawType == null :
|
||||
rawType.equals(thatRawType));
|
||||
|
||||
boolean typeArgEquality = Arrays.equals(actualTypeArguments, // avoid clone
|
||||
that.getActualTypeArguments());
|
||||
for (Type t : actualTypeArguments) {
|
||||
System.out.printf("\t\t%s%s%n", t, t.getClass());
|
||||
}
|
||||
|
||||
System.out.printf("\towner %s\traw %s\ttypeArg %s%n",
|
||||
ownerEquality, rawEquality, typeArgEquality);
|
||||
return ownerEquality && rawEquality && typeArgEquality;
|
||||
}
|
||||
|
||||
return
|
||||
Objects.equals(ownerType, thatOwner) &&
|
||||
Objects.equals(rawType, thatRawType) &&
|
||||
Arrays.equals(actualTypeArguments, // avoid clone
|
||||
that.getActualTypeArguments());
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return
|
||||
Arrays.hashCode(actualTypeArguments) ^
|
||||
Objects.hashCode(ownerType) ^
|
||||
Objects.hashCode(rawType);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (ownerType != null) {
|
||||
sb.append(ownerType.getTypeName());
|
||||
|
||||
sb.append("$");
|
||||
|
||||
if (ownerType instanceof ParameterizedTypeImpl) {
|
||||
// Find simple name of nested type by removing the
|
||||
// shared prefix with owner.
|
||||
sb.append(rawType.getName().replace( ((ParameterizedTypeImpl)ownerType).rawType.getName() + "$",
|
||||
""));
|
||||
} else
|
||||
sb.append(rawType.getSimpleName());
|
||||
} else
|
||||
sb.append(rawType.getName());
|
||||
|
||||
if (actualTypeArguments != null) {
|
||||
StringJoiner sj = new StringJoiner(", ", "<", ">");
|
||||
sj.setEmptyValue("");
|
||||
for(Type t: actualTypeArguments) {
|
||||
sj.add(t.getTypeName());
|
||||
}
|
||||
sb.append(sj.toString());
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,249 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.reflectiveObjects;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.GenericDeclaration;
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import sun.reflect.annotation.AnnotationSupport;
|
||||
import sun.reflect.annotation.TypeAnnotationParser;
|
||||
import sun.reflect.annotation.AnnotationType;
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.tree.FieldTypeSignature;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
import sun.reflect.misc.ReflectUtil;
|
||||
|
||||
/**
|
||||
* Implementation of {@code java.lang.reflect.TypeVariable} interface
|
||||
* for core reflection.
|
||||
*/
|
||||
public class TypeVariableImpl<D extends GenericDeclaration>
|
||||
extends LazyReflectiveObjectGenerator implements TypeVariable<D> {
|
||||
private final D genericDeclaration;
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The upper bounds. Lazily converted from FieldTypeSignature[] to Type[].
|
||||
* We are required to evaluate the bounds lazily, so we store them as ASTs
|
||||
* until we are first asked for them. This also neatly solves the problem
|
||||
* with F-bounds - you can't reify them before the formal is defined.
|
||||
*/
|
||||
private volatile Object[] bounds;
|
||||
|
||||
// constructor is private to enforce access through static factory
|
||||
private TypeVariableImpl(D decl, String n, FieldTypeSignature[] bs,
|
||||
GenericsFactory f) {
|
||||
super(f);
|
||||
genericDeclaration = decl;
|
||||
name = n;
|
||||
bounds = bs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method.
|
||||
* @param decl - the reflective object that declared the type variable
|
||||
* that this method should create
|
||||
* @param name - the name of the type variable to be returned
|
||||
* @param bs - an array of ASTs representing the bounds for the type
|
||||
* variable to be created
|
||||
* @param f - a factory that can be used to manufacture reflective
|
||||
* objects that represent the bounds of this type variable
|
||||
* @return A type variable with name, bounds, declaration and factory
|
||||
* specified
|
||||
*/
|
||||
public static <T extends GenericDeclaration>
|
||||
TypeVariableImpl<T> make(T decl, String name,
|
||||
FieldTypeSignature[] bs,
|
||||
GenericsFactory f) {
|
||||
|
||||
if (!((decl instanceof Class) ||
|
||||
(decl instanceof Method) ||
|
||||
(decl instanceof Constructor))) {
|
||||
throw new AssertionError("Unexpected kind of GenericDeclaration" +
|
||||
decl.getClass().toString());
|
||||
}
|
||||
return new TypeVariableImpl<T>(decl, name, bs, f);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of {@code Type} objects representing the
|
||||
* upper bound(s) of this type variable. Note that if no upper bound is
|
||||
* explicitly declared, the upper bound is {@code Object}.
|
||||
*
|
||||
* <p>For each upper bound B:
|
||||
* <ul>
|
||||
* <li>if B is a parameterized type or a type variable, it is created,
|
||||
* (see {@link #ParameterizedType} for the details of the creation
|
||||
* process for parameterized types).
|
||||
* <li>Otherwise, B is resolved.
|
||||
* </ul>
|
||||
*
|
||||
* @throws {@code TypeNotPresentException} if any of the
|
||||
* bounds refers to a non-existent type declaration
|
||||
* @throws {@code MalformedParameterizedTypeException} if any of the
|
||||
* bounds refer to a parameterized type that cannot be instantiated
|
||||
* for any reason
|
||||
* @return an array of Types representing the upper bound(s) of this
|
||||
* type variable
|
||||
*/
|
||||
public Type[] getBounds() {
|
||||
Object[] value = bounds;
|
||||
if (value instanceof FieldTypeSignature[]) {
|
||||
value = reifyBounds((FieldTypeSignature[])value);
|
||||
bounds = value;
|
||||
}
|
||||
return (Type[])value.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@code GenericDeclaration} object representing the
|
||||
* generic declaration that declared this type variable.
|
||||
*
|
||||
* @return the generic declaration that declared this type variable.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public D getGenericDeclaration() {
|
||||
if (genericDeclaration instanceof Class)
|
||||
ReflectUtil.checkPackageAccess((Class)genericDeclaration);
|
||||
else if ((genericDeclaration instanceof Method) ||
|
||||
(genericDeclaration instanceof Constructor))
|
||||
ReflectUtil.conservativeCheckMemberAccess((Member)genericDeclaration);
|
||||
else
|
||||
throw new AssertionError("Unexpected kind of GenericDeclaration");
|
||||
return genericDeclaration;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of this type variable, as it occurs in the source code.
|
||||
*
|
||||
* @return the name of this type variable, as it appears in the source code
|
||||
*/
|
||||
public String getName() { return name; }
|
||||
|
||||
public String toString() {return getName();}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof TypeVariable &&
|
||||
o.getClass() == TypeVariableImpl.class) {
|
||||
TypeVariable<?> that = (TypeVariable<?>) o;
|
||||
|
||||
GenericDeclaration thatDecl = that.getGenericDeclaration();
|
||||
String thatName = that.getName();
|
||||
|
||||
return Objects.equals(genericDeclaration, thatDecl) &&
|
||||
Objects.equals(name, thatName);
|
||||
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return genericDeclaration.hashCode() ^ name.hashCode();
|
||||
}
|
||||
|
||||
// Implementations of AnnotatedElement methods.
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
|
||||
Objects.requireNonNull(annotationClass);
|
||||
// T is an Annotation type, the return value of get will be an annotation
|
||||
return (T)mapAnnotations(getAnnotations()).get(annotationClass);
|
||||
}
|
||||
|
||||
public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) {
|
||||
Objects.requireNonNull(annotationClass);
|
||||
return getAnnotation(annotationClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
|
||||
Objects.requireNonNull(annotationClass);
|
||||
return AnnotationSupport.getDirectlyAndIndirectlyPresent(mapAnnotations(getAnnotations()), annotationClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) {
|
||||
Objects.requireNonNull(annotationClass);
|
||||
return getAnnotationsByType(annotationClass);
|
||||
}
|
||||
|
||||
public Annotation[] getAnnotations() {
|
||||
int myIndex = typeVarIndex();
|
||||
if (myIndex < 0)
|
||||
throw new AssertionError("Index must be non-negative.");
|
||||
return TypeAnnotationParser.parseTypeVariableAnnotations(getGenericDeclaration(), myIndex);
|
||||
}
|
||||
|
||||
public Annotation[] getDeclaredAnnotations() {
|
||||
return getAnnotations();
|
||||
}
|
||||
|
||||
public AnnotatedType[] getAnnotatedBounds() {
|
||||
return TypeAnnotationParser.parseAnnotatedBounds(getBounds(),
|
||||
getGenericDeclaration(),
|
||||
typeVarIndex());
|
||||
}
|
||||
|
||||
private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
|
||||
|
||||
// Helpers for annotation methods
|
||||
private int typeVarIndex() {
|
||||
TypeVariable<?>[] tVars = getGenericDeclaration().getTypeParameters();
|
||||
int i = -1;
|
||||
for (TypeVariable<?> v : tVars) {
|
||||
i++;
|
||||
if (equals(v))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static Map<Class<? extends Annotation>, Annotation> mapAnnotations(Annotation[] annos) {
|
||||
Map<Class<? extends Annotation>, Annotation> result =
|
||||
new LinkedHashMap<>();
|
||||
for (Annotation a : annos) {
|
||||
Class<? extends Annotation> klass = a.annotationType();
|
||||
AnnotationType type = AnnotationType.getInstance(klass);
|
||||
if (type.retention() == RetentionPolicy.RUNTIME)
|
||||
if (result.put(klass, a) != null)
|
||||
throw new AnnotationFormatError("Duplicate annotation for class: "+klass+": " + a);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.reflectiveObjects;
|
||||
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.WildcardType;
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.tree.FieldTypeSignature;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of WildcardType interface for core reflection.
|
||||
*/
|
||||
public class WildcardTypeImpl extends LazyReflectiveObjectGenerator
|
||||
implements WildcardType {
|
||||
|
||||
/*
|
||||
* We are required to evaluate the bounds lazily, so we store them as ASTs
|
||||
* until we are first asked for them. This also neatly solves the problem
|
||||
* with F-bounds - you can't reify them before the formal is defined.
|
||||
*/
|
||||
|
||||
/** The upper bounds. Lazily converted from FieldTypeSignature[] to Type[]. */
|
||||
private volatile Object[] upperBounds;
|
||||
|
||||
/** The lower bounds. Lazily converted from FieldTypeSignature[] to Type[]. */
|
||||
private volatile Object[] lowerBounds;
|
||||
|
||||
// constructor is private to enforce access through static factory
|
||||
private WildcardTypeImpl(FieldTypeSignature[] ubs,
|
||||
FieldTypeSignature[] lbs,
|
||||
GenericsFactory f) {
|
||||
super(f);
|
||||
upperBounds = ubs;
|
||||
lowerBounds = lbs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method.
|
||||
* @param ubs - an array of ASTs representing the upper bounds for the type
|
||||
* variable to be created
|
||||
* @param lbs - an array of ASTs representing the lower bounds for the type
|
||||
* variable to be created
|
||||
* @param f - a factory that can be used to manufacture reflective
|
||||
* objects that represent the bounds of this wildcard type
|
||||
* @return a wild card type with the requested bounds and factory
|
||||
*/
|
||||
public static WildcardTypeImpl make(FieldTypeSignature[] ubs,
|
||||
FieldTypeSignature[] lbs,
|
||||
GenericsFactory f) {
|
||||
return new WildcardTypeImpl(ubs, lbs, f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of {@code Type} objects representing the upper
|
||||
* bound(s) of this type variable. Note that if no upper bound is
|
||||
* explicitly declared, the upper bound is {@code Object}.
|
||||
*
|
||||
* <p>For each upper bound B :
|
||||
* <ul>
|
||||
* <li>if B is a parameterized type or a type variable, it is created,
|
||||
* (see {@link #ParameterizedType} for the details of the creation
|
||||
* process for parameterized types).
|
||||
* <li>Otherwise, B is resolved.
|
||||
* </ul>
|
||||
*
|
||||
* @return an array of Types representing the upper bound(s) of this
|
||||
* type variable
|
||||
* @throws {@code TypeNotPresentException} if any of the
|
||||
* bounds refers to a non-existent type declaration
|
||||
* @throws {@code MalformedParameterizedTypeException} if any of the
|
||||
* bounds refer to a parameterized type that cannot be instantiated
|
||||
* for any reason
|
||||
*/
|
||||
public Type[] getUpperBounds() {
|
||||
Object[] value = upperBounds;
|
||||
if (value instanceof FieldTypeSignature[]) {
|
||||
value = reifyBounds((FieldTypeSignature[])value);
|
||||
upperBounds = value;
|
||||
}
|
||||
return (Type[])value.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of {@code Type} objects representing the
|
||||
* lower bound(s) of this type variable. Note that if no lower bound is
|
||||
* explicitly declared, the lower bound is the type of {@code null}.
|
||||
* In this case, a zero length array is returned.
|
||||
*
|
||||
* <p>For each lower bound B :
|
||||
* <ul>
|
||||
* <li>if B is a parameterized type or a type variable, it is created,
|
||||
* (see {@link #ParameterizedType} for the details of the creation
|
||||
* process for parameterized types).
|
||||
* <li>Otherwise, B is resolved.
|
||||
* </ul>
|
||||
*
|
||||
* @return an array of Types representing the lower bound(s) of this
|
||||
* type variable
|
||||
* @throws {@code TypeNotPresentException} if any of the
|
||||
* bounds refers to a non-existent type declaration
|
||||
* @throws {@code MalformedParameterizedTypeException} if any of the
|
||||
* bounds refer to a parameterized type that cannot be instantiated
|
||||
* for any reason
|
||||
*/
|
||||
public Type[] getLowerBounds() {
|
||||
Object[] value = lowerBounds;
|
||||
if (value instanceof FieldTypeSignature[]) {
|
||||
value = reifyBounds((FieldTypeSignature[])value);
|
||||
lowerBounds = value;
|
||||
}
|
||||
return (Type[])value.clone();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
Type[] lowerBounds = getLowerBounds();
|
||||
Type[] bounds = lowerBounds;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (lowerBounds.length > 0)
|
||||
sb.append("? super ");
|
||||
else {
|
||||
Type[] upperBounds = getUpperBounds();
|
||||
if (upperBounds.length > 0 && !upperBounds[0].equals(Object.class) ) {
|
||||
bounds = upperBounds;
|
||||
sb.append("? extends ");
|
||||
} else
|
||||
return "?";
|
||||
}
|
||||
|
||||
assert bounds.length > 0;
|
||||
|
||||
StringJoiner sj = new StringJoiner(" & ");
|
||||
for(Type bound: bounds) {
|
||||
sj.add(bound.getTypeName());
|
||||
}
|
||||
sb.append(sj.toString());
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof WildcardType) {
|
||||
WildcardType that = (WildcardType) o;
|
||||
return
|
||||
Arrays.equals(this.getLowerBounds(),
|
||||
that.getLowerBounds()) &&
|
||||
Arrays.equals(this.getUpperBounds(),
|
||||
that.getUpperBounds());
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
Type [] lowerBounds = getLowerBounds();
|
||||
Type [] upperBounds = getUpperBounds();
|
||||
|
||||
return Arrays.hashCode(lowerBounds) ^ Arrays.hashCode(upperBounds);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.repository;
|
||||
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.tree.Tree;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract superclass for representing the generic type information for
|
||||
* a reflective entity.
|
||||
* The code is not dependent on a particular reflective implementation.
|
||||
* It is designed to be used unchanged by at least core reflection and JDI.
|
||||
*/
|
||||
public abstract class AbstractRepository<T extends Tree> {
|
||||
|
||||
// A factory used to produce reflective objects. Provided when the
|
||||
//repository is created. Will vary across implementations.
|
||||
private final GenericsFactory factory;
|
||||
|
||||
private final T tree; // the AST for the generic type info
|
||||
|
||||
//accessors
|
||||
private GenericsFactory getFactory() { return factory;}
|
||||
|
||||
/**
|
||||
* Accessor for {@code tree}.
|
||||
* @return the cached AST this repository holds
|
||||
*/
|
||||
protected T getTree(){ return tree;}
|
||||
|
||||
/**
|
||||
* Returns a {@code Reifier} used to convert parts of the
|
||||
* AST into reflective objects.
|
||||
* @return a {@code Reifier} used to convert parts of the
|
||||
* AST into reflective objects
|
||||
*/
|
||||
protected Reifier getReifier(){return Reifier.make(getFactory());}
|
||||
|
||||
/**
|
||||
* Constructor. Should only be used by subclasses. Concrete subclasses
|
||||
* should make their constructors private and provide public factory
|
||||
* methods.
|
||||
* @param rawSig - the generic signature of the reflective object
|
||||
* that this repository is servicing
|
||||
* @param f - a factory that will provide instances of reflective
|
||||
* objects when this repository converts its AST
|
||||
*/
|
||||
protected AbstractRepository(String rawSig, GenericsFactory f) {
|
||||
tree = parse(rawSig);
|
||||
factory = f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the AST for the generic type info of this entity.
|
||||
* @param s - a string representing the generic signature of this
|
||||
* entity
|
||||
* @return the AST for the generic type info of this entity.
|
||||
*/
|
||||
protected abstract T parse(String s);
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.repository;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.tree.ClassSignature;
|
||||
import sun.reflect.generics.tree.TypeTree;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
import sun.reflect.generics.parser.SignatureParser;
|
||||
|
||||
|
||||
/**
|
||||
* This class represents the generic type information for a class.
|
||||
* The code is not dependent on a particular reflective implementation.
|
||||
* It is designed to be used unchanged by at least core reflection and JDI.
|
||||
*/
|
||||
public class ClassRepository extends GenericDeclRepository<ClassSignature> {
|
||||
|
||||
public static final ClassRepository NONE = ClassRepository.make("Ljava/lang/Object;", null);
|
||||
|
||||
/** The generic superclass info. Lazily initialized. */
|
||||
private volatile Type superclass;
|
||||
|
||||
/** The generic superinterface info. Lazily initialized. */
|
||||
private volatile Type[] superInterfaces;
|
||||
|
||||
// private, to enforce use of static factory
|
||||
private ClassRepository(String rawSig, GenericsFactory f) {
|
||||
super(rawSig, f);
|
||||
}
|
||||
|
||||
protected ClassSignature parse(String s) {
|
||||
return SignatureParser.make().parseClassSig(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static factory method.
|
||||
* @param rawSig - the generic signature of the reflective object
|
||||
* that this repository is servicing
|
||||
* @param f - a factory that will provide instances of reflective
|
||||
* objects when this repository converts its AST
|
||||
* @return a {@code ClassRepository} that manages the generic type
|
||||
* information represented in the signature {@code rawSig}
|
||||
*/
|
||||
public static ClassRepository make(String rawSig, GenericsFactory f) {
|
||||
return new ClassRepository(rawSig, f);
|
||||
}
|
||||
|
||||
/*
|
||||
* When queried for a particular piece of type information, the
|
||||
* general pattern is to consult the corresponding cached value.
|
||||
* If the corresponding field is non-null, it is returned.
|
||||
* If not, it is created lazily. This is done by selecting the appropriate
|
||||
* part of the tree and transforming it into a reflective object
|
||||
* using a visitor, which is created by feeding it the factory
|
||||
* with which the repository was created.
|
||||
*/
|
||||
|
||||
public Type getSuperclass() {
|
||||
Type value = superclass;
|
||||
if (value == null) {
|
||||
value = computeSuperclass();
|
||||
superclass = value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public Type[] getSuperInterfaces() {
|
||||
Type[] value = superInterfaces;
|
||||
if (value == null) {
|
||||
value = computeSuperInterfaces();
|
||||
superInterfaces = value;
|
||||
}
|
||||
return value.clone();
|
||||
}
|
||||
|
||||
private Type computeSuperclass() {
|
||||
Reifier r = getReifier(); // obtain visitor
|
||||
// Extract superclass subtree from AST and reify
|
||||
getTree().getSuperclass().accept(r);
|
||||
return r.getResult();
|
||||
}
|
||||
|
||||
private Type[] computeSuperInterfaces() {
|
||||
// first, extract super interface subtree(s) from AST
|
||||
TypeTree[] ts = getTree().getSuperInterfaces();
|
||||
// create array to store reified subtree(s)
|
||||
int length = ts.length;
|
||||
Type[] superInterfaces = new Type[length];
|
||||
// reify all subtrees
|
||||
for (int i = 0; i < length; i++) {
|
||||
Reifier r = getReifier(); // obtain visitor
|
||||
ts[i].accept(r);// reify subtree
|
||||
// extract result from visitor and store it
|
||||
superInterfaces[i] = r.getResult();
|
||||
}
|
||||
return superInterfaces;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.repository;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.parser.SignatureParser;
|
||||
import sun.reflect.generics.tree.FieldTypeSignature;
|
||||
import sun.reflect.generics.tree.MethodTypeSignature;
|
||||
import sun.reflect.generics.tree.TypeSignature;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This class represents the generic type information for a constructor.
|
||||
* The code is not dependent on a particular reflective implementation.
|
||||
* It is designed to be used unchanged by at least core reflection and JDI.
|
||||
*/
|
||||
public class ConstructorRepository
|
||||
extends GenericDeclRepository<MethodTypeSignature> {
|
||||
|
||||
/** The generic parameter types. Lazily initialized. */
|
||||
private volatile Type[] parameterTypes;
|
||||
|
||||
/** The generic exception types. Lazily initialized. */
|
||||
private volatile Type[] exceptionTypes;
|
||||
|
||||
// protected, to enforce use of static factory yet allow subclassing
|
||||
protected ConstructorRepository(String rawSig, GenericsFactory f) {
|
||||
super(rawSig, f);
|
||||
}
|
||||
|
||||
protected MethodTypeSignature parse(String s) {
|
||||
return SignatureParser.make().parseMethodSig(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static factory method.
|
||||
* @param rawSig - the generic signature of the reflective object
|
||||
* that this repository is servicing
|
||||
* @param f - a factory that will provide instances of reflective
|
||||
* objects when this repository converts its AST
|
||||
* @return a {@code ConstructorRepository} that manages the generic type
|
||||
* information represented in the signature {@code rawSig}
|
||||
*/
|
||||
public static ConstructorRepository make(String rawSig, GenericsFactory f) {
|
||||
return new ConstructorRepository(rawSig, f);
|
||||
}
|
||||
|
||||
/*
|
||||
* When queried for a particular piece of type information, the
|
||||
* general pattern is to consult the corresponding cached value.
|
||||
* If the corresponding field is non-null, it is returned.
|
||||
* If not, it is created lazily. This is done by selecting the appropriate
|
||||
* part of the tree and transforming it into a reflective object
|
||||
* using a visitor, which is created by feeding it the factory
|
||||
* with which the repository was created.
|
||||
*/
|
||||
|
||||
public Type[] getParameterTypes() {
|
||||
Type[] value = parameterTypes;
|
||||
if (value == null) {
|
||||
value = computeParameterTypes();
|
||||
parameterTypes = value;
|
||||
}
|
||||
return value.clone();
|
||||
}
|
||||
|
||||
public Type[] getExceptionTypes() {
|
||||
Type[] value = exceptionTypes;
|
||||
if (value == null) {
|
||||
value = computeExceptionTypes();
|
||||
exceptionTypes = value;
|
||||
}
|
||||
return value.clone();
|
||||
}
|
||||
|
||||
private Type[] computeParameterTypes() {
|
||||
// first, extract parameter type subtree(s) from AST
|
||||
TypeSignature[] pts = getTree().getParameterTypes();
|
||||
// create array to store reified subtree(s)
|
||||
int length = pts.length;
|
||||
Type[] parameterTypes = new Type[length];
|
||||
// reify all subtrees
|
||||
for (int i = 0; i < length; i++) {
|
||||
Reifier r = getReifier(); // obtain visitor
|
||||
pts[i].accept(r); // reify subtree
|
||||
// extract result from visitor and store it
|
||||
parameterTypes[i] = r.getResult();
|
||||
}
|
||||
return parameterTypes;
|
||||
}
|
||||
|
||||
private Type[] computeExceptionTypes() {
|
||||
// first, extract exception type subtree(s) from AST
|
||||
FieldTypeSignature[] ets = getTree().getExceptionTypes();
|
||||
// create array to store reified subtree(s)
|
||||
int length = ets.length;
|
||||
Type[] exceptionTypes = new Type[length];
|
||||
// reify all subtrees
|
||||
for (int i = 0; i < length; i++) {
|
||||
Reifier r = getReifier(); // obtain visitor
|
||||
ets[i].accept(r); // reify subtree
|
||||
// extract result from visitor and store it
|
||||
exceptionTypes[i] = r.getResult();
|
||||
}
|
||||
return exceptionTypes;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.repository;
|
||||
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.tree.TypeSignature;
|
||||
import sun.reflect.generics.parser.SignatureParser;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This class represents the generic type information for a constructor.
|
||||
* The code is not dependent on a particular reflective implementation.
|
||||
* It is designed to be used unchanged by at least core reflection and JDI.
|
||||
*/
|
||||
public class FieldRepository extends AbstractRepository<TypeSignature> {
|
||||
|
||||
/** The generic type info. Lazily initialized. */
|
||||
private volatile Type genericType;
|
||||
|
||||
// protected, to enforce use of static factory yet allow subclassing
|
||||
protected FieldRepository(String rawSig, GenericsFactory f) {
|
||||
super(rawSig, f);
|
||||
}
|
||||
|
||||
protected TypeSignature parse(String s) {
|
||||
return SignatureParser.make().parseTypeSig(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static factory method.
|
||||
* @param rawSig - the generic signature of the reflective object
|
||||
* that this repository is servicing
|
||||
* @param f - a factory that will provide instances of reflective
|
||||
* objects when this repository converts its AST
|
||||
* @return a {@code FieldRepository} that manages the generic type
|
||||
* information represented in the signature {@code rawSig}
|
||||
*/
|
||||
public static FieldRepository make(String rawSig, GenericsFactory f) {
|
||||
return new FieldRepository(rawSig, f);
|
||||
}
|
||||
|
||||
/*
|
||||
* When queried for a particular piece of type information, the
|
||||
* general pattern is to consult the corresponding cached value.
|
||||
* If the corresponding field is non-null, it is returned.
|
||||
* If not, it is created lazily. This is done by selecting the appropriate
|
||||
* part of the tree and transforming it into a reflective object
|
||||
* using a visitor, which is created by feeding it the factory
|
||||
* with which the repository was created.
|
||||
*/
|
||||
|
||||
public Type getGenericType() {
|
||||
Type value = genericType;
|
||||
if (value == null) {
|
||||
value = computeGenericType();
|
||||
genericType = value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private Type computeGenericType() {
|
||||
Reifier r = getReifier(); // obtain visitor
|
||||
getTree().accept(r); // reify subtree
|
||||
return r.getResult(); // extract result from visitor
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.repository;
|
||||
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.tree.FormalTypeParameter;
|
||||
import sun.reflect.generics.tree.Signature;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This class represents the generic type information for a generic
|
||||
* declaration.
|
||||
* The code is not dependent on a particular reflective implementation.
|
||||
* It is designed to be used unchanged by at least core reflection and JDI.
|
||||
*/
|
||||
public abstract class GenericDeclRepository<S extends Signature>
|
||||
extends AbstractRepository<S> {
|
||||
|
||||
/** The formal type parameters. Lazily initialized. */
|
||||
private volatile TypeVariable<?>[] typeParameters;
|
||||
|
||||
protected GenericDeclRepository(String rawSig, GenericsFactory f) {
|
||||
super(rawSig, f);
|
||||
}
|
||||
|
||||
/*
|
||||
* When queried for a particular piece of type information, the
|
||||
* general pattern is to consult the corresponding cached value.
|
||||
* If the corresponding field is non-null, it is returned.
|
||||
* If not, it is created lazily. This is done by selecting the appropriate
|
||||
* part of the tree and transforming it into a reflective object
|
||||
* using a visitor, which is created by feeding it the factory
|
||||
* with which the repository was created.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the formal type parameters of this generic declaration.
|
||||
* @return the formal type parameters of this generic declaration
|
||||
*/
|
||||
public TypeVariable<?>[] getTypeParameters() {
|
||||
TypeVariable<?>[] value = typeParameters;
|
||||
if (value == null) {
|
||||
value = computeTypeParameters();
|
||||
typeParameters = value;
|
||||
}
|
||||
return value.clone();
|
||||
}
|
||||
|
||||
private TypeVariable<?>[] computeTypeParameters() {
|
||||
// first, extract type parameter subtree(s) from AST
|
||||
FormalTypeParameter[] ftps = getTree().getFormalTypeParameters();
|
||||
// create array to store reified subtree(s)
|
||||
int length = ftps.length;
|
||||
TypeVariable<?>[] typeParameters = new TypeVariable<?>[length];
|
||||
// reify all subtrees
|
||||
for (int i = 0; i < length; i++) {
|
||||
Reifier r = getReifier(); // obtain visitor
|
||||
ftps[i].accept(r); // reify subtree
|
||||
// extract result from visitor and store it
|
||||
typeParameters[i] = (TypeVariable<?>) r.getResult();
|
||||
}
|
||||
return typeParameters;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.repository;
|
||||
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This class represents the generic type information for a method.
|
||||
* The code is not dependent on a particular reflective implementation.
|
||||
* It is designed to be used unchanged by at least core reflection and JDI.
|
||||
*/
|
||||
public class MethodRepository extends ConstructorRepository {
|
||||
|
||||
/** The generic return type info. Lazily initialized. */
|
||||
private volatile Type returnType;
|
||||
|
||||
// private, to enforce use of static factory
|
||||
private MethodRepository(String rawSig, GenericsFactory f) {
|
||||
super(rawSig, f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static factory method.
|
||||
* @param rawSig - the generic signature of the reflective object
|
||||
* that this repository is servicing
|
||||
* @param f - a factory that will provide instances of reflective
|
||||
* objects when this repository converts its AST
|
||||
* @return a {@code MethodRepository} that manages the generic type
|
||||
* information represented in the signature {@code rawSig}
|
||||
*/
|
||||
public static MethodRepository make(String rawSig, GenericsFactory f) {
|
||||
return new MethodRepository(rawSig, f);
|
||||
}
|
||||
|
||||
public Type getReturnType() {
|
||||
Type value = returnType;
|
||||
if (value == null) {
|
||||
value = computeReturnType();
|
||||
returnType = value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private Type computeReturnType() {
|
||||
Reifier r = getReifier(); // obtain visitor
|
||||
// Extract return type subtree from AST and reify
|
||||
getTree().getReturnType().accept(r);
|
||||
// extract result from visitor and cache it
|
||||
return r.getResult();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.scope;
|
||||
|
||||
import java.lang.reflect.GenericDeclaration;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract superclass for lazy scope objects, used when building
|
||||
* factories for generic information repositories.
|
||||
* The type parameter {@code D} represents the type of reflective
|
||||
* object whose scope this class is representing.
|
||||
* <p> To subclass this, all one needs to do is implement
|
||||
* {@code computeEnclosingScope} and the subclass' constructor.
|
||||
*/
|
||||
public abstract class AbstractScope<D extends GenericDeclaration>
|
||||
implements Scope {
|
||||
|
||||
private final D recvr; // the declaration whose scope this instance represents
|
||||
|
||||
/** The enclosing scope of this scope. Lazily initialized. */
|
||||
private volatile Scope enclosingScope;
|
||||
|
||||
/**
|
||||
* Constructor. Takes a reflective object whose scope the newly
|
||||
* constructed instance will represent.
|
||||
* @param decl - A generic declaration whose scope the newly
|
||||
* constructed instance will represent
|
||||
*/
|
||||
protected AbstractScope(D decl){ recvr = decl;}
|
||||
|
||||
/**
|
||||
* Accessor for the receiver - the object whose scope this {@code Scope}
|
||||
* object represents.
|
||||
* @return The object whose scope this {@code Scope} object represents
|
||||
*/
|
||||
protected D getRecvr() {return recvr;}
|
||||
|
||||
/** This method must be implemented by any concrete subclass.
|
||||
* It must return the enclosing scope of this scope. If this scope
|
||||
* is a top-level scope, an instance of DummyScope must be returned.
|
||||
* @return The enclosing scope of this scope
|
||||
*/
|
||||
protected abstract Scope computeEnclosingScope();
|
||||
|
||||
/**
|
||||
* Accessor for the enclosing scope, which is computed lazily and cached.
|
||||
* @return the enclosing scope
|
||||
*/
|
||||
protected Scope getEnclosingScope() {
|
||||
Scope value = enclosingScope;
|
||||
if (value == null) {
|
||||
value = computeEnclosingScope();
|
||||
enclosingScope = value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a type variable in the scope, using its name. Returns null if
|
||||
* no type variable with this name is declared in this scope or any of its
|
||||
* surrounding scopes.
|
||||
* @param name - the name of the type variable being looked up
|
||||
* @return the requested type variable, if found
|
||||
*/
|
||||
public TypeVariable<?> lookup(String name) {
|
||||
TypeVariable<?>[] tas = getRecvr().getTypeParameters();
|
||||
for (TypeVariable<?> tv : tas) {
|
||||
if (tv.getName().equals(name)) {return tv;}
|
||||
}
|
||||
return getEnclosingScope().lookup(name);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.scope;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
||||
/**
|
||||
* This class represents the scope containing the type variables of
|
||||
* a class.
|
||||
*/
|
||||
public class ClassScope extends AbstractScope<Class<?>> implements Scope {
|
||||
|
||||
// constructor is private to enforce use of factory method
|
||||
private ClassScope(Class<?> c){
|
||||
super(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the abstract method in the superclass.
|
||||
* @return the enclosing scope
|
||||
*/
|
||||
protected Scope computeEnclosingScope() {
|
||||
Class<?> receiver = getRecvr();
|
||||
|
||||
Method m = receiver.getEnclosingMethod();
|
||||
if (m != null)
|
||||
// Receiver is a local or anonymous class enclosed in a
|
||||
// method.
|
||||
return MethodScope.make(m);
|
||||
|
||||
Constructor<?> cnstr = receiver.getEnclosingConstructor();
|
||||
if (cnstr != null)
|
||||
// Receiver is a local or anonymous class enclosed in a
|
||||
// constructor.
|
||||
return ConstructorScope.make(cnstr);
|
||||
|
||||
Class<?> c = receiver.getEnclosingClass();
|
||||
// if there is a declaring class, recvr is a member class
|
||||
// and its enclosing scope is that of the declaring class
|
||||
if (c != null)
|
||||
// Receiver is a local class, an anonymous class, or a
|
||||
// member class (static or not).
|
||||
return ClassScope.make(c);
|
||||
|
||||
// otherwise, recvr is a top level class, and it has no real
|
||||
// enclosing scope.
|
||||
return DummyScope.make();
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method. Takes a {@code Class} object and creates a
|
||||
* scope for it.
|
||||
* @param c - a Class whose scope we want to obtain
|
||||
* @return The type-variable scope for the class c
|
||||
*/
|
||||
public static ClassScope make(Class<?> c) { return new ClassScope(c);}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.scope;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
|
||||
/**
|
||||
* This class represents the scope containing the type variables of
|
||||
* a constructor.
|
||||
*/
|
||||
public class ConstructorScope extends AbstractScope<Constructor<?>> {
|
||||
|
||||
// constructor is private to enforce use of factory method
|
||||
private ConstructorScope(Constructor<?> c){
|
||||
super(c);
|
||||
}
|
||||
|
||||
// utility method; computes enclosing class, from which we can
|
||||
// derive enclosing scope.
|
||||
private Class<?> getEnclosingClass(){
|
||||
return getRecvr().getDeclaringClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the abstract method in the superclass.
|
||||
* @return the enclosing scope
|
||||
*/
|
||||
protected Scope computeEnclosingScope() {
|
||||
// the enclosing scope of a (generic) constructor is the scope of the
|
||||
// class in which it was declared.
|
||||
return ClassScope.make(getEnclosingClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method. Takes a {@code Constructor} object and creates a
|
||||
* scope for it.
|
||||
* @param c - A Constructor whose scope we want to obtain
|
||||
* @return The type-variable scope for the constructor m
|
||||
*/
|
||||
public static ConstructorScope make(Constructor<?> c) {
|
||||
return new ConstructorScope(c);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.scope;
|
||||
|
||||
import java.lang.reflect.TypeVariable;
|
||||
|
||||
/**
|
||||
* This class is used to provide enclosing scopes for top level classes.
|
||||
* We cannot use {@code null} to represent such a scope, since the
|
||||
* enclosing scope is computed lazily, and so the field storing it is
|
||||
* null until it has been computed. Therefore, {@code null} is reserved
|
||||
* to represent an as-yet-uncomputed scope, and cannot be used for any
|
||||
* other kind of scope.
|
||||
*/
|
||||
public class DummyScope implements Scope {
|
||||
// Caches the unique instance of this class; instances contain no data
|
||||
// so we can use the singleton pattern
|
||||
private static final DummyScope singleton = new DummyScope();
|
||||
|
||||
// constructor is private to enforce use of factory method
|
||||
private DummyScope(){}
|
||||
|
||||
/**
|
||||
* Factory method. Enforces the singleton pattern - only one
|
||||
* instance of this class ever exists.
|
||||
*/
|
||||
public static DummyScope make() {
|
||||
return singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a type variable in the scope, using its name. Always returns
|
||||
* {@code null}.
|
||||
* @param name - the name of the type variable being looked up
|
||||
* @return null
|
||||
*/
|
||||
public TypeVariable<?> lookup(String name) {return null;}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.scope;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
||||
/**
|
||||
* This class represents the scope containing the type variables of
|
||||
* a method.
|
||||
*/
|
||||
public class MethodScope extends AbstractScope<Method> {
|
||||
|
||||
// constructor is private to enforce use of factory method
|
||||
private MethodScope(Method m){
|
||||
super(m);
|
||||
}
|
||||
|
||||
// utility method; computes enclosing class, from which we can
|
||||
// derive enclosing scope.
|
||||
private Class<?> getEnclosingClass(){
|
||||
return getRecvr().getDeclaringClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the abstract method in the superclass.
|
||||
* @return the enclosing scope
|
||||
*/
|
||||
protected Scope computeEnclosingScope() {
|
||||
// the enclosing scope of a (generic) method is the scope of the
|
||||
// class in which it was declared.
|
||||
return ClassScope.make(getEnclosingClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method. Takes a {@code Method} object and creates a
|
||||
* scope for it.
|
||||
* @param m - A Method whose scope we want to obtain
|
||||
* @return The type-variable scope for the method m
|
||||
*/
|
||||
public static MethodScope make(Method m) {
|
||||
return new MethodScope(m);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.scope;
|
||||
|
||||
import java.lang.reflect.TypeVariable;
|
||||
|
||||
|
||||
public interface Scope {
|
||||
TypeVariable<?> lookup(String name);
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
public class ArrayTypeSignature implements FieldTypeSignature {
|
||||
private final TypeSignature componentType;
|
||||
|
||||
private ArrayTypeSignature(TypeSignature ct) {componentType = ct;}
|
||||
|
||||
public static ArrayTypeSignature make(TypeSignature ct) {
|
||||
return new ArrayTypeSignature(ct);
|
||||
}
|
||||
|
||||
public TypeSignature getComponentType(){return componentType;}
|
||||
|
||||
public void accept(TypeTreeVisitor<?> v){
|
||||
v.visitArrayTypeSignature(this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
/**
|
||||
* Common superinterface for all nodes representing a primitive type.
|
||||
* Corresponds to the production of the same name in the JVMS
|
||||
* section on signatures.
|
||||
*/
|
||||
public interface BaseType
|
||||
extends TypeSignature{}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
/** AST that represents the type boolean. */
|
||||
public class BooleanSignature implements BaseType {
|
||||
private static final BooleanSignature singleton = new BooleanSignature();
|
||||
|
||||
private BooleanSignature(){}
|
||||
|
||||
public static BooleanSignature make() {return singleton;}
|
||||
|
||||
public void accept(TypeTreeVisitor<?> v){
|
||||
v.visitBooleanSignature(this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
public class BottomSignature implements FieldTypeSignature {
|
||||
private static final BottomSignature singleton = new BottomSignature();
|
||||
|
||||
private BottomSignature(){}
|
||||
|
||||
public static BottomSignature make() {return singleton;}
|
||||
|
||||
public void accept(TypeTreeVisitor<?> v){v.visitBottomSignature(this);}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
/** AST that represents the type byte. */
|
||||
public class ByteSignature implements BaseType {
|
||||
private static final ByteSignature singleton = new ByteSignature();
|
||||
|
||||
private ByteSignature(){}
|
||||
|
||||
public static ByteSignature make() {return singleton;}
|
||||
|
||||
public void accept(TypeTreeVisitor<?> v){
|
||||
v.visitByteSignature(this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
/** AST that represents the type char. */
|
||||
public class CharSignature implements BaseType {
|
||||
private static final CharSignature singleton = new CharSignature();
|
||||
|
||||
private CharSignature(){}
|
||||
|
||||
public static CharSignature make() {return singleton;}
|
||||
|
||||
public void accept(TypeTreeVisitor<?> v){
|
||||
v.visitCharSignature(this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.Visitor;
|
||||
|
||||
public class ClassSignature implements Signature {
|
||||
private final FormalTypeParameter[] formalTypeParams;
|
||||
private final ClassTypeSignature superclass;
|
||||
private final ClassTypeSignature[] superInterfaces;
|
||||
|
||||
private ClassSignature(FormalTypeParameter[] ftps,
|
||||
ClassTypeSignature sc,
|
||||
ClassTypeSignature[] sis) {
|
||||
formalTypeParams = ftps;
|
||||
superclass = sc;
|
||||
superInterfaces = sis;
|
||||
}
|
||||
|
||||
public static ClassSignature make(FormalTypeParameter[] ftps,
|
||||
ClassTypeSignature sc,
|
||||
ClassTypeSignature[] sis) {
|
||||
return new ClassSignature(ftps, sc, sis);
|
||||
}
|
||||
|
||||
public FormalTypeParameter[] getFormalTypeParameters(){
|
||||
return formalTypeParams;
|
||||
}
|
||||
public ClassTypeSignature getSuperclass(){return superclass;}
|
||||
public ClassTypeSignature[] getSuperInterfaces(){return superInterfaces;}
|
||||
|
||||
public void accept(Visitor<?> v){v.visitClassSignature(this);}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import java.util.List;
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
|
||||
/**
|
||||
* AST representing class types.
|
||||
*/
|
||||
public class ClassTypeSignature implements FieldTypeSignature {
|
||||
private final List<SimpleClassTypeSignature> path;
|
||||
|
||||
|
||||
private ClassTypeSignature(List<SimpleClassTypeSignature> p) {
|
||||
path = p;
|
||||
}
|
||||
|
||||
public static ClassTypeSignature make(List<SimpleClassTypeSignature> p) {
|
||||
return new ClassTypeSignature(p);
|
||||
}
|
||||
|
||||
public List<SimpleClassTypeSignature> getPath(){return path;}
|
||||
|
||||
public void accept(TypeTreeVisitor<?> v){v.visitClassTypeSignature(this);}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
/** AST that represents the type double. */
|
||||
public class DoubleSignature implements BaseType {
|
||||
private static final DoubleSignature singleton = new DoubleSignature();
|
||||
|
||||
private DoubleSignature(){}
|
||||
|
||||
public static DoubleSignature make() {return singleton;}
|
||||
|
||||
public void accept(TypeTreeVisitor<?> v){v.visitDoubleSignature(this);}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
/**
|
||||
* Common superinterface for nodes that represent a (possibly generic)
|
||||
* type.
|
||||
* Corresponds to the production of the same name in the JVMS
|
||||
* section on signatures.
|
||||
*/
|
||||
public interface FieldTypeSignature
|
||||
extends BaseType, TypeSignature, TypeArgument {}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
/** AST that represents the type float. */
|
||||
public class FloatSignature implements BaseType {
|
||||
private static final FloatSignature singleton = new FloatSignature();
|
||||
|
||||
private FloatSignature(){}
|
||||
|
||||
public static FloatSignature make() {return singleton;}
|
||||
|
||||
public void accept(TypeTreeVisitor<?> v){v.visitFloatSignature(this);}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
/** AST that represents a formal type parameter. */
|
||||
public class FormalTypeParameter implements TypeTree {
|
||||
private final String name;
|
||||
private final FieldTypeSignature[] bounds;
|
||||
|
||||
private FormalTypeParameter(String n, FieldTypeSignature[] bs) {
|
||||
name = n;
|
||||
bounds = bs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method.
|
||||
* Returns a formal type parameter with the requested name and bounds.
|
||||
* @param n the name of the type variable to be created by this method.
|
||||
* @param bs - the bounds of the type variable to be created by this method.
|
||||
* @return a formal type parameter with the requested name and bounds
|
||||
*/
|
||||
public static FormalTypeParameter make(String n, FieldTypeSignature[] bs){
|
||||
return new FormalTypeParameter(n,bs);
|
||||
}
|
||||
|
||||
public FieldTypeSignature[] getBounds(){return bounds;}
|
||||
public String getName(){return name;}
|
||||
|
||||
public void accept(TypeTreeVisitor<?> v){v.visitFormalTypeParameter(this);}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
/** AST that represents the type int. */
|
||||
public class IntSignature implements BaseType {
|
||||
private static final IntSignature singleton = new IntSignature();
|
||||
|
||||
private IntSignature(){}
|
||||
|
||||
public static IntSignature make() {return singleton;}
|
||||
|
||||
public void accept(TypeTreeVisitor<?> v){v.visitIntSignature(this);}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
/** AST that represents the type long. */
|
||||
public class LongSignature implements BaseType {
|
||||
private static final LongSignature singleton = new LongSignature();
|
||||
|
||||
private LongSignature(){}
|
||||
|
||||
public static LongSignature make() {return singleton;}
|
||||
|
||||
public void accept(TypeTreeVisitor<?> v){v.visitLongSignature(this);}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.Visitor;
|
||||
|
||||
public class MethodTypeSignature implements Signature {
|
||||
private final FormalTypeParameter[] formalTypeParams;
|
||||
private final TypeSignature[] parameterTypes;
|
||||
private final ReturnType returnType;
|
||||
private final FieldTypeSignature[] exceptionTypes;
|
||||
|
||||
private MethodTypeSignature(FormalTypeParameter[] ftps,
|
||||
TypeSignature[] pts,
|
||||
ReturnType rt,
|
||||
FieldTypeSignature[] ets) {
|
||||
formalTypeParams = ftps;
|
||||
parameterTypes = pts;
|
||||
returnType = rt;
|
||||
exceptionTypes = ets;
|
||||
}
|
||||
|
||||
public static MethodTypeSignature make(FormalTypeParameter[] ftps,
|
||||
TypeSignature[] pts,
|
||||
ReturnType rt,
|
||||
FieldTypeSignature[] ets) {
|
||||
return new MethodTypeSignature(ftps, pts, rt, ets);
|
||||
}
|
||||
|
||||
public FormalTypeParameter[] getFormalTypeParameters(){
|
||||
return formalTypeParams;
|
||||
}
|
||||
public TypeSignature[] getParameterTypes(){return parameterTypes;}
|
||||
public ReturnType getReturnType(){return returnType;}
|
||||
public FieldTypeSignature[] getExceptionTypes(){return exceptionTypes;}
|
||||
|
||||
public void accept(Visitor<?> v){v.visitMethodTypeSignature(this);}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
public interface ReturnType extends TypeTree{}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
/** AST that represents the type short. */
|
||||
public class ShortSignature implements BaseType {
|
||||
private static final ShortSignature singleton = new ShortSignature();
|
||||
|
||||
private ShortSignature(){}
|
||||
|
||||
public static ShortSignature make() {return singleton;}
|
||||
|
||||
public void accept(TypeTreeVisitor<?> v){
|
||||
v.visitShortSignature(this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
/**
|
||||
* Common superinterface for generic signatures. These are the signatures
|
||||
* of complete class and method/constructor declarations.
|
||||
*/
|
||||
public interface Signature extends Tree{
|
||||
FormalTypeParameter[] getFormalTypeParameters();
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
public class SimpleClassTypeSignature implements FieldTypeSignature {
|
||||
private final boolean dollar;
|
||||
private final String name;
|
||||
private final TypeArgument[] typeArgs;
|
||||
|
||||
private SimpleClassTypeSignature(String n, boolean dollar, TypeArgument[] tas) {
|
||||
name = n;
|
||||
this.dollar = dollar;
|
||||
typeArgs = tas;
|
||||
}
|
||||
|
||||
public static SimpleClassTypeSignature make(String n,
|
||||
boolean dollar,
|
||||
TypeArgument[] tas){
|
||||
return new SimpleClassTypeSignature(n, dollar, tas);
|
||||
}
|
||||
|
||||
/*
|
||||
* Should a '$' be used instead of '.' to separate this component
|
||||
* of the name from the previous one when composing a string to
|
||||
* pass to Class.forName; in other words, is this a transition to
|
||||
* a nested class.
|
||||
*/
|
||||
public boolean getDollar(){return dollar;}
|
||||
public String getName(){return name;}
|
||||
public TypeArgument[] getTypeArguments(){return typeArgs;}
|
||||
|
||||
public void accept(TypeTreeVisitor<?> v){
|
||||
v.visitSimpleClassTypeSignature(this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
/** Root of the abstract syntax tree hierarchy for generic signatures */
|
||||
public interface Tree{}
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
/** Common supertype for all possible type arguments in the
|
||||
* generic signature AST. Corresponds to the production TypeArgument
|
||||
* in the JVMS.
|
||||
*/
|
||||
public interface TypeArgument extends TypeTree {}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
/**
|
||||
* Common superinterface for all signatures that represent a
|
||||
* type expression.
|
||||
* Corresponds to the production of the same name in the JVMS
|
||||
* section on signatures.
|
||||
*/
|
||||
public interface TypeSignature extends ReturnType {}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
/** Common supertype for all nodes that represent type expressions in
|
||||
* the generic signature AST.
|
||||
*/
|
||||
public interface TypeTree extends Tree {
|
||||
/**
|
||||
* Accept method for the visitor pattern.
|
||||
* @param v a {@code TypeTreeVisitor} that will process this
|
||||
* tree
|
||||
*/
|
||||
void accept(TypeTreeVisitor<?> v);
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
public class TypeVariableSignature implements FieldTypeSignature {
|
||||
private final String identifier;
|
||||
|
||||
private TypeVariableSignature(String id) {identifier = id;}
|
||||
|
||||
|
||||
public static TypeVariableSignature make(String id) {
|
||||
return new TypeVariableSignature(id);
|
||||
}
|
||||
|
||||
public String getIdentifier(){return identifier;}
|
||||
|
||||
public void accept(TypeTreeVisitor<?> v){
|
||||
v.visitTypeVariableSignature(this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
|
||||
/** AST that represents the pseudo-type void. */
|
||||
public class VoidDescriptor implements ReturnType {
|
||||
private static final VoidDescriptor singleton = new VoidDescriptor();
|
||||
|
||||
private VoidDescriptor(){}
|
||||
|
||||
public static VoidDescriptor make() {return singleton;}
|
||||
|
||||
|
||||
|
||||
public void accept(TypeTreeVisitor<?> v){v.visitVoidDescriptor(this);}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.tree;
|
||||
|
||||
import sun.reflect.generics.visitor.TypeTreeVisitor;
|
||||
|
||||
public class Wildcard implements TypeArgument {
|
||||
private final FieldTypeSignature[] upperBounds;
|
||||
private final FieldTypeSignature[] lowerBounds;
|
||||
|
||||
private Wildcard(FieldTypeSignature[] ubs, FieldTypeSignature[] lbs) {
|
||||
upperBounds = ubs;
|
||||
lowerBounds = lbs;
|
||||
}
|
||||
|
||||
private static final FieldTypeSignature[] emptyBounds = new FieldTypeSignature[0];
|
||||
|
||||
public static Wildcard make(FieldTypeSignature[] ubs,
|
||||
FieldTypeSignature[] lbs) {
|
||||
return new Wildcard(ubs, lbs);
|
||||
}
|
||||
|
||||
public FieldTypeSignature[] getUpperBounds() {
|
||||
return upperBounds;
|
||||
}
|
||||
|
||||
public FieldTypeSignature[] getLowerBounds() {
|
||||
if (lowerBounds.length == 1 &&
|
||||
lowerBounds[0] == BottomSignature.make())
|
||||
return emptyBounds;
|
||||
else
|
||||
return lowerBounds;
|
||||
}
|
||||
|
||||
public void accept(TypeTreeVisitor<?> v){v.visitWildcard(this);}
|
||||
}
|
|
@ -0,0 +1,218 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.visitor;
|
||||
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import sun.reflect.generics.tree.*;
|
||||
import sun.reflect.generics.factory.*;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Visitor that converts AST to reified types.
|
||||
*/
|
||||
public class Reifier implements TypeTreeVisitor<Type> {
|
||||
private Type resultType;
|
||||
private final GenericsFactory factory;
|
||||
|
||||
private Reifier(GenericsFactory f){
|
||||
factory = f;
|
||||
}
|
||||
|
||||
private GenericsFactory getFactory(){ return factory;}
|
||||
|
||||
/**
|
||||
* Factory method. The resulting visitor will convert an AST
|
||||
* representing generic signatures into corresponding reflective
|
||||
* objects, using the provided factory, {@code f}.
|
||||
* @param f - a factory that can be used to manufacture reflective
|
||||
* objects returned by this visitor
|
||||
* @return A visitor that can be used to reify ASTs representing
|
||||
* generic type information into reflective objects
|
||||
*/
|
||||
public static Reifier make(GenericsFactory f){
|
||||
return new Reifier(f);
|
||||
}
|
||||
|
||||
// Helper method. Visits an array of TypeArgument and produces
|
||||
// reified Type array.
|
||||
private Type[] reifyTypeArguments(TypeArgument[] tas) {
|
||||
Type[] ts = new Type[tas.length];
|
||||
for (int i = 0; i < tas.length; i++) {
|
||||
tas[i].accept(this);
|
||||
ts[i] = resultType;
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Accessor for the result of the last visit by this visitor,
|
||||
* @return The type computed by this visitor based on its last
|
||||
* visit
|
||||
*/
|
||||
public Type getResult() { assert resultType != null;return resultType;}
|
||||
|
||||
public void visitFormalTypeParameter(FormalTypeParameter ftp){
|
||||
resultType = getFactory().makeTypeVariable(ftp.getName(),
|
||||
ftp.getBounds());
|
||||
}
|
||||
|
||||
|
||||
public void visitClassTypeSignature(ClassTypeSignature ct){
|
||||
// This method examines the pathname stored in ct, which has the form
|
||||
// n1.n2...nk<targs>....
|
||||
// where n1 ... nk-1 might not exist OR
|
||||
// nk might not exist (but not both). It may be that k equals 1.
|
||||
// The idea is that nk is the simple class type name that has
|
||||
// any type parameters associated with it.
|
||||
// We process this path in two phases.
|
||||
// First, we scan until we reach nk (if it exists).
|
||||
// If nk does not exist, this identifies a raw class n1 ... nk-1
|
||||
// which we can return.
|
||||
// if nk does exist, we begin the 2nd phase.
|
||||
// Here nk defines a parameterized type. Every further step nj (j > k)
|
||||
// down the path must also be represented as a parameterized type,
|
||||
// whose owner is the representation of the previous step in the path,
|
||||
// n{j-1}.
|
||||
|
||||
// extract iterator on list of simple class type sigs
|
||||
List<SimpleClassTypeSignature> scts = ct.getPath();
|
||||
assert(!scts.isEmpty());
|
||||
Iterator<SimpleClassTypeSignature> iter = scts.iterator();
|
||||
SimpleClassTypeSignature sc = iter.next();
|
||||
StringBuilder n = new StringBuilder(sc.getName());
|
||||
boolean dollar = sc.getDollar();
|
||||
|
||||
// phase 1: iterate over simple class types until
|
||||
// we are either done or we hit one with non-empty type parameters
|
||||
while (iter.hasNext() && sc.getTypeArguments().length == 0) {
|
||||
sc = iter.next();
|
||||
dollar = sc.getDollar();
|
||||
n.append(dollar?"$":".").append(sc.getName());
|
||||
}
|
||||
|
||||
// Now, either sc is the last element of the list, or
|
||||
// it has type arguments (or both)
|
||||
assert(!(iter.hasNext()) || (sc.getTypeArguments().length > 0));
|
||||
// Create the raw type
|
||||
Type c = getFactory().makeNamedType(n.toString());
|
||||
// if there are no type arguments
|
||||
if (sc.getTypeArguments().length == 0) {
|
||||
//we have surely reached the end of the path
|
||||
assert(!iter.hasNext());
|
||||
resultType = c; // the result is the raw type
|
||||
} else {
|
||||
assert(sc.getTypeArguments().length > 0);
|
||||
// otherwise, we have type arguments, so we create a parameterized
|
||||
// type, whose declaration is the raw type c, and whose owner is
|
||||
// the declaring class of c (if any). This latter fact is indicated
|
||||
// by passing null as the owner.
|
||||
// First, we reify the type arguments
|
||||
Type[] pts = reifyTypeArguments(sc.getTypeArguments());
|
||||
|
||||
Type owner = getFactory().makeParameterizedType(c, pts, null);
|
||||
// phase 2: iterate over remaining simple class types
|
||||
dollar =false;
|
||||
while (iter.hasNext()) {
|
||||
sc = iter.next();
|
||||
dollar = sc.getDollar();
|
||||
n.append(dollar?"$":".").append(sc.getName()); // build up raw class name
|
||||
c = getFactory().makeNamedType(n.toString()); // obtain raw class
|
||||
pts = reifyTypeArguments(sc.getTypeArguments());// reify params
|
||||
// Create a parameterized type, based on type args, raw type
|
||||
// and previous owner
|
||||
owner = getFactory().makeParameterizedType(c, pts, owner);
|
||||
}
|
||||
resultType = owner;
|
||||
}
|
||||
}
|
||||
|
||||
public void visitArrayTypeSignature(ArrayTypeSignature a){
|
||||
// extract and reify component type
|
||||
a.getComponentType().accept(this);
|
||||
Type ct = resultType;
|
||||
resultType = getFactory().makeArrayType(ct);
|
||||
}
|
||||
|
||||
public void visitTypeVariableSignature(TypeVariableSignature tv){
|
||||
resultType = getFactory().findTypeVariable(tv.getIdentifier());
|
||||
}
|
||||
|
||||
public void visitWildcard(Wildcard w){
|
||||
resultType = getFactory().makeWildcard(w.getUpperBounds(),
|
||||
w.getLowerBounds());
|
||||
}
|
||||
|
||||
public void visitSimpleClassTypeSignature(SimpleClassTypeSignature sct){
|
||||
resultType = getFactory().makeNamedType(sct.getName());
|
||||
}
|
||||
|
||||
public void visitBottomSignature(BottomSignature b){
|
||||
|
||||
}
|
||||
|
||||
public void visitByteSignature(ByteSignature b){
|
||||
resultType = getFactory().makeByte();
|
||||
}
|
||||
|
||||
public void visitBooleanSignature(BooleanSignature b){
|
||||
resultType = getFactory().makeBool();
|
||||
}
|
||||
|
||||
public void visitShortSignature(ShortSignature s){
|
||||
resultType = getFactory().makeShort();
|
||||
}
|
||||
|
||||
public void visitCharSignature(CharSignature c){
|
||||
resultType = getFactory().makeChar();
|
||||
}
|
||||
|
||||
public void visitIntSignature(IntSignature i){
|
||||
resultType = getFactory().makeInt();
|
||||
}
|
||||
|
||||
public void visitLongSignature(LongSignature l){
|
||||
resultType = getFactory().makeLong();
|
||||
}
|
||||
|
||||
public void visitFloatSignature(FloatSignature f){
|
||||
resultType = getFactory().makeFloat();
|
||||
}
|
||||
|
||||
public void visitDoubleSignature(DoubleSignature d){
|
||||
resultType = getFactory().makeDouble();
|
||||
}
|
||||
|
||||
public void visitVoidDescriptor(VoidDescriptor v){
|
||||
resultType = getFactory().makeVoid();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.visitor;
|
||||
|
||||
import sun.reflect.generics.tree.*;
|
||||
|
||||
/**
|
||||
* Visit a TypeTree and produce a result of type T.
|
||||
*/
|
||||
public interface TypeTreeVisitor<T> {
|
||||
|
||||
/**
|
||||
* Returns the result of the visit.
|
||||
* @return the result of the visit
|
||||
*/
|
||||
T getResult();
|
||||
|
||||
// Visitor methods, per node type
|
||||
|
||||
void visitFormalTypeParameter(FormalTypeParameter ftp);
|
||||
|
||||
void visitClassTypeSignature(ClassTypeSignature ct);
|
||||
void visitArrayTypeSignature(ArrayTypeSignature a);
|
||||
void visitTypeVariableSignature(TypeVariableSignature tv);
|
||||
void visitWildcard(Wildcard w);
|
||||
|
||||
void visitSimpleClassTypeSignature(SimpleClassTypeSignature sct);
|
||||
void visitBottomSignature(BottomSignature b);
|
||||
|
||||
// Primitives and Void
|
||||
void visitByteSignature(ByteSignature b);
|
||||
void visitBooleanSignature(BooleanSignature b);
|
||||
void visitShortSignature(ShortSignature s);
|
||||
void visitCharSignature(CharSignature c);
|
||||
void visitIntSignature(IntSignature i);
|
||||
void visitLongSignature(LongSignature l);
|
||||
void visitFloatSignature(FloatSignature f);
|
||||
void visitDoubleSignature(DoubleSignature d);
|
||||
|
||||
void visitVoidDescriptor(VoidDescriptor v);
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.generics.visitor;
|
||||
|
||||
import sun.reflect.generics.tree.*;
|
||||
|
||||
public interface Visitor<T> extends TypeTreeVisitor<T> {
|
||||
|
||||
void visitClassSignature(ClassSignature cs);
|
||||
void visitMethodTypeSignature(MethodTypeSignature ms);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue