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.

SimpleAnnotationValue.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* *******************************************************************
  2. * Copyright (c) 2006 Contributors
  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 IBM initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver;
  13. public class SimpleAnnotationValue extends AnnotationValue {
  14. public SimpleAnnotationValue(int kind) {
  15. super(kind);
  16. }
  17. public SimpleAnnotationValue(int kind, Object value) {
  18. super(kind);
  19. switch (kind) {
  20. case AnnotationValue.PRIMITIVE_BYTE:
  21. theByte = ((Byte) value).byteValue();
  22. break;
  23. case AnnotationValue.PRIMITIVE_CHAR:
  24. theChar = ((Character) value).charValue();
  25. break;
  26. case AnnotationValue.PRIMITIVE_INT:
  27. theInt = ((Integer) value).intValue();
  28. break;
  29. case AnnotationValue.STRING:
  30. theString = (String) value;
  31. break;
  32. case AnnotationValue.PRIMITIVE_DOUBLE:
  33. theDouble = ((Double) value).doubleValue();
  34. break;
  35. case AnnotationValue.PRIMITIVE_FLOAT:
  36. theFloat = ((Float) value).floatValue();
  37. break;
  38. case AnnotationValue.PRIMITIVE_LONG:
  39. theLong = ((Long) value).longValue();
  40. break;
  41. case AnnotationValue.PRIMITIVE_SHORT:
  42. theShort = ((Short) value).shortValue();
  43. break;
  44. case AnnotationValue.PRIMITIVE_BOOLEAN:
  45. theBoolean = ((Boolean) value).booleanValue();
  46. break;
  47. default:
  48. throw new BCException("Not implemented for this kind: " + whatKindIsThis(kind));
  49. }
  50. }
  51. private byte theByte;
  52. private char theChar;
  53. private int theInt;
  54. private String theString;
  55. private double theDouble;
  56. private float theFloat;
  57. private long theLong;
  58. private short theShort;
  59. private boolean theBoolean;
  60. public void setValueString(String s) {
  61. theString = s;
  62. }
  63. public void setValueByte(byte b) {
  64. theByte = b;
  65. }
  66. public void setValueChar(char c) {
  67. theChar = c;
  68. }
  69. public void setValueInt(int i) {
  70. theInt = i;
  71. }
  72. public String stringify() {
  73. switch (valueKind) {
  74. case 'B': // byte
  75. return Byte.toString(theByte);
  76. case 'C': // char
  77. return new Character(theChar).toString();
  78. case 'D': // double
  79. return Double.toString(theDouble);
  80. case 'F': // float
  81. return Float.toString(theFloat);
  82. case 'I': // int
  83. return Integer.toString(theInt);
  84. case 'J': // long
  85. return Long.toString(theLong);
  86. case 'S': // short
  87. return Short.toString(theShort);
  88. case 'Z': // boolean
  89. return new Boolean(theBoolean).toString();
  90. case 's': // String
  91. return theString;
  92. default:
  93. throw new BCException("Do not understand this kind: " + valueKind);
  94. }
  95. }
  96. public String toString() {
  97. return stringify();
  98. }
  99. }