Parse tree evaluation - most of it.
diff --git a/tests/org.eclipse.jem.tests/javatests/TestCtorWithNull.java b/tests/org.eclipse.jem.tests/javatests/TestCtorWithNull.java new file mode 100644 index 0000000..e72e97f --- /dev/null +++ b/tests/org.eclipse.jem.tests/javatests/TestCtorWithNull.java
@@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +/* + * $RCSfile: TestCtorWithNull.java,v $ + * $Revision: 1.1 $ $Date: 2004/02/03 23:18:13 $ + */ + +/** + * + * @since 1.0.0 + */ +public class TestCtorWithNull { + + public TestCtorWithNull(String x) { + // This is just a test to see that ctor will be selected if it has a null passed in for Tree Expression Processing. + } + +}
diff --git a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/instantiation/TestStandard.java b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/instantiation/TestStandard.java index 921b9e7..6c7aeff 100644 --- a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/instantiation/TestStandard.java +++ b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/instantiation/TestStandard.java
@@ -172,10 +172,10 @@ pw.println( "<xmi:XMI xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:_-javaprim=\"java:/\" xmlns:org.eclipse.jem.internal.instantiation=\"http:///org/eclipse/jem/internal/instantiation.ecore\" xmlns:org.eclipse.jem.tests.beaninfo=\"java:/org.eclipse.jem.tests.beaninfo\">"); pw.println(" <org.eclipse.jem.tests.beaninfo:Test1Class set=\"/1\">"); - pw.println(" <allocation xsi:type=\"org.eclipse.jem.internal.instantiation:InitStringAllocation\" allocString=\"new Test1Class()\" initString=\"new Test1Class()\"/>"); + pw.println(" <allocation xsi:type=\"org.eclipse.jem.internal.instantiation:InitStringAllocation\" initString=\"new Test1Class()\"/>"); pw.println(" </org.eclipse.jem.tests.beaninfo:Test1Class>"); pw.println(" <_-javaprim:boolean>"); - pw.println(" <allocation xsi:type=\"org.eclipse.jem.internal.instantiation:InitStringAllocation\" allocString=\"true\" initString=\"true\"/>"); + pw.println(" <allocation xsi:type=\"org.eclipse.jem.internal.instantiation:InitStringAllocation\" initString=\"true\"/>"); pw.println(" </_-javaprim:boolean>"); pw.println("</xmi:XMI>"); pw.close();
diff --git a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/ExpressionTest.java b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/ExpressionTest.java new file mode 100644 index 0000000..247c473 --- /dev/null +++ b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/ExpressionTest.java
@@ -0,0 +1,1158 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +/* + * $RCSfile: ExpressionTest.java,v $ + * $Revision: 1.1 $ $Date: 2004/02/03 23:18:13 $ + */ +package org.eclipse.jem.tests.proxy; + +import org.eclipse.jem.internal.proxy.core.*; +import org.eclipse.jem.internal.proxy.initParser.tree.IExpressionConstants; +import org.eclipse.jem.internal.proxy.initParser.tree.IExpressionConstants.NoExpressionValueException; + +/** + * + * @since 1.0.0 + */ +public class ExpressionTest extends AbstractTestProxy { + + /** + * + * + * @since 1.0.0 + */ + public ExpressionTest() { + super(); + } + + /** + * @param name + * + * @since 1.0.0 + */ + public ExpressionTest(String name) { + super(name); + } + + public void testCastStringType() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createCastExpression(IExpressionConstants.ROOTEXPRESSION, "short"); + exp.createPrimitiveLiteral(IExpressionConstants.CAST_EXPRESSION, 10l); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("short", result.getTypeProxy().getTypeName()); + assertEquals((short) 10, ((INumberBeanProxy) result).shortValue()); + } + + public void testCastProxyType() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createCastExpression(IExpressionConstants.ROOTEXPRESSION, proxyTypeFactory.getBeanTypeProxy("short")); + exp.createPrimitiveLiteral(IExpressionConstants.CAST_EXPRESSION, 'a'); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("short", result.getTypeProxy().getTypeName()); + assertEquals((short) 'a', ((INumberBeanProxy) result).shortValue()); + } + + public void testCastError() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createCastExpression(IExpressionConstants.ROOTEXPRESSION, proxyTypeFactory.getBeanTypeProxy("short")); + try { + exp.createProxyExpression(IExpressionConstants.CAST_EXPRESSION, proxyFactory.createBeanProxyWith(Boolean.TRUE)); + exp.getExpressionValue(); + fail("Should of thrown ClassCastException"); + } catch (ThrowableProxy e) { + if (!e.getTypeProxy().getFormalTypeName().equals("java.lang.ClassCastException")) + throw e; // Some other exception, rethrow it. + } + } + + public void testCastFailed() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createCastExpression(IExpressionConstants.ROOTEXPRESSION, proxyTypeFactory.getBeanTypeProxy("short")); + try { + exp.getExpressionValue(); + fail("Should of gotton IllegalStateException"); + } catch (IllegalStateException e) { + System.out.println(e.getLocalizedMessage()); + } + } + + public void testInstanceofStringType() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInstanceofExpression(IExpressionConstants.ROOTEXPRESSION, "java.lang.String"); + exp.createStringLiteral(IExpressionConstants.INSTANCEOF_VALUE, "asdf"); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(true, ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testInstanceofProxyType() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInstanceofExpression(IExpressionConstants.ROOTEXPRESSION, proxyTypeFactory.getBeanTypeProxy("java.lang.String")); + exp.createStringLiteral(IExpressionConstants.INSTANCEOF_VALUE, "asdf"); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(true, ((IBooleanBeanProxy) result).booleanValue()); + + } + + public void testInstanceofFailed() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInstanceofExpression(IExpressionConstants.ROOTEXPRESSION, proxyTypeFactory.getBeanTypeProxy("java.lang.String")); + try { + exp.getExpressionValue(); + fail("Should of gotton IllegalStateException"); + } catch (IllegalStateException e) { + System.out.println(e.getLocalizedMessage()); + } + } + + public void testTypeLiteral() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createTypeLiteral(IExpressionConstants.ROOTEXPRESSION, "java.lang.String"); + IBeanProxy result = exp.getExpressionValue(); + assertTrue("Not a bean type proxy.", result instanceof IBeanTypeProxy); + IBeanTypeProxy type = (IBeanTypeProxy) result; + assertTrue("Not valid.", type.isValid()); + assertEquals("java.lang.String", type.getFormalTypeName()); + } + + public void testTypeFails() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + try { + exp.createTypeLiteral(IExpressionConstants.ROOTEXPRESSION, "java.lang.Stng"); + exp.getExpressionValue(); + fail("Should not of gotton a result."); + } catch (ThrowableProxy e) { + System.out.println(e.getProxyLocalizedMessage()); + } + } + + public void testNesting() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInstanceofExpression(IExpressionConstants.ROOTEXPRESSION, "short"); + exp.createCastExpression(IExpressionConstants.INSTANCEOF_VALUE, "short"); + exp.createPrimitiveLiteral(IExpressionConstants.CAST_EXPRESSION, (short) 10); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(true, ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testPrefixPlus() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createPrefixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.PRE_PLUS); + exp.createPrimitiveLiteral(IExpressionConstants.PREFIX_OPERAND, 10); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals(10, ((INumberBeanProxy) result).intValue()); + + } + + public void testPrefixMinus() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createPrefixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.PRE_MINUS); + exp.createPrimitiveLiteral(IExpressionConstants.PREFIX_OPERAND, 10); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals(-10, ((INumberBeanProxy) result).intValue()); + + } + + public void testPrefixMinusChar() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createPrefixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.PRE_MINUS); + exp.createPrimitiveLiteral(IExpressionConstants.PREFIX_OPERAND, 'a'); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals(-'a', ((INumberBeanProxy) result).intValue()); + + } + + public void testPrefixComplement() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createPrefixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.PRE_COMPLEMENT); + exp.createPrimitiveLiteral(IExpressionConstants.PREFIX_OPERAND, (short) 10); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals(~10, ((INumberBeanProxy) result).intValue()); + + } + + public void testPrefixNot() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createPrefixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.PRE_NOT); + exp.createPrimitiveLiteral(IExpressionConstants.PREFIX_OPERAND, true); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(false, ((IBooleanBeanProxy) result).booleanValue()); + + } + + public void testPrefixFail() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createPrefixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.PRE_NOT); + try { + exp.createPrimitiveLiteral(IExpressionConstants.PREFIX_OPERAND, 10); + exp.getExpressionValue(); + fail("Should of failed."); + } catch (ThrowableProxy e) { + System.out.println(e.getProxyLocalizedMessage()); + } + + } + + public void testTimes() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_TIMES, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 3); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 4); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals(3*4, ((INumberBeanProxy) result).intValue()); + + } + + public void testTimesExtended() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_TIMES, 1); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 3); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 4); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_EXTENDED, 5d); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("double", result.getTypeProxy().getTypeName()); + assertEquals((3*4*5d), ((INumberBeanProxy) result).doubleValue(), 0); + + } + + public void testTimesExtendedNested() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_TIMES, 1); + exp.createInfixExpression(IExpressionConstants.INFIX_LEFT, IExpressionConstants.IN_MINUS, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 10); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 5); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 4); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_EXTENDED, 5d); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("double", result.getTypeProxy().getTypeName()); + assertEquals(((10-5)*4*5d), ((INumberBeanProxy) result).doubleValue(), 0); + + } + + public void testDivide() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_DIVIDE, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 4); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 2); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals(4/2, ((INumberBeanProxy) result).intValue()); + + } + + public void testDivideExtended() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_DIVIDE, 1); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 12); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_EXTENDED, 2d); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("double", result.getTypeProxy().getTypeName()); + assertEquals((12/3/2d), ((INumberBeanProxy) result).doubleValue(), 0); + + } + + public void testRemainder() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_REMAINDER, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 4); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals(4%3, ((INumberBeanProxy) result).intValue()); + + } + + public void testRemainderExtended() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_REMAINDER, 1); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 12); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 9); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_EXTENDED, 2d); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("double", result.getTypeProxy().getTypeName()); + assertEquals((12%9%2d), ((INumberBeanProxy) result).doubleValue(), 0); + + } + + public void testMinus() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_MINUS, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 4); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals(4-3, ((INumberBeanProxy) result).intValue()); + + } + + public void testMinusExtended() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_MINUS, 1); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 12); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 9); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_EXTENDED, 2d); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("double", result.getTypeProxy().getTypeName()); + assertEquals((12-9-2d), ((INumberBeanProxy) result).doubleValue(), 0); + + } + + public void testLeftShift() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_LEFT_SHIFT, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 4); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals(4<<3, ((INumberBeanProxy) result).intValue()); + + } + + public void testLeftShiftExtended() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_LEFT_SHIFT, 1); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 12); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 9); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_EXTENDED, 2); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals((12<<9<<2), ((INumberBeanProxy) result).intValue(), 0); + } + + public void testRightShiftSigned() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_RIGHT_SHIFT_SIGNED, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, -10000000); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals(-10000000>>3, ((INumberBeanProxy) result).intValue()); + } + + public void testRightShiftSignedExtended() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_RIGHT_SHIFT_SIGNED, 1); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, -10000000); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 4); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_EXTENDED, 2); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals((-10000000>>4>>2), ((INumberBeanProxy) result).intValue(), 0); + } + public void testRightShiftUnSigned() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_RIGHT_SHIFT_UNSIGNED, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, -10000000); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals(-10000000>>>3, ((INumberBeanProxy) result).intValue()); + } + + public void testRightShiftUnSignedExtended() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_RIGHT_SHIFT_UNSIGNED, 1); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, -10000000); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 4); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_EXTENDED, 2); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals((-10000000>>>4>>>2), ((INumberBeanProxy) result).intValue(), 0); + } + + public void testLess() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_LESS, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, -10000000); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(-10000000<3, ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testLessEquals() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_LESS_EQUALS, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 3); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(3<=3, ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testGreater() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_GREATER, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, -10000000); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(-10000000>3, ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testGreaterEquals() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_GREATER_EQUALS, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 2); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(2>=3, ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testEqualsPrimitives() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_EQUALS, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 3d); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(3d==3, ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testEqualsObjects() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_EQUALS, 0); + exp.createTypeLiteral(IExpressionConstants.INFIX_LEFT, "java.lang.String"); + exp.createTypeLiteral(IExpressionConstants.INFIX_RIGHT, "java.lang.String"); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(String.class == String.class, ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testNotEqualsPrimitives() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_NOT_EQUALS, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 3d); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(3d!=3, ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testNotEqualsObjects() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_NOT_EQUALS, 0); + exp.createTypeLiteral(IExpressionConstants.INFIX_LEFT, "java.lang.String"); + exp.createTypeLiteral(IExpressionConstants.INFIX_RIGHT, "java.lang.String"); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(String.class != String.class, ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testXOR() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_XOR, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 5); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals(5^3, ((INumberBeanProxy) result).intValue()); + + } + + public void testXORExtended() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_XOR, 1); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 23); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 9); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_EXTENDED, 2); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals((23^9^2), ((INumberBeanProxy) result).intValue(), 0); + + } + + public void testAnd() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_AND, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 5); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals(5&3, ((INumberBeanProxy) result).intValue()); + } + + public void testAndExtended() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_AND, 1); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 13); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 15); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_EXTENDED, 1); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals((13&5&1), ((INumberBeanProxy) result).intValue(), 0); + } + + public void testOr() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_OR, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 5); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 2); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals(5|2, ((INumberBeanProxy) result).intValue()); + } + + public void testOrExtended() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_OR, 1); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 13); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 6); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_EXTENDED, 2); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals((13|6|2), ((INumberBeanProxy) result).intValue(), 0); + } + + public void testPlus() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_PLUS, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 5); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 2); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getTypeName()); + assertEquals(5+2, ((INumberBeanProxy) result).intValue()); + } + + public void testPlusExtended() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_PLUS, 1); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 5); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 2); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_EXTENDED, 2l); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("long", result.getTypeProxy().getTypeName()); + assertEquals(5+2+2l, ((INumberBeanProxy) result).intValue()); + } + + public void testPlusStringLeft() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_PLUS, 0); + exp.createProxyExpression(IExpressionConstants.INFIX_LEFT, proxyFactory.createBeanProxyWith("abc")); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 2); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("java.lang.String", result.getTypeProxy().getTypeName()); + assertEquals("abc"+2, ((IStringBeanProxy) result).stringValue()); + } + + public void testPlusStringRight() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_PLUS, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 2); + exp.createProxyExpression(IExpressionConstants.INFIX_RIGHT, proxyFactory.createBeanProxyWith("abc")); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("java.lang.String", result.getTypeProxy().getTypeName()); + assertEquals(2+"abc", ((IStringBeanProxy) result).stringValue()); + } + + public void testPlusStringLeftNull() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_PLUS, 0); + exp.createProxyExpression(IExpressionConstants.INFIX_LEFT, proxyFactory.createBeanProxyWith("abc")); + exp.createNull(IExpressionConstants.INFIX_RIGHT); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("java.lang.String", result.getTypeProxy().getTypeName()); + assertEquals("abc"+null, ((IStringBeanProxy) result).stringValue()); + } + + public void testPlusStringRightNull() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_PLUS, 0); + exp.createNull(IExpressionConstants.INFIX_LEFT); + exp.createProxyExpression(IExpressionConstants.INFIX_RIGHT, proxyFactory.createBeanProxyWith("abc")); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("java.lang.String", result.getTypeProxy().getTypeName()); + assertEquals(null+"abc", ((IStringBeanProxy) result).stringValue()); + } + + public void testPlusStringLeftChar() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_PLUS, 0); + exp.createProxyExpression(IExpressionConstants.INFIX_LEFT, proxyFactory.createBeanProxyWith("abc")); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 'a'); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("java.lang.String", result.getTypeProxy().getTypeName()); + assertEquals("abc"+'a', ((IStringBeanProxy) result).stringValue()); + } + + public void testPlusStringRightChar() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_PLUS, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 'a'); + exp.createProxyExpression(IExpressionConstants.INFIX_RIGHT, proxyFactory.createBeanProxyWith("abc")); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("java.lang.String", result.getTypeProxy().getTypeName()); + assertEquals('a'+"abc", ((IStringBeanProxy) result).stringValue()); + } + + public void testConditionalAnd() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_CONDITIONAL_AND, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, true); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, true); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(true && true, ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testConditionalAndExtended() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_CONDITIONAL_AND, 1); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, true); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, true); + exp.createInfixExpression(IExpressionConstants.INFIX_EXTENDED, IExpressionConstants.IN_EQUALS, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 3); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(true && true && (3 == 3), ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testConditionalAndFalseLast() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_CONDITIONAL_AND, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, true); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, false); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(true && false, ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testConditionalAndFalseFirst() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_CONDITIONAL_AND, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, false); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, true); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(false && true, ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testConditionalAndExtendedAndFalseFirst() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_CONDITIONAL_AND, 1); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, false); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, true); + exp.createInfixExpression(IExpressionConstants.INFIX_EXTENDED, IExpressionConstants.IN_EQUALS, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 3); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(false && true && (3 == 3), ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testConditionalOr() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_CONDITIONAL_OR, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, false); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, true); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(false || true, ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testConditionalOrExtended() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_CONDITIONAL_OR, 1); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, false); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, false); + exp.createInfixExpression(IExpressionConstants.INFIX_EXTENDED, IExpressionConstants.IN_EQUALS, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 3); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(false || false || (3 == 3), ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testConditionalOrTrueFirst() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_CONDITIONAL_OR, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, true); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, false); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(true || false, ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testConditionalOrExtendedAndTrueMiddle() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createInfixExpression(IExpressionConstants.ROOTEXPRESSION, IExpressionConstants.IN_CONDITIONAL_OR, 1); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, false); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, true); + exp.createInfixExpression(IExpressionConstants.INFIX_EXTENDED, IExpressionConstants.IN_EQUALS, 0); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_LEFT, 3); + exp.createPrimitiveLiteral(IExpressionConstants.INFIX_RIGHT, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("boolean", result.getTypeProxy().getTypeName()); + assertEquals(false || true || (3 == 3), ((IBooleanBeanProxy) result).booleanValue()); + } + + public void testArrayAccess() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IArrayBeanProxy array = (IArrayBeanProxy) proxyFactory.createBeanProxyWith(proxyTypeFactory.getBeanTypeProxy("short"), 1); + array.set(proxyFactory.createBeanProxyWith((short) 3), 0); + + IExpression exp = proxyFactory.createExpression(); + exp.createArrayAccess(IExpressionConstants.ROOTEXPRESSION, 1); + exp.createProxyExpression(IExpressionConstants.ARRAYACCESS_ARRAY, array); + exp.createPrimitiveLiteral(IExpressionConstants.ARRAYACCESS_INDEX, 0); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("short", result.getTypeProxy().getTypeName()); + assertEquals(((INumberBeanProxy) result).shortValue(), (short) 3); + } + + public void testMultiArrayAccess() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IArrayBeanProxy array = (IArrayBeanProxy) proxyFactory.createBeanProxyWith(proxyTypeFactory.getBeanTypeProxy("short"), new int[] {2,1}); + array.set(proxyFactory.createBeanProxyWith((short) 3), new int[]{1,0}); + + IExpression exp = proxyFactory.createExpression(); + exp.createArrayAccess(IExpressionConstants.ROOTEXPRESSION, 1); + exp.createProxyExpression(IExpressionConstants.ARRAYACCESS_ARRAY, array); + exp.createPrimitiveLiteral(IExpressionConstants.ARRAYACCESS_INDEX, 1); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("short[]", result.getTypeProxy().getFormalTypeName()); + } + + public void testMultiArrayAccess1() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IArrayBeanProxy array = (IArrayBeanProxy) proxyFactory.createBeanProxyWith(proxyTypeFactory.getBeanTypeProxy("short"), new int[] {2,1}); + array.set(proxyFactory.createBeanProxyWith((short) 3), new int[]{1,0}); + + IExpression exp = proxyFactory.createExpression(); + exp.createArrayAccess(IExpressionConstants.ROOTEXPRESSION, 2); + exp.createProxyExpression(IExpressionConstants.ARRAYACCESS_ARRAY, array); + exp.createPrimitiveLiteral(IExpressionConstants.ARRAYACCESS_INDEX, 1); + exp.createPrimitiveLiteral(IExpressionConstants.ARRAYACCESS_INDEX, 0); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("short", result.getTypeProxy().getFormalTypeName()); + assertEquals((short) 3, ((INumberBeanProxy) result).shortValue()); + } + + public void testArrayCreation() throws IllegalStateException, IllegalArgumentException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createArrayCreation(IExpressionConstants.ROOTEXPRESSION, "int[]", 1); + exp.createPrimitiveLiteral(IExpressionConstants.ARRAYCREATION_DIMENSION, 2); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int[]", result.getTypeProxy().getFormalTypeName()); + assertEquals(2, ((IArrayBeanProxy) result).getLength()); + } + + public void testMultiArrayCreation() throws IllegalStateException, IllegalArgumentException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createArrayCreation(IExpressionConstants.ROOTEXPRESSION, "int[][]", 2); + exp.createPrimitiveLiteral(IExpressionConstants.ARRAYCREATION_DIMENSION, 2); + exp.createPrimitiveLiteral(IExpressionConstants.ARRAYCREATION_DIMENSION, 4); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int[][]", result.getTypeProxy().getFormalTypeName()); + assertEquals(2, ((IArrayBeanProxy) result).getLength()); + assertEquals(4, ((IArrayBeanProxy)((IArrayBeanProxy) result).get(0)).getLength()); + } + + public void testMultiPartialArrayCreation() throws IllegalStateException, IllegalArgumentException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createArrayCreation(IExpressionConstants.ROOTEXPRESSION, "int[][][]", 2); + exp.createPrimitiveLiteral(IExpressionConstants.ARRAYCREATION_DIMENSION, 2); + exp.createPrimitiveLiteral(IExpressionConstants.ARRAYCREATION_DIMENSION, 4); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int[][][]", result.getTypeProxy().getFormalTypeName()); + assertEquals(2, ((IArrayBeanProxy) result).getLength()); + assertEquals(4, ((IArrayBeanProxy)((IArrayBeanProxy) result).get(0)).getLength()); + assertNull(((IArrayBeanProxy)((IArrayBeanProxy) result).get(0)).get(0)); + } + + public void testArrayInitializerEmpty() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createArrayCreation(IExpressionConstants.ROOTEXPRESSION, "int[]", 0); + exp.createArrayInitializer(0); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int[]", result.getTypeProxy().getFormalTypeName()); + assertEquals(0, ((IArrayBeanProxy) result).getLength()); + } + + public void testArrayInitializerOneDim() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createArrayCreation(IExpressionConstants.ROOTEXPRESSION, "int[]", 0); + exp.createArrayInitializer(1); + exp.createPrimitiveLiteral(IExpressionConstants.ARRAYINITIALIZER_EXPRESSION, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int[]", result.getTypeProxy().getFormalTypeName()); + assertEquals(1, ((IArrayBeanProxy) result).getLength()); + assertEquals(3, ((INumberBeanProxy) ((IArrayBeanProxy) result).get(0)).intValue()); + } + + public void testArrayInitializerTwoDimEmpty() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createArrayCreation(IExpressionConstants.ROOTEXPRESSION, "int[][]", 0); + exp.createArrayInitializer(0); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int[][]", result.getTypeProxy().getFormalTypeName()); + assertEquals(0, ((IArrayBeanProxy) result).getLength()); + } + + public void testArrayInitializerTwoDim() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createArrayCreation(IExpressionConstants.ROOTEXPRESSION, "int[][]", 0); + exp.createArrayInitializer(1); + exp.createArrayInitializer(0); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int[][]", result.getTypeProxy().getFormalTypeName()); + assertEquals(1, ((IArrayBeanProxy) result).getLength()); + assertEquals(0, ((IArrayBeanProxy) ((IArrayBeanProxy) result).get(0)).getLength()); + } + + public void testArrayInitializerTwoDimNotEmpty() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createArrayCreation(IExpressionConstants.ROOTEXPRESSION, "int[][]", 0); + exp.createArrayInitializer(2); + exp.createNull(IExpressionConstants.ARRAYINITIALIZER_EXPRESSION); + exp.createArrayInitializer(2); + exp.createPrimitiveLiteral(IExpressionConstants.ARRAYINITIALIZER_EXPRESSION, 3); + exp.createPrimitiveLiteral(IExpressionConstants.ARRAYINITIALIZER_EXPRESSION, 4); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int[][]", result.getTypeProxy().getFormalTypeName()); + assertEquals(2, ((IArrayBeanProxy) result).getLength()); + assertNull((IArrayBeanProxy) ((IArrayBeanProxy) result).get(0)); + assertEquals(2, ((IArrayBeanProxy) ((IArrayBeanProxy) result).get(1)).getLength()); + assertEquals(4, ((INumberBeanProxy)((IArrayBeanProxy) ((IArrayBeanProxy) result).get(1)).get(1)).intValue()); + } + + public void testArrayInitializerShortInt() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createArrayCreation(IExpressionConstants.ROOTEXPRESSION, "short[]", 0); + exp.createArrayInitializer(1); + exp.createPrimitiveLiteral(IExpressionConstants.ARRAYINITIALIZER_EXPRESSION, 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("short[]", result.getTypeProxy().getFormalTypeName()); + assertEquals(1, ((IArrayBeanProxy) result).getLength()); + assertEquals(3, ((INumberBeanProxy) ((IArrayBeanProxy) result).get(0)).intValue()); + } + + public void testClassInstanceCreationDefault() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createClassInstanceCreation(IExpressionConstants.ROOTEXPRESSION, "java.lang.Object", 0); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("java.lang.Object", result.getTypeProxy().getFormalTypeName()); + } + + public void testClassInstanceCreationDefaultWithBeanTypeProxy() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createClassInstanceCreation(IExpressionConstants.ROOTEXPRESSION, proxyTypeFactory.getBeanTypeProxy("java.lang.Object"), 0); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("java.lang.Object", result.getTypeProxy().getFormalTypeName()); + } + + public void testClassInstanceCreationOneArg() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createClassInstanceCreation(IExpressionConstants.ROOTEXPRESSION, "java.lang.Integer", 1); + exp.createStringLiteral(IExpressionConstants.CLASSINSTANCECREATION_ARGUMENT, "3"); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("java.lang.Integer", result.getTypeProxy().getFormalTypeName()); + assertEquals(3, ((INumberBeanProxy) result).intValue()); + } + + public void testClassInstanceCreationOneArgWithPrimWidening() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createClassInstanceCreation(IExpressionConstants.ROOTEXPRESSION, "java.lang.Short", 1); + exp.createPrimitiveLiteral(IExpressionConstants.CLASSINSTANCECREATION_ARGUMENT, (byte)3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("java.lang.Short", result.getTypeProxy().getFormalTypeName()); + assertEquals((short)3, ((INumberBeanProxy) result).shortValue()); + } + + public void testClassInstanceCreationNullArg() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createClassInstanceCreation(IExpressionConstants.ROOTEXPRESSION, "TestCtorWithNull", 1); + exp.createNull(IExpressionConstants.CLASSINSTANCECREATION_ARGUMENT); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("TestCtorWithNull", result.getTypeProxy().getFormalTypeName()); + } + + public void testClassInstanceCreationMismatchArg() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createClassInstanceCreation(IExpressionConstants.ROOTEXPRESSION, "TestCtorWithNull", 1); + try { + exp.createPrimitiveLiteral(IExpressionConstants.CLASSINSTANCECREATION_ARGUMENT, 1); + exp.getExpressionValue(); + fail("Exception should of been thrown."); + } catch (ThrowableProxy e) { + assertEquals("java.lang.NoSuchMethodException", e.getTypeProxy().getFormalTypeName()); + } + } + + public void testStaticFieldAccess() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createFieldAccess(IExpressionConstants.ROOTEXPRESSION, "RED", true); + exp.createTypeReceiver("java.awt.Color"); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("java.awt.Color", result.getTypeProxy().getFormalTypeName()); + IBeanTypeProxy colorType = result.getTypeProxy(); + IMethodProxy red = colorType.getMethodProxy("getRed"); + IMethodProxy green = colorType.getMethodProxy("getGreen"); + IMethodProxy blue = colorType.getMethodProxy("getBlue"); + assertEquals(255, ((INumberBeanProxy) red.invoke(result)).intValue()); + assertEquals(0, ((INumberBeanProxy) green.invoke(result)).intValue()); + assertEquals(0, ((INumberBeanProxy) blue.invoke(result)).intValue()); + } + + public void testNonStaticFieldAccess() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createFieldAccess(IExpressionConstants.ROOTEXPRESSION, "x", true); + exp.createClassInstanceCreation(IExpression.FIELD_RECEIVER, "java.awt.Point", 2); + exp.createPrimitiveLiteral(IExpression.CLASSINSTANCECREATION_ARGUMENT, 1); + exp.createPrimitiveLiteral(IExpression.CLASSINSTANCECREATION_ARGUMENT, 2); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getFormalTypeName()); + assertEquals(1, ((INumberBeanProxy) result).intValue()); + } + + public void testStaticMethodInvoke() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createMethodInvocation(IExpressionConstants.ROOTEXPRESSION, "valueOf", true, 1); + exp.createTypeReceiver("java.lang.String"); + exp.createPrimitiveLiteral(IExpression.METHOD_ARGUMENT, true); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("java.lang.String", result.getTypeProxy().getFormalTypeName()); + assertEquals("true", ((IStringBeanProxy) result).stringValue()); + } + + public void testNonStaticMethodInvoke() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createMethodInvocation(IExpressionConstants.ROOTEXPRESSION, "compareTo", true, 1); + exp.createClassInstanceCreation(IExpression.METHOD_RECEIVER, "java.lang.Integer", 1); + exp.createPrimitiveLiteral(IExpression.CLASSINSTANCECREATION_ARGUMENT, 3); + exp.createClassInstanceCreation(IExpression.METHOD_ARGUMENT, "java.lang.Integer", 1); + exp.createPrimitiveLiteral(IExpression.CLASSINSTANCECREATION_ARGUMENT, 4); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getFormalTypeName()); + assertTrue("CompareTo wasn't less than 0.", ((INumberBeanProxy) result).intValue() < 0); + } + + public void testConditionalTrue() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createConditionalExpression(IExpression.ROOTEXPRESSION); + exp.createInfixExpression(IExpression.CONDITIONAL_CONDITION, IExpressionConstants.IN_EQUALS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, (byte) 3); + exp.createPrimitiveLiteral(IExpression.INFIX_RIGHT, (short) 3); + exp.createInfixExpression(IExpression.CONDITIONAL_TRUE, IExpressionConstants.IN_PLUS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, (byte) 3); + exp.createPrimitiveLiteral(IExpression.INFIX_RIGHT, (short) 3); + exp.createInfixExpression(IExpression.CONDITIONAL_FALSE, IExpressionConstants.IN_PLUS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, (byte) 3); + exp.createPrimitiveLiteral(IExpression.INFIX_RIGHT, (short) 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getFormalTypeName()); + assertEquals(6, ((INumberBeanProxy) result).intValue()); + } + + public void testConditionalFalse() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createConditionalExpression(IExpression.ROOTEXPRESSION); + exp.createInfixExpression(IExpression.CONDITIONAL_CONDITION, IExpressionConstants.IN_EQUALS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, (byte) 4); + exp.createPrimitiveLiteral(IExpression.INFIX_RIGHT, (short) 3); + exp.createInfixExpression(IExpression.CONDITIONAL_TRUE, IExpressionConstants.IN_PLUS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, (byte) 3); + exp.createPrimitiveLiteral(IExpression.INFIX_RIGHT, (short) 3); + exp.createInfixExpression(IExpression.CONDITIONAL_FALSE, IExpressionConstants.IN_MINUS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, (byte) 3); + exp.createPrimitiveLiteral(IExpression.INFIX_RIGHT, (short) 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getFormalTypeName()); + assertEquals(0, ((INumberBeanProxy) result).intValue()); + } + + public void testNestedConditionalTrueTrue() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createConditionalExpression(IExpression.ROOTEXPRESSION); + exp.createInfixExpression(IExpression.CONDITIONAL_CONDITION, IExpressionConstants.IN_EQUALS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, (byte) 3); + exp.createPrimitiveLiteral(IExpression.INFIX_RIGHT, (short) 3); + exp.createConditionalExpression(IExpression.CONDITIONAL_TRUE); + exp.createInfixExpression(IExpression.CONDITIONAL_CONDITION, IExpressionConstants.IN_EQUALS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, (byte) 3); + exp.createPrimitiveLiteral(IExpression.INFIX_RIGHT, (short) 3); + exp.createInfixExpression(IExpression.CONDITIONAL_TRUE, IExpressionConstants.IN_PLUS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, (byte) 4); + exp.createPrimitiveLiteral(IExpression.INFIX_RIGHT, (short) 4); + exp.createInfixExpression(IExpression.CONDITIONAL_FALSE, IExpressionConstants.IN_MINUS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, (byte) 4); + exp.createPrimitiveLiteral(IExpression.INFIX_RIGHT, (short) 3); + exp.createInfixExpression(IExpression.CONDITIONAL_FALSE, IExpressionConstants.IN_MINUS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, (byte) 5); + exp.createPrimitiveLiteral(IExpression.INFIX_RIGHT, (short) 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getFormalTypeName()); + assertEquals(8, ((INumberBeanProxy) result).intValue()); + } + + public void testNestedConditionalFalseFalse() throws IllegalStateException, ThrowableProxy, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createConditionalExpression(IExpression.ROOTEXPRESSION); + exp.createInfixExpression(IExpression.CONDITIONAL_CONDITION, IExpressionConstants.IN_EQUALS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, (byte) 3); + exp.createPrimitiveLiteral(IExpression.INFIX_RIGHT, (short) 2); + exp.createConditionalExpression(IExpression.CONDITIONAL_TRUE); + exp.createInfixExpression(IExpression.CONDITIONAL_CONDITION, IExpressionConstants.IN_EQUALS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, (byte) 2); + exp.createPrimitiveLiteral(IExpression.INFIX_RIGHT, (short) 3); + exp.createInfixExpression(IExpression.CONDITIONAL_TRUE, IExpressionConstants.IN_PLUS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, (byte) 4); + exp.createPrimitiveLiteral(IExpression.INFIX_RIGHT, (short) 4); + exp.createInfixExpression(IExpression.CONDITIONAL_FALSE, IExpressionConstants.IN_MINUS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, (byte) 4); + exp.createPrimitiveLiteral(IExpression.INFIX_RIGHT, (short) 3); + exp.createInfixExpression(IExpression.CONDITIONAL_FALSE, IExpressionConstants.IN_MINUS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, (byte) 5); + exp.createPrimitiveLiteral(IExpression.INFIX_RIGHT, (short) 3); + IBeanProxy result = exp.getExpressionValue(); + assertNotNull(result); + assertEquals("int", result.getTypeProxy().getFormalTypeName()); + assertEquals(2, ((INumberBeanProxy) result).intValue()); + } + + public void testVoidReturnType() throws IllegalStateException, ThrowableProxy { + IExpression exp = proxyFactory.createExpression(); + try { + exp.createInfixExpression(IExpression.ROOTEXPRESSION, IExpressionConstants.IN_PLUS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, 3); + exp.createMethodInvocation(IExpression.INFIX_RIGHT, "gc", true, 0); + exp.createTypeReceiver("java.lang.System"); + exp.getExpressionValue(); + fail("Should of received no expression value exception."); + } catch (NoExpressionValueException e) { + if (e.getLocalizedMessage() != null) + System.out.println(e.getLocalizedMessage()); + } + } + + public void testWrongReturnType() throws ThrowableProxy, IllegalStateException, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + try { + exp.createInfixExpression(IExpression.ROOTEXPRESSION, IExpressionConstants.IN_PLUS, 0); + exp.createPrimitiveLiteral(IExpression.INFIX_LEFT, 3); + exp.createMethodInvocation(IExpression.INFIX_RIGHT, "getSecurityManager", true, 0); + exp.createTypeReceiver("java.lang.System"); + exp.getExpressionValue(); + fail("Should of received class cast proxy exception."); + } catch (ThrowableProxy e) { + if (!e.getTypeProxy().getFormalTypeName().equals("java.lang.IllegalArgumentException")) + throw e; // Some other exception, rethrow it. + } + } + + public void testInvoke() throws ThrowableProxy, IllegalStateException, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + exp.createMethodInvocation(IExpression.ROOTEXPRESSION, "getSecurityManager", true, 0); + exp.createTypeReceiver("java.lang.System"); + exp.invokeExpression(); + } + + public void testInvokeFail() throws ThrowableProxy, IllegalStateException, NoExpressionValueException { + IExpression exp = proxyFactory.createExpression(); + try { + exp.createMethodInvocation(IExpression.ROOTEXPRESSION, "getenv", true, 1); + exp.createTypeReceiver("java.lang.System"); + exp.createNull(IExpression.METHOD_ARGUMENT); + exp.invokeExpression(); + } catch (ThrowableProxy e) { + if (!e.getTypeProxy().getFormalTypeName().equals("java.lang.Error")) + throw e; // Some other exception, rethrow it. + } + } +}
diff --git a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/ProxySuite.java b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/ProxySuite.java index 067fad5..c017960 100644 --- a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/ProxySuite.java +++ b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/ProxySuite.java
@@ -11,7 +11,7 @@ *******************************************************************************/ /* * $RCSfile: ProxySuite.java,v $ - * $Revision: 1.2 $ $Date: 2003/10/27 17:32:36 $ + * $Revision: 1.3 $ $Date: 2004/02/03 23:18:13 $ */ import java.util.List; @@ -39,6 +39,7 @@ private static Class testsList[] = { TestStandard.class, TestAWTProxy.class, + ExpressionTest.class, } ; public static String pkgName = "org.eclipse.jem.tests.proxy" ;
diff --git a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/OverloadingTest.java b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/OverloadingTest.java index 014e97d..99360a6 100644 --- a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/OverloadingTest.java +++ b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/OverloadingTest.java
@@ -11,7 +11,7 @@ *******************************************************************************/ /* * $RCSfile: OverloadingTest.java,v $ - * $Revision: 1.3 $ $Date: 2004/01/23 22:53:36 $ + * $Revision: 1.4 $ $Date: 2004/02/03 23:18:13 $ */ /** @@ -32,9 +32,9 @@ } public void testOverloadString() throws Throwable { - testHelper.testInitString("new String(\"Frog\")", "Frog"); + testHelper.testInitString("new Integer(\"3\")", new Integer(3)); } public void testOverloadShort() throws Throwable { - testHelper.testInitString("new String((short)3)", "3"); + testHelper.testInitString("new Integer(5)", new Integer(5)); } }
diff --git a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTArraysTest.java b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTArraysTest.java index 358e6dc..4d8fe1b 100644 --- a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTArraysTest.java +++ b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTArraysTest.java
@@ -10,10 +10,11 @@ *******************************************************************************/ /* * $RCSfile: ASTArraysTest.java,v $ - * $Revision: 1.1 $ $Date: 2004/01/19 22:50:22 $ + * $Revision: 1.2 $ $Date: 2004/02/03 23:18:13 $ */ package org.eclipse.jem.tests.proxy.initParser.tree; +import org.eclipse.jem.internal.proxy.core.IExpression; import org.eclipse.jem.tests.proxy.initParser.ArrayConstructorTest; /** @@ -27,15 +28,37 @@ super(name); } + protected ASTTreeInitStringParserTestHelper getTreeParser() { + return (ASTTreeInitStringParserTestHelper) testHelper; + } + public void testUndefinedSecondDim() throws Throwable { - testHelper.testInitString("new int[3][]", new int[3][]); + IExpression exp = getTreeParser().getRegistry().getBeanProxyFactory().createExpression(); + exp.createArrayCreation(IExpression.ROOTEXPRESSION, "int[][]", 1); + exp.createPrimitiveLiteral(IExpression.ARRAYCREATION_DIMENSION, 3); + testHelper.testInitString("new int[3][]", exp.getExpressionValue()); } public void testArrayAccess() throws Throwable { - testHelper.testInitString("(new Integer[3])[0]", (new Integer[3])[0]); + IExpression exp = getTreeParser().getRegistry().getBeanProxyFactory().createExpression(); + exp.createArrayAccess(IExpression.ROOTEXPRESSION, 1); + exp.createArrayCreation(IExpression.ARRAYACCESS_ARRAY, "java.lang.Integer[]", 1); + exp.createPrimitiveLiteral(IExpression.ARRAYCREATION_DIMENSION, 3); + exp.createPrimitiveLiteral(IExpression.ARRAYACCESS_INDEX, 0); + testHelper.testInitString("(new Integer[3])[0]", exp.getExpressionValue()); } public void testMutltiArrayAccess() throws Throwable { - testHelper.testInitString("(new int[][] {{2}, {4}})[0][0]", new Integer(((new int[][] {{2}, {4}})[0][0]))); + IExpression exp = getTreeParser().getRegistry().getBeanProxyFactory().createExpression(); + exp.createArrayAccess(IExpression.ROOTEXPRESSION, 2); + exp.createArrayCreation(IExpression.ARRAYACCESS_ARRAY, "int[][]", 0); + exp.createArrayInitializer(2); + exp.createArrayInitializer(1); + exp.createPrimitiveLiteral(IExpression.ARRAYINITIALIZER_EXPRESSION, 2); + exp.createArrayInitializer(1); + exp.createPrimitiveLiteral(IExpression.ARRAYINITIALIZER_EXPRESSION, 4); + exp.createPrimitiveLiteral(IExpression.ARRAYACCESS_INDEX, 0); + exp.createPrimitiveLiteral(IExpression.ARRAYACCESS_INDEX, 0); + testHelper.testInitString("(new int[][] {{2}, {4}})[0][0]", exp.getExpressionValue()); } }
diff --git a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTFieldAccessTest.java b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTFieldAccessTest.java index 9525f14..b54eb32 100644 --- a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTFieldAccessTest.java +++ b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTFieldAccessTest.java
@@ -10,12 +10,11 @@ *******************************************************************************/ /* * $RCSfile: ASTFieldAccessTest.java,v $ - * $Revision: 1.1 $ $Date: 2004/01/23 22:53:36 $ + * $Revision: 1.2 $ $Date: 2004/02/03 23:18:13 $ */ package org.eclipse.jem.tests.proxy.initParser.tree; -import java.awt.Color; - +import org.eclipse.jem.internal.proxy.core.IExpression; import org.eclipse.jem.tests.proxy.initParser.AbstractInitParserTestCase; /** @@ -39,27 +38,34 @@ } public void testNonQualifiedFieldAccess() throws Throwable { - getTreeParser().testInitString("Color.red", new String[] {"java.awt.*"}, Color.red); + getTreeParser().testInitString("Color.red", new String[] {"java.awt.*"}, getTreeParser().getRegistry().getBeanTypeProxyFactory().getBeanTypeProxy("java.awt.Color").newInstance("java.awt.Color.red") ); } public void testExpressionFieldAccess() throws Throwable { - getTreeParser().testInitString("(Color.red).red", new String[] {"java.awt.*"}, Color.red); // Should not use this form, but it is valid, use valid form for expected results so no warnings. + getTreeParser().testInitString("(Color.red).red", new String[] {"java.awt.*"}, getTreeParser().getRegistry().getBeanTypeProxyFactory().getBeanTypeProxy("java.awt.Color").newInstance("java.awt.Color.red") ); // Should not use this form, but it is valid, use valid form for expected results so no warnings. } public void testNestedFieldAccess() throws Throwable { - getTreeParser().testInitString("ASTNestFieldAccessTestData.acolor.red", new String[] {"org.eclipse.jem.tests.proxy.initParser.tree.ASTNestFieldAccessTestData"}, Color.red); // Should not use this form, but it is valid, use valid form for expected results so no warnings. + getTreeParser().testInitString("ASTNestFieldAccessTestData.acolor.red", new String[] {"org.eclipse.jem.tests.proxy.initParser.tree.ASTNestFieldAccessTestData"}, getTreeParser().getRegistry().getBeanTypeProxyFactory().getBeanTypeProxy("java.awt.Color").newInstance("java.awt.Color.red")); // Should not use this form, but it is valid, use valid form for expected results so no warnings. } public void testNestedFieldExpressionAccess() throws Throwable { - getTreeParser().testInitString("new ASTNestFieldAccessTestData().acolor.red", new String[] {"org.eclipse.jem.tests.proxy.initParser.tree.ASTNestFieldAccessTestData"}, Color.red); // Should not use this form, but it is valid, use valid form for expected results so no warnings. + getTreeParser().testInitString("new ASTNestFieldAccessTestData().acolor.red", new String[] {"org.eclipse.jem.tests.proxy.initParser.tree.ASTNestFieldAccessTestData"}, getTreeParser().getRegistry().getBeanTypeProxyFactory().getBeanTypeProxy("java.awt.Color").newInstance("java.awt.Color.red")); // Should not use this form, but it is valid, use valid form for expected results so no warnings. } public void testNonstaticFieldAccess() throws Throwable { - getTreeParser().testInitString("new ASTNestFieldAccessTestData().arect", new String[] {"org.eclipse.jem.tests.proxy.initParser.tree.ASTNestFieldAccessTestData"}, new ASTNestFieldAccessTestData().arect); + IExpression exp = getTreeParser().getRegistry().getBeanProxyFactory().createExpression(); + exp.createFieldAccess(IExpression.ROOTEXPRESSION, "arect", true); + exp.createClassInstanceCreation(IExpression.FIELD_RECEIVER, "org.eclipse.jem.tests.proxy.initParser.tree.ASTNestFieldAccessTestData", 0); + getTreeParser().testInitString("new ASTNestFieldAccessTestData().arect", new String[] {"org.eclipse.jem.tests.proxy.initParser.tree.ASTNestFieldAccessTestData"}, exp.getExpressionValue()); } public void testNonstaticNestedFieldAccess() throws Throwable { - getTreeParser().testInitString("new ASTNestFieldAccessTestData().arect.x", new String[] {"org.eclipse.jem.tests.proxy.initParser.tree.ASTNestFieldAccessTestData"}, new Integer(new ASTNestFieldAccessTestData().arect.x)); + IExpression exp = getTreeParser().getRegistry().getBeanProxyFactory().createExpression(); + exp.createFieldAccess(IExpression.ROOTEXPRESSION, "x", true); + exp.createFieldAccess(IExpression.FIELD_RECEIVER, "arect", true); + exp.createClassInstanceCreation(IExpression.FIELD_RECEIVER, "org.eclipse.jem.tests.proxy.initParser.tree.ASTNestFieldAccessTestData", 0); + getTreeParser().testInitString("new ASTNestFieldAccessTestData().arect.x", new String[] {"org.eclipse.jem.tests.proxy.initParser.tree.ASTNestFieldAccessTestData"}, exp.getExpressionValue()); } }
diff --git a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTInnerClassAccessTest.java b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTInnerClassAccessTest.java index ae789ef..b4442b3 100644 --- a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTInnerClassAccessTest.java +++ b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTInnerClassAccessTest.java
@@ -10,10 +10,11 @@ *******************************************************************************/ /* * $RCSfile: ASTInnerClassAccessTest.java,v $ - * $Revision: 1.1 $ $Date: 2004/01/23 22:53:36 $ + * $Revision: 1.2 $ $Date: 2004/02/03 23:18:13 $ */ package org.eclipse.jem.tests.proxy.initParser.tree; +import org.eclipse.jem.internal.proxy.core.IExpression; import org.eclipse.jem.tests.proxy.initParser.AbstractInitParserTestCase; /** @@ -30,7 +31,6 @@ */ public ASTInnerClassAccessTest(String name) { super(name); - // TODO Auto-generated constructor stub } protected ASTTreeInitStringParserTestHelper getTreeParser() { @@ -38,21 +38,34 @@ } public void testInnerFieldAccess() throws Throwable { - getTreeParser().testInitString("InnerClassTestData.InnerInnerClass.GREEN", new String[] {"org.eclipse.jem.tests.proxy.initParser.tree.*"}, InnerClassTestData.InnerInnerClass.GREEN); + IExpression exp = getTreeParser().getRegistry().getBeanProxyFactory().createExpression(); + exp.createFieldAccess(IExpression.ROOTEXPRESSION, "GREEN", true); + exp.createTypeReceiver("org.eclipse.jem.tests.proxy.initParser.tree.InnerClassTestData$InnerInnerClass"); + getTreeParser().testInitString("InnerClassTestData.InnerInnerClass.GREEN", new String[] {"org.eclipse.jem.tests.proxy.initParser.tree.*"}, exp.getExpressionValue()); } public void testInnerFieldAccess2() throws Throwable { + IExpression exp = getTreeParser().getRegistry().getBeanProxyFactory().createExpression(); + exp.createFieldAccess(IExpression.ROOTEXPRESSION, "GREEN", true); + exp.createTypeReceiver("org.eclipse.jem.tests.proxy.initParser.tree.InnerClassTestData$InnerInnerClass"); + // Test where the inner class is the top level listed. - getTreeParser().testInitString("InnerInnerClass.GREEN", new String[] {"org.eclipse.jem.tests.proxy.initParser.tree.InnerClassTestData.InnerInnerClass"}, InnerClassTestData.InnerInnerClass.GREEN); + getTreeParser().testInitString("InnerInnerClass.GREEN", new String[] {"org.eclipse.jem.tests.proxy.initParser.tree.InnerClassTestData.InnerInnerClass"}, exp.getExpressionValue()); } public void testInnerInnerFieldAccess() throws Throwable { - getTreeParser().testInitString("InnerClassTestData.InnerInnerClass.InnerInnerInnerClass.RED", new String[] {"org.eclipse.jem.tests.proxy.initParser.tree.*"}, InnerClassTestData.InnerInnerClass.InnerInnerInnerClass.RED); + IExpression exp = getTreeParser().getRegistry().getBeanProxyFactory().createExpression(); + exp.createFieldAccess(IExpression.ROOTEXPRESSION, "RED", true); + exp.createTypeReceiver("org.eclipse.jem.tests.proxy.initParser.tree.InnerClassTestData$InnerInnerClass$InnerInnerInnerClass"); + + getTreeParser().testInitString("InnerClassTestData.InnerInnerClass.InnerInnerInnerClass.RED", new String[] {"org.eclipse.jem.tests.proxy.initParser.tree.*"}, exp.getExpressionValue()); } public void testInnerClassCreation() throws Throwable { + IExpression exp = getTreeParser().getRegistry().getBeanProxyFactory().createExpression(); + exp.createClassInstanceCreation(IExpression.ROOTEXPRESSION, "org.eclipse.jem.tests.proxy.initParser.tree.InnerClassTestData$InnerInnerClass", 0); // Create static inner class - getTreeParser().testInitString("new InnerClassTestData.InnerInnerClass()", new String[] {"org.eclipse.jem.tests.proxy.initParser.tree.*"}, new InnerClassTestData.InnerInnerClass()); + getTreeParser().testInitString("new InnerClassTestData.InnerInnerClass()", new String[] {"org.eclipse.jem.tests.proxy.initParser.tree.*"}, exp.getExpressionValue()); } }
diff --git a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTOperationsTest.java b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTOperationsTest.java index 7f5c734..58af25f 100644 --- a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTOperationsTest.java +++ b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTOperationsTest.java
@@ -10,7 +10,7 @@ *******************************************************************************/ /* * $RCSfile: ASTOperationsTest.java,v $ - * $Revision: 1.1 $ $Date: 2004/01/23 22:53:36 $ + * $Revision: 1.2 $ $Date: 2004/02/03 23:18:13 $ */ package org.eclipse.jem.tests.proxy.initParser.tree; @@ -32,32 +32,53 @@ super(name); } + protected ASTTreeInitStringParserTestHelper getTreeParser() { + return (ASTTreeInitStringParserTestHelper) testHelper; + } + public void testTwoOpers() throws Throwable { - testHelper.testInitString("3+4", new Integer(3+4)); + testHelper.testInitString("3+4", getTreeParser().getRegistry().getBeanProxyFactory().createBeanProxyWith(3+4)); } public void testFourOpersExtended() throws Throwable { - testHelper.testInitString("3+4+5+6", new Integer(3+4+5+6)); + testHelper.testInitString("3+4+5+6", getTreeParser().getRegistry().getBeanProxyFactory().createBeanProxyWith(3+4+5+6)); } public void testMixedOpers() throws Throwable { - testHelper.testInitString("3+4-5", new Integer(3+4-5)); + testHelper.testInitString("3+4-5", getTreeParser().getRegistry().getBeanProxyFactory().createBeanProxyWith(3+4-5)); } public void testMixedOpersPrecedence() throws Throwable { - testHelper.testInitString("6 | 3+4 | 8", new Integer(6 | 3+4 | 8)); + testHelper.testInitString("6 | 3+4 | 8", getTreeParser().getRegistry().getBeanProxyFactory().createBeanProxyWith(6 | 3+4 | 8)); } public void testConditional() throws Throwable { - testHelper.testInitString("java.awt.Color.red != null ? 3 : 5", new Integer(java.awt.Color.red != null ? 3 : 5)); + testHelper.testInitString("java.awt.Color.red != null ? 3 : 5", getTreeParser().getRegistry().getBeanProxyFactory().createBeanProxyWith(java.awt.Color.red != null ? 3 : 5)); } public void testInstanceof() throws Throwable { - testHelper.testInitString("java.awt.Color.red instanceof java.awt.Color", new Boolean(java.awt.Color.red instanceof java.awt.Color)); + testHelper.testInitString("java.awt.Color.red instanceof java.awt.Color", getTreeParser().getRegistry().getBeanProxyFactory().createBeanProxyWith(java.awt.Color.red instanceof java.awt.Color)); } public void testTypeLiteral() throws Throwable { - testHelper.testInitString("Object.class", Object.class); + testHelper.testInitString("Object.class", getTreeParser().getRegistry().getBeanTypeProxyFactory().getBeanTypeProxy("java.lang.Object")); } + public void testStringPlusOperations() throws Throwable { + testHelper.testInitString("3+\"a\"", getTreeParser().getRegistry().getBeanProxyFactory().createBeanProxyWith(3+"a")); + } + + public void testStringPlusOperations1() throws Throwable { + testHelper.testInitString("\"a\"+3", getTreeParser().getRegistry().getBeanProxyFactory().createBeanProxyWith("a"+3)); + } + + public void testStringPlusExtendedOperations() throws Throwable { + testHelper.testInitString("3+4+\"a\"", getTreeParser().getRegistry().getBeanProxyFactory().createBeanProxyWith(3+4+"a")); + } + + public void testStringPlusExtendedOperations1() throws Throwable { + testHelper.testInitString("3+\"a\"+4", getTreeParser().getRegistry().getBeanProxyFactory().createBeanProxyWith(3+"a"+4)); + } + + }
diff --git a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTParserSuite.java b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTParserSuite.java index 51e7da5..d273882 100644 --- a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTParserSuite.java +++ b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTParserSuite.java
@@ -11,10 +11,11 @@ *******************************************************************************/ /* * $RCSfile: ASTParserSuite.java,v $ - * $Revision: 1.2 $ $Date: 2004/01/23 22:53:36 $ + * $Revision: 1.3 $ $Date: 2004/02/03 23:18:13 $ */ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.IJavaProject; @@ -25,8 +26,12 @@ import junit.framework.Test; import junit.framework.TestSuite; +import org.eclipse.jem.internal.proxy.core.*; +import org.eclipse.jem.internal.proxy.core.ProxyFactoryRegistry; +import org.eclipse.jem.internal.proxy.core.ProxyPlugin; import org.eclipse.jem.tests.JavaProjectUtil; import org.eclipse.jem.tests.JavaTestsPlugin; +import org.eclipse.jem.tests.proxy.ProxySuite; import org.eclipse.jem.tests.proxy.initParser.*; /** @@ -79,6 +84,8 @@ populateSuite() ; } + ProxyFactoryRegistry registry; + private void populateSuite () { TestSuite suite = (TestSuite) getTest(); for (int i=0; i<testsList.length; i++) @@ -90,7 +97,18 @@ // Add javatests.jar (i.e. this plugins jar) so that the classes within the tests jar are available // to the jdt parser for referencing. JavaProjectUtil.addPluginJarToPath(JavaTestsPlugin.getPlugin(), "javatests.jar", jproject, null); - AbstractInitParserTestCase.initSuite(suite, new ASTTreeInitStringParserTestHelper(project)); + + // We're going to use the remote proxy, because it is easier to start up, but we aren't really testing + // the remote proxy expression evaluation. We are really testing AST->ParseTree->BeanProxy. If any expression + // type errors show up (i.e. the proxy expression itself is not working correctly). Then that should be fixed + // and a junit test in the proxy suite should be created instead. + registry = ProxyPlugin.getPlugin().startImplementation( + project, + "JUnit Parse Tree Test", + new IConfigurationContributor[] { ProxySuite.getProxySuiteContributor()}, + new NullProgressMonitor()); + + AbstractInitParserTestCase.initSuite(suite, new ASTTreeInitStringParserTestHelper(project, registry)); } catch (CoreException e) { Assert.assertNotNull(e); } @@ -106,6 +124,9 @@ * @see junit.extensions.TestSetup#tearDown() */ protected void tearDown() throws Exception { + if (registry != null) + registry.terminateRegistry(); + JavaProjectUtil.deleteProject(JavaProjectUtil.getProject(AST_PROJECT)); }
diff --git a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTTreeInitStringParserTestHelper.java b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTTreeInitStringParserTestHelper.java index c3d752b..59e625a 100644 --- a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTTreeInitStringParserTestHelper.java +++ b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ASTTreeInitStringParserTestHelper.java
@@ -10,7 +10,7 @@ *******************************************************************************/ /* * $RCSfile: ASTTreeInitStringParserTestHelper.java,v $ - * $Revision: 1.2 $ $Date: 2004/01/23 22:53:36 $ + * $Revision: 1.3 $ $Date: 2004/02/03 23:18:13 $ */ package org.eclipse.jem.tests.proxy.initParser.tree; @@ -25,6 +25,7 @@ import org.eclipse.jdt.core.dom.*; import org.eclipse.jem.internal.instantiation.PTExpression; +import org.eclipse.jem.internal.proxy.core.*; import org.eclipse.jem.tests.proxy.initParser.AbstractInitStringParserTestHelper; import org.eclipse.jem.workbench.utility.ASTBoundResolver; import org.eclipse.jem.workbench.utility.ParseTreeCreationFromAST; @@ -41,27 +42,47 @@ private IJavaProject project; private ParseTreeCreationFromAST parser = new ParseTreeCreationFromAST(new ASTBoundResolver()); + private ProxyFactoryRegistry registry; public ASTTreeInitStringParserTestHelper() { } - public ASTTreeInitStringParserTestHelper(IProject project) { + public ASTTreeInitStringParserTestHelper(IProject project, ProxyFactoryRegistry registry) { this.project = JavaCore.create(project); + this.registry = registry; } + + public ASTTreeInitStringParserTestHelper(IProject project) { + this(project, null); + } + + public ProxyFactoryRegistry getRegistry() { + return registry; + } + /* (non-Javadoc) * @see org.eclipse.jem.tests.proxy.initParser.AbstractInitStringParserTestHelper#testInitString(java.lang.String, java.lang.Object, boolean, boolean) */ public void testInitString(String aString, Object expectedResult, boolean throwsException, boolean equalsOnly) throws Throwable { String testClass = MessageFormat.format(TEMPLATE_CLASS, new Object[] {aString}); CompilationUnit cu = project != null ? AST.parseCompilationUnit(testClass.toCharArray(), "TEMPLATE.java", project) : AST.parseCompilationUnit(testClass.toCharArray()); - testInitString(aString, cu, expectedResult, throwsException, equalsOnly); + // This is the only method that is called from both init string and parse allocation. So we can be assume that + // it is a straight init string. In that case we can go ahead and do regular proxy init string parsing to + // get a proxy to pass into the parse testing. + IBeanProxy expectedProxy = null; + if (expectedResult instanceof IBeanProxy) + expectedProxy = (IBeanProxy) expectedResult; + else if (expectedResult != null && !throwsException && registry != null) { + expectedProxy = registry.getBeanProxyFactory().createBeanProxyFrom(aString); + } + testInitString(aString, cu, expectedProxy, throwsException, equalsOnly); } - public void testInitString(String aString, String[] imports, Object expectedResult) throws Throwable { + public void testInitString(String aString, String[] imports, IBeanProxy expectedResult) throws Throwable { testInitString(aString, imports,expectedResult, false, true); } - public void testInitString(String aString, String[] imports, Object expectedResult, boolean throwsException, boolean equalsOnly) throws Throwable { + public void testInitString(String aString, String[] imports, IBeanProxy expectedResult, boolean throwsException, boolean equalsOnly) throws Throwable { StringBuffer importLines = new StringBuffer(100); for (int i = 0; i < imports.length; i++) { importLines.append("import "); @@ -73,29 +94,130 @@ testInitString(aString, cu, expectedResult, throwsException, equalsOnly); } - protected void testInitString(String aString, CompilationUnit cu, Object expectedResult, boolean throwsException, boolean equalsOnly) throws Throwable { + protected void testInitString( + String aString, + CompilationUnit cu, + IBeanProxy expectedResult, + boolean throwsException, + boolean equalsOnly) + throws Throwable { IProblem[] problems = cu.getProblems(); if (problems.length > 0) { boolean errors = false; StringBuffer buf = new StringBuffer(100); for (int i = 0; i < problems.length; i++) { errors = errors | problems[i].isError(); - buf.append(" "+problems[i].getMessage()); + buf.append(" " + problems[i].getMessage()); } // If only warnings, try going on. Only errors should cause a failure. if (errors) - Assert.fail("Problems with \""+aString+"\": "+ buf); + if (!throwsException) + Assert.fail("Problems with \"" + aString + "\": " + buf); + else + return; // Treat this as an exception. else { // Else just log the warnings. - System.err.println("Warnings ocurred for \""+aString+"\":"+buf); + System.err.println("Warnings ocurred for \"" + aString + "\":" + buf); } } - + TypeDeclaration td = (TypeDeclaration) cu.types().get(0); ExpressionStatement es = (ExpressionStatement) td.getMethods()[0].getBody().statements().get(0); MethodInvocation mi = (MethodInvocation) es.getExpression(); org.eclipse.jdt.core.dom.Expression exp = (org.eclipse.jdt.core.dom.Expression) mi.arguments().get(0); PTExpression parseExp = parser.createExpression(exp); + + if (registry != null) { + ParseTreeAllocationInstantiationVisitor v = new ParseTreeAllocationInstantiationVisitor(); + try { + IBeanProxy bean = v.getBeanProxy(parseExp, registry); + if (throwsException) + Assert.fail("Should of thrown exception. Instead result was \"" + (bean != null ? bean.toBeanString() : null) + "\""); + if (bean == expectedResult) + return; + if ((bean == null && expectedResult != null) || (expectedResult == null && bean != null)) + Assert.fail( + "ExpectedResult=" + + (expectedResult != null ? expectedResult.toBeanString() : null) + + " result=" + + (bean != null ? bean.toBeanString() : null)); + if (bean.equals(expectedResult)) + return; + // It may be that the equals expression is bad. If so use the toString() to do + // a partial comparison + if (bean.getTypeProxy() == expectedResult.getTypeProxy()) { + if (bean.toBeanString().equals(expectedResult.toBeanString())) { + return; + } else { + // The toStrings do not match perfectly but the classes do. + // Try and see how close the two strings are + if (expectedResult.getTypeProxy().isArray() && bean.getTypeProxy().isArray()) { + IBeanTypeProxy expectedResultClass = ((IArrayBeanTypeProxy) expectedResult.getTypeProxy()).getComponentType(); + IBeanTypeProxy resultClass = ((IArrayBeanTypeProxy) bean.getTypeProxy()).getComponentType(); + int resultLength = ((IArrayBeanProxy) bean).getLength(); + int expectedLength = ((IArrayBeanProxy) expectedResult).getLength(); + if (expectedLength == resultLength) { + if (resultClass == expectedResultClass) { + // TODO Should actually step in and check each element too. + return; + } else { + Assert.fail( + aString + + " ExpectedResult=" + + expectedResult.toBeanString() + + " ActualResult=" + + bean.toBeanString() + + " ExpectedClass=" + + expectedResult.getTypeProxy().getFormalTypeName() + + " ActualClass=" + + bean.getTypeProxy().getFormalTypeName()); + } + } else { + Assert.fail( + aString + + " ExpectedResult=" + + expectedResult.toBeanString() + + " ActualResult=" + + bean.toBeanString() + + " ExpectedClass=" + + expectedResult.getTypeProxy().getFormalTypeName() + + " ActualClass=" + + bean.getTypeProxy().getFormalTypeName()); + } + } else { + if (equalsOnly) + Assert.fail( + aString + + " ExpectedResult=" + + expectedResult.toBeanString() + + " ActualResult=" + + bean.toBeanString() + + " ExpectedClass=" + + expectedResult.getTypeProxy().getFormalTypeName() + + " ActualClass=" + + bean.getTypeProxy().getFormalTypeName()); + return; + } + } + } else { + Assert.fail( + aString + + " ExpectedResult=" + + expectedResult.toBeanString() + + " ActualResult=" + + bean.toBeanString() + + " ExpectedClass=" + + expectedResult.getTypeProxy().getFormalTypeName() + + " ActualClass=" + + bean.getTypeProxy().getFormalTypeName()); + } + } catch (Exception e) { + if (throwsException) + return; // This is ok, it should of thrown exception. + else + throw e; + } + } } }
diff --git a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/InnerClassTestData.java b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/InnerClassTestData.java index e7e5161..46f60db 100644 --- a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/InnerClassTestData.java +++ b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/InnerClassTestData.java
@@ -10,7 +10,7 @@ *******************************************************************************/ /* * $RCSfile: InnerClassTestData.java,v $ - * $Revision: 1.1 $ $Date: 2004/01/23 22:53:36 $ + * $Revision: 1.2 $ $Date: 2004/02/03 23:18:13 $ */ package org.eclipse.jem.tests.proxy.initParser.tree; @@ -42,7 +42,35 @@ */ public class InnerInnerInnerInnerClass { + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + return super.equals(obj) || obj instanceof InnerInnerInnerInnerClass; + } + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + return super.equals(obj) || obj instanceof InnerInnerInnerClass; } } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + return super.equals(obj) || obj instanceof InnerInnerClass; + } } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + return super.equals(obj) || obj instanceof InnerClassTestData; + } + } \ No newline at end of file
diff --git a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ParseTreeAllocationInstantiationVisitor.java b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ParseTreeAllocationInstantiationVisitor.java new file mode 100644 index 0000000..c2dc075 --- /dev/null +++ b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/proxy/initParser/tree/ParseTreeAllocationInstantiationVisitor.java
@@ -0,0 +1,580 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +/* + * $RCSfile: ParseTreeAllocationInstantiationVisitor.java,v $ + * $Revision: 1.1 $ $Date: 2004/02/03 23:18:13 $ + */ +package org.eclipse.jem.tests.proxy.initParser.tree; + +import java.util.List; + +import org.eclipse.jem.internal.instantiation.*; +import org.eclipse.jem.internal.instantiation.ParseVisitor; +import org.eclipse.jem.internal.proxy.core.*; +import org.eclipse.jem.internal.proxy.initParser.tree.IExpressionConstants; +import org.eclipse.jem.internal.proxy.initParser.tree.IExpressionConstants.NoExpressionValueException; + +/** + * This is the standard parse visitor for instantiating a bean proxy from a java parse tree allocation. + * It can be reused, but is not thread-safe. + * + * TODO Temporary here until we get logger moved to wtp.common, then remove org.eclipse.jem prereq from proxy and + * add optional prereq from jem to proxy. + * + * @since 1.0.0 + */ +public class ParseTreeAllocationInstantiationVisitor extends ParseVisitor { + + /** + * Registry for processing the expressions against. + */ + private ProxyFactoryRegistry registry; + + /** + * The expression that is being created and evaluated. + */ + private IExpression expression; + + /* + * The next expression type that should be used. It is used when one expression is sending the + * visitation to the next expression. It will set this to what that expression should be using. This + * is necessary because the next expression doesn't know what it should be. + */ + private int nextExpression = IExpression.ROOTEXPRESSION; + + /** + * An exception occurred during processing. It is a RuntimeException because + * it can be thrown at any time. It wrappers another exception. That exception + * can be retrieved from the cause of the ProcessingException. + * + * @see Throwable#getCause() + * @since 1.0.0 + */ + public static class ProcessingException extends RuntimeException { + + /** + * @param cause + * + * @since 1.0.0 + */ + public ProcessingException(Throwable cause) { + super(cause); + } + } + + static final int[] INFIXTOPROXY; + static { + INFIXTOPROXY = new int[PTInfixOperator.VALUES.size()]; + INFIXTOPROXY[PTInfixOperator.AND] = IExpressionConstants.IN_AND; + INFIXTOPROXY[PTInfixOperator.CONDITIONAL_AND] = IExpressionConstants.IN_CONDITIONAL_AND; + INFIXTOPROXY[PTInfixOperator.CONDITIONAL_OR] = IExpressionConstants.IN_CONDITIONAL_OR; + INFIXTOPROXY[PTInfixOperator.DIVIDE] = IExpressionConstants.IN_DIVIDE; + INFIXTOPROXY[PTInfixOperator.EQUALS] = IExpressionConstants.IN_EQUALS; + INFIXTOPROXY[PTInfixOperator.GREATER] = IExpressionConstants.IN_GREATER; + INFIXTOPROXY[PTInfixOperator.GREATER_EQUALS] = IExpressionConstants.IN_GREATER_EQUALS; + INFIXTOPROXY[PTInfixOperator.LEFT_SHIFT] = IExpressionConstants.IN_LEFT_SHIFT; + INFIXTOPROXY[PTInfixOperator.LESS] = IExpressionConstants.IN_LESS; + INFIXTOPROXY[PTInfixOperator.LESS_EQUALS] = IExpressionConstants.IN_LESS_EQUALS; + INFIXTOPROXY[PTInfixOperator.MINUS] = IExpressionConstants.IN_MINUS; + INFIXTOPROXY[PTInfixOperator.NOT_EQUALS] = IExpressionConstants.IN_NOT_EQUALS; + INFIXTOPROXY[PTInfixOperator.OR] = IExpressionConstants.IN_OR; + INFIXTOPROXY[PTInfixOperator.PLUS] = IExpressionConstants.IN_PLUS; + INFIXTOPROXY[PTInfixOperator.REMAINDER] = IExpressionConstants.IN_REMAINDER; + INFIXTOPROXY[PTInfixOperator.RIGHT_SHIFT_SIGNED] = IExpressionConstants.IN_RIGHT_SHIFT_SIGNED; + INFIXTOPROXY[PTInfixOperator.RIGHT_SHIFT_UNSIGNED] = IExpressionConstants.IN_RIGHT_SHIFT_UNSIGNED; + INFIXTOPROXY[PTInfixOperator.TIMES] = IExpressionConstants.IN_TIMES; + INFIXTOPROXY[PTInfixOperator.XOR] = IExpressionConstants.IN_XOR; + } + + /** + * A helper method to convert the parse tree's infix operator to the Proxy infix operator. + * + * @param operator + * @return + * + * @since 1.0.0 + */ + public static int convertPTInfixOperatorToProxyInfixOperator(PTInfixOperator operator) { + return INFIXTOPROXY[operator.getValue()]; + } + + static final int[] PREFIXTOPROXY; + static { + PREFIXTOPROXY = new int[PTPrefixOperator.VALUES.size()]; + PREFIXTOPROXY[PTPrefixOperator.COMPLEMENT] = IExpressionConstants.PRE_COMPLEMENT; + PREFIXTOPROXY[PTPrefixOperator.MINUS] = IExpressionConstants.PRE_MINUS; + PREFIXTOPROXY[PTPrefixOperator.NOT] = IExpressionConstants.PRE_NOT; + PREFIXTOPROXY[PTPrefixOperator.PLUS] = IExpressionConstants.PRE_PLUS; + } + + /** + * A helper method to convert the parse tree's prefix operator to the Proxy prefix operator. + * + * @param operator + * @return + * + * @since 1.0.0 + */ + public static int convertPTPrefixOperatorToProxyPrefixOperator(PTPrefixOperator operator) { + return PREFIXTOPROXY[operator.getValue()]; + } + + /** + * Create the visitor with the given registry. + * + * @param registry + * + * @since 1.0.0 + */ + public ParseTreeAllocationInstantiationVisitor() { + } + + /** + * Get the current registry. + * + * @return + * + * @since 1.0.0 + */ + protected final ProxyFactoryRegistry getRegistry() { + return registry; + } + + /** + * Get the current expression. + * + * @return + * + * @since 1.0.0 + */ + protected final IExpression getExpression() { + return expression; + } + + /** + * Get the beanproxy for the given expression and registry. + * + * @param expression + * @param registry + * @return + * @throws IllegalStateException + * @throws ThrowableProxy + * @throws NoExpressionValueException + * @throws ProcessingException + * + * @since 1.0.0 + */ + public IBeanProxy getBeanProxy(PTExpression expression, ProxyFactoryRegistry registry) throws IllegalStateException, IllegalArgumentException, ThrowableProxy, NoExpressionValueException, ProcessingException { + this.registry = registry; + this.expression = registry.getBeanProxyFactory().createExpression(); + setNextExpression(IExpression.ROOTEXPRESSION); + try { + expression.accept(this); + } catch (ProcessingException e) { + // Handle the most common that make sense to be know distinctly and throw them instead of ProcessingException. + Throwable t = e.getCause(); + if (t instanceof ThrowableProxy) + throw (ThrowableProxy) t; + else if (t instanceof NoExpressionValueException) + throw (NoExpressionValueException) t; + else + throw e; + } + + return getExpression().getExpressionValue(); + } + + /** + * Set the next expression type. (i.e. the <code>forExpression</code> field of most of the create expression methods. + * + * @param nextExpression + * + * @see IExpression#createInfixExpression(int, int, int) + * @since 1.0.0 + */ + protected final void setNextExpression(int nextExpression) { + this.nextExpression = nextExpression; + } + + /** + * Get the next expression type. (i.e. the <code>forExpression</code> field of most of the create expression methods. + * + * @return + * + * @see IExpression#createInfixExpression(int, int, int) + * @since 1.0.0 + */ + protected final int getNextExpression() { + return nextExpression; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTArrayAccess) + */ + public boolean visit(PTArrayAccess node) { + try { + getExpression().createArrayAccess(getNextExpression(), node.getIndexes().size()); + setNextExpression(IExpression.ARRAYACCESS_ARRAY); + node.getArray().accept(this); + List idx = node.getIndexes(); + int s = idx.size(); + for (int i = 0; i < s; i++) { + setNextExpression(IExpression.ARRAYACCESS_INDEX); + ((PTExpression) idx.get(i)).accept(this); + } + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTArrayCreation) + */ + public boolean visit(PTArrayCreation node) { + try { + getExpression().createArrayCreation(getNextExpression(), node.getType(), node.getDimensions().size()); + if (node.getDimensions().isEmpty()) { + node.getInitializer().accept(this); // Array initializer doesn't require a next expression. + } else { + List dims = node.getDimensions(); + int s = dims.size(); + for (int i = 0; i < s; i++) { + setNextExpression(IExpression.ARRAYCREATION_DIMENSION); + ((PTExpression) dims.get(i)).accept(this); + } + } + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTArrayInitializer) + */ + public boolean visit(PTArrayInitializer node) { + try { + getExpression().createArrayInitializer(node.getExpressions().size()); + List exps = node.getExpressions(); + int s = exps.size(); + for (int i = 0; i < s; i++) { + setNextExpression(IExpression.ARRAYINITIALIZER_EXPRESSION); + ((PTExpression) exps.get(i)).accept(this); + } + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTBooleanLiteral) + */ + public boolean visit(PTBooleanLiteral node) { + try { + getExpression().createPrimitiveLiteral(getNextExpression(), node.isBooleanValue()); + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTCastExpression) + */ + public boolean visit(PTCastExpression node) { + try { + getExpression().createCastExpression(getNextExpression(), node.getType()); + setNextExpression(IExpression.CAST_EXPRESSION); + node.getExpression().accept(this); + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTCharacterLiteral) + */ + public boolean visit(PTCharacterLiteral node) { + try { + getExpression().createPrimitiveLiteral(getNextExpression(), node.getCharValue()); + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTClassInstanceCreation) + */ + public boolean visit(PTClassInstanceCreation node) { + try { + getExpression().createClassInstanceCreation(getNextExpression(), node.getType(), node.getArguments().size()); + List args = node.getArguments(); + int s = args.size(); + for (int i = 0; i < s; i++) { + setNextExpression(IExpression.CLASSINSTANCECREATION_ARGUMENT); + ((PTExpression) args.get(i)).accept(this); + } + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTConditionalExpression) + */ + public boolean visit(PTConditionalExpression node) { + try { + getExpression().createConditionalExpression(getNextExpression()); + setNextExpression(IExpression.CONDITIONAL_CONDITION); + node.getCondition().accept(this); + setNextExpression(IExpression.CONDITIONAL_TRUE); + node.getTrue().accept(this); + setNextExpression(IExpression.CONDITIONAL_FALSE); + node.getFalse().accept(this); + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTFieldAccess) + */ + public boolean visit(PTFieldAccess node) { + try { + getExpression().createFieldAccess(getNextExpression(), node.getField(), node.getReceiver() != null); + if (node.getReceiver() != null) { + setNextExpression(IExpression.FIELD_RECEIVER); + node.getReceiver().accept(this); + } + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTInfixExpression) + */ + public boolean visit(PTInfixExpression node) { + try { + getExpression().createInfixExpression(getNextExpression(), convertPTInfixOperatorToProxyInfixOperator(node.getOperator()), node.getExtendedOperands().size()); + setNextExpression(IExpression.INFIX_LEFT); + node.getLeftOperand().accept(this); + setNextExpression(IExpression.INFIX_RIGHT); + node.getRightOperand().accept(this); + List extended = node.getExtendedOperands(); + int s = extended.size(); + for (int i = 0; i < s; i++) { + setNextExpression(IExpression.INFIX_EXTENDED); + ((PTExpression) extended.get(i)).accept(this); + } + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTInstanceof) + */ + public boolean visit(PTInstanceof node) { + try { + getExpression().createInstanceofExpression(getNextExpression(), node.getType()); + setNextExpression(IExpression.INSTANCEOF_VALUE); + node.getOperand().accept(this); + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTInvalidExpression) + */ + public boolean visit(PTInvalidExpression node) { + throw new IllegalArgumentException(node.getMessage()); + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTMethodInvocation) + */ + public boolean visit(PTMethodInvocation node) { + try { + getExpression().createMethodInvocation(getNextExpression(), node.getName(), node.getReceiver() != null, node.getArguments().size()); + if (node.getReceiver() != null) { + setNextExpression(IExpression.METHOD_RECEIVER); + node.getReceiver().accept(this); + } + List args = node.getArguments(); + int s = args.size(); + for (int i = 0; i < s; i++) { + setNextExpression(IExpression.METHOD_ARGUMENT); + ((PTExpression) args.get(i)).accept(this); + } + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTName) + */ + public boolean visit(PTName node) { + try { + // This is special in the PTName can only be used as a type receiver at this time. + getExpression().createTypeReceiver(node.getName()); + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTNullLiteral) + */ + public boolean visit(PTNullLiteral node) { + try { + // This is special in the PTName can only be used as a type receiver at this time. + getExpression().createNull(getNextExpression()); + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTNumberLiteral) + */ + public boolean visit(PTNumberLiteral node) { + try { + // It is assumed the tokens are trimmed. + String lit = node.getToken(); + char lastChar = lit.charAt(lit.length()-1); + if (lastChar == 'l' || lastChar == 'L' ) { + // It is definitely a long. + // Using decode so that things like 0x3 will be parsed. parseLong won't recognize those. + getExpression().createPrimitiveLiteral(getNextExpression(), Long.decode(lit.substring(0, lit.length()-1)).longValue()); + } else if (lastChar == 'F' || lastChar == 'f') { + // It is definitely a float. + getExpression().createPrimitiveLiteral(getNextExpression(), Float.parseFloat(lit.substring(0, lit.length()-1))); + } else if (lastChar == 'D' || lastChar == 'd') { + // It is definitely a double. + getExpression().createPrimitiveLiteral(getNextExpression(), Double.parseDouble(lit.substring(0, lit.length()-1))); + } else if (lit.indexOf('.') != -1 || lit.indexOf('e') != -1 || lit.indexOf('E') != -1) { + // It is definitely a double. (has a period or an exponent, but does not have an 'f' on the end is always a double). + getExpression().createPrimitiveLiteral(getNextExpression(), Double.parseDouble(lit.substring(0, lit.length()))); + } else { + // Using decode so that things like 0x3 will be parsed. parseInt won't recognize those. + getExpression().createPrimitiveLiteral(getNextExpression(), Integer.decode(lit).intValue()); + } + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTParenthesizedExpression) + */ + public boolean visit(PTParenthesizedExpression node) { + node.getExpression().accept(this); // For instantiation purposes, the parenthesis can be ignored. + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTPrefixExpression) + */ + public boolean visit(PTPrefixExpression node) { + try { + getExpression().createPrefixExpression(getNextExpression(), convertPTPrefixOperatorToProxyPrefixOperator(node.getOperator())); + setNextExpression(IExpression.PREFIX_OPERAND); + node.getExpression().accept(this); + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTStringLiteral) + */ + public boolean visit(PTStringLiteral node) { + try { + getExpression().createProxyExpression(getNextExpression(), getRegistry().getBeanProxyFactory().createBeanProxyWith(node.getLiteralValue())); + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTThisLiteral) + */ + public boolean visit(PTThisLiteral node) { + throw new IllegalArgumentException("Currently \"this\" is not supported"); + } + + /* (non-Javadoc) + * @see org.eclipse.jem.internal.instantiation.ParseVisitor#visit(org.eclipse.jem.internal.instantiation.PTTypeLiteral) + */ + public boolean visit(PTTypeLiteral node) { + try { + getExpression().createTypeLiteral(getNextExpression(), node.getType()); + } catch (ThrowableProxy e) { + new ProcessingException(e); + } catch (NoExpressionValueException e) { + new ProcessingException(e); + } + return false; + } + +}