home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
DTConstructor.java
< prev
next >
Wrap
Text File
|
1998-10-25
|
5KB
|
167 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 DTConstructor extends DTMember implements java.io.Serializable
{
static final long serialVersionUID = -5975450004844899437L;
transient boolean valid; // set by validate
/**
* Constructor. Only the dtreflect package may construct a DTConstructor.
*/
DTConstructor(DTClass clazz, String name, int modifiers, String parameters, String parameterNames, String exceptions) {
super(clazz,name,modifiers,parameters,parameterNames,"",exceptions);
}
/**
* Constructor for serialization.
*/
DTConstructor() {}
/**
* gets the text range from the beginning of the constructor 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 constructor's Javadoc comment
* to the closing asterisk-slash characters
*/
public Range getJavadocRange() {
return clazz.getJavadocRange(this);
}
/**
* Compares this DTConstructor against the specified object. Returns
* true if the objects are the same. Two constructors are the same if
* they were declared by the same class and have the same name
* and formal parameter types.
*/
public boolean equals(Object obj) {
if (obj instanceof DTConstructor) {
DTConstructor other = (DTConstructor)obj;
return this.equals(other);
}
return false;
}
/**
* Compares this DTConstructor against the specified DTConstructor. Returns
* true if the constructors are the same. Two Constructors are the same if
* they were declared by the same class and have the same name
* and formal parameter types.
*/
public boolean equals(DTConstructor other) {
if ((other != null)
&& (clazz.equals(other.clazz))
&& (name.equals(other.name))
&& (parameters.equals(other.parameters))
&& (exceptions.equals(other.exceptions))
&& (modifiers == other.modifiers))
return true;
return false;
}
/**
* Compares the formal signature of this DTConstructor with another.
* Returns true if the unqualified method name and number and
* types of arguments are the same.
public boolean equalSignatures(DTConstructor other) {
if (other != null
&& getName().equals(other.getName())
&& getParameters().equals(other.getParameters()))
return true;
return false;
}
/**
* Returns a string describing this DTConstructor. The string is
* formatted as the constructor access modifiers, if any,
* followed by a space, followed by the
* class declaring the constructor, followed by a period, followed by
* the constructor name, followed by a parenthesized, comma-separated
* list of the constructor's formal parameter types. If the constructor
* throws checked exceptions, the parameter list is followed by a
* space, followed by the word throws followed by a
* comma-separated list of the thrown exception types.
* For example:
* <pre>
* public boolean java.lang.Object.equals(java.lang.Object)
* </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());
sb.append("(");
sb.append(parameters);
sb.append(")");
if (exceptions.length() > 0) {
sb.append(" throws ");
sb.append(exceptions);
}
return sb.toString();
} catch (Exception e) {
return "<" + e + ">";
}
}
/**
* Returns a short string describing this DTConstructor.
* The string consists of the constructor name followed by the
* parameter types in parenthesis, e.g., "substring(int,int)".
*/
public String toShortString() {
try {
StringBuffer sb = new StringBuffer();
sb.append(name + "(");
sb.append(parameters);
sb.append(")");
return sb.toString();
} catch (Exception e) {
return "<" + e + ">";
}
}
/**
* Finish serializing in.
*/
private void readObject(java.io.ObjectInputStream in)
throws java.io.IOException, ClassNotFoundException {
in.defaultReadObject();
validate();
}
public boolean validate() {
DTConstructor cons = clazz.getDeclaredConstructor(getParameterTypes());
return valid = equals(cons);
}
}