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.

LocalVariableTypeTableTest.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* *******************************************************************
  2. * Copyright (c) 2004 IBM
  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.classfile.Code;
  14. import org.aspectj.apache.bcel.classfile.JavaClass;
  15. import org.aspectj.apache.bcel.classfile.LocalVariable;
  16. import org.aspectj.apache.bcel.classfile.LocalVariableTypeTable;
  17. import org.aspectj.apache.bcel.classfile.Method;
  18. import org.aspectj.apache.bcel.classfile.Utility;
  19. public class LocalVariableTypeTableTest extends BcelTestCase {
  20. protected void setUp() throws Exception {
  21. super.setUp();
  22. }
  23. /**
  24. * Check the local variable type table includes information about generic signatures.
  25. */
  26. public void testLocalVariableTypeTableAttribute() throws ClassNotFoundException {
  27. JavaClass clazz = getClassFromJar("SimpleGenericsProgram");
  28. Method mainMethod = getMethod(clazz,"main");
  29. Code codeAttr = (Code) findAttribute("Code",mainMethod.getAttributes());
  30. LocalVariableTypeTable localVariableTypeTable =
  31. (LocalVariableTypeTable) findAttribute("LocalVariableTypeTable",codeAttr.getAttributes());
  32. assertTrue("Should be two entries in the LocalVariableTypeTable but found "+localVariableTypeTable.getTableLength(),
  33. localVariableTypeTable.getTableLength()==2);
  34. LocalVariable[] lvtable = localVariableTypeTable.getLocalVariableTypeTable();
  35. boolean tc1OK = false;
  36. boolean tc2OK = false;
  37. String errormessage = null;
  38. for (LocalVariable localVariable : lvtable) {
  39. String sig = Utility.signatureToString(localVariable.getSignature());
  40. if (localVariable.getName().equals("tc1")) {
  41. if (!sig.equals("TreasureChest<String>")) {
  42. errormessage = "Expected signature of 'TreasureChest<String>' for tc1 but got " + sig;
  43. } else {
  44. tc1OK = true;
  45. }
  46. }
  47. if (localVariable.getName().equals("tc2")) {
  48. if (!sig.equals("TreasureChest<Integer>")) {
  49. errormessage = "Expected signature of 'TreasureChest<Integer>' for tc2 but got " + sig;
  50. } else {
  51. tc2OK = true;
  52. }
  53. }
  54. }
  55. if (!tc1OK || !tc2OK) fail(errormessage);
  56. }
  57. protected void tearDown() throws Exception {
  58. super.tearDown();
  59. }
  60. }