feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View 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);
}
}

View 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);}
}

View 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);
}
}

View 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;}
}

View 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);
}
}

View 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);
}