private CodegenMethod getMapCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { return codegenMethodScope.makeChild(Object.class, this.getClass(), codegenClassScope).addParam(Map.class, "map").getBlock() .declareVar(Object.class, "value", exprDotMethod(ref("map"), "get", constant(propertyMap))) .ifRefNullReturnNull("value") .ifInstanceOf("value", EventBean.class) .blockReturn(mapEntryGetter.eventBeanGetCodegen(castRef(EventBean.class, "value"), codegenMethodScope, codegenClassScope)) .methodReturn(mapEntryGetter.underlyingGetCodegen(castRef(mapEntryGetter.getTargetType(), "value"), codegenMethodScope, codegenClassScope)); }
private CodegenMethod navigateMethodCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { CodegenMethod navigateRecordMethod = navigateRecordMethodCodegen(codegenMethodScope, codegenClassScope); return codegenMethodScope.makeChild(GenericData.Record.class, this.getClass(), codegenClassScope).addParam(GenericData.Record.class, "record").getBlock() .declareVar(Object.class, "value", staticMethod(AvroEventBeanGetterNestedIndexRooted.class, "getAtIndex", ref("record"), constant(posTop), constant(index))) .ifRefNullReturnNull("value") .methodReturn(CodegenExpressionBuilder.localMethod(navigateRecordMethod, castRef(GenericData.Record.class, "value"))); }
private CodegenMethod handleIsExistsTrailingChainCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { CodegenBlock block = codegenMethodScope.makeChild(boolean.class, this.getClass(), codegenClassScope).addParam(Object.class, "result").getBlock(); for (int i = 1; i < mapGetterChain.length; i++) { block.ifRefNullReturnFalse("result"); MapEventPropertyGetter getter = mapGetterChain[i]; if (i == mapGetterChain.length - 1) { block.ifNotInstanceOf("result", Map.class) .ifInstanceOf("result", EventBean.class) .assignRef("result", getter.eventBeanExistsCodegen(castRef(EventBean.class, "result"), codegenMethodScope, codegenClassScope)) .ifElse() .blockReturn(constantFalse()) .ifElse() .blockReturn(getter.underlyingExistsCodegen(castRef(Map.class, "result"), codegenMethodScope, codegenClassScope)); } block.ifNotInstanceOf("result", Map.class) .ifInstanceOf("result", EventBean.class) .assignRef("result", getter.eventBeanGetCodegen(castRef(EventBean.class, "result"), codegenMethodScope, codegenClassScope)) .ifElse() .blockReturn(constantFalse()) .ifElse() .assignRef("result", getter.underlyingGetCodegen(castRef(Map.class, "result"), codegenMethodScope, codegenClassScope)) .blockEnd(); } return block.methodReturn(constantTrue()); }
private CodegenMethod handleGetterTrailingChainCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { CodegenBlock block = codegenMethodScope.makeChild(Object.class, this.getClass(), codegenClassScope).addParam(Object.class, "result").getBlock(); for (int i = 1; i < mapGetterChain.length; i++) { block.ifRefNullReturnNull("result"); MapEventPropertyGetter getter = mapGetterChain[i]; block.ifNotInstanceOf("result", Map.class) .ifInstanceOf("result", EventBean.class) .assignRef("result", getter.eventBeanGetCodegen(castRef(EventBean.class, "result"), codegenMethodScope, codegenClassScope)) .ifElse() .blockReturn(constantNull()) .ifElse() .assignRef("result", getter.underlyingGetCodegen(castRef(Map.class, "result"), codegenMethodScope, codegenClassScope)) .blockEnd(); } return block.methodReturn(ref("result")); } }
private CodegenMethod getMapMethodCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) throws PropertyAccessException { return codegenMethodScope.makeChild(Object.class, this.getClass(), codegenClassScope).addParam(Map.class, "map").getBlock() .declareVar(Object.class, "valueTopObj", exprDotMethod(ref("map"), "get", constant(propertyMap))) .ifRefNotTypeReturnConst("valueTopObj", Map.class, null) .declareVar(Map.class, "value", castRef(Map.class, "valueTopObj")) .methodReturn(getter.underlyingGetCodegen(ref("value"), codegenMethodScope, codegenClassScope)); }
private CodegenMethod isMapExistsPropertyCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) throws PropertyAccessException { return codegenMethodScope.makeChild(boolean.class, this.getClass(), codegenClassScope).addParam(Map.class, "map").getBlock() .declareVar(Object.class, "valueTopObj", exprDotMethod(ref("map"), "get", constant(propertyMap))) .ifRefNotTypeReturnConst("valueTopObj", Map.class, false) .declareVar(Map.class, "value", castRef(Map.class, "valueTopObj")) .methodReturn(getter.underlyingExistsCodegen(ref("value"), codegenMethodScope, codegenClassScope)); }
private CodegenMethod navigateRecordMethodCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { CodegenBlock block = codegenMethodScope.makeChild(GenericData.Record.class, this.getClass(), codegenClassScope).addParam(GenericData.Record.class, "record").getBlock() .declareVar(GenericData.Record.class, "current", ref("record")) .declareVarNull(Object.class, "value"); for (int i = 0; i < nested.length - 1; i++) { block.assignRef("value", nested[i].underlyingGetCodegen(ref("current"), codegenMethodScope, codegenClassScope)) .ifRefNotTypeReturnConst("value", GenericData.Record.class, null) .assignRef("current", castRef(GenericData.Record.class, "value")); } return block.methodReturn(ref("current")); } }
private CodegenMethod getObjectArrayCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { return codegenMethodScope.makeChild(Object.class, this.getClass(), codegenClassScope).addParam(Object[].class, "array").getBlock() .declareVar(Object.class, "value", arrayAtIndex(ref("array"), constant(propertyIndex))) .ifRefNullReturnNull("value") .ifInstanceOf("value", EventBean.class) .blockReturn(entryGetter.eventBeanGetCodegen(castRef(EventBean.class, "value"), codegenMethodScope, codegenClassScope)) .methodReturn(entryGetter.underlyingGetCodegen(cast(entryGetter.getTargetType(), ref("value")), codegenMethodScope, codegenClassScope)); }
private CodegenMethod isExistsPropertyCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { return codegenMethodScope.makeChild(boolean.class, this.getClass(), codegenClassScope).addParam(Object[].class, "array").getBlock() .declareVar(Object.class, "value", arrayAtIndex(ref("array"), constant(propertyIndex))) .ifRefNullReturnFalse("value") .ifInstanceOf("value", EventBean.class) .blockReturn(entryGetter.eventBeanExistsCodegen(castRef(EventBean.class, "value"), codegenMethodScope, codegenClassScope)) .methodReturn(entryGetter.underlyingExistsCodegen(cast(entryGetter.getTargetType(), ref("value")), codegenMethodScope, codegenClassScope)); }