All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.graalvm.polyglot.impl.ModuleToUnnamedByteSequenceGen Maven / Gradle / Ivy
package org.graalvm.polyglot.impl;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Objects;
import java.util.stream.IntStream;
import org.graalvm.polyglot.impl.ModuleToUnnamedBridge.ModuleToUnnamedByteSequence;
import org.graalvm.polyglot.io.ByteSequence;
/**
* Generated code used for Truffle unnamed to named module bridge.
* This code allows polyglot on the classpath to delegate to polyglot on the module-path.
* This code is generated by the polyglot annotation processor.asdf
*/
final class ModuleToUnnamedByteSequenceGen extends ModuleToUnnamedByteSequence {
private static final Handles HANDLES;
static {
Lookup lookup = methodHandleLookup();
if (lookup != null) {
try {
HANDLES = new Handles(lookup);
} catch (ReflectiveOperationException e) {
throw new InternalError("Failed to initialize method handles for module bridge.", e);
}
} else {
HANDLES = null;
}
}
final Object receiver;
public ModuleToUnnamedByteSequenceGen(Object receiver) {
this.receiver = Objects.requireNonNull(receiver);
}
@Override
public byte byteAt(int index_) {
try {
byte result = (byte) HANDLES.byteAt_.invoke(receiver, index_);
return result;
} catch (Throwable t) {
throw handleException_(t);
}
}
@Override
public IntStream bytes() {
try {
IntStream result = (IntStream) HANDLES.bytes_.invoke(receiver);
return result;
} catch (Throwable t) {
throw handleException_(t);
}
}
@Override
public boolean equals(Object obj_) {
try {
boolean result = (boolean) HANDLES.equals_.invoke(receiver, obj_);
return result;
} catch (Throwable t) {
throw handleException_(t);
}
}
@Override
public int hashCode() {
try {
int result = (int) HANDLES.hashCode_.invoke(receiver);
return result;
} catch (Throwable t) {
throw handleException_(t);
}
}
@Override
public int length() {
try {
int result = (int) HANDLES.length_.invoke(receiver);
return result;
} catch (Throwable t) {
throw handleException_(t);
}
}
@Override
public ByteSequence subSequence(int startIndex_, int endIndex_) {
try {
Object result = HANDLES.subSequence_.invoke(receiver, startIndex_, endIndex_);
return ModuleToUnnamedByteSequence.fromByteSequence(result);
} catch (Throwable t) {
throw handleException_(t);
}
}
@Override
public byte[] toByteArray() {
try {
byte[] result = (byte[]) HANDLES.toByteArray_.invoke(receiver);
return result;
} catch (Throwable t) {
throw handleException_(t);
}
}
@Override
public String toString() {
try {
String result = (String) HANDLES.toString_.invoke(receiver);
return result;
} catch (Throwable t) {
throw handleException_(t);
}
}
@SuppressWarnings("unchecked")
private static RuntimeException handleException_(Throwable t) throws T {
throw (T)t;
}
static final class Handles extends Object {
private final MethodHandle byteAt_;
private final MethodHandle bytes_;
private final MethodHandle equals_;
private final MethodHandle hashCode_;
private final MethodHandle length_;
private final MethodHandle subSequence_;
private final MethodHandle toByteArray_;
private final MethodHandle toString_;
Handles(Lookup lookup) throws ReflectiveOperationException {
Class> typeByteSequence_ = lookup.findClass(ByteSequence.class.getName());
Class> typeByteSequence = lookup.findClass(ByteSequence.class.getName());
Class> typeObject = lookup.findClass(Object.class.getName());
this.byteAt_ = lookup.findVirtual(typeByteSequence, "byteAt", MethodType.methodType(byte.class, List.of(int.class)));
this.bytes_ = lookup.findVirtual(typeByteSequence, "bytes", MethodType.methodType(IntStream.class, List.of()));
this.equals_ = lookup.findVirtual(typeObject, "equals", MethodType.methodType(boolean.class, List.of(Object.class)));
this.hashCode_ = lookup.findVirtual(typeObject, "hashCode", MethodType.methodType(int.class, List.of()));
this.length_ = lookup.findVirtual(typeByteSequence, "length", MethodType.methodType(int.class, List.of()));
this.subSequence_ = lookup.findVirtual(typeByteSequence, "subSequence", MethodType.methodType(typeByteSequence_, List.of(int.class, int.class)));
this.toByteArray_ = lookup.findVirtual(typeByteSequence, "toByteArray", MethodType.methodType(byte[].class, List.of()));
this.toString_ = lookup.findVirtual(typeObject, "toString", MethodType.methodType(String.class, List.of()));
}
}
}