зеркало из https://github.com/mozilla/pjs.git
1. Added ClassFileWriter.classNameToSignature to convert Java class name into JVM signature.
2. The public method getFullyQualifieedForm that was used to replace . to / is removed since all classname API accepts both form of class names and convertion to the internal /-form can be done in ClassFileWriter in a more efficient way.
This commit is contained in:
Родитель
c4b928f49a
Коммит
429111a705
|
@ -68,7 +68,7 @@ public class ClassFileWriter {
|
||||||
public ClassFileWriter(String className, String superClassName,
|
public ClassFileWriter(String className, String superClassName,
|
||||||
String sourceFileName)
|
String sourceFileName)
|
||||||
{
|
{
|
||||||
itsConstantPool = new ConstantPool();
|
itsConstantPool = new ConstantPool(this);
|
||||||
itsThisClassIndex = itsConstantPool.addClass(className);
|
itsThisClassIndex = itsConstantPool.addClass(className);
|
||||||
itsSuperClassIndex = itsConstantPool.addClass(superClassName);
|
itsSuperClassIndex = itsConstantPool.addClass(superClassName);
|
||||||
if (sourceFileName != null)
|
if (sourceFileName != null)
|
||||||
|
@ -120,10 +120,32 @@ public class ClassFileWriter {
|
||||||
itsFlags = flags;
|
itsFlags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String fullyQualifiedForm(String name) {
|
static String getSlashedForm(String name)
|
||||||
|
{
|
||||||
return name.replace('.', '/');
|
return name.replace('.', '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert Java class name in dot notation into
|
||||||
|
* "Lname-with-dots-replaced-by-slashes;" form suitable for use as
|
||||||
|
* JVM type signatures.
|
||||||
|
*/
|
||||||
|
public String classNameToSignature(String name)
|
||||||
|
{
|
||||||
|
int nameLength = name.length();
|
||||||
|
int colonPos = 1 + nameLength;
|
||||||
|
char[] buf = getCharBuffer(colonPos + 1);
|
||||||
|
buf[0] = 'L';
|
||||||
|
buf[colonPos] = ';';
|
||||||
|
name.getChars(0, nameLength, buf, 1);
|
||||||
|
for (int i = 1; i != colonPos; ++i) {
|
||||||
|
if (buf[i] == '.') {
|
||||||
|
buf[i] = '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new String(buf, 0, colonPos + 1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a field to the class.
|
* Add a field to the class.
|
||||||
*
|
*
|
||||||
|
@ -2245,6 +2267,16 @@ public class ClassFileWriter {
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final char[] getCharBuffer(int minimalSize)
|
||||||
|
{
|
||||||
|
if (minimalSize > tmpCharBuffer.length) {
|
||||||
|
int newSize = tmpCharBuffer.length * 2;
|
||||||
|
if (minimalSize > newSize) { newSize = minimalSize; }
|
||||||
|
tmpCharBuffer = new char[newSize];
|
||||||
|
}
|
||||||
|
return tmpCharBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
private static final int LineNumberTableSize = 16;
|
private static final int LineNumberTableSize = 16;
|
||||||
private static final int ExceptionTableSize = 4;
|
private static final int ExceptionTableSize = 4;
|
||||||
|
@ -2285,6 +2317,8 @@ public class ClassFileWriter {
|
||||||
private short itsSourceFileNameIndex;
|
private short itsSourceFileNameIndex;
|
||||||
|
|
||||||
private LabelTable itsLabels = new LabelTable();
|
private LabelTable itsLabels = new LabelTable();
|
||||||
|
|
||||||
|
private char[] tmpCharBuffer = new char[64];
|
||||||
}
|
}
|
||||||
|
|
||||||
final class ExceptionTableEntry
|
final class ExceptionTableEntry
|
||||||
|
@ -2433,8 +2467,9 @@ final class ClassFileMethod
|
||||||
final class ConstantPool
|
final class ConstantPool
|
||||||
{
|
{
|
||||||
|
|
||||||
ConstantPool()
|
ConstantPool(ClassFileWriter cfw)
|
||||||
{
|
{
|
||||||
|
this.cfw = cfw;
|
||||||
itsTopIndex = 1; // the zero'th entry is reserved
|
itsTopIndex = 1; // the zero'th entry is reserved
|
||||||
itsPool = new byte[ConstantPoolSize];
|
itsPool = new byte[ConstantPoolSize];
|
||||||
itsTop = 0;
|
itsTop = 0;
|
||||||
|
@ -2574,7 +2609,7 @@ final class ConstantPool
|
||||||
itsPool[top++] = CONSTANT_Utf8;
|
itsPool[top++] = CONSTANT_Utf8;
|
||||||
top += 2; // skip length
|
top += 2; // skip length
|
||||||
|
|
||||||
char[] chars = getCharBuffer(strLen);
|
char[] chars = cfw.getCharBuffer(strLen);
|
||||||
k.getChars(0, strLen, chars, 0);
|
k.getChars(0, strLen, chars, 0);
|
||||||
|
|
||||||
for (int i = 0; i != strLen; i++) {
|
for (int i = 0; i != strLen; i++) {
|
||||||
|
@ -2628,7 +2663,7 @@ final class ConstantPool
|
||||||
if (theIndex == -1) {
|
if (theIndex == -1) {
|
||||||
String slashed = className;
|
String slashed = className;
|
||||||
if (className.indexOf('.') > 0) {
|
if (className.indexOf('.') > 0) {
|
||||||
slashed = ClassFileWriter.fullyQualifiedForm(className);
|
slashed = ClassFileWriter.getSlashedForm(className);
|
||||||
theIndex = itsClassHash.get(slashed, -1);
|
theIndex = itsClassHash.get(slashed, -1);
|
||||||
if (theIndex != -1) {
|
if (theIndex != -1) {
|
||||||
itsClassHash.put(className, theIndex);
|
itsClassHash.put(className, theIndex);
|
||||||
|
@ -2713,15 +2748,8 @@ final class ConstantPool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private char[] getCharBuffer(int minimalSize) {
|
private ClassFileWriter cfw;
|
||||||
if (minimalSize > tmpCharBuffer.length) {
|
|
||||||
int newSize = tmpCharBuffer.length * 2;
|
|
||||||
if (minimalSize > newSize) { newSize = minimalSize; }
|
|
||||||
tmpCharBuffer = new char[newSize];
|
|
||||||
}
|
|
||||||
return tmpCharBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final int MAX_UTF_ENCODING_SIZE = 65535;
|
private static final int MAX_UTF_ENCODING_SIZE = 65535;
|
||||||
|
|
||||||
private UintMap itsStringConstHash = new UintMap();
|
private UintMap itsStringConstHash = new UintMap();
|
||||||
|
@ -2730,7 +2758,6 @@ final class ConstantPool
|
||||||
private ObjToIntMap itsMethodRefHash = new ObjToIntMap();
|
private ObjToIntMap itsMethodRefHash = new ObjToIntMap();
|
||||||
private UintMap nameAndTypeHash = new UintMap();
|
private UintMap nameAndTypeHash = new UintMap();
|
||||||
private ObjToIntMap itsClassHash = new ObjToIntMap();
|
private ObjToIntMap itsClassHash = new ObjToIntMap();
|
||||||
private char[] tmpCharBuffer = new char[64];
|
|
||||||
|
|
||||||
private int itsTop;
|
private int itsTop;
|
||||||
private int itsTopIndex;
|
private int itsTopIndex;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче