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 17package com.android.dx.rop.cst; 18 19import com.android.dx.rop.type.Type; 20 21/** 22 * Constant type to represent a reference to a particular constant 23 * value of an enumerated type. 24 */ 25public final class CstEnumRef extends CstMemberRef { 26 /** {@code null-ok;} the corresponding field ref, lazily initialized */ 27 private CstFieldRef fieldRef; 28 29 /** 30 * Constructs an instance. 31 * 32 * @param nat {@code non-null;} the name-and-type; the defining class is derived 33 * from this 34 */ 35 public CstEnumRef(CstNat nat) { 36 super(new CstType(nat.getFieldType()), nat); 37 38 fieldRef = null; 39 } 40 41 /** {@inheritDoc} */ 42 @Override 43 public String typeName() { 44 return "enum"; 45 } 46 47 /** 48 * {@inheritDoc} 49 * 50 * <b>Note:</b> This returns the enumerated type. 51 */ 52 public Type getType() { 53 return getDefiningClass().getClassType(); 54 } 55 56 /** 57 * Get a {@link CstFieldRef} that corresponds with this instance. 58 * 59 * @return {@code non-null;} the corresponding field reference 60 */ 61 public CstFieldRef getFieldRef() { 62 if (fieldRef == null) { 63 fieldRef = new CstFieldRef(getDefiningClass(), getNat()); 64 } 65 66 return fieldRef; 67 } 68} 69