MulOpAxis extends AbstractObAxis { @Override protected Type getReturnType(final int mOp1, final int mOp2) throws SirixXPathException { Type type1; Type type2; try { type1 = Type.getType(mOp1).getPrimitiveBaseType(); type2 = Type.getType(mOp2).getPrimitiveBaseType(); } catch (final IllegalStateException e) { throw new XPathError(ErrorType.XPTY0004); } if (type1.isNumericType() && type2.isNumericType()) { if (type1 == type2) { return type1; } if (type1 == Type.DOUBLE || type2 == Type.DOUBLE) { return Type.DOUBLE; } else if (type1 == Type.FLOAT || type2 == Type.FLOAT) { return Type.FLOAT; } else { assert (type1 == Type.DECIMAL || type2 == Type.DECIMAL); return Type.DECIMAL; } } else { switch (type1) { case YEAR_MONTH_DURATION: if (type2.isNumericType()) { return type1; } break; case DAY_TIME_DURATION: if (type2.isNumericType()) { return type1; } break; case DOUBLE: case FLOAT: case DECIMAL: case INTEGER: if (type2 == Type.DAY_TIME_DURATION || type2 == Type.YEAR_MONTH_DURATION) { return type2; } break; default: throw new XPathError(ErrorType.XPTY0004); } throw new XPathError(ErrorType.XPTY0004); } } MulOpAxis(final XmlNodeReadOnlyTrx rtx, final Axis mOp1, final Axis mOp2); @Override Node operate(final AtomicValue mOperand1, final AtomicValue mOperand2);  }
@Test public final void testGetReturnType() throws SirixException { AbstractAxis op1 = new SequenceAxis(holder.getXmlNodeReadTrx()); AbstractAxis op2 = new SequenceAxis(holder.getXmlNodeReadTrx()); AbstractObAxis axis = new MulOpAxis(holder.getXmlNodeReadTrx(), op1, op2); assertEquals( Type.DOUBLE, axis.getReturnType( holder.getXmlNodeReadTrx().keyForName("xs:double"), holder.getXmlNodeReadTrx().keyForName("xs:double"))); assertEquals( Type.DOUBLE, axis.getReturnType( holder.getXmlNodeReadTrx().keyForName("xs:decimal"), holder.getXmlNodeReadTrx().keyForName("xs:double"))); assertEquals( Type.FLOAT, axis.getReturnType( holder.getXmlNodeReadTrx().keyForName("xs:float"), holder.getXmlNodeReadTrx().keyForName("xs:decimal"))); assertEquals( Type.DECIMAL, axis.getReturnType( holder.getXmlNodeReadTrx().keyForName("xs:decimal"), holder.getXmlNodeReadTrx().keyForName("xs:integer"))); assertEquals( Type.YEAR_MONTH_DURATION, axis.getReturnType( holder.getXmlNodeReadTrx().keyForName("xs:yearMonthDuration"), holder.getXmlNodeReadTrx().keyForName("xs:double"))); assertEquals( Type.YEAR_MONTH_DURATION, axis.getReturnType( holder.getXmlNodeReadTrx().keyForName("xs:integer"), holder.getXmlNodeReadTrx().keyForName("xs:yearMonthDuration"))); assertEquals( Type.DAY_TIME_DURATION, axis.getReturnType( holder.getXmlNodeReadTrx().keyForName("xs:dayTimeDuration"), holder.getXmlNodeReadTrx().keyForName("xs:double"))); assertEquals( Type.DAY_TIME_DURATION, axis.getReturnType( holder.getXmlNodeReadTrx().keyForName("xs:integer"), holder.getXmlNodeReadTrx().keyForName("xs:dayTimeDuration"))); try { axis.getReturnType( holder.getXmlNodeReadTrx().keyForName("xs:dateTime"), holder.getXmlNodeReadTrx().keyForName("xs:yearMonthDuration")); fail("Expected an XPathError-Exception."); } catch (XPathError e) { assertThat( e.getMessage(), is( "err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules.")); } try { axis.getReturnType( holder.getXmlNodeReadTrx().keyForName("xs:dateTime"), holder.getXmlNodeReadTrx().keyForName("xs:double")); fail("Expected an XPathError-Exception."); } catch (XPathError e) { assertThat( e.getMessage(), is( "err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules.")); } try { axis.getReturnType( holder.getXmlNodeReadTrx().keyForName("xs:string"), holder.getXmlNodeReadTrx().keyForName("xs:yearMonthDuration")); fail("Expected an XPathError-Exception."); } catch (XPathError e) { assertThat( e.getMessage(), is( "err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules.")); } try { axis.getReturnType( holder.getXmlNodeReadTrx().keyForName("xs:yearMonthDuration"), holder.getXmlNodeReadTrx().keyForName("xs:yearMonthDuration")); fail("Expected an XPathError-Exception."); } catch (XPathError e) { assertThat( e.getMessage(), is( "err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules.")); } }