PageRenderTime 44ms CodeModel.GetById 25ms app.highlight 16ms RepoModel.GetById 0ms app.codeStats 1ms

/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
Possible License(s): Apache-2.0
  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*/
 33package de.tud.cs.st.bat.resolved
 34package reader
 35
 36import de.tud.cs.st.bat.reader.AnnotationsReader
 37import de.tud.cs.st.bat.reader.RuntimeInvisibleAnnotations_attributeReader
 38import de.tud.cs.st.bat.reader.RuntimeVisibleAnnotations_attributeReader
 39import de.tud.cs.st.bat.reader.RuntimeInvisibleParameterAnnotations_attributeReader
 40import de.tud.cs.st.bat.reader.RuntimeVisibleParameterAnnotations_attributeReader
 41import de.tud.cs.st.bat.reader.ParameterAnnotationsReader
 42import de.tud.cs.st.bat.reader.AnnotationDefault_attributeReader
 43import de.tud.cs.st.bat.reader.ElementValuePairsReader
 44
 45/**
 46 * Factory methods to create representations of Java annotations.
 47 *
 48 * @author Michael Eichberg
 49 */
 50trait AnnotationsBinding
 51        extends AnnotationsReader
 52        with RuntimeInvisibleAnnotations_attributeReader
 53        with RuntimeVisibleAnnotations_attributeReader
 54        with RuntimeInvisibleParameterAnnotations_attributeReader
 55        with RuntimeVisibleParameterAnnotations_attributeReader
 56        with ParameterAnnotationsReader
 57        with AnnotationDefault_attributeReader
 58        with ElementValuePairsReader
 59        with ConstantPoolBinding
 60        with AttributeBinding {
 61
 62    type Annotation = de.tud.cs.st.bat.resolved.Annotation
 63    type AnnotationDefault_attribute = de.tud.cs.st.bat.resolved.ElementValue
 64    type ElementValue = de.tud.cs.st.bat.resolved.ElementValue
 65    val ElementValueManifest: ClassManifest[ElementValue] = implicitly
 66    type EnumValue = de.tud.cs.st.bat.resolved.EnumValue
 67    type AnnotationValue = de.tud.cs.st.bat.resolved.AnnotationValue
 68    type ByteValue = de.tud.cs.st.bat.resolved.ByteValue
 69    type CharValue = de.tud.cs.st.bat.resolved.CharValue
 70    type ShortValue = de.tud.cs.st.bat.resolved.ShortValue
 71    type IntValue = de.tud.cs.st.bat.resolved.IntValue
 72    type LongValue = de.tud.cs.st.bat.resolved.LongValue
 73    type FloatValue = de.tud.cs.st.bat.resolved.FloatValue
 74    type DoubleValue = de.tud.cs.st.bat.resolved.DoubleValue
 75    type ArrayValue = de.tud.cs.st.bat.resolved.ArrayValue
 76    type ClassValue = de.tud.cs.st.bat.resolved.ClassValue
 77    type BooleanValue = de.tud.cs.st.bat.resolved.BooleanValue
 78    type ElementValuePair = de.tud.cs.st.bat.resolved.ElementValuePair
 79    val ElementValuePairManifest: ClassManifest[ElementValuePair] = implicitly
 80    type RuntimeVisibleAnnotations_attribute = de.tud.cs.st.bat.resolved.RuntimeVisibleAnnotationTable
 81    type RuntimeInvisibleAnnotations_attribute = de.tud.cs.st.bat.resolved.RuntimeInvisibleAnnotationTable
 82    type RuntimeVisibleParameterAnnotations_attribute = de.tud.cs.st.bat.resolved.RuntimeVisibleParameterAnnotationTable
 83    type RuntimeInvisibleParameterAnnotations_attribute = de.tud.cs.st.bat.resolved.RuntimeInvisibleParameterAnnotationTable
 84
 85    val AnnotationManifest: ClassManifest[Annotation] = implicitly
 86
 87    def ElementValuePair(element_name_index: Constant_Pool_Index,
 88                         element_value: ElementValue)(
 89                             implicit cp: Constant_Pool): ElementValuePair = {
 90        new ElementValuePair(element_name_index.asString, element_value)
 91    }
 92
 93    def ByteValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
 94        val cv: ConstantValue[_] = const_value_index.asConstantValue
 95        new ByteValue(cv.toByte)
 96    }
 97
 98    def CharValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
 99        val cv: ConstantValue[_] = const_value_index.asConstantValue
