You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MethodParametersTest.java 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* *******************************************************************
  2. * Copyright (c) 2013 VMware
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Andy Clement - initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.apache.bcel.classfile.tests;
  13. import org.aspectj.apache.bcel.Constants;
  14. import org.aspectj.apache.bcel.classfile.JavaClass;
  15. import org.aspectj.apache.bcel.classfile.Method;
  16. import org.aspectj.apache.bcel.classfile.MethodParameters;
  17. public class MethodParametersTest extends BcelTestCase {
  18. protected void setUp() throws Exception {
  19. super.setUp();
  20. }
  21. public void testMethodParameters1() throws Exception {
  22. JavaClass jc = getClassFromJava8Jar("Parameters");
  23. Method m = getMethod(jc, "foo");
  24. MethodParameters mp = (MethodParameters)getAttribute(m.getAttributes(),Constants.ATTR_METHOD_PARAMETERS);
  25. assertEquals(3,mp.getParametersCount());
  26. assertEquals("abc",mp.getParameterName(0));
  27. assertEquals("def",mp.getParameterName(1));
  28. assertEquals("ghi",mp.getParameterName(2));
  29. assertFalse(mp.isFinal(0));
  30. assertFalse(mp.isSynthetic(0));
  31. assertFalse(mp.isMandated(0));
  32. }
  33. // this method specifies the receiver
  34. public void testMethodParameters2() throws Exception {
  35. JavaClass jc = getClassFromJava8Jar("Parameters");
  36. Method m = getMethod(jc, "bar");
  37. MethodParameters mp = (MethodParameters)getAttribute(m.getAttributes(),Constants.ATTR_METHOD_PARAMETERS);
  38. assertEquals(1,mp.getParametersCount());
  39. assertEquals("abc",mp.getParameterName(0));
  40. assertFalse(mp.isFinal(0));
  41. assertFalse(mp.isSynthetic(0));
  42. assertFalse(mp.isMandated(0));
  43. }
  44. // access flags
  45. public void testMethodParameters3() throws Exception {
  46. JavaClass jc = getClassFromJava8Jar("Parameters$Inner");
  47. Method m = getMethod(jc, "<init>");
  48. MethodParameters mp = (MethodParameters)getAttribute(m.getAttributes(),Constants.ATTR_METHOD_PARAMETERS);
  49. assertEquals(2,mp.getParametersCount());
  50. assertEquals("this$0",mp.getParameterName(0));
  51. assertTrue(mp.isFinal(0));
  52. assertFalse(mp.isSynthetic(0));
  53. assertTrue(mp.isMandated(0));
  54. assertEquals("x",mp.getParameterName(1));
  55. assertFalse(mp.isFinal(1));
  56. assertFalse(mp.isSynthetic(1));
  57. assertFalse(mp.isMandated(1));
  58. }
  59. // access flags
  60. public void testMethodParameters4() throws Exception {
  61. JavaClass jc = getClassFromJava8Jar("Parameters$Color");
  62. Method m = getMethod(jc, "<init>");
  63. MethodParameters mp = (MethodParameters)getAttribute(m.getAttributes(),Constants.ATTR_METHOD_PARAMETERS);
  64. assertEquals(2,mp.getParametersCount());
  65. assertEquals("$enum$name",mp.getParameterName(0));
  66. assertFalse(mp.isFinal(0));
  67. assertTrue(mp.isSynthetic(0));
  68. assertFalse(mp.isMandated(0));
  69. assertEquals("$enum$ordinal",mp.getParameterName(1));
  70. assertFalse(mp.isFinal(1));
  71. assertTrue(mp.isSynthetic(1));
  72. assertFalse(mp.isMandated(1));
  73. }
  74. }