private CodegenMethod getCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) throws PropertyAccessException { return codegenMethodScope.makeChild(Object.class, this.getClass(), codegenClassScope).addParam(Node.class, "node").getBlock() .declareVar(Object.class, "value", getter.underlyingGetCodegen(ref("node"), codegenMethodScope, codegenClassScope)) .methodReturn(staticMethod(this.getClass(), "getXPathNodeListWCheck", ref("value"), constant(index))); }
private CodegenMethod getCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { return codegenMethodScope.makeChild(Object.class, this.getClass(), codegenClassScope).addParam(EventBean.class, "theEvent").getBlock() .declareVarWCast(DecoratingEventBean.class, "wrapperEvent", "theEvent") .declareVar(Map.class, "map", exprDotMethod(ref("wrapperEvent"), "getDecoratingProperties")) .methodReturn(mapGetter.underlyingGetCodegen(ref("map"), codegenMethodScope, codegenClassScope)); }
private CodegenMethod getMapCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) throws PropertyAccessException { return codegenMethodScope.makeChild(Object.class, this.getClass(), codegenClassScope).addParam(Map.class, "map").getBlock() .declareVar(Object.class, "result", getterChain[0].underlyingGetCodegen(ref("map"), codegenMethodScope, codegenClassScope)) .methodReturn(localMethod(handleGetterTrailingChainCodegen(codegenMethodScope, codegenClassScope), ref("result"))); }
private CodegenMethod isMapExistsPropertyCodegen(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) throws PropertyAccessException { return codegenMethodScope.makeChild(boolean.class, this.getClass(), codegenClassScope).addParam(Map.class, "map").getBlock() .ifConditionReturnConst(getterChain[0].underlyingExistsCodegen(ref("map"), codegenMethodScope, codegenClassScope), false) .declareVar(Object.class, "result", getterChain[0].underlyingGetCodegen(ref("map"), codegenMethodScope, codegenClassScope)) .methodReturn(localMethod(handleIsExistsTrailingChainCodegen(codegenMethodScope, codegenClassScope), ref("result"))); }
private CodegenExpression codegenGet(Class requiredType, CodegenMethodScope codegenMethodScope, ExprForgeCodegenSymbol exprSymbol, CodegenClassScope codegenClassScope) { if (returnType == null) { return constantNull(); } Class castTargetType = getCodegenReturnType(requiredType); boolean useUnderlying = exprSymbol.isAllowUnderlyingReferences() && !identNode.getResolvedPropertyName().contains("?") && !(eventType instanceof WrapperEventType) && !(eventType instanceof VariantEventType); if (useUnderlying && !optionalEvent) { CodegenExpressionRef underlying = exprSymbol.getAddRequiredUnderlying(codegenMethodScope, streamNum, eventType, false); return CodegenLegoCast.castSafeFromObjectType(castTargetType, propertyGetter.underlyingGetCodegen(underlying, codegenMethodScope, codegenClassScope)); } CodegenMethod method = codegenMethodScope.makeChild(castTargetType, this.getClass(), codegenClassScope); CodegenBlock block = method.getBlock(); if (useUnderlying) { CodegenExpressionRef underlying = exprSymbol.getAddRequiredUnderlying(method, streamNum, eventType, true); block.ifRefNullReturnNull(underlying) .methodReturn(CodegenLegoCast.castSafeFromObjectType(castTargetType, propertyGetter.underlyingGetCodegen(underlying, method, codegenClassScope))); } else { CodegenExpressionRef refEPS = exprSymbol.getAddEPS(method); method.getBlock().declareVar(EventBean.class, "event", arrayAtIndex(refEPS, constant(streamNum))); if (optionalEvent) { block.ifRefNullReturnNull("event"); } block.methodReturn(CodegenLegoCast.castSafeFromObjectType(castTargetType, propertyGetter.eventBeanGetCodegen(ref("event"), method, codegenClassScope))); } return localMethod(method); }
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 < getterChain.length; i++) { block.ifRefNullReturnNull("result"); EventPropertyGetterSPI getter = getterChain[i]; CodegenBlock blockBean = block.ifInstanceOf("result", EventBean.class); blockBean.assignRef("result", getter.eventBeanGetCodegen(cast(EventBean.class, ref("result")), codegenMethodScope, codegenClassScope)); if (getter instanceof BeanEventPropertyGetter) { Class type = ((BeanEventPropertyGetter) getter).getTargetType(); blockBean.ifElse() .assignRef("result", getter.underlyingGetCodegen(cast(type, ref("result")), codegenMethodScope, codegenClassScope)) .blockEnd(); } else if (getter instanceof MapEventPropertyGetter) { blockBean.ifElse() .ifRefNotTypeReturnConst("result", Map.class, null) .assignRef("result", getter.underlyingGetCodegen(cast(Map.class, ref("result")), codegenMethodScope, codegenClassScope)) .blockEnd(); } else { blockBean.ifElse().blockReturn(constantNull()); } } return block.methodReturn(ref("result")); } }
public static CodegenMethod from(CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope, Class expectedUnderlyingType, EventPropertyGetterSPI innerGetter, AccessType accessType, Class generator) { CodegenMethod methodNode = codegenMethodScope.makeChild(accessType == AccessType.EXISTS ? boolean.class : Object.class, generator, codegenClassScope).addParam(Object.class, "value"); CodegenBlock block = methodNode.getBlock() .ifNotInstanceOf("value", expectedUnderlyingType) .ifInstanceOf("value", EventBean.class) .declareVarWCast(EventBean.class, "bean", "value"); if (accessType == AccessType.GET) { block = block.blockReturn(innerGetter.eventBeanGetCodegen(ref("bean"), codegenMethodScope, codegenClassScope)); } else if (accessType == AccessType.EXISTS) { block = block.blockReturn(innerGetter.eventBeanExistsCodegen(ref("bean"), codegenMethodScope, codegenClassScope)); } else if (accessType == AccessType.FRAGMENT) { block = block.blockReturn(innerGetter.eventBeanFragmentCodegen(ref("bean"), codegenMethodScope, codegenClassScope)); } else { throw new UnsupportedOperationException("Invalid access type " + accessType); } block = block.blockReturn(constant(accessType == AccessType.EXISTS ? false : null)); CodegenExpression expression; if (accessType == AccessType.GET) { expression = innerGetter.underlyingGetCodegen(cast(expectedUnderlyingType, ref("value")), codegenMethodScope, codegenClassScope); } else if (accessType == AccessType.EXISTS) { expression = innerGetter.underlyingExistsCodegen(cast(expectedUnderlyingType, ref("value")), codegenMethodScope, codegenClassScope); } else if (accessType == AccessType.FRAGMENT) { expression = innerGetter.underlyingFragmentCodegen(cast(expectedUnderlyingType, ref("value")), codegenMethodScope, codegenClassScope); } else { throw new UnsupportedOperationException("Invalid access type " + accessType); } block.methodReturn(expression); return methodNode; }
Class type = ((BeanEventPropertyGetter) getter).getTargetType(); blockBean.ifElse() .assignRef("result", getter.underlyingGetCodegen(cast(type, ref("result")), codegenMethodScope, codegenClassScope)) .blockEnd(); } else if (getter instanceof MapEventPropertyGetter) { blockBean.ifElse() .ifRefNotTypeReturnConst("result", Map.class, false) .assignRef("result", getter.underlyingGetCodegen(cast(Map.class, ref("result")), codegenMethodScope, codegenClassScope)) .blockEnd(); } else {
public static CodegenExpression codegenGetterMayMultiKeyWCoerce(EventType eventType, EventPropertyGetterSPI[] getters, Class[] types, Class[] optionalCoercionTypes, CodegenMethod method, Class generator, CodegenClassScope classScope) { if (getters.length == 1) { return codegenGetterWCoerce(getters[0], types[0], optionalCoercionTypes == null ? null : optionalCoercionTypes[0], method, generator, classScope); } CodegenExpressionNewAnonymousClass anonymous = newAnonymousClass(method.getBlock(), EventPropertyValueGetter.class); CodegenMethod get = CodegenMethod.makeParentNode(Object.class, generator, classScope).addParam(CodegenNamedParam.from(EventBean.class, "bean")); anonymous.addMethod("get", get); get.getBlock() .declareVar(eventType.getUnderlyingType(), "und", cast(eventType.getUnderlyingType(), exprDotUnderlying(ref("bean")))) .declareVar(Object[].class, "values", newArrayByLength(Object.class, constant(getters.length))) .declareVar(HashableMultiKey.class, "valuesMk", newInstance(HashableMultiKey.class, ref("values"))); for (int i = 0; i < getters.length; i++) { CodegenExpression result = getters[i].underlyingGetCodegen(ref("und"), get, classScope); Class typeBoxed = JavaClassHelper.getBoxedType(types[i]); if (optionalCoercionTypes != null && typeBoxed != JavaClassHelper.getBoxedType(optionalCoercionTypes[i])) { SimpleNumberCoercer coercer = SimpleNumberCoercerFactory.getCoercer(typeBoxed, JavaClassHelper.getBoxedType(optionalCoercionTypes[i])); get.getBlock().declareVar(typeBoxed, "prop_" + i, CodegenLegoCast.castSafeFromObjectType(typeBoxed, result)); result = coercer.coerceCodegen(ref("prop_" + i), typeBoxed); } get.getBlock().assignArrayElement("values", constant(i), result); } get.getBlock().methodReturn(ref("valuesMk")); return anonymous; }