home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
DTField.java
< prev
next >
Wrap
Text File
|
1998-10-25
|
4KB
|
146 lines
/*
* Copyright 1998 Symantec Corporation, All Rights Reserved.
*/
package com.symantec.itools.vcafe.openapi.dtreflect;
import com.symantec.itools.vcafe.openapi.Range;
import java.lang.reflect.*;
public class DTField extends DTMember implements java.io.Serializable
{
static final long serialVersionUID = -1442822286115441750L;
transient boolean valid; // set by validate
/**
* Constructor. Used only by DTClass native methods.
*/
DTField(DTClass clazz, String name, int modifiers, String returns) {
super(clazz,name,modifiers,"","",returns,"");
}
/**
* Constructor for serialization.
*/
private DTField() {
}
/**
* gets the text range from the beginning of the field declaration to the closing brace
*/
public Range getSourceRange() {
return clazz.getSourceRange(this);
}
/**
* gets the text range from the beginning of the first line of the field's Javadoc comment
* to the closing asterisk-slash characters
*/
public Range getJavadocRange() {
return clazz.getJavadocRange(this);
}
/**
* Renames the field to new name
* @param newName: The new name of the field
* @return Success (true) or failure (false)...
*/
public boolean rename(String newName) {
return clazz.rename(this, newName);
}
/**
* Compares this DTField against the specified object. Returns
* true if the objects are the same. Two Fields are the same if
* they were declared by the same class and have the same name,
* type and modifiers.
*/
public boolean equals(Object obj) {
if (obj instanceof DTField) {
DTField other = (DTField)obj;
return this.equals(other);
}
return false;
}
/**
* Compares this DTField against the specified DTField. Returns
* true if the fields are the same. Two Fields are the same if
* they were declared by the same class and have the same name,
* type and modifiers.
*/
public boolean equals(DTField other) {
if ((other != null)
&& (clazz.equals(other.clazz))
&& (name.equals(other.name))
&& (returns.equals(other.returns))
&& (modifiers == other.modifiers))
return true;
return false;
}
/**
* Returns a string describing this DTField. The string is
* formatted as the field access modifiers, if any, followed by
* the field type, followed by the
* class declaring the field, followed by a period, followed by
* the field name.
* For example:
* <pre>
* private float java.lang.Float.value
* </pre>
*
* <p>The access modifiers are placed in canonical order as
* specified by "The Java Language Specification". This is
* <tt>public</tt>, <tt>protected</tt> or <tt>private</tt> first,
* and then other modifiers in the following order:
* <tt>abstract</tt>, <tt>static</tt>, <tt>final</tt>,
* <tt>synchronized</tt> <tt>native</tt>.
*/
public String toString() {
try {
StringBuffer sb = new StringBuffer();
int mod = getModifiers();
if (mod != 0) {
sb.append(Modifier.toString(mod));
sb.append(" ");
}
sb.append(returns);
sb.append(" ");
sb.append(getDeclaringClass().getName());
sb.append(".");
sb.append(getName());
return sb.toString();
} catch (Exception e) {
return "<" + e + ">";
}
}
/**
* Returns a short string describing this DTField.
* The string consists of the field name,
* e.g., "substring(int,int)".
*/
public String toShortString() {
return getName();
}
/**
* Finish serializing in.
*/
private void readObject(java.io.ObjectInputStream in)
throws java.io.IOException, ClassNotFoundException {
in.defaultReadObject();
validate();
}
public boolean validate() {
DTField field = clazz.getDeclaredField(getName());
if (field == null || !field.getReturns().equals(getReturns()))
return valid = false;
return valid = true;
}
}