1 | /*
|
---|
2 | * Copyright 2000-2002,2004 The Apache Software Foundation
|
---|
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 org.apache.tools.ant.taskdefs.optional.depend.constantpool;
|
---|
18 |
|
---|
19 | import java.io.DataInputStream;
|
---|
20 | import java.io.IOException;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * A NameAndType CP Info
|
---|
24 | *
|
---|
25 | */
|
---|
26 | public class NameAndTypeCPInfo extends ConstantPoolEntry {
|
---|
27 |
|
---|
28 | /** Constructor. */
|
---|
29 | public NameAndTypeCPInfo() {
|
---|
30 | super(CONSTANT_NAMEANDTYPE, 1);
|
---|
31 | }
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * read a constant pool entry from a class stream.
|
---|
35 | *
|
---|
36 | * @param cpStream the DataInputStream which contains the constant pool
|
---|
37 | * entry to be read.
|
---|
38 | * @exception IOException if there is a problem reading the entry from
|
---|
39 | * the stream.
|
---|
40 | */
|
---|
41 | public void read(DataInputStream cpStream) throws IOException {
|
---|
42 | nameIndex = cpStream.readUnsignedShort();
|
---|
43 | descriptorIndex = cpStream.readUnsignedShort();
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Print a readable version of the constant pool entry.
|
---|
48 | *
|
---|
49 | * @return the string representation of this constant pool entry.
|
---|
50 | */
|
---|
51 | public String toString() {
|
---|
52 | String value;
|
---|
53 |
|
---|
54 | if (isResolved()) {
|
---|
55 | value = "Name = " + name + ", type = " + type;
|
---|
56 | } else {
|
---|
57 | value = "Name index = " + nameIndex
|
---|
58 | + ", descriptor index = " + descriptorIndex;
|
---|
59 | }
|
---|
60 |
|
---|
61 | return value;
|
---|
62 | }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Resolve this constant pool entry with respect to its dependents in
|
---|
66 | * the constant pool.
|
---|
67 | *
|
---|
68 | * @param constantPool the constant pool of which this entry is a member
|
---|
69 | * and against which this entry is to be resolved.
|
---|
70 | */
|
---|
71 | public void resolve(ConstantPool constantPool) {
|
---|
72 | name = ((Utf8CPInfo) constantPool.getEntry(nameIndex)).getValue();
|
---|
73 | type = ((Utf8CPInfo) constantPool.getEntry(descriptorIndex)).getValue();
|
---|
74 |
|
---|
75 | super.resolve(constantPool);
|
---|
76 | }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Get the name component of this entry
|
---|
80 | *
|
---|
81 | * @return the name of this name and type entry
|
---|
82 | */
|
---|
83 | public String getName() {
|
---|
84 | return name;
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Get the type signature of this entry
|
---|
89 | *
|
---|
90 | * @return the type signature of this entry
|
---|
91 | */
|
---|
92 | public String getType() {
|
---|
93 | return type;
|
---|
94 | }
|
---|
95 |
|
---|
96 | /** the name component of this entry */
|
---|
97 | private String name;
|
---|
98 | /** the type component of this entry */
|
---|
99 | private String type;
|
---|
100 | /**
|
---|
101 | * the index into the constant pool at which the name component's string
|
---|
102 | * value is stored
|
---|
103 | */
|
---|
104 | private int nameIndex;
|
---|
105 | /**
|
---|
106 | * the index into the constant pool where the type descriptor string is
|
---|
107 | * stored.
|
---|
108 | */
|
---|
109 | private int descriptorIndex;
|
---|
110 | }
|
---|
111 |
|
---|