100        new CharValue(cv.toChar)
101    }
102
103    def DoubleValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
104        val cv: ConstantValue[_] = const_value_index.asConstantValue
105        new DoubleValue(cv.toDouble)
106    }
107
108    def FloatValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
109        val cv: ConstantValue[_] = const_value_index.asConstantValue
110        new FloatValue(cv.toFloat)
111    }
112
113    def IntValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
114        val cv: ConstantValue[_] = const_value_index.asConstantValue
115        new IntValue(cv.toInt)
116    }
117
118    def LongValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
119        val cv: ConstantValue[_] = const_value_index.asConstantValue
120        new LongValue(cv.toLong)
121    }
122
123    def ShortValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
124        val cv: ConstantValue[_] = const_value_index.asConstantValue
125        new ShortValue(cv.toShort)
126    }
127
128    def BooleanValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
129        val cv: ConstantValue[_] = const_value_index.asConstantValue
130        new BooleanValue(cv.toBoolean)
131    }
132
133    def StringValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
134        val cv: ConstantValue[_] = const_value_index.asConstantValue
135        new StringValue(cv.toUTF8)
136    }
137
138    def ClassValue(const_value_index: Constant_Pool_Index)(implicit cp: Constant_Pool): ElementValue = {
139        val rt: String = const_value_index.asString
140        new ClassValue(ReturnType(rt))
141    }
142
143    def EnumValue(type_name_index: Constant_Pool_Index,
144                  const_name_index: Constant_Pool_Index)(
145                      implicit cp: Constant_Pool): ElementValue = {
146        // TODO Looks suspicious... either comment or fix.
147        new EnumValue(type_name_index.asFieldType.asInstanceOf[ObjectType], const_name_index.asString)
148    }
149
150    def AnnotationValue(annotation: Annotation)(implicit cp: Constant_Pool): ElementValue =
151        new AnnotationValue(annotation)
152
153    def ArrayValue(values: ElementValues)(implicit cp: Constant_Pool): ElementValue =
154        new ArrayValue(values)
155
156    def Annotation(type_index: Constant_Pool_Index,
157                   element_value_pairs: ElementValuePairs)(
158                       implicit cp: Constant_Pool) = {
159        new Annotation(type_index.asFieldType, element_value_pairs)
160    }
161
162    def AnnotationDefault_attribute(attribute_name_index: Constant_Pool_Index,
163                                    attribute_length: Int,
164                                    element_value: ElementValue)(
165                                        implicit cp: Constant_Pool) = {
166        element_value
167    }
168
169    def RuntimeVisibleAnnotations_attribute(attribute_name_index: Constant_Pool_Index,
170                                            attribute_length: Int,
171                                            annotations: Annotations)(
172                                                implicit cp: Constant_Pool) =
173        new RuntimeVisibleAnnotations_attribute(annotations)
174
175    def RuntimeInvisibleAnnotations_attribute(attribute_name_index: Constant_Pool_Index,
176                                              attribute_length: Int,
177                                              annotations: Annotations)(
178                                                  implicit cp: Constant_Pool) =
179        new RuntimeInvisibleAnnotations_attribute(annotations)
180
181    def RuntimeVisibleParameterAnnotations_attribute(attribute_name_index: Constant_Pool_Index,
182                                                     attribute_length: Int,
183                                                     parameter_annotations: ParameterAnnotations)(
184                                                         implicit cp: Constant_Pool) =
185        new RuntimeVisibleParameterAnnotations_attribute(parameter_annotations)
186
187    def RuntimeInvisibleParameterAnnotations_attribute(attribute_name_index: Constant_Pool_Index,
188                                                       attribute_length: Int,
189                                                       parameter_annotations: ParameterAnnotations)(
190                                                           implicit cp: Constant_Pool) =
191        new RuntimeInvisibleParameterAnnotations_attribute(parameter_annotations)
192
193}
194
195