use of com.google.spanner.v1.Type in project java-spanner by googleapis.
the class Type method fromProto.
static Type fromProto(com.google.spanner.v1.Type proto) {
Code type = Code.fromProto(proto.getCode(), proto.getTypeAnnotation());
switch(type) {
case BOOL:
return bool();
case INT64:
return int64();
case FLOAT64:
return float64();
case NUMERIC:
return numeric();
case PG_NUMERIC:
return pgNumeric();
case STRING:
return string();
case JSON:
return json();
case BYTES:
return bytes();
case TIMESTAMP:
return timestamp();
case DATE:
return date();
case ARRAY:
checkArgument(proto.hasArrayElementType(), "Missing expected 'array_element_type' field in 'Type' message: %s", proto);
Type elementType;
try {
elementType = fromProto(proto.getArrayElementType());
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Could not parse 'array_element_type' attribute in 'Type' message: " + proto, e);
}
return array(elementType);
case STRUCT:
checkArgument(proto.hasStructType(), "Missing expected 'struct_type' field in 'Type' message: %s", proto);
List<StructField> fields = new ArrayList<>(proto.getStructType().getFieldsCount());
for (com.google.spanner.v1.StructType.Field field : proto.getStructType().getFieldsList()) {
checkArgument(field.hasType(), "Missing expected 'type' attribute in 'Field': %s", proto);
// Names may be empty; for example, the name of the column returned by "SELECT 1".
String name = Strings.nullToEmpty(field.getName());
fields.add(StructField.of(name, fromProto(field.getType())));
}
return struct(fields);
default:
throw new AssertionError("Unimplemented case: " + type);
}
}
use of com.google.spanner.v1.Type in project openwebbeans by apache.
the class NormalScopeProxyFactory method delegateNonInterceptedMethods.
@Override
protected void delegateNonInterceptedMethods(ClassLoader classLoader, ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] noninterceptedMethods) throws ProxyGenerationException {
for (Method delegatedMethod : noninterceptedMethods) {
if (isIgnoredMethod(delegatedMethod)) {
return;
}
String methodDescriptor = Type.getMethodDescriptor(delegatedMethod);
// X TODO handle generic exception types?
Class[] exceptionTypes = delegatedMethod.getExceptionTypes();
String[] exceptionTypeNames = new String[exceptionTypes.length];
for (int i = 0; i < exceptionTypes.length; i++) {
exceptionTypeNames[i] = Type.getType(exceptionTypes[i]).getInternalName();
}
int targetModifiers = delegatedMethod.getModifiers() & (Modifier.PROTECTED | Modifier.PUBLIC | MODIFIER_VARARGS);
MethodVisitor mv = cw.visitMethod(targetModifiers, delegatedMethod.getName(), methodDescriptor, null, exceptionTypeNames);
// fill method body
mv.visitCode();
// load the contextual instance Provider
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, proxyClassFileName, FIELD_INSTANCE_PROVIDER, Type.getDescriptor(Provider.class));
// invoke the get() method on the Provider
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Provider.class), "get", "()Ljava/lang/Object;", true);
// and convert the Object to the target class type
mv.visitTypeInsn(Opcodes.CHECKCAST, Type.getInternalName(classToProxy));
// now calculate the parameters
int offset = 1;
for (Class<?> aClass : delegatedMethod.getParameterTypes()) {
Type type = Type.getType(aClass);
mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), offset);
offset += type.getSize();
}
// and finally invoke the target method on the provided Contextual Instance
Type declaringClass = Type.getType(delegatedMethod.getDeclaringClass());
boolean interfaceMethod = Modifier.isInterface(delegatedMethod.getDeclaringClass().getModifiers());
mv.visitMethodInsn(interfaceMethod ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL, declaringClass.getInternalName(), delegatedMethod.getName(), methodDescriptor, interfaceMethod);
generateReturn(mv, delegatedMethod);
mv.visitMaxs(-1, -1);
mv.visitEnd();
}
}
use of com.google.spanner.v1.Type in project osate2 by osate.
the class TypedElementImpl method setType.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setType(Type newType) {
Type oldType = type;
type = newType;
if (eNotificationRequired()) {
eNotify(new ENotificationImpl(this, Notification.SET, Aadl2Package.TYPED_ELEMENT__TYPE, oldType, type));
}
}
use of com.google.spanner.v1.Type in project cel-java by projectnessie.
the class CELTest method GlobalVars.
@Test
void GlobalVars() {
Type mapStrDyn = Decls.newMapType(Decls.String, Decls.Dyn);
Env e = newEnv(declarations(Decls.newVar("attrs", mapStrDyn), Decls.newVar("default", Decls.Dyn), Decls.newFunction("get", Decls.newInstanceOverload("get_map", asList(mapStrDyn, Decls.String, Decls.Dyn), Decls.Dyn))));
AstIssuesTuple astIss = e.compile("attrs.get(\"first\", attrs.get(\"second\", default))");
// Create the program.
ProgramOption funcs = functions(Overload.function("get", args -> {
if (args.length != 3) {
return newErr("invalid arguments to 'get'");
}
if (!(args[0] instanceof Mapper)) {
return newErr("invalid operand of type '%s' to obj.get(key, def)", args[0].type());
}
Mapper attrs = (Mapper) args[0];
if (!(args[1] instanceof StringT)) {
return newErr("invalid key of type '%s' to obj.get(key, def)", args[1].type());
}
StringT key = (StringT) args[1];
Val defVal = args[2];
if (attrs.contains(key) == True) {
return attrs.get(key);
}
return defVal;
}));
// Global variables can be configured as a ProgramOption and optionally overridden on Eval.
Program prg = e.program(astIss.getAst(), funcs, globals(mapOf("default", "third")));
// t.Run("global_default", func(t *testing.T) {
Object vars = mapOf("attrs", mapOf());
EvalResult out = prg.eval(vars);
assertThat(out.getVal().equal(stringOf("third"))).isSameAs(True);
// })
// t.Run("attrs_alt", func(t *testing.T) {
vars = mapOf("attrs", mapOf("second", "yep"));
out = prg.eval(vars);
assertThat(out.getVal().equal(stringOf("yep"))).isSameAs(True);
// })
// t.Run("local_default", func(t *testing.T) {
vars = mapOf("attrs", mapOf(), "default", "fourth");
out = prg.eval(vars);
assertThat(out.getVal().equal(stringOf("fourth"))).isSameAs(True);
// })
}
use of com.google.spanner.v1.Type in project cel-java by projectnessie.
the class ProtoTypeRegistry method register.
@Override
public void register(Object t) {
if (t instanceof Message) {
Set<FileDescriptor> fds = collectFileDescriptorSet((Message) t);
for (FileDescriptor fd : fds) {
registerDescriptor(fd);
}
registerMessage((Message) t);
} else if (t instanceof org.projectnessie.cel.common.types.ref.Type) {
registerType((org.projectnessie.cel.common.types.ref.Type) t);
} else {
throw new RuntimeException(String.format("unsupported type: %s", t.getClass().getName()));
}
}
Aggregations