Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 public class AnnotationValueInfo
     18 {
     19     private Object mValue;
     20     private String mString;
     21     private MethodInfo mElement;
     22 
     23     public AnnotationValueInfo(MethodInfo element)
     24     {
     25         mElement = element;
     26     }
     27 
     28     public void init(Object value)
     29     {
     30         mValue = value;
     31     }
     32 
     33     public MethodInfo element()
     34     {
     35         return mElement;
     36     }
     37 
     38     public Object value()
     39     {
     40         return mValue;
     41     }
     42 
     43     public String valueString()
     44     {
     45         Object v = mValue;
     46         if (v instanceof TypeInfo) {
     47             return ((TypeInfo)v).fullName();
     48         }
     49         else if (v instanceof FieldInfo) {
     50             StringBuilder str = new StringBuilder();
     51             FieldInfo f = (FieldInfo)v;
     52             str.append(f.containingClass().qualifiedName());
     53             str.append('.');
     54             str.append(f.name());
     55             return str.toString();
     56         }
     57         else if (v instanceof AnnotationInstanceInfo) {
     58             return v.toString();
     59         }
     60         else if (v instanceof AnnotationValueInfo[]) {
     61             StringBuilder str = new StringBuilder();
     62             AnnotationValueInfo[] array = (AnnotationValueInfo[])v;
     63             final int N = array.length;
     64             str.append("{");
     65             for (int i=0; i<array.length; i++) {
     66                 str.append(array[i].valueString());
     67                 if (i != N-1) {
     68                     str.append(",");
     69                 }
     70             }
     71             str.append("}");
     72             return str.toString();
     73         }
     74         else {
     75             return FieldInfo.constantLiteralValue(v);
     76         }
     77     }
     78 }
     79 
     80