Search in sources :

Example 1 with DirectNamedListProxy

use of org.apache.ignite.internal.configuration.direct.DirectNamedListProxy in project ignite-3 by apache.

the class DirectProxyAsmGenerator method addGetMethod.

/**
 * Generates getter based on the field.
 */
private void addGetMethod(Field schemaField) {
    Class<?> schemaFieldType = schemaField.getType();
    String fieldName = schemaField.getName();
    SchemaClassesInfo schemaClassInfo = cgen.schemaInfo(schemaFieldType);
    ParameterizedType returnType;
    // Return type is determined like in ConfigurationImpl class.
    if (isConfigValue(schemaField)) {
        returnType = typeFromJavaClassName(schemaClassInfo.cfgClassName);
    } else if (isNamedConfigValue(schemaField)) {
        returnType = type(NamedConfigurationTree.class);
    } else {
        assert isValue(schemaField) || isPolymorphicId(schemaField) || isInjectedName(schemaField) || isInternalId(schemaField) : schemaField;
        returnType = type(ConfigurationValue.class);
    }
    MethodDefinition methodDef = classDef.declareMethod(of(PUBLIC), fieldName, returnType);
    BytecodeBlock body = methodDef.getBody();
    if (isValue(schemaField) || isPolymorphicId(schemaField) || isInjectedName(schemaField) || isInternalId(schemaField)) {
        // new DirectValueProxy(appendKey(this.keys, new KeyPathNode("name")), changer);
        // or
        // new DirectValueProxy(appendKey(this.keys, new KeyPathNode("<internal_id>")), changer);
        body.append(newInstance(DirectValueProxy.class, invokeStatic(APPEND_KEY, methodDef.getThis().getField("keys", List.class), newInstance(KeyPathNode.class, constantString(isInjectedName(schemaField) ? InnerNode.INJECTED_NAME : isInternalId(schemaField) ? InnerNode.INTERNAL_ID : fieldName))), methodDef.getThis().getField("changer", DynamicConfigurationChanger.class)));
    } else {
        SchemaClassesInfo fieldSchemaClassInfo = cgen.schemaInfo(schemaField.getType());
        ParameterizedType resultType = typeFromJavaClassName(fieldSchemaClassInfo.directProxyClassName);
        if (isConfigValue(schemaField)) {
            // new BarDirectProxy(appendKey(this.keys, new KeyPathNode("name")), changer);
            body.append(newInstance(resultType, invokeStatic(APPEND_KEY, methodDef.getThis().getField("keys", List.class), newInstance(KeyPathNode.class, constantString(fieldName))), methodDef.getThis().getField("changer", DynamicConfigurationChanger.class)));
        } else {
            // new DirectNamedListProxy(appendKey(this.keys, new KeyPathNode("name")), changer, BarDirectProxy::new);
            body.append(newInstance(DirectNamedListProxy.class, invokeStatic(APPEND_KEY, methodDef.getThis().getField("keys", List.class), newInstance(KeyPathNode.class, constantString(fieldName))), methodDef.getThis().getField("changer", DynamicConfigurationChanger.class), newDirectProxyLambda(fieldSchemaClassInfo)));
        }
    }
    // Return object from the above.
    body.retObject();
}
Also used : ParameterizedType(com.facebook.presto.bytecode.ParameterizedType) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) DirectValueProxy(org.apache.ignite.internal.configuration.direct.DirectValueProxy) Arrays.asList(java.util.Arrays.asList) List(java.util.List) BytecodeExpressions.constantString(com.facebook.presto.bytecode.expression.BytecodeExpressions.constantString) KeyPathNode(org.apache.ignite.internal.configuration.direct.KeyPathNode) DirectNamedListProxy(org.apache.ignite.internal.configuration.direct.DirectNamedListProxy)

Aggregations

BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)1 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)1 ParameterizedType (com.facebook.presto.bytecode.ParameterizedType)1 BytecodeExpressions.constantString (com.facebook.presto.bytecode.expression.BytecodeExpressions.constantString)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 DirectNamedListProxy (org.apache.ignite.internal.configuration.direct.DirectNamedListProxy)1 DirectValueProxy (org.apache.ignite.internal.configuration.direct.DirectValueProxy)1 KeyPathNode (org.apache.ignite.internal.configuration.direct.KeyPathNode)1