Home | History | Annotate | Download | only in dex
      1 /*
      2  * Copyright (C) 2011 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 package com.android.dex;
     18 
     19 /**
     20  * A type definition.
     21  */
     22 public final class ClassDef {
     23     public static final int NO_INDEX = -1;
     24     private final Dex buffer;
     25     private final int offset;
     26     private final int typeIndex;
     27     private final int accessFlags;
     28     private final int supertypeIndex;
     29     private final int interfacesOffset;
     30     private final int sourceFileIndex;
     31     private final int annotationsOffset;
     32     private final int classDataOffset;
     33     private final int staticValuesOffset;
     34 
     35     public ClassDef(Dex buffer, int offset, int typeIndex, int accessFlags,
     36             int supertypeIndex, int interfacesOffset, int sourceFileIndex,
     37             int annotationsOffset, int classDataOffset, int staticValuesOffset) {
     38         this.buffer = buffer;
     39         this.offset = offset;
     40         this.typeIndex = typeIndex;
     41         this.accessFlags = accessFlags;
     42         this.supertypeIndex = supertypeIndex;
     43         this.interfacesOffset = interfacesOffset;
     44         this.sourceFileIndex = sourceFileIndex;
     45         this.annotationsOffset = annotationsOffset;
     46         this.classDataOffset = classDataOffset;
     47         this.staticValuesOffset = staticValuesOffset;
     48     }
     49 
     50     public int getOffset() {
     51         return offset;
     52     }
     53 
     54     public int getTypeIndex() {
     55         return typeIndex;
     56     }
     57 
     58     public int getSupertypeIndex() {
     59         return supertypeIndex;
     60     }
     61 
     62     public int getInterfacesOffset() {
     63         return interfacesOffset;
     64     }
     65 
     66     public short[] getInterfaces() {
     67         return buffer.readTypeList(interfacesOffset).getTypes();
     68     }
     69 
     70     public int getAccessFlags() {
     71         return accessFlags;
     72     }
     73 
     74     public int getSourceFileIndex() {
     75         return sourceFileIndex;
     76     }
     77 
     78     public int getAnnotationsOffset() {
     79         return annotationsOffset;
     80     }
     81 
     82     public int getClassDataOffset() {
     83         return classDataOffset;
     84     }
     85 
     86     public int getStaticValuesOffset() {
     87         return staticValuesOffset;
     88     }
     89 
     90     @Override
     91     public String toString() {
     92         if (buffer == null) {
     93             return typeIndex + " " + supertypeIndex;
     94         }
     95 
     96         StringBuilder result = new StringBuilder();
     97         result.append(buffer.typeNames().get(typeIndex));
     98         if (supertypeIndex != NO_INDEX) {
     99             result.append(" extends ").append(buffer.typeNames().get(supertypeIndex));
    100         }
    101         return result.toString();
    102     }
    103 }
    104