Search in sources :

Example 6 with Type

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);
    }
}
Also used : ArrayList(java.util.ArrayList) TypeCode(com.google.spanner.v1.TypeCode) TypeAnnotationCode(com.google.spanner.v1.TypeAnnotationCode)

Example 7 with 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();
    }
}
Also used : Type(org.apache.xbean.asm9.Type) Method(java.lang.reflect.Method) MethodVisitor(org.apache.xbean.asm9.MethodVisitor) Provider(javax.inject.Provider)

Example 8 with Type

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));
    }
}
Also used : Type(org.osate.aadl2.Type) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 9 with 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);
// })
}
Also used : BoolT(org.projectnessie.cel.common.types.BoolT) Interpretable(org.projectnessie.cel.interpreter.Interpretable) Macro(org.projectnessie.cel.parser.Macro) Call(com.google.api.expr.v1alpha1.Expr.Call) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PartialActivation(org.projectnessie.cel.interpreter.Activation.PartialActivation) EnvOption.container(org.projectnessie.cel.EnvOption.container) Macro.newReceiverMacro(org.projectnessie.cel.parser.Macro.newReceiverMacro) Activation.emptyActivation(org.projectnessie.cel.interpreter.Activation.emptyActivation) Disabled(org.junit.jupiter.api.Disabled) InterpretableDecorator(org.projectnessie.cel.interpreter.InterpretableDecorator) Collections.singletonList(java.util.Collections.singletonList) True(org.projectnessie.cel.common.types.BoolT.True) Err.isError(org.projectnessie.cel.common.types.Err.isError) Container(org.projectnessie.cel.common.types.traits.Container) Arrays.asList(java.util.Arrays.asList) CEL.estimateCost(org.projectnessie.cel.CEL.estimateCost) OptPartialEval(org.projectnessie.cel.EvalOption.OptPartialEval) ProtoTypeRegistry.newEmptyRegistry(org.projectnessie.cel.common.types.pb.ProtoTypeRegistry.newEmptyRegistry) ParsedExpr(com.google.api.expr.v1alpha1.ParsedExpr) EnvOption.customTypeProvider(org.projectnessie.cel.EnvOption.customTypeProvider) Val(org.projectnessie.cel.common.types.ref.Val) TypeRegistry(org.projectnessie.cel.common.types.ref.TypeRegistry) InterpretableAttribute(org.projectnessie.cel.interpreter.Interpretable.InterpretableAttribute) Collections.emptyList(java.util.Collections.emptyList) Expr(com.google.api.expr.v1alpha1.Expr) Ident(com.google.api.expr.v1alpha1.Expr.Ident) InterpretableCall(org.projectnessie.cel.interpreter.Interpretable.InterpretableCall) OptExhaustiveEval(org.projectnessie.cel.EvalOption.OptExhaustiveEval) OptTrackState(org.projectnessie.cel.EvalOption.OptTrackState) StringT.stringOf(org.projectnessie.cel.common.types.StringT.stringOf) Decls(org.projectnessie.cel.checker.Decls) CEL.attributePattern(org.projectnessie.cel.CEL.attributePattern) Executors(java.util.concurrent.Executors) Test(org.junit.jupiter.api.Test) ProgramOption.functions(org.projectnessie.cel.ProgramOption.functions) DefaultTypeAdapter(org.projectnessie.cel.common.types.pb.DefaultTypeAdapter) Overload(org.projectnessie.cel.interpreter.functions.Overload) EvalResult(org.projectnessie.cel.Program.EvalResult) Err.newErr(org.projectnessie.cel.common.types.Err.newErr) IntOne(org.projectnessie.cel.common.types.IntT.IntOne) IntStream(java.util.stream.IntStream) Overloads(org.projectnessie.cel.common.types.Overloads) Env.newEnv(org.projectnessie.cel.Env.newEnv) StdLib(org.projectnessie.cel.Library.StdLib) IntT(org.projectnessie.cel.common.types.IntT) Trait(org.projectnessie.cel.common.types.traits.Trait) EnvOption.declarations(org.projectnessie.cel.EnvOption.declarations) CompletableFuture(java.util.concurrent.CompletableFuture) Err.valOrErr(org.projectnessie.cel.common.types.Err.valOrErr) CEL.partialVars(org.projectnessie.cel.CEL.partialVars) AtomicReference(java.util.concurrent.atomic.AtomicReference) EnvOption.customTypeAdapter(org.projectnessie.cel.EnvOption.customTypeAdapter) AstIssuesTuple(org.projectnessie.cel.Env.AstIssuesTuple) Mapper(org.projectnessie.cel.common.types.traits.Mapper) ProgramOption.evalOptions(org.projectnessie.cel.ProgramOption.evalOptions) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Type(com.google.api.expr.v1alpha1.Type) CEL.astToCheckedExpr(org.projectnessie.cel.CEL.astToCheckedExpr) CEL.noVars(org.projectnessie.cel.CEL.noVars) ExecutorService(java.util.concurrent.ExecutorService) Collections.emptyMap(java.util.Collections.emptyMap) CEL.astToString(org.projectnessie.cel.CEL.astToString) ProgramOption.globals(org.projectnessie.cel.ProgramOption.globals) Operator(org.projectnessie.cel.common.operators.Operator) NamespacedAttribute(org.projectnessie.cel.interpreter.AttributeFactory.NamespacedAttribute) UnknownT(org.projectnessie.cel.common.types.UnknownT) Cost(org.projectnessie.cel.interpreter.Coster.Cost) EnvOption.types(org.projectnessie.cel.EnvOption.types) ProgramOption.customDecorator(org.projectnessie.cel.ProgramOption.customDecorator) EnvOption.macros(org.projectnessie.cel.EnvOption.macros) Interpretable.newConstValue(org.projectnessie.cel.interpreter.Interpretable.newConstValue) CheckedExpr(com.google.api.expr.v1alpha1.CheckedExpr) CEL.parsedExprToAst(org.projectnessie.cel.CEL.parsedExprToAst) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) InterpretableConst(org.projectnessie.cel.interpreter.Interpretable.InterpretableConst) CEL.astToParsedExpr(org.projectnessie.cel.CEL.astToParsedExpr) CEL.checkedExprToAst(org.projectnessie.cel.CEL.checkedExprToAst) EvalState(org.projectnessie.cel.interpreter.EvalState) Util.mapOf(org.projectnessie.cel.Util.mapOf) StringT(org.projectnessie.cel.common.types.StringT) EnvOption.homogeneousAggregateLiterals(org.projectnessie.cel.EnvOption.homogeneousAggregateLiterals) Env.newCustomEnv(org.projectnessie.cel.Env.newCustomEnv) EnvOption.abbrevs(org.projectnessie.cel.EnvOption.abbrevs) Val(org.projectnessie.cel.common.types.ref.Val) Mapper(org.projectnessie.cel.common.types.traits.Mapper) Type(com.google.api.expr.v1alpha1.Type) EvalResult(org.projectnessie.cel.Program.EvalResult) Env.newEnv(org.projectnessie.cel.Env.newEnv) Env.newCustomEnv(org.projectnessie.cel.Env.newCustomEnv) AstIssuesTuple(org.projectnessie.cel.Env.AstIssuesTuple) StringT(org.projectnessie.cel.common.types.StringT) Test(org.junit.jupiter.api.Test)

