Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2003 Sun Microsystems, Inc.  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.  Sun designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  * CA 95054 USA or visit www.sun.com if you need additional information or
  * have any questions.
  */
 
 package sun.reflect.generics.factory;
 
 
 
Factory for reflective generic type objects for use by core reflection (java.lang.reflect).
 
 public class CoreReflectionFactory implements GenericsFactory {
     private GenericDeclaration decl;
     private Scope scope;
 
     private CoreReflectionFactory(GenericDeclaration dScope s) {
          = d;
          = s;
     }
 
     private GenericDeclaration getDecl(){ return ;}
 
     private Scope getScope(){ return ;}
 
 
     private ClassLoader getDeclsLoader() {
         if ( instanceof Class) {return ((Class).getClassLoader();}
         if ( instanceof Method) {
             return ((Method).getDeclaringClass().getClassLoader();
         }
         assert  instanceof Constructor : "Constructor expected";
         return ((Constructor).getDeclaringClass().getClassLoader();
 
     }

    
Factory for this class. Returns an instance of CoreReflectionFactory for the declaration and scope provided. This factory will produce reflective objects of the appropriate kind. Classes produced will be those that would be loaded by the defining class loader of the declaration d (if d is a type declaration, or by the defining loader of the declaring class of d otherwise.

Type variables will be created or lookup as necessary in the scope s.

Parameters:
d - the generic declaration (class, interface, method or constructor) that thsi factory services
s the scope in which the factory will allocate and search for type variables
Returns:
an instance of CoreReflectionFactory
 
     public static CoreReflectionFactory make(GenericDeclaration dScope s) {
         return new CoreReflectionFactory(ds);
     }
 
     public TypeVariable<?> makeTypeVariable(String name,
                                             FieldTypeSignature[] bounds){
         return TypeVariableImpl.make(getDecl(), nameboundsthis);
     }
 
                                      FieldTypeSignature[] lbs) {
         return WildcardTypeImpl.make(ubslbsthis);
     }
    public ParameterizedType makeParameterizedType(Type declaration,
                                                   Type[] typeArgs,
                                                   Type owner) {
        return ParameterizedTypeImpl.make((Class<?>) declaration,
                                          typeArgsowner);
    }
    public TypeVariable<?> findTypeVariable(String name){
        return getScope().lookup(name);
    }
    public Type makeNamedType(String name){
        try {return Class.forName(namefalse// don't initialize
                                  getDeclsLoader());}
        catch (ClassNotFoundException c) {
            throw new TypeNotPresentException(namec);
        }
    }
    public Type makeArrayType(Type componentType){
        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;}
New to GrepCode? Check out our FAQ X