home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
DTMember.java
< prev
next >
Wrap
Text File
|
1998-10-25
|
8KB
|
263 lines
/*
* Copyright 1998 Symantec Corporation, All Rights Reserved.
*/
package com.symantec.itools.vcafe.openapi.dtreflect;
import com.symantec.itools.vcafe.openapi.Range;
import java.util.Vector;
import java.io.*;
public abstract class DTMember implements java.io.Serializable
{
static final long serialVersionUID = -4216301143967605388L;
protected DTClass clazz; // declaring class
protected String name; // method name
protected int modifiers; // flags
protected String parameters; // expressed as "[typename1[,typename2,...]]"
protected String parameterNames; // expressed as "[name1[,name2,...]]"
protected String returns; // expressed as "typename"
protected String exceptions; // expressed as "[typename1[,typename2,...]]"
/**
* Constructor. Only the dtreflect package may construct a DTMember.
*/
DTMember(DTClass clazz, String name, int modifiers, String parameters, String parameterNames, String returns, String exceptions) {
this.clazz = clazz;
this.name = name;
this.modifiers = modifiers;
this.parameters = parameters;
this.parameterNames = parameterNames;
this.returns = returns;
this.exceptions = exceptions;
}
/**
* Constructor for serialization.
*/
DTMember() {
}
/**
* Identifies the set of all public members of a class or interface,
* including inherited members.
*/
public static final int PUBLIC = 0;
/**
* Identifies the set of declared members of a class or interface.
* Inherited members are not included.
*/
public static final int DECLARED = 1;
/**
* Returns the Class object representing the class or interface
* that declares the member or constructor represented by this Member.
*/
public DTClass getDeclaringClass() {
return clazz;
}
/**
* Returns the simple name of the underlying member or constructor
* represented by this Member.
*/
public String getName() {
return name;
}
/**
* Returns the Java language modifiers for the member or
* constructor represented by this Member, as an integer. The
* Modifier class should be used to decode the modifiers in
* the integer.
* @see Modifier
*/
public int getModifiers() {
return modifiers;
}
/**
* Returns the parameters of the method represented by this DTMember
* object, as a String, e.g., "java.lang.String,int".
* For fields, getParameters() returns an empty string.
*/
public String getParameters() {
return parameters;
}
/**
* Returns the number of parameters of the method represented by this DTMember.
*/
public int getNumParameters() {
if (parameters.equals(""))
return 0;
int num = 1, pos = 0;
while ((pos = parameters.indexOf(',', pos)) != -1)
{
num++;
pos++;
}
return num;
}
/**
* Returns an array of DTClass objects that represent the formal
* parameter types, in declaration order, of the method/constructor
* represented by this DTMember object. Returns an array of length
* 0 if the underlying method takes no parameters or for a field.
*
* <p>Returns null if a class could not be created.
*/
public DTClass[] getParameterTypes() {
return parametersToClassArray(parameters);
}
/**
* Returns an array of String objects that represent the formal
* parameter type names, in declaration order, of the method/constructor
* represented by this DTMember object. Returns an array of length
* 0 if the underlying method takes no parameters,or for a field.
*
* <p>Returns null if a class could not be created.
*/
public String[] getParameterTypeNames() {
return parametersToStringArray(parameters);
}
/**
* Returns the parameter names of the method represented by this DTMember
* object, as a String, e.g., "c,i".
* For fields, getParameters() returns an empty string.
*/
public String getParameterNames() {
return parameterNames;
}
/**
* Returns the return type as a String, e.g., "java.lang.String".
* For constructors, the type is "void". For fields, this is
* the field type.
*/
public String getReturns() {
return returns;
}
/**
* Returns a Class object that identifies the declared type for
* the field or the return type of the method. Constructor type
* is always DTClass.VoidType.
*/
public DTClass getType() {
return returns == "" ? DTClass.VoidType : DTClass.findClass(clazz.getProject(), returns);
}
/**
* Returns the exceptions of the method represented by this DTMethod
* object, as a String, e.g., "java.lang.NullPointerException,java.lang.NumberFormatException".
* The exceptions appear in alphabetical order.
*/
public String getExceptions() {
return exceptions;
}
/**
* Returns an array of DTClass objects that represent the types of
* the checked exceptions thrown by the underlying method
* represented by this DTMethod object. Returns an array of length
* 0 if the method throws no checked exceptions. Returns null
* in the corresponding array element if a class cannot be created.
* @see DTClass#nonNull
*/
public DTClass[] getExceptionTypes() {
return parametersToClassArray(exceptions);
}
/**
* Returns a hashcode for this DTMember. The hashcode is computed
* as the exclusive-or of the hashcodes for the declaring class name
* and the member's name.
*/
public int hashCode() {
return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
}
/**
* gets the text range from the beginning of the member declaration to the closing brace
* (or semicolon for native or abstract members)
*/
public abstract Range getSourceRange();
/**
* gets the text range from the beginning of the first line of the member's Javadoc comment
* to the closing asterisk-slash characters
*/
public abstract Range getJavadocRange();
/**
* Ensure that this member is valid in its project
*/
public abstract boolean validate();
/**
* Return true if one expression is equivalent to another.
* <p>Argument values are not taken into account in the comparision,
* just the "value" of the expression.
*/
public boolean equals(Object obj) {
if (obj != null && getClass() == obj.getClass()) {
DTMember other = (DTMember) obj;
return clazz.equals(other.clazz) && name.equals(other.name) && modifiers == other.modifiers
&& (parameters == null ? other.parameters == null : parameters.equals(other.parameters));
}
return false;
}
/**
* Utility method converts a comma-delimited string of
* type names into an array of DTClass. Like most
* other methods, does not throw if DTClass can't be
* created, just returns null in the corresponding
* array entry.
*
* @param sig string of types, e.g., "int,java.lang.String"
*/
public DTClass[] parametersToClassArray(String sig) {
int start = 0, len = sig.length();
Vector v = new Vector();
while (start < len) {
int i = sig.indexOf(',', start);
if (i < 0)
i = len;
v.addElement(DTClass.findClass(clazz.getProject(),sig.substring(start,i)));
start = i + 1;
}
DTClass[] ret = new DTClass[v.size()];
v.copyInto(ret);
return ret;
}
/**
* Utility method converts a comma-delimited string of
* type names into an array of String.
*
* @param sig string of types, e.g., "int,java.lang.String"
*/
public String[] parametersToStringArray(String sig) {
int start = 0, len = sig.length();
Vector v = new Vector();
while (start < len) {
int i = sig.indexOf(',', start);
if (i < 0)
i = len;
v.addElement(sig.substring(start,i));
start = i + 1;
}
String[] ret = new String[v.size()];
v.copyInto(ret);
return ret;
}
}