aboutsummaryrefslogtreecommitdiffstats
path: root/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/annotation/ClassElementValue.java
blob: c946b213f11b360d718ba664ed9454d05d434371 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* *******************************************************************
 * Copyright (c) 2004 IBM
 * All rights reserved.
 * This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License v 2.0
 * which accompanies this distribution and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
 *
 * Contributors:
 *     Andy Clement -     initial implementation {date}
 * ******************************************************************/

package org.aspectj.apache.bcel.classfile.annotation;

import java.io.DataOutputStream;
import java.io.IOException;

import org.aspectj.apache.bcel.classfile.ConstantPool;
import org.aspectj.apache.bcel.classfile.ConstantUtf8;
import org.aspectj.apache.bcel.generic.ObjectType;

public class ClassElementValue extends ElementValue {

	// For primitive types and string type, this points to the value entry in the cpool
	// For 'class' this points to the class entry in the cpool
	private int idx;

	protected ClassElementValue(int typeIdx, ConstantPool cpool) {
		super(ElementValue.CLASS, cpool);
		this.idx = typeIdx;
	}

	public ClassElementValue(ObjectType t, ConstantPool cpool) {
		super(ElementValue.CLASS, cpool);
		// this.idx = cpool.addClass(t);
		idx = cpool.addUtf8(t.getSignature());
	}

	/**
	 * Return immutable variant of this ClassElementValueGen
	 */
	// public ElementValueGen getElementValue() {
	// return new ClassElementValueGen(type,idx,cpGen);
	// }
	public ClassElementValue(ClassElementValue value, ConstantPool cpool, boolean copyPoolEntries) {
		super(CLASS, cpool);
		if (copyPoolEntries) {
			// idx = cpool.addClass(value.getClassString());
			idx = cpool.addUtf8(value.getClassString());
		} else {
			idx = value.getIndex();

		}
	}

	public int getIndex() {
		return idx;
	}

	public String getClassString() {
		ConstantUtf8 cu8 = (ConstantUtf8) getConstantPool().getConstant(idx);
		return cu8.getValue();
		// ConstantClass c = (ConstantClass)getConstantPool().getConstant(idx);
		// ConstantUtf8 utf8 = (ConstantUtf8)getConstantPool().getConstant(c.getNameIndex());
		// return utf8.getBytes();
	}

	@Override
	public String stringifyValue() {
		return getClassString();
	}

	@Override
	public void dump(DataOutputStream dos) throws IOException {
		dos.writeByte(type); // u1 kind of value
		dos.writeShort(idx);
	}

}