Example 10 with Type

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()));
    }
}
Also used : DoubleType(org.projectnessie.cel.common.types.DoubleT.DoubleType) IntType(org.projectnessie.cel.common.types.IntT.IntType) MapType(org.projectnessie.cel.common.types.MapT.MapType) FieldType(org.projectnessie.cel.common.types.ref.FieldType) Err.anyWithEmptyType(org.projectnessie.cel.common.types.Err.anyWithEmptyType) DurationType(org.projectnessie.cel.common.types.DurationT.DurationType) UintType(org.projectnessie.cel.common.types.UintT.UintType) TypeType(org.projectnessie.cel.common.types.TypeT.TypeType) JavaType(com.google.protobuf.Descriptors.FieldDescriptor.JavaType) StringType(org.projectnessie.cel.common.types.StringT.StringType) NullType(org.projectnessie.cel.common.types.NullT.NullType) Type(com.google.api.expr.v1alpha1.Type) BytesType(org.projectnessie.cel.common.types.BytesT.BytesType) ListType(org.projectnessie.cel.common.types.ListT.ListType) BoolType(org.projectnessie.cel.common.types.BoolT.BoolType) Err.unknownType(org.projectnessie.cel.common.types.Err.unknownType) TimestampType(org.projectnessie.cel.common.types.TimestampT.TimestampType) PbTypeDescription.typeNameFromMessage(org.projectnessie.cel.common.types.pb.PbTypeDescription.typeNameFromMessage) Message(com.google.protobuf.Message) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor)

Aggregations

Type (com.google.api.expr.v1alpha1.Type)30 Test (org.junit.Test)22 Type (edu.stanford.CVC4.Type)14 ArrayList (java.util.ArrayList)14 ByteString (com.google.protobuf.ByteString)13 Type (com.google.spanner.v1.Type)12 ArrayType (edu.stanford.CVC4.ArrayType)11 BitVectorType (edu.stanford.CVC4.BitVectorType)11 Expr (edu.stanford.CVC4.Expr)11 MapType (com.google.api.expr.v1alpha1.Type.MapType)10 Type (org.apache.xbean.asm9.Type)10 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)9 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)9 CheckedExpr (com.google.api.expr.v1alpha1.CheckedExpr)8 FieldType (org.projectnessie.cel.common.types.ref.FieldType)8 FormulaType (org.sosy_lab.java_smt.api.FormulaType)8 ListValue (com.google.protobuf.ListValue)7 CheckerEnv.dynElementType (org.projectnessie.cel.checker.CheckerEnv.dynElementType)7 CheckerEnv.getObjectWellKnownType (org.projectnessie.cel.checker.CheckerEnv.getObjectWellKnownType)7 CheckerEnv.isObjectWellKnownType (org.projectnessie.cel.checker.CheckerEnv.isObjectWellKnownType)7