1
|
package jdeserialize;
|
2
|
import java.io.*;
|
3
|
import java.util.*;
|
4
|
|
5
|
/**
|
6
|
* This class represents a field within a class description/declaration (classdesc). It
|
7
|
* contains information about the type and name of the field. Fields themselves don't
|
8
|
* have a handle; inside the stream, they exist only as part of a class description.
|
9
|
*/
|
10
|
public class field {
|
11
|
/**
|
12
|
* The type of the field.
|
13
|
*/
|
14
|
public fieldtype type;
|
15
|
|
16
|
/**
|
17
|
* The name of the field.
|
18
|
*/
|
19
|
public String name;
|
20
|
|
21
|
/**
|
22
|
* The string object representing the class name.
|
23
|
*/
|
24
|
public stringobj classname;
|
25
|
|
26
|
private boolean isInnerClassReference = false;
|
27
|
|
28
|
/**
|
29
|
* Tells whether or not this class is an inner class reference. This value is set by
|
30
|
* connectMemberClasses() -- if this hasn't been called, or if the field hasn't been
|
31
|
* otherwise set by setIsInnerClassReference(), it will be false;
|
32
|
*
|
33
|
* @return true if the class is an inner class reference
|
34
|
*/
|
35
|
public boolean isInnerClassReference() {
|
36
|
return isInnerClassReference;
|
37
|
}
|
38
|
|
39
|
/**
|
40
|
* Sets the flag that denotes whether this class is an inner class reference.
|
41
|
*
|
42
|
* @param nis the value to set; true iff the class is an inner class reference.
|
43
|
*/
|
44
|
public void setIsInnerClassReference(boolean nis) {
|
45
|
this.isInnerClassReference = nis;
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* Constructor.
|
50
|
*
|
51
|
* @param type the field type
|
52
|
* @param name the field name
|
53
|
* @param classname the class name
|
54
|
*/
|
55
|
public field(fieldtype type, String name, stringobj classname) throws ValidityException {
|
56
|
this.type = type;
|
57
|
this.name = name;
|
58
|
this.classname = classname;
|
59
|
if(classname != null) {
|
60
|
validate(classname.value);
|
61
|
}
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* Constructor for simple fields.
|
66
|
*
|
67
|
* @param type the field type
|
68
|
* @param name the field name
|
69
|
*/
|
70
|
public field(fieldtype type, String name) throws ValidityException {
|
71
|
this(type, name, null);
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* Get a string representing the type for this field in Java (the language)
|
76
|
* format.
|
77
|
* @return a string representing the fully-qualified type of the field
|
78
|
* @throws IOException if a validity or I/O error occurs
|
79
|
*/
|
80
|
public String getJavaType() throws IOException {
|
81
|
return jdeserialize.resolveJavaType(this.type, this.classname == null ? null : this.classname.value, true, false);
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* Changes the name of an object reference to the name specified. This is used by
|
86
|
* the inner-class-connection code to fix up field references.
|
87
|
* @param newname the fully-qualified class
|
88
|
* @throws ValidityException if the field isn't a reference type, or another
|
89
|
* validity error occurs
|
90
|
*/
|
91
|
public void setReferenceTypeName(String newname) throws ValidityException {
|
92
|
if(this.type != fieldtype.OBJECT) {
|
93
|
throw new ValidityException("can't fix up a non-reference field!");
|
94
|
}
|
95
|
String nname = "L" + newname.replace('.', '/') + ";";
|
96
|
this.classname.value = nname;
|
97
|
}
|
98
|
public void validate(String jt) throws ValidityException {
|
99
|
if(this.type == fieldtype.OBJECT) {
|
100
|
if(jt == null) {
|
101
|
throw new ValidityException("classname can't be null");
|
102
|
}
|
103
|
if(jt.charAt(0) != 'L') {
|
104
|
throw new ValidityException("invalid object field type descriptor: " + classname.value);
|
105
|
}
|
106
|
int end = jt.indexOf(';');
|
107
|
if(end == -1 || end != (jt.length()-1)) {
|
108
|
throw new ValidityException("invalid object field type descriptor (must end with semicolon): " + classname.value);
|
109
|
}
|
110
|
}
|
111
|
}
|
112
|
}
|