本文整理汇总了Java中jdk.internal.dynalink.beans.StaticClass类的典型用法代码示例。如果您正苦于以下问题:Java StaticClass类的具体用法?Java StaticClass怎么用?Java StaticClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StaticClass类属于jdk.internal.dynalink.beans包,在下文中一共展示了StaticClass类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createProperty
import jdk.internal.dynalink.beans.StaticClass; //导入依赖的package包/类
private Object createProperty(final String name) {
final int len = args.length;
for (int i = len - 1; i > -1; i--) {
final Object obj = args[i];
if (obj instanceof StaticClass) {
if (((StaticClass)obj).getRepresentedClass().getSimpleName().equals(name)) {
return obj;
}
} else if (obj instanceof NativeJavaPackage) {
final String pkgName = ((NativeJavaPackage)obj).getName();
final String fullName = pkgName.isEmpty() ? name : (pkgName + "." + name);
final Context context = Global.instance().getContext();
try {
return StaticClass.forClass(context.findClass(fullName));
} catch (final ClassNotFoundException e) {
// IGNORE
}
}
}
return null;
}
示例2: getInstanceAdapterClass
import jdk.internal.dynalink.beans.StaticClass; //导入依赖的package包/类
private StaticClass getInstanceAdapterClass(final ProtectionDomain protectionDomain) {
CodeSource codeSource = protectionDomain.getCodeSource();
if(codeSource == null) {
codeSource = MINIMAL_PERMISSION_DOMAIN.getCodeSource();
}
StaticClass instanceAdapterClass = instanceAdapters.get(codeSource);
if(instanceAdapterClass != null) {
return instanceAdapterClass;
}
// Any "unknown source" code source will default to no permission domain.
final ProtectionDomain effectiveDomain = codeSource.equals(MINIMAL_PERMISSION_DOMAIN.getCodeSource()) ?
MINIMAL_PERMISSION_DOMAIN : protectionDomain;
instanceAdapterClass = instanceAdapterGenerator.generateClass(commonLoader, effectiveDomain);
final StaticClass existing = instanceAdapters.putIfAbsent(codeSource, instanceAdapterClass);
return existing == null ? instanceAdapterClass : existing;
}
示例3: INSTANCEOF
import jdk.internal.dynalink.beans.StaticClass; //导入依赖的package包/类
/**
* ECMA 11.8.6 - The strict instanceof operator - generic implementation
*
* @param obj first object to compare
* @param clazz type to check against
*
* @return true if {@code obj} is an instanceof {@code clazz}
*/
public static boolean INSTANCEOF(final Object obj, final Object clazz) {
if (clazz instanceof ScriptFunction) {
if (obj instanceof ScriptObject) {
return ((ScriptObject)clazz).isInstance((ScriptObject)obj);
}
return false;
}
if (clazz instanceof StaticClass) {
return ((StaticClass)clazz).getRepresentedClass().isInstance(obj);
}
if (clazz instanceof JSObject) {
return ((JSObject)clazz).isInstance(obj);
}
// provide for reverse hook
if (obj instanceof JSObject) {
return ((JSObject)obj).isInstanceOf(clazz);
}
throw typeError("instanceof.on.non.object");
}
示例4: generateDynamicListener
import jdk.internal.dynalink.beans.StaticClass; //导入依赖的package包/类
public Object generateDynamicListener(Map<StaticClass, Set<Consumer<? extends Event>>> map) {
Object o = null;
try {
byte[] b = generateDynamicListenerbc(map);
o = loadClass("cz.neumimto.rpg.listeners.DynamicListener", b);
Class<?> listener = Class.forName("cz.neumimto.rpg.listeners.DynamicListener");
o = listener.newInstance();
for (Field field : listener.getDeclaredFields()) {
if (Set.class.isAssignableFrom(field.getType())) {
Set s = (Set) field.get(o);
ParameterizedType paramtype = (ParameterizedType) field.getGenericType();
ParameterizedType type = (ParameterizedType) paramtype.getActualTypeArguments()[0];
Class<? extends Event> event = (Class<? extends Event>) type.getActualTypeArguments()[0];
map.entrySet().stream()
.filter(m -> m.getKey().getRepresentedClass() == event)
.forEach(a -> s.addAll(a.getValue()));
}
}
} catch (Exception e) {
e.printStackTrace();
}
return o;
}
示例5: noSuchProperty
import jdk.internal.dynalink.beans.StaticClass; //导入依赖的package包/类
/**
* Handle creation of new attribute.
* @param desc the call site descriptor
* @param request the link request
* @return Link to be invoked at call site.
*/
@Override
public GuardedInvocation noSuchProperty(final CallSiteDescriptor desc, final LinkRequest request) {
final String propertyName = desc.getNameToken(2);
final String fullName = name.isEmpty() ? propertyName : name + "." + propertyName;
final Context context = Context.getContextTrusted();
Class<?> javaClass = null;
try {
javaClass = context.findClass(fullName);
} catch (final NoClassDefFoundError | ClassNotFoundException e) {
//ignored
}
if (javaClass == null) {
set(propertyName, new NativeJavaPackage(fullName, getProto()), false);
} else {
set(propertyName, StaticClass.forClass(javaClass), false);
}
return super.lookup(desc, request);
}
示例6: createProperty
import jdk.internal.dynalink.beans.StaticClass; //导入依赖的package包/类
private Object createProperty(final String name) {
final int len = args.length;
for (int i = len - 1; i > -1; i--) {
final Object obj = args[i];
if (obj instanceof StaticClass) {
if (((StaticClass)obj).getRepresentedClass().getSimpleName().equals(name)) {
return obj;
}
} else if (obj instanceof NativeJavaPackage) {
final String pkgName = ((NativeJavaPackage)obj).getName();
final String fullName = pkgName.isEmpty() ? name : (pkgName + "." + name);
try {
return StaticClass.forClass(Class.forName(fullName));
} catch (final ClassNotFoundException e) {
// IGNORE
}
}
}
return null;
}
示例7: convert
import jdk.internal.dynalink.beans.StaticClass; //导入依赖的package包/类
/**
* Convert the given object to the given type.
*
* @param obj object to be converted
* @param type destination type to convert to
* @return converted object
*/
public static Object convert(final Object obj, final Object type) {
if (obj == null) {
return null;
}
final Class<?> clazz;
if (type instanceof Class) {
clazz = (Class<?>)type;
} else if (type instanceof StaticClass) {
clazz = ((StaticClass)type).getRepresentedClass();
} else {
throw new IllegalArgumentException("type expected");
}
final LinkerServices linker = Bootstrap.getLinkerServices();
final Object objToConvert = unwrap(obj);
final MethodHandle converter = linker.getTypeConverter(objToConvert.getClass(), clazz);
if (converter == null) {
// no supported conversion!
throw new UnsupportedOperationException("conversion not supported");
}
try {
return converter.invoke(objToConvert);
} catch (final RuntimeException | Error e) {
throw e;
} catch (final Throwable t) {
throw new RuntimeException(t);
}
}
示例8: typeName
import jdk.internal.dynalink.beans.StaticClass; //导入依赖的package包/类
/**
* Returns name of a java type {@link StaticClass}.
* @param self not used
* @param type the type whose name is returned
* @return name of the given type
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object typeName(final Object self, final Object type) {
if (type instanceof StaticClass) {
return ((StaticClass)type).getRepresentedClass().getName();
} else if (type instanceof Class) {
return ((Class<?>)type).getName();
} else {
return UNDEFINED;
}
}
示例9: getAdapterClassFor
import jdk.internal.dynalink.beans.StaticClass; //导入依赖的package包/类
private static StaticClass getAdapterClassFor(final Class<?>[] types, final ScriptObject classOverrides, final ProtectionDomain protectionDomain) {
assert types != null && types.length > 0;
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
for (final Class<?> type : types) {
// check for restricted package access
Context.checkPackageAccess(type);
// check for classes, interfaces in reflection
ReflectionCheckLinker.checkReflectionAccess(type, true);
}
}
return getAdapterInfo(types).getAdapterClass(classOverrides, protectionDomain);
}
示例10: getAdapterClass
import jdk.internal.dynalink.beans.StaticClass; //导入依赖的package包/类
StaticClass getAdapterClass(final ScriptObject classOverrides, final ProtectionDomain protectionDomain) {
if(adaptationResult.getOutcome() != AdaptationResult.Outcome.SUCCESS) {
throw adaptationResult.typeError();
}
return classOverrides == null ? getInstanceAdapterClass(protectionDomain) :
getClassAdapterClass(classOverrides, protectionDomain);
}
示例11: getClassAdapterClass
import jdk.internal.dynalink.beans.StaticClass; //导入依赖的package包/类
private StaticClass getClassAdapterClass(final ScriptObject classOverrides, final ProtectionDomain protectionDomain) {
JavaAdapterServices.setClassOverrides(classOverrides);
try {
return classAdapterGenerator.generateClass(commonLoader, protectionDomain);
} finally {
JavaAdapterServices.setClassOverrides(null);
}
}
示例12: isCallable
import jdk.internal.dynalink.beans.StaticClass; //导入依赖的package包/类
/**
* Returns if the given object is a "callable"
* @param obj object to be checked for callability
* @return true if the obj is callable
*/
public static boolean isCallable(final Object obj) {
if (obj == ScriptRuntime.UNDEFINED || obj == null) {
return false;
}
return obj instanceof ScriptFunction ||
isJSObjectFunction(obj) ||
BeansLinker.isDynamicMethod(obj) ||
obj instanceof BoundCallable ||
isFunctionalInterfaceObject(obj) ||
obj instanceof StaticClass;
}
示例13: isStrictCallable
import jdk.internal.dynalink.beans.StaticClass; //导入依赖的package包/类
/**
* Returns true if the given object is a strict callable
* @param callable the callable object to be checked for strictness
* @return true if the obj is a strict callable, false if it is a non-strict callable.
* @throws ECMAException with {@code TypeError} if the object is not a callable.
*/
public static boolean isStrictCallable(final Object callable) {
if (callable instanceof ScriptFunction) {
return ((ScriptFunction)callable).isStrict();
} else if (isJSObjectFunction(callable)) {
return ((JSObject)callable).isStrictFunction();
} else if (callable instanceof BoundCallable) {
return isStrictCallable(((BoundCallable)callable).getCallable());
} else if (BeansLinker.isDynamicMethod(callable) || callable instanceof StaticClass) {
return false;
}
throw notFunction(callable);
}
示例14: getGuardedInvocation
import jdk.internal.dynalink.beans.StaticClass; //导入依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception {
final LinkRequest request = linkRequest.withoutRuntimeContext(); // Nashorn has no runtime context
final Object self = request.getReceiver();
if (self.getClass() != StaticClass.class) {
return null;
}
final Class<?> receiverClass = ((StaticClass) self).getRepresentedClass();
Bootstrap.checkReflectionAccess(receiverClass, true);
final CallSiteDescriptor desc = request.getCallSiteDescriptor();
// We intercept "new" on StaticClass instances to provide additional capabilities
if ("new".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) {
if (! Modifier.isPublic(receiverClass.getModifiers())) {
throw ECMAErrors.typeError("new.on.nonpublic.javatype", receiverClass.getName());
}
// make sure new is on accessible Class
Context.checkPackageAccess(receiverClass);
// Is the class abstract? (This includes interfaces.)
if (NashornLinker.isAbstractClass(receiverClass)) {
// Change this link request into a link request on the adapter class.
final Object[] args = request.getArguments();
args[0] = JavaAdapterFactory.getAdapterClassFor(new Class<?>[] { receiverClass }, null,
linkRequest.getCallSiteDescriptor().getLookup());
final LinkRequest adapterRequest = request.replaceArguments(request.getCallSiteDescriptor(), args);
final GuardedInvocation gi = checkNullConstructor(delegate(linkerServices, adapterRequest), receiverClass);
// Finally, modify the guard to test for the original abstract class.
return gi.replaceMethods(gi.getInvocation(), Guards.getIdentityGuard(self));
}
// If the class was not abstract, just delegate linking to the standard StaticClass linker. Make an
// additional check to ensure we have a constructor. We could just fall through to the next "return"
// statement, except we also insert a call to checkNullConstructor() which throws an ECMAScript TypeError
// with a more intuitive message when no suitable constructor is found.
return checkNullConstructor(delegate(linkerServices, request), receiverClass);
}
// In case this was not a "new" operation, just delegate to the the standard StaticClass linker.
return delegate(linkerServices, request);
}
示例15: generateClass
import jdk.internal.dynalink.beans.StaticClass; //导入依赖的package包/类
/**
* Loads the generated adapter class into the JVM.
* @param parentLoader the parent class loader for the generated class loader
* @param protectionDomain the protection domain for the generated class
* @return the generated adapter class
*/
StaticClass generateClass(final ClassLoader parentLoader, final ProtectionDomain protectionDomain) {
assert protectionDomain != null;
return AccessController.doPrivileged(new PrivilegedAction<StaticClass>() {
@Override
public StaticClass run() {
try {
return StaticClass.forClass(Class.forName(className, true, createClassLoader(parentLoader, protectionDomain)));
} catch (final ClassNotFoundException e) {
throw new AssertionError(e); // cannot happen
}
}
}, CREATE_LOADER_ACC_CTXT);
}