feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -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
|
||||
* <tt>CoreReflectionFactory</tt> 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 <tt>d</tt> (if <tt>d</tt>
|
||||
* is a type declaration, or by the defining loader of the declaring
|
||||
* class of <tt>d</tt> otherwise.
|
||||
* <p> Type variables will be created or lookup as necessary in the
|
||||
* scope <tt> s</tt>.
|
||||
* @param d - the generic declaration (class, interface, method or
|
||||
* constructor) that thsi factory services
|
||||
* @param s the scope in which the factory will allocate and search for
|
||||
* type variables
|
||||
* @return an instance of <tt>CoreReflectionFactory</tt>
|
||||
*/
|
||||
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;}
|
||||
}
|
||||
190
jdkSrc/jdk8/sun/reflect/generics/factory/GenericsFactory.java
Normal file
190
jdkSrc/jdk8/sun/reflect/generics/factory/GenericsFactory.java
Normal file
@@ -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
|
||||
* tpe 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 <tt>name</tt>
|
||||
* may be empty (but not <tt>null</tt>). If <tt>bounds</tt> is
|
||||
* empty, a bound of <tt>java.lang.Object</tt> 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 <tt>bounds</tt> are <tt>null</tt>.
|
||||
*/
|
||||
TypeVariable<?> makeTypeVariable(String name,
|
||||
FieldTypeSignature[] bounds);
|
||||
/**
|
||||
* Return an instance of the <tt>ParameterizedType</tt> interface
|
||||
* that corresponds to a generic type instantiation of the
|
||||
* generic declaration <tt>declaration</tt> with actual type arguments
|
||||
* <tt>typeArgs</tt>.
|
||||
* If <tt>owner</tt> is <tt>null</tt>, the declaring class of
|
||||
* <tt>declaration</tt> 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 <tt>GenericDeclaration</tt>).
|
||||
* If the number of actual type arguments (i.e., the size of the
|
||||
* array <tt>typeArgs</tt>) 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 <tt>declaration</tt>
|
||||
* , <tt>typeArgs</tt>
|
||||
* or any of the elements of <tt>typeArgs</tt> are <tt>null</tt>
|
||||
*/
|
||||
ParameterizedType makeParameterizedType(Type declaration,
|
||||
Type[] typeArgs,
|
||||
Type owner);
|
||||
|
||||
/**
|
||||
* Returns the type variable with name <tt>name</tt>, if such
|
||||
* a type variable is declared in the
|
||||
* scope used to create this factory.
|
||||
* Returns <tt>null</tt> otherwise.
|
||||
* @param name - the name of the type variable to search for
|
||||
* @return - the type variable with name <tt>name</tt>, or <tt>null</tt>
|
||||
* @throws NullPointerException - if any of actual parameters are
|
||||
* <tt>null</tt>
|
||||
*/
|
||||
TypeVariable<?> findTypeVariable(String name);
|
||||
|
||||
/**
|
||||
* Returns a new wildcard type variable. If
|
||||
* <tt>ubs</tt> is empty, a bound of <tt>java.lang.Object</tt> 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 <tt>ubs</tt> or <tt>lbs</tt>are
|
||||
* <tt>null</tt>
|
||||
*/
|
||||
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 arguemnts, otherwise
|
||||
* a MalformedParameterizedTypeException is thrown.
|
||||
* @param componentType - the component type of the array
|
||||
* @return a (possibly generic) array type.
|
||||
* @throws MalformedParameterizedTypeException if <tt>componentType</tt>
|
||||
* is a parameterized type with non-wildcard type arguments
|
||||
* @throws NullPointerException - if any of the actual parameters
|
||||
* are <tt>null</tt>
|
||||
*/
|
||||
Type makeArrayType(Type componentType);
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of type <tt>byte</tt>.
|
||||
* @return the reflective representation of type <tt>byte</tt>.
|
||||
*/
|
||||
Type makeByte();
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of type <tt>boolean</tt>.
|
||||
* @return the reflective representation of type <tt>boolean</tt>.
|
||||
*/
|
||||
Type makeBool();
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of type <tt>short</tt>.
|
||||
* @return the reflective representation of type <tt>short</tt>.
|
||||
*/
|
||||
Type makeShort();
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of type <tt>char</tt>.
|
||||
* @return the reflective representation of type <tt>char</tt>.
|
||||
*/
|
||||
Type makeChar();
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of type <tt>int</tt>.
|
||||
* @return the reflective representation of type <tt>int</tt>.
|
||||
*/
|
||||
Type makeInt();
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of type <tt>long</tt>.
|
||||
* @return the reflective representation of type <tt>long</tt>.
|
||||
*/
|
||||
Type makeLong();
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of type <tt>float</tt>.
|
||||
* @return the reflective representation of type <tt>float</tt>.
|
||||
*/
|
||||
Type makeFloat();
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of type <tt>double</tt>.
|
||||
* @return the reflective representation of type <tt>double</tt>.
|
||||
*/
|
||||
Type makeDouble();
|
||||
|
||||
/**
|
||||
* Returns the reflective representation of <tt>void</tt>.
|
||||
* @return the reflective representation of <tt>void</tt>.
|
||||
*/
|
||||
Type makeVoid();
|
||||
}
|
||||
634
jdkSrc/jdk8/sun/reflect/generics/parser/SignatureParser.java
Normal file
634
jdkSrc/jdk8/sun/reflect/generics/parser/SignatureParser.java
Normal file
@@ -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 <tt>SignatureParser</tt>
|
||||
*/
|
||||
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,93 @@
|
||||
/*
|
||||
* 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.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 <tt>Type</tt> object representing the component type
|
||||
* of this array.
|
||||
*
|
||||
* @return a <tt>Type</tt> object representing the component type
|
||||
* of this array
|
||||
* @since 1.5
|
||||
*/
|
||||
public Type getGenericComponentType() {
|
||||
return genericComponentType; // return cached component type
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
Type componentType = getGenericComponentType();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (componentType instanceof Class)
|
||||
sb.append(((Class)componentType).getName() );
|
||||
else
|
||||
sb.append(componentType.toString());
|
||||
sb.append("[]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@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,57 @@
|
||||
/*
|
||||
* 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 sun.reflect.generics.factory.GenericsFactory;
|
||||
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());}
|
||||
|
||||
}
|
||||
@@ -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,242 @@
|
||||
/*
|
||||
* 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 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.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 <tt>typeArgs</tt>) 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 <tt>ParameterizedType</tt>
|
||||
* @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 <tt>Type</tt> 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 <tt>Type</tt> objects representing the actual type
|
||||
* arguments to this type
|
||||
* @throws <tt>TypeNotPresentException</tt> if any of the
|
||||
* actual type arguments refers to a non-existent type declaration
|
||||
* @throws <tt>MalformedParameterizedTypeException</tt> 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 <tt>Type</tt> object representing the class or interface
|
||||
* that declared this type.
|
||||
*
|
||||
* @return the <tt>Type</tt> object representing the class or interface
|
||||
* that declared this type
|
||||
*/
|
||||
public Class<?> getRawType() {
|
||||
return rawType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a <tt>Type</tt> object representing the type that this type
|
||||
* is a member of. For example, if this type is <tt>O<T>.I<S></tt>,
|
||||
* return a representation of <tt>O<T></tt>.
|
||||
*
|
||||
* <p>If this type is a top-level type, <tt>null</tt> is returned.
|
||||
*
|
||||
* @return a <tt>Type</tt> object representing the type that
|
||||
* this type is a member of. If this type is a top-level type,
|
||||
* <tt>null</tt> is returned
|
||||
* @throws <tt>TypeNotPresentException</tt> if the owner type
|
||||
* refers to a non-existent type declaration
|
||||
* @throws <tt>MalformedParameterizedTypeException</tt> 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) {
|
||||
if (ownerType instanceof Class)
|
||||
sb.append(((Class)ownerType).getName());
|
||||
else
|
||||
sb.append(ownerType.toString());
|
||||
|
||||
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 &&
|
||||
actualTypeArguments.length > 0) {
|
||||
sb.append("<");
|
||||
boolean first = true;
|
||||
for(Type t: actualTypeArguments) {
|
||||
if (!first)
|
||||
sb.append(", ");
|
||||
sb.append(t.getTypeName());
|
||||
first = false;
|
||||
}
|
||||
sb.append(">");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
/*
|
||||
* 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 <tt>java.lang.reflect.TypeVariable</tt> interface
|
||||
* for core reflection.
|
||||
*/
|
||||
public class TypeVariableImpl<D extends GenericDeclaration>
|
||||
extends LazyReflectiveObjectGenerator implements TypeVariable<D> {
|
||||
D genericDeclaration;
|
||||
private String name;
|
||||
// upper bounds - evaluated lazily
|
||||
private Type[] bounds;
|
||||
|
||||
// The ASTs for the bounds. We are required to evaluate the bounds
|
||||
// lazily, so we store these at least until we are first asked
|
||||
// for the bounds. This also neatly solves the
|
||||
// problem with F-bounds - you can't reify them before the formal
|
||||
// is defined.
|
||||
private FieldTypeSignature[] boundASTs;
|
||||
|
||||
// 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;
|
||||
boundASTs = bs;
|
||||
}
|
||||
|
||||
// Accessors
|
||||
|
||||
// accessor for ASTs for bounds. Must not be called after
|
||||
// bounds have been evaluated, because we might throw the ASTs
|
||||
// away (but that is not thread-safe, is it?)
|
||||
private FieldTypeSignature[] getBoundASTs() {
|
||||
// check that bounds were not evaluated yet
|
||||
assert(bounds == null);
|
||||
return boundASTs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 <tt>Type</tt> objects representing the
|
||||
* upper bound(s) of this type variable. Note that if no upper bound is
|
||||
* explicitly declared, the upper bound is <tt>Object</tt>.
|
||||
*
|
||||
* <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 <tt>TypeNotPresentException</tt> if any of the
|
||||
* bounds refers to a non-existent type declaration
|
||||
* @throws <tt>MalformedParameterizedTypeException</tt> 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() {
|
||||
// lazily initialize bounds if necessary
|
||||
if (bounds == null) {
|
||||
FieldTypeSignature[] fts = getBoundASTs(); // get AST
|
||||
// allocate result array; note that
|
||||
// keeping ts and bounds separate helps with threads
|
||||
Type[] ts = new Type[fts.length];
|
||||
// iterate over bound trees, reifying each in turn
|
||||
for ( int j = 0; j < fts.length; j++) {
|
||||
Reifier r = getReifier();
|
||||
fts[j].accept(r);
|
||||
ts[j] = r.getResult();
|
||||
}
|
||||
// cache result
|
||||
bounds = ts;
|
||||
// could throw away bound ASTs here; thread safety?
|
||||
}
|
||||
return bounds.clone(); // return cached bounds
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>GenericDeclaration</tt> 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,231 @@
|
||||
/*
|
||||
* 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.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;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of WildcardType interface for core reflection.
|
||||
*/
|
||||
public class WildcardTypeImpl extends LazyReflectiveObjectGenerator
|
||||
implements WildcardType {
|
||||
// upper bounds - evaluated lazily
|
||||
private Type[] upperBounds;
|
||||
// lower bounds - evaluated lazily
|
||||
private Type[] lowerBounds;
|
||||
// The ASTs for the bounds. We are required to evaluate the bounds
|
||||
// lazily, so we store these at least until we are first asked
|
||||
// for the bounds. This also neatly solves the
|
||||
// problem with F-bounds - you can't reify them before the formal
|
||||
// is defined.
|
||||
private FieldTypeSignature[] upperBoundASTs;
|
||||
private FieldTypeSignature[] lowerBoundASTs;
|
||||
|
||||
// constructor is private to enforce access through static factory
|
||||
private WildcardTypeImpl(FieldTypeSignature[] ubs,
|
||||
FieldTypeSignature[] lbs,
|
||||
GenericsFactory f) {
|
||||
super(f);
|
||||
upperBoundASTs = ubs;
|
||||
lowerBoundASTs = 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);
|
||||
}
|
||||
|
||||
// Accessors
|
||||
|
||||
// accessor for ASTs for upper bounds. Must not be called after upper
|
||||
// bounds have been evaluated, because we might throw the ASTs
|
||||
// away (but that is not thread-safe, is it?)
|
||||
private FieldTypeSignature[] getUpperBoundASTs() {
|
||||
// check that upper bounds were not evaluated yet
|
||||
assert(upperBounds == null);
|
||||
return upperBoundASTs;
|
||||
}
|
||||
// accessor for ASTs for lower bounds. Must not be called after lower
|
||||
// bounds have been evaluated, because we might throw the ASTs
|
||||
// away (but that is not thread-safe, is it?)
|
||||
private FieldTypeSignature[] getLowerBoundASTs() {
|
||||
// check that lower bounds were not evaluated yet
|
||||
assert(lowerBounds == null);
|
||||
return lowerBoundASTs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of <tt>Type</tt> objects representing the upper
|
||||
* bound(s) of this type variable. Note that if no upper bound is
|
||||
* explicitly declared, the upper bound is <tt>Object</tt>.
|
||||
*
|
||||
* <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 <tt>TypeNotPresentException</tt> if any of the
|
||||
* bounds refers to a non-existent type declaration
|
||||
* @throws <tt>MalformedParameterizedTypeException</tt> if any of the
|
||||
* bounds refer to a parameterized type that cannot be instantiated
|
||||
* for any reason
|
||||
*/
|
||||
public Type[] getUpperBounds() {
|
||||
// lazily initialize bounds if necessary
|
||||
if (upperBounds == null) {
|
||||
FieldTypeSignature[] fts = getUpperBoundASTs(); // get AST
|
||||
|
||||
// allocate result array; note that
|
||||
// keeping ts and bounds separate helps with threads
|
||||
Type[] ts = new Type[fts.length];
|
||||
// iterate over bound trees, reifying each in turn
|
||||
for ( int j = 0; j < fts.length; j++) {
|
||||
Reifier r = getReifier();
|
||||
fts[j].accept(r);
|
||||
ts[j] = r.getResult();
|
||||
}
|
||||
// cache result
|
||||
upperBounds = ts;
|
||||
// could throw away upper bound ASTs here; thread safety?
|
||||
}
|
||||
return upperBounds.clone(); // return cached bounds
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of <tt>Type</tt> 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 <tt>null</tt>.
|
||||
* 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 <tt>TypeNotPresentException</tt> if any of the
|
||||
* bounds refers to a non-existent type declaration
|
||||
* @throws <tt>MalformedParameterizedTypeException</tt> if any of the
|
||||
* bounds refer to a parameterized type that cannot be instantiated
|
||||
* for any reason
|
||||
*/
|
||||
public Type[] getLowerBounds() {
|
||||
// lazily initialize bounds if necessary
|
||||
if (lowerBounds == null) {
|
||||
FieldTypeSignature[] fts = getLowerBoundASTs(); // get AST
|
||||
// allocate result array; note that
|
||||
// keeping ts and bounds separate helps with threads
|
||||
Type[] ts = new Type[fts.length];
|
||||
// iterate over bound trees, reifying each in turn
|
||||
for ( int j = 0; j < fts.length; j++) {
|
||||
Reifier r = getReifier();
|
||||
fts[j].accept(r);
|
||||
ts[j] = r.getResult();
|
||||
}
|
||||
// cache result
|
||||
lowerBounds = ts;
|
||||
// could throw away lower bound ASTs here; thread safety?
|
||||
}
|
||||
return lowerBounds.clone(); // return cached bounds
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
boolean first = true;
|
||||
for(Type bound: bounds) {
|
||||
if (!first)
|
||||
sb.append(" & ");
|
||||
|
||||
first = false;
|
||||
sb.append(bound.getTypeName());
|
||||
}
|
||||
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 <tt>tree</tt>.
|
||||
* @return the cached AST this repository holds
|
||||
*/
|
||||
protected T getTree(){ return tree;}
|
||||
|
||||
/**
|
||||
* Returns a <tt>Reifier</tt> used to convert parts of the
|
||||
* AST into reflective objects.
|
||||
* @return a <tt>Reifier</tt> 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 genric 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);
|
||||
}
|
||||
116
jdkSrc/jdk8/sun/reflect/generics/repository/ClassRepository.java
Normal file
116
jdkSrc/jdk8/sun/reflect/generics/repository/ClassRepository.java
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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 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;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
|
||||
/**
|
||||
* 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 <tt>ClassRepository</tt> that manages the generic type
|
||||
* information represented in the signature <tt>rawSig</tt>
|
||||
*/
|
||||
public static ClassRepository make(String rawSig, GenericsFactory f) {
|
||||
return new ClassRepository(rawSig, f);
|
||||
}
|
||||
|
||||
// public API
|
||||
/*
|
||||
* 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.
|
||||
* a visitor, which is created by feeding it the factory
|
||||
* with which the repository was created.
|
||||
*/
|
||||
|
||||
public Type getSuperclass() {
|
||||
Type superclass = this.superclass;
|
||||
if (superclass == null) { // lazily initialize superclass
|
||||
Reifier r = getReifier(); // obtain visitor
|
||||
// Extract superclass subtree from AST and reify
|
||||
getTree().getSuperclass().accept(r);
|
||||
// extract result from visitor and cache it
|
||||
superclass = r.getResult();
|
||||
this.superclass = superclass;
|
||||
}
|
||||
return superclass; // return cached result
|
||||
}
|
||||
|
||||
public Type[] getSuperInterfaces() {
|
||||
Type[] superInterfaces = this.superInterfaces;
|
||||
if (superInterfaces == null) { // lazily initialize super interfaces
|
||||
// first, extract super interface subtree(s) from AST
|
||||
TypeTree[] ts = getTree().getSuperInterfaces();
|
||||
// create array to store reified subtree(s)
|
||||
superInterfaces = new Type[ts.length];
|
||||
// reify all subtrees
|
||||
for (int i = 0; i < ts.length; i++) {
|
||||
Reifier r = getReifier(); // obtain visitor
|
||||
ts[i].accept(r);// reify subtree
|
||||
// extract result from visitor and store it
|
||||
superInterfaces[i] = r.getResult();
|
||||
}
|
||||
this.superInterfaces = superInterfaces;
|
||||
}
|
||||
return superInterfaces.clone(); // return cached result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* 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> {
|
||||
|
||||
private Type[] paramTypes; // caches the generic parameter types info
|
||||
private Type[] exceptionTypes; // caches the generic exception types info
|
||||
|
||||
// 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 <tt>ConstructorRepository</tt> that manages the generic type
|
||||
* information represented in the signature <tt>rawSig</tt>
|
||||
*/
|
||||
public static ConstructorRepository make(String rawSig,
|
||||
GenericsFactory f) {
|
||||
return new ConstructorRepository(rawSig, f);
|
||||
}
|
||||
|
||||
// public API
|
||||
|
||||
/*
|
||||
* 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.
|
||||
* a visitor, which is created by feeding it the factory
|
||||
* with which the repository was created.
|
||||
*/
|
||||
|
||||
public Type[] getParameterTypes(){
|
||||
if (paramTypes == null) { // lazily initialize parameter types
|
||||
// first, extract parameter type subtree(s) from AST
|
||||
TypeSignature[] pts = getTree().getParameterTypes();
|
||||
// create array to store reified subtree(s)
|
||||
Type[] ps = new Type[pts.length];
|
||||
// reify all subtrees
|
||||
for (int i = 0; i < pts.length; i++) {
|
||||
Reifier r = getReifier(); // obtain visitor
|
||||
pts[i].accept(r); // reify subtree
|
||||
// extract result from visitor and store it
|
||||
ps[i] = r.getResult();
|
||||
}
|
||||
paramTypes = ps; // cache overall result
|
||||
}
|
||||
return paramTypes.clone(); // return cached result
|
||||
}
|
||||
|
||||
public Type[] getExceptionTypes(){
|
||||
if (exceptionTypes == null) { // lazily initialize exception types
|
||||
// first, extract exception type subtree(s) from AST
|
||||
FieldTypeSignature[] ets = getTree().getExceptionTypes();
|
||||
// create array to store reified subtree(s)
|
||||
Type[] es = new Type[ets.length];
|
||||
// reify all subtrees
|
||||
for (int i = 0; i < ets.length; i++) {
|
||||
Reifier r = getReifier(); // obtain visitor
|
||||
ets[i].accept(r); // reify subtree
|
||||
// extract result from visitor and store it
|
||||
es[i] = r.getResult();
|
||||
}
|
||||
exceptionTypes = es; // cache overall result
|
||||
}
|
||||
return exceptionTypes.clone(); // return cached result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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> {
|
||||
|
||||
private Type genericType; // caches the generic type info
|
||||
|
||||
// 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 <tt>FieldRepository</tt> that manages the generic type
|
||||
* information represented in the signature <tt>rawSig</tt>
|
||||
*/
|
||||
public static FieldRepository make(String rawSig,
|
||||
GenericsFactory f) {
|
||||
return new FieldRepository(rawSig, f);
|
||||
}
|
||||
|
||||
// public API
|
||||
|
||||
/*
|
||||
* 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.
|
||||
* a visitor, which is created by feeding it the factory
|
||||
* with which the repository was created.
|
||||
*/
|
||||
|
||||
public Type getGenericType(){
|
||||
if (genericType == null) { // lazily initialize generic type
|
||||
Reifier r = getReifier(); // obtain visitor
|
||||
getTree().accept(r); // reify subtree
|
||||
// extract result from visitor and cache it
|
||||
genericType = r.getResult();
|
||||
}
|
||||
return genericType; // return cached result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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<?>[] typeParams;
|
||||
|
||||
protected GenericDeclRepository(String rawSig, GenericsFactory f) {
|
||||
super(rawSig, f);
|
||||
}
|
||||
|
||||
// public API
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return the formal type parameters of this generic declaration.
|
||||
* @return the formal type parameters of this generic declaration
|
||||
*/
|
||||
public TypeVariable<?>[] getTypeParameters() {
|
||||
TypeVariable<?>[] typeParams = this.typeParams;
|
||||
if (typeParams == null) { // lazily initialize type parameters
|
||||
// first, extract type parameter subtree(s) from AST
|
||||
FormalTypeParameter[] ftps = getTree().getFormalTypeParameters();
|
||||
// create array to store reified subtree(s)
|
||||
typeParams = new TypeVariable<?>[ftps.length];
|
||||
// reify all subtrees
|
||||
for (int i = 0; i < ftps.length; i++) {
|
||||
Reifier r = getReifier(); // obtain visitor
|
||||
ftps[i].accept(r); // reify subtree
|
||||
// extract result from visitor and store it
|
||||
typeParams[i] = (TypeVariable<?>) r.getResult();
|
||||
}
|
||||
this.typeParams = typeParams; // cache overall result
|
||||
}
|
||||
return typeParams.clone(); // return cached result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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 {
|
||||
|
||||
private Type returnType; // caches the generic return type info
|
||||
|
||||
// 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 <tt>MethodRepository</tt> that manages the generic type
|
||||
* information represented in the signature <tt>rawSig</tt>
|
||||
*/
|
||||
public static MethodRepository make(String rawSig, GenericsFactory f) {
|
||||
return new MethodRepository(rawSig, f);
|
||||
}
|
||||
|
||||
// public API
|
||||
|
||||
public Type getReturnType() {
|
||||
if (returnType == null) { // lazily initialize return type
|
||||
Reifier r = getReifier(); // obtain visitor
|
||||
// Extract return type subtree from AST and reify
|
||||
getTree().getReturnType().accept(r);
|
||||
// extract result from visitor and cache it
|
||||
returnType = r.getResult();
|
||||
}
|
||||
return returnType; // return cached result
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
98
jdkSrc/jdk8/sun/reflect/generics/scope/AbstractScope.java
Normal file
98
jdkSrc/jdk8/sun/reflect/generics/scope/AbstractScope.java
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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 <tt>D</tt> represents the type of reflective
|
||||
* object whose scope this class is representing.
|
||||
* <p> To subclass this, all one needs to do is implement
|
||||
* <tt>computeEnclosingScope</tt> 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 D - 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 <tt>Scope</tt>
|
||||
* object represents.
|
||||
* @return The object whose scope this <tt>Scope</tt> 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 enclosingScope = this.enclosingScope;
|
||||
if (enclosingScope == null) {
|
||||
enclosingScope = computeEnclosingScope();
|
||||
this.enclosingScope = enclosingScope;
|
||||
}
|
||||
return enclosingScope;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
83
jdkSrc/jdk8/sun/reflect/generics/scope/ClassScope.java
Normal file
83
jdkSrc/jdk8/sun/reflect/generics/scope/ClassScope.java
Normal file
@@ -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 <tt>Class</tt> 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);}
|
||||
|
||||
}
|
||||
67
jdkSrc/jdk8/sun/reflect/generics/scope/ConstructorScope.java
Normal file
67
jdkSrc/jdk8/sun/reflect/generics/scope/ConstructorScope.java
Normal file
@@ -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 <tt>Constructor</tt> object and creates a
|
||||
* scope for it.
|
||||
* @param m - 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);
|
||||
}
|
||||
}
|
||||
61
jdkSrc/jdk8/sun/reflect/generics/scope/DummyScope.java
Normal file
61
jdkSrc/jdk8/sun/reflect/generics/scope/DummyScope.java
Normal file
@@ -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 <tt>null</tt> 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, <tt>null</tt> 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
|
||||
* <tt>null</tt>.
|
||||
* @param name - the name of the type variable being looked up
|
||||
* @return null
|
||||
*/
|
||||
public TypeVariable<?> lookup(String name) {return null;}
|
||||
}
|
||||
67
jdkSrc/jdk8/sun/reflect/generics/scope/MethodScope.java
Normal file
67
jdkSrc/jdk8/sun/reflect/generics/scope/MethodScope.java
Normal file
@@ -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 <tt>Method</tt> 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);
|
||||
}
|
||||
}
|
||||
33
jdkSrc/jdk8/sun/reflect/generics/scope/Scope.java
Normal file
33
jdkSrc/jdk8/sun/reflect/generics/scope/Scope.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
34
jdkSrc/jdk8/sun/reflect/generics/tree/BaseType.java
Normal file
34
jdkSrc/jdk8/sun/reflect/generics/tree/BaseType.java
Normal file
@@ -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{}
|
||||
41
jdkSrc/jdk8/sun/reflect/generics/tree/BooleanSignature.java
Normal file
41
jdkSrc/jdk8/sun/reflect/generics/tree/BooleanSignature.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
38
jdkSrc/jdk8/sun/reflect/generics/tree/BottomSignature.java
Normal file
38
jdkSrc/jdk8/sun/reflect/generics/tree/BottomSignature.java
Normal file
@@ -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);}
|
||||
}
|
||||
41
jdkSrc/jdk8/sun/reflect/generics/tree/ByteSignature.java
Normal file
41
jdkSrc/jdk8/sun/reflect/generics/tree/ByteSignature.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
41
jdkSrc/jdk8/sun/reflect/generics/tree/CharSignature.java
Normal file
41
jdkSrc/jdk8/sun/reflect/generics/tree/CharSignature.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
56
jdkSrc/jdk8/sun/reflect/generics/tree/ClassSignature.java
Normal file
56
jdkSrc/jdk8/sun/reflect/generics/tree/ClassSignature.java
Normal file
@@ -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);}
|
||||
}
|
||||
39
jdkSrc/jdk8/sun/reflect/generics/tree/DoubleSignature.java
Normal file
39
jdkSrc/jdk8/sun/reflect/generics/tree/DoubleSignature.java
Normal file
@@ -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 {}
|
||||
39
jdkSrc/jdk8/sun/reflect/generics/tree/FloatSignature.java
Normal file
39
jdkSrc/jdk8/sun/reflect/generics/tree/FloatSignature.java
Normal file
@@ -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);}
|
||||
}
|
||||
39
jdkSrc/jdk8/sun/reflect/generics/tree/IntSignature.java
Normal file
39
jdkSrc/jdk8/sun/reflect/generics/tree/IntSignature.java
Normal file
@@ -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);}
|
||||
}
|
||||
39
jdkSrc/jdk8/sun/reflect/generics/tree/LongSignature.java
Normal file
39
jdkSrc/jdk8/sun/reflect/generics/tree/LongSignature.java
Normal file
@@ -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);}
|
||||
}
|
||||
28
jdkSrc/jdk8/sun/reflect/generics/tree/ReturnType.java
Normal file
28
jdkSrc/jdk8/sun/reflect/generics/tree/ReturnType.java
Normal file
@@ -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{}
|
||||
41
jdkSrc/jdk8/sun/reflect/generics/tree/ShortSignature.java
Normal file
41
jdkSrc/jdk8/sun/reflect/generics/tree/ShortSignature.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
34
jdkSrc/jdk8/sun/reflect/generics/tree/Signature.java
Normal file
34
jdkSrc/jdk8/sun/reflect/generics/tree/Signature.java
Normal file
@@ -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 delcarations.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
29
jdkSrc/jdk8/sun/reflect/generics/tree/Tree.java
Normal file
29
jdkSrc/jdk8/sun/reflect/generics/tree/Tree.java
Normal file
@@ -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{}
|
||||
32
jdkSrc/jdk8/sun/reflect/generics/tree/TypeArgument.java
Normal file
32
jdkSrc/jdk8/sun/reflect/generics/tree/TypeArgument.java
Normal file
@@ -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 {}
|
||||
34
jdkSrc/jdk8/sun/reflect/generics/tree/TypeSignature.java
Normal file
34
jdkSrc/jdk8/sun/reflect/generics/tree/TypeSignature.java
Normal file
@@ -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 {}
|
||||
40
jdkSrc/jdk8/sun/reflect/generics/tree/TypeTree.java
Normal file
40
jdkSrc/jdk8/sun/reflect/generics/tree/TypeTree.java
Normal file
@@ -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 <tt>TypeTreeVisitor</tt> 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);
|
||||
}
|
||||
}
|
||||
42
jdkSrc/jdk8/sun/reflect/generics/tree/VoidDescriptor.java
Normal file
42
jdkSrc/jdk8/sun/reflect/generics/tree/VoidDescriptor.java
Normal file
@@ -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);}
|
||||
}
|
||||
59
jdkSrc/jdk8/sun/reflect/generics/tree/Wildcard.java
Normal file
59
jdkSrc/jdk8/sun/reflect/generics/tree/Wildcard.java
Normal file
@@ -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 FieldTypeSignature[] upperBounds;
|
||||
private 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);}
|
||||
}
|
||||
218
jdkSrc/jdk8/sun/reflect/generics/visitor/Reifier.java
Normal file
218
jdkSrc/jdk8/sun/reflect/generics/visitor/Reifier.java
Normal file
@@ -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 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, <tt>f</tt>.
|
||||
* @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);
|
||||
}
|
||||
34
jdkSrc/jdk8/sun/reflect/generics/visitor/Visitor.java
Normal file
34
jdkSrc/jdk8/sun/reflect/generics/visitor/Visitor.java
Normal file
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user