Initial commit from SVN.

This commit is contained in:
wcrisman
2014-05-30 10:31:51 -07:00
commit b45e56b890
1968 changed files with 370949 additions and 0 deletions

View File

@@ -0,0 +1,122 @@
package com.de22.javabytecode;
/**
* Copyright Wynne Crisman 1999,2006<p>
*/
public abstract class Component implements ITypeComponent {
public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
private Type type = null;
/**
* Converts a class name in the java class file format to class name in the java source format.
* @param type The class to convert to a java format (which except for native non-array types (such as int), can be sent to a class loader).
* @return The java source formatted class name.
*/
public static String classFileFormatToJavaFormat(String type) {
String result = null;
if(type.charAt(0) == '[') {
result = type.replace('/', '.');
}//if//
else if(type.charAt(0) == 'L') {
result = type.substring(1, type.length() - 1).replace('/', '.');
}//else if//
else {
switch(type.charAt(0)) {
case 'V': {
result = Void.TYPE.getName();
break;
}//case//
case 'I': {
result = Integer.TYPE.getName();
break;
}//case//
case 'B': {
result = Byte.TYPE.getName();
break;
}//case//
case 'C': {
result = Character.TYPE.getName();
break;
}//case//
case 'S': {
result = Short.TYPE.getName();
break;
}//case//
case 'Z': {
result = Boolean.TYPE.getName();
break;
}//case//
case 'D': {
result = Double.TYPE.getName();
break;
}//case//
case 'F': {
result = Float.TYPE.getName();
break;
}//case//
case 'J': {
result = Long.TYPE.getName();
break;
}//case//
}//switch//
}//else//
return result;
}//classFileFormatToJavaFormat()//
/**
* Converts class names in the java class file format to class names in the java source format.
* @param types The classes to convert to a java format.
* @return The java source formatted class names.
*/
public static String[] classFileFormatToJavaFormat(String[] types) {
String[] result = new String[types.length];
for(int typeIndex = 0; typeIndex < types.length; typeIndex++) {
result[typeIndex] = classFileFormatToJavaFormat(types[typeIndex]);
}//for//
return result;
}//classFileFormatToJavaFormat()//
/**
* Component constructor.
*/
public Component(Type type) {
super();
this.type = type;
}//Component()//
/**
* Appends a the end of line characters to the buffer.
* <p>This is a utility method to assist the toString(StringBuffer, int) implementations.
* @param buffer The buffer to write an end of line to.
*/
protected static void appendEndOfLine(StringBuffer buffer) {
buffer.append('\r');
buffer.append('\n');
}//appendEndOfLine()//
/**
* Appends tab characters to the buffer.
* <p>This is a utility method to assist the toString(StringBuffer, int) implementations.
* @param buffer The buffer to write a tabs to.
* @param tabCount The number of tabs to append.
*/
protected static void appendTabs(StringBuffer buffer, int tabCount) {
while(tabCount-- != 0) {
buffer.append('\t');
}//while//
}//appendTabs()//
/**
* Gets the class associated with this component.
* @return The class information that this component is a member of.
*/
protected Type getType() {
return type;
}//getType()//
/**
* Displays the component and all subcomponents in human readable string form.
* @param buffer The buffer to display to.
* @param tabCount The number of tabs to prepend to each line.
*/
public abstract void toString(StringBuffer buffer, int tabCount);
}//Component//