/src/main/scala/de/tud/cs/st/bat/resolved/reader/AnnotationsBinding.scala

http://github.com/Delors/BAT · Scala · 195 lines · 130 code · 27 blank · 38 comment · 0 complexity · eb22d59251dd8d0944e1b4d2bd966804 MD5 · raw file

  1. /* License (BSD Style License):
  2. * Copyright (c) 2009, 2011
  3. * Software Technology Group
  4. * Department of Computer Science
  5. * Technische Universit?t Darmstadt
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * - Redistributions of source code must retain the above copyright notice,
  12. * this list of conditions and the following disclaimer.
  13. * - Redistributions in binary form must reproduce the above copyright notice,
  14. * this list of conditions and the following disclaimer in the documentation
  15. * and/or other materials provided with the distribution.
  16. * - Neither the name of the Software Technology Group or Technische
  17. * Universit?t Darmstadt nor the names of its contributors may be used to
  18. * endorse or promote products derived from this software without specific
  19. * prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  25. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. * POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. package de.tud.cs.st.bat.resolved
  34. package reader
  35. import de.tud.cs.st.bat.reader.AnnotationsReader
  36. import de.tud.cs.st.bat.reader.RuntimeInvisibleAnnotations_attributeReader
  37. import de.tud.cs.st.bat.reader.RuntimeVisibleAnnotations_attributeReader
  38. import de.tud.cs.st.bat.reader.RuntimeInvisibleParameterAnnotations_attributeReader
  39. import de.tud.cs.st.bat.reader.RuntimeVisibleParameterAnnotations_attributeReader
  40. import de.tud.cs.st.bat.reader.ParameterAnnotationsReader
  41. import de.tud.cs.st.bat.reader.AnnotationDefault_attributeReader
  42. import de.tud.cs.st.bat.reader.ElementValuePairsReader
  43. /**
  44. * Factory methods to create representations of Java annotations.
  45. *
  46. * @author Michael Eichberg
  47. */
  48. trait AnnotationsBinding
  49. extends AnnotationsReader
  50. with RuntimeInvisibleAnnotations_attributeReader
  51. with RuntimeVisibleAnnotations_attributeReader
  52. with RuntimeInvisibleParameterAnnotations_attributeReader
  53. with RuntimeVisibleParameterAnnotations_attributeReader
  54. with ParameterAnnotationsReader
  55. with AnnotationDefault_attributeReader
  56. with ElementValuePairsReader
  57. with ConstantPoolBinding
  58. with AttributeBinding {
  59. type Annotation = de.tud.cs.st.bat.resolved.Annotation
  60. type AnnotationDefault_attribute = de.tud.cs.st.bat.resolved.ElementValue
  61. type ElementValue = de.tud.cs.st.bat.resolved.ElementValue
  62. val ElementValueManifest: ClassManifest[ElementValue] = implicitly
  63. type EnumValue = de.tud.cs.st.bat.resolved.EnumValue
  64. type AnnotationValue = de.tud.cs.st.bat.resolved.AnnotationValue
  65. type ByteValue = de.tud.cs.st.bat.resolved.ByteValue
  66. type CharValue = de.tud.cs.st.bat.resolved.CharValue
  67. type ShortValue = de.tud.cs.st.bat.resolved.ShortValue
  68. type IntValue = de.tud.cs.st.bat.resolved.IntValue
  69. type LongValue = de.tud.cs.st.bat.resolved.LongValue
  70. type FloatValue = de.tud.cs.st.bat.resolved.FloatValue
  71. type DoubleValue = de.tud.cs.st.bat.resolved.DoubleValue
  72. type ArrayValue = de.tud.cs.st.bat.resolved.ArrayValue
  73. type ClassValue = de.tud.cs.st.bat.resolved.ClassValue
  74. type BooleanValue = de.tud.cs.st.bat.resolved.BooleanValue
  75. type ElementValuePair = de.tud.cs.st.bat.resolved.ElementValuePair
  76. val ElementValuePairManifest: ClassManifest[ElementValuePair] = implicitly
  77. type RuntimeVisibleAnnotations_attribute = de.tud.cs.st.bat.resolved.RuntimeVisibleAnnotationTable
  78. type RuntimeInvisibleAnnotations_attribute = de.tud.cs.st.bat.resolved.RuntimeInvisibleAnnotationTable
  79. type RuntimeVisibleParameterAnnotations_attribute = de.tud.cs.st.bat.resolved.RuntimeVisibleParameterAnnotationTable
  80. type RuntimeInvisibleParameterAnnotations_attribute = de.tud.cs.st.bat.resolved.RuntimeInvisibleParameterAnnotationTable
  81. val AnnotationManifest: ClassManifest[Annotation] = implicitly
  82. def ElementValuePair(element_name_index: Constant_Pool_Index,
  83. element_value: ElementValue)(
  84. implicit cp: Constant_Pool): ElementValuePair = {
  85. new ElementValuePair(element_name_index.asString, element_value)
  86. }
  87. def ByteValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
  88. val cv: ConstantValue[_] = const_value_index.asConstantValue
  89. new ByteValue(cv.toByte)
  90. }
  91. def CharValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
  92. val cv: ConstantValue[_] = const_value_index.asConstantValue
  93. new CharValue(cv.toChar)
  94. }
  95. def DoubleValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
  96. val cv: ConstantValue[_] = const_value_index.asConstantValue
  97. new DoubleValue(cv.toDouble)
  98. }
  99. def FloatValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
  100. val cv: ConstantValue[_] = const_value_index.asConstantValue
  101. new FloatValue(cv.toFloat)
  102. }
  103. def IntValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
  104. val cv: ConstantValue[_] = const_value_index.asConstantValue
  105. new IntValue(cv.toInt)
  106. }
  107. def LongValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
  108. val cv: ConstantValue[_] = const_value_index.asConstantValue
  109. new LongValue(cv.toLong)
  110. }
  111. def ShortValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
  112. val cv: ConstantValue[_] = const_value_index.asConstantValue
  113. new ShortValue(cv.toShort)
  114. }
  115. def BooleanValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
  116. val cv: ConstantValue[_] = const_value_index.asConstantValue
  117. new BooleanValue(cv.toBoolean)
  118. }
  119. def StringValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
  120. val cv: ConstantValue[_] = const_value_index.asConstantValue
  121. new StringValue(cv.toUTF8)
  122. }
  123. def ClassValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
  124. val rt: String = const_value_index.asString
  125. new ClassValue(ReturnType(rt))
  126. }
  127. def EnumValue(type_name_index: Constant_Pool_Index,
  128. const_name_index: Constant_Pool_Index)(
  129. implicit cp: Constant_Pool): ElementValue = {
  130. // TODO Looks suspicious... either comment or fix.
  131. new EnumValue(type_name_index.asFieldType.asInstanceOf[ObjectType], const_name_index.asString)
  132. }
  133. def AnnotationValue(annotation: Annotation)(implicit cp: Constant_Pool): ElementValue =
  134. new AnnotationValue(annotation)
  135. def ArrayValue(values: ElementValues)(implicit cp: Constant_Pool): ElementValue =
  136. new ArrayValue(values)
  137. def Annotation(type_index: Constant_Pool_Index,
  138. element_value_pairs: ElementValuePairs)(
  139. implicit cp: Constant_Pool) = {
  140. new Annotation(type_index.asFieldType, element_value_pairs)
  141. }
  142. def AnnotationDefault_attribute(attribute_name_index: Constant_Pool_Index,
  143. attribute_length: Int,
  144. element_value: ElementValue)(
  145. implicit cp: Constant_Pool) = {
  146. element_value
  147. }
  148. def RuntimeVisibleAnnotations_attribute(attribute_name_index: Constant_Pool_Index,
  149. attribute_length: Int,
  150. annotations: Annotations)(
  151. implicit cp: Constant_Pool) =
  152. new RuntimeVisibleAnnotations_attribute(annotations)
  153. def RuntimeInvisibleAnnotations_attribute(attribute_name_index: Constant_Pool_Index,
  154. attribute_length: Int,
  155. annotations: Annotations)(
  156. implicit cp: Constant_Pool) =
  157. new RuntimeInvisibleAnnotations_attribute(annotations)
  158. def RuntimeVisibleParameterAnnotations_attribute(attribute_name_index: Constant_Pool_Index,
  159. attribute_length: Int,
  160. parameter_annotations: ParameterAnnotations)(
  161. implicit cp: Constant_Pool) =
  162. new RuntimeVisibleParameterAnnotations_attribute(parameter_annotations)
  163. def RuntimeInvisibleParameterAnnotations_attribute(attribute_name_index: Constant_Pool_Index,
  164. attribute_length: Int,
  165. parameter_annotations: ParameterAnnotations)(
  166. implicit cp: Constant_Pool) =
  167. new RuntimeInvisibleParameterAnnotations_attribute(parameter_annotations)
  168. }