📄 cpinfo.java
字号:
/**
*
*/
package gen.info.constant;
import gen.ClassFile;
import gen.constvalue.CpInfoConst;
import java.io.DataOutputStream;
import java.io.IOException;
/**
* constant pool information
*
* @author liuyi
*
*/
public abstract class CpInfo implements CpInfoConst {
protected int tag;
protected short index;
protected ClassFile classFile;
public CpInfo(int tag, ClassFile classFile) {
this.tag = tag;
this.classFile = classFile;
index = -1;
}
public int getTag() {
return tag;
}
/**
* @param size
*/
public void setIndex(int size) {
this.index = (short)size;
}
public short getIndex() {
return index;
}
public boolean sameAs(CpInfo cpInfo) {
if (tag != cpInfo.tag) {
return false;
} else {
switch (tag) {
case CpInfoConst.CONSTANT_Integer:
ConstantIntegerInfo intThis = (ConstantIntegerInfo) this;
ConstantIntegerInfo intThat = (ConstantIntegerInfo) cpInfo;
if (intThis.getBytes() != intThat.getBytes()) {
return false;
}
break;
// case CpInfoConst.CONSTANT_Long:
case CpInfoConst.CONSTANT_Float:
ConstantFloatInfo floatThis = (ConstantFloatInfo) this;
ConstantFloatInfo floatThat = (ConstantFloatInfo) cpInfo;
if (floatThis.getBytes() != floatThat.getBytes()) {
return false;
}
break;
// case CpInfoConst.CONSTANT_Double:
case CpInfoConst.CONSTANT_Utf8:
ConstantUtf8Info utf8This = (ConstantUtf8Info) this;
ConstantUtf8Info utf8That = (ConstantUtf8Info) cpInfo;
if (!new String(utf8This.getBytes()).equals(new String(utf8That.getBytes()))) {
return false;
}
break;
case CpInfoConst.CONSTANT_String:
ConstantStringInfo strthis = (ConstantStringInfo) this;
ConstantStringInfo strthat = (ConstantStringInfo) cpInfo;
if(strthis.getStringIndex() != strthat.getStringIndex()){
return false;
}
break;
case CpInfoConst.CONSTANT_Fieldref:
ConstantFieldrefInfo fieldthis = (ConstantFieldrefInfo) this;
ConstantFieldrefInfo fieldthat = (ConstantFieldrefInfo) cpInfo;
if(fieldthis.getClassIndex() != fieldthat.getClassIndex()
|| fieldthis.getNameAndTypeIndex() != fieldthat.getNameAndTypeIndex()){
return false;
}
break;
case CpInfoConst.CONSTANT_Methodref:
ConstantMethodrefInfo methodthis = (ConstantMethodrefInfo) this;
ConstantMethodrefInfo methodthat = (ConstantMethodrefInfo) cpInfo;
if(methodthis.getClassIndex() != methodthat.getClassIndex()
|| methodthis.getNameAndTypeIndex() != methodthat.getNameAndTypeIndex()){
return false;
}
break;
case CpInfoConst.CONSTANT_Class:
ConstantClassInfo classthis = (ConstantClassInfo) this;
ConstantClassInfo classthat = (ConstantClassInfo) cpInfo;
if(classthis.getNameIndex() != classthat.getNameIndex()){
return false;
}
break;
case CpInfoConst.CONSTANT_NameAndType:
ConstantNameAndTypeInfo NATthis = (ConstantNameAndTypeInfo) this;
ConstantNameAndTypeInfo NATthat = (ConstantNameAndTypeInfo) cpInfo;
if(NATthis.getNameIndex() != NATthat.getNameIndex()
|| NATthis.getDescriptorIndex() != NATthat.getDescriptorIndex()){
return false;
}
break;
default:
System.out.println("CpInfo/sameAs: haven't ever realized! tag: " + tag);
return false;
}
}
return true;
}
public String getRefString(){
throw new UnsupportedOperationException();
}
public void toBinary(DataOutputStream writer) throws IOException{
throw new UnsupportedOperationException();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -