本文整理汇总了Java中org.apache.bcel.generic.Type类的典型用法代码示例。如果您正苦于以下问题:Java Type类的具体用法?Java Type怎么用?Java Type使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Type类属于org.apache.bcel.generic包,在下文中一共展示了Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sawOpcode
import org.apache.bcel.generic.Type; //导入依赖的package包/类
public void sawOpcode(int seen) {
try {
if ((seen == INVOKEINTERFACE)
&& (getClassConstantOperand().equals("java/sql/ResultSet"))) {
String methodName = getNameConstantOperand();
if ((methodName.startsWith("get") && dbFieldTypesSet.contains(methodName.substring(3)))
|| (methodName.startsWith("update") && dbFieldTypesSet.contains(methodName.substring(6)))) {
String signature = getSigConstantOperand();
Type[] argTypes = Type.getArgumentTypes(signature);
int numParms = argTypes.length;
if (stack.getStackDepth() >= numParms) {
OpcodeStack.Item item = stack.getStackItem(numParms-1);
Object cons = item.getConstant();
if ((cons != null) && ("I".equals(item.getSignature())) && (((Integer) cons).intValue() == 0)) {
bugReporter.reportBug(new BugInstance(this, "BRSA_BAD_RESULTSET_ACCESS", NORMAL_PRIORITY)
.addClassAndMethod(this)
.addSourceLine(this));
}
}
}
}
} finally {
stack.sawOpcode(this, seen);
}
}
示例2: isCompatible
import org.apache.bcel.generic.Type; //导入依赖的package包/类
/**
* Determines whether a method is compatible with the Method of
* this definition.
* @param aMethodName the name of the method to check.
* @param aArgTypes the method argument types.
* @return true if the method is compatible with the Method of
* this definition.
*/
public boolean isCompatible(String aMethodName, Type[] aArgTypes)
{
// same name?
if (!getName().equals(aMethodName)) {
return false;
}
// compatible argument types?
final Type[] methodTypes = getArgumentTypes();
if (methodTypes.length != aArgTypes.length) {
return false;
}
for (int i = 0; i < aArgTypes.length; i++) {
if (!Utils.isCompatible(aArgTypes[i], methodTypes[i])) {
return false;
}
}
return true;
}
示例3: findNarrowestMethod
import org.apache.bcel.generic.Type; //导入依赖的package包/类
/**
* Finds the narrowest method that is compatible with a method.
* An invocation of the given method can be resolved as an invocation
* of the narrowest method.
* @param aClassName the class for the method.
* @param aMethodName the name of the method.
* @param aArgTypes the types for the method.
* @return the narrowest compatible method.
*/
public MethodDefinition findNarrowestMethod(
String aClassName,
String aMethodName,
Type[] aArgTypes)
{
MethodDefinition result = null;
final String javaClassName = mJavaClass.getClassName();
if (Repository.instanceOf(aClassName, javaClassName)) {
// check all
for (int i = 0; i < mMethodDefs.length; i++) {
// TODO: check access privileges
if (mMethodDefs[i].isCompatible(aMethodName, aArgTypes)) {
if (result == null) {
result = mMethodDefs[i];
}
//else if (mMethodDefs[i].isAsNarrow(result)) {
else if (result.isCompatible(mMethodDefs[i])) {
result = mMethodDefs[i];
}
}
}
}
return result;
}
示例4: assertSupported
import org.apache.bcel.generic.Type; //导入依赖的package包/类
/**
* Check the signature of defineClass0
* @param args
*/
private static void assertSupported(Type[] args) {
if (args.length >= 5 &&
(
args[0].getSignature().equals("Ljava/lang/String;")
&& args[1].getSignature().equals("[B")
&& args[2].getSignature().equals("I")
&& args[3].getSignature().equals("I")
&& args[4].getSignature().equals("Ljava/security/ProtectionDomain;")
))
;
else {
StringBuffer sign = new StringBuffer("(");
for (int i = 0; i < args.length; i++) {
sign.append(args[i].toString());
if (i < args.length - 1)
sign.append(", ");
}
sign.append(")");
throw new Error("non standard JDK, native call not supported " + sign.toString());
}
}
示例5: isIllegalFinalType
import org.apache.bcel.generic.Type; //导入依赖的package包/类
private static boolean isIllegalFinalType(Type type, ClassContext classContext) {
if (type instanceof ObjectType) {
try {
String className = ((ObjectType) type).getClassName();
if (className.startsWith("java.")) {
// Types in java.lang are final for security reasons.
return false;
}
JavaClass cls = classContext.getAnalysisContext().lookupClass(className);
return cls.isFinal() && !cls.isEnum();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
return false;
}
示例6: generateFields
import org.apache.bcel.generic.Type; //导入依赖的package包/类
private void generateFields(RootClass k, ConstantPoolGen cp, ClassGen cg)
{
RootMember[] members = k.getMembers();
for (int i = 0; i < members.length; i++)
{
if (cg.containsField(members[i].getName()) == null)
{
Type type = ((BasicMember) members[i]).getJavaType();
if (type != null)
{
FieldGen fg = new FieldGen(ACC_PRIVATE, type, members[i].getName(), cp);
cg.addField(fg.getField());
}
}
}
}
示例7: available_slot
import org.apache.bcel.generic.Type; //导入依赖的package包/类
private boolean available_slot(Type[] types, int ind, Type t) {
Type tp = types[ind];
if (tp != null) {
if (t.equals(tp)) {
return true;
}
return false;
}
if (t.equals(Type.LONG) || t.equals(Type.DOUBLE)) {
if (types[ind + 1] != null) {
return false;
}
types[ind + 1] = Type.VOID;
}
types[ind] = t;
return true;
}
示例8: getAllLocalDecls
import org.apache.bcel.generic.Type; //导入依赖的package包/类
static String[] getAllLocalDecls(Method m) {
LocalVariable[] lt = getLocalTable(m).getLocalVariableTable();
Vector<String> v = new Vector<String>();
for (int i = 0; i < lt.length; i++) {
LocalVariable l = lt[i];
Type tp = Type.getType(l.getSignature());
String e = tp.toString() + " "
+ generatedLocalName(tp, l.getName()) + ";";
if (!v.contains(e)) {
v.addElement(e);
}
}
String[] result = new String[v.size()];
result = v.toArray(result);
// for (int i = 0; i < v.size(); i++) {
// result[i] = (String) v.elementAt(i);
// System.out.println("localdecls for " + m + ": " + result[i]);
// }
return result;
}
示例9: insertDeleteSpawncounter
import org.apache.bcel.generic.Type; //导入依赖的package包/类
InstructionHandle insertDeleteSpawncounter(InstructionList il,
InstructionHandle i, int maxLocals) {
// In this case, jumps to the return must in fact jump to
// the new instruction sequence! So, we change the instruction
// at the handle.
// First, save the return instruction.
Instruction r = i.getInstruction();
i.setInstruction(new ALOAD(maxLocals));
i = il
.append(i, ins_f.createInvoke(
"ibis.cashmere.impl.spawnSync.SpawnCounter", "deleteSpawnCounter",
Type.VOID, new Type[] { spawnCounterType },
Constants.INVOKESTATIC));
i = il.append(i, r);
return i;
}
示例10: pushParams
import org.apache.bcel.generic.Type; //导入依赖的package包/类
InstructionHandle pushParams(InstructionList il, Method m) {
Type[] params = mtab.typesOfParams(m);
InstructionHandle pos = il.getStart();
for (int i = 0, param = 0; i < params.length; i++, param++) {
if (params[i].equals(Type.BOOLEAN) || params[i].equals(Type.BYTE)
|| params[i].equals(Type.SHORT) || params[i].equals(Type.CHAR)
|| params[i].equals(Type.INT)) {
il.insert(pos, new ILOAD(param));
} else if (params[i].equals(Type.FLOAT)) {
il.insert(pos, new FLOAD(param));
} else if (params[i].equals(Type.LONG)) {
il.insert(pos, new LLOAD(param));
param++;
} else if (params[i].equals(Type.DOUBLE)) {
il.insert(pos, new DLOAD(param));
param++;
} else {
il.insert(pos, new ALOAD(param));
}
}
return pos;
}
示例11: rewriteStore
import org.apache.bcel.generic.Type; //导入依赖的package包/类
InstructionHandle rewriteStore(MethodGen m, InstructionList il,
InstructionHandle i, int maxLocals, String localClassName) {
LocalVariableInstruction curr = (LocalVariableInstruction) (i
.getInstruction());
Type type = mtab.getLocalType(m, curr, i.getPosition());
if (type == null) {
return i;
}
String name = mtab.getLocalName(m, curr, i.getPosition());
String fieldName = MethodTable.generatedLocalName(type, name);
i.setInstruction(new ALOAD(maxLocals));
i = i.getNext();
if (type.equals(Type.LONG) || type.equals(Type.DOUBLE)) {
il.insert(i, new DUP_X2());
il.insert(i, new POP());
} else {
il.insert(i, new SWAP());
}
i = il.insert(i, ins_f.createFieldAccess(localClassName, fieldName,
type, Constants.PUTFIELD));
return i;
}
示例12: rewriteLoad
import org.apache.bcel.generic.Type; //导入依赖的package包/类
InstructionHandle rewriteLoad(MethodGen m, InstructionList il,
InstructionHandle i, int maxLocals, String localClassName) {
LocalVariableInstruction curr = (LocalVariableInstruction) (i
.getInstruction());
Type type = mtab.getLocalType(m, curr, i.getPosition());
if (type == null) {
return i;
}
String name = mtab.getLocalName(m, curr, i.getPosition());
String fieldName = MethodTable.generatedLocalName(type, name);
i.setInstruction(new ALOAD(maxLocals));
i = i.getNext();
i = il.insert(i, ins_f.createFieldAccess(localClassName, fieldName,
type, Constants.GETFIELD));
return i;
}
示例13: MethodGen
import org.apache.bcel.generic.Type; //导入依赖的package包/类
/** Instantiate from an existing method.
*
* @param method method
* @param className class name containing this method
* @param constantPoolGen constant pool
*/
public MethodGen(Method method, String className, ConstantPoolGen constantPoolGen) {
super(method, className, constantPoolGen);
// Analyze how many stack positions are for parameters.
// We won't touch those.
parameterPos = isStatic() ? 0 : 1;
Type[] parameters = getArgumentTypes();
parameterPos += parameters.length;
for (int i = 0; i < parameters.length; i++) {
if (parameters[i].equals(Type.LONG)
|| parameters[i].equals(Type.DOUBLE)) {
parameterPos++;
}
}
}
示例14: getSignature
import org.apache.bcel.generic.Type; //导入依赖的package包/类
@Override
public String getSignature() {
StringBuilder sb = new StringBuilder("");
Type[] arguments = method.getArgumentTypes();
boolean first = true;
for (Type argument : arguments) {
if (first) {
first = false;
sb.append(argument);
}
else {
sb.append(", ").append(argument);
}
}
return sb.toString();
}
示例15: createHelperMethodForDotClassCalls
import org.apache.bcel.generic.Type; //导入依赖的package包/类
/**
* Creates a method class$(String) which is used
* during SomeClass.class instruction
*
* @param generatedClassName the instance class name
*/
protected void createHelperMethodForDotClassCalls(String generatedClassName) {
InstructionList il = new InstructionList();
MethodGen method = new MethodGen(Constants.ACC_STATIC, new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, new String[]{"arg0"}, "class$", generatedClassName, il, constantsPool);
InstructionHandle ih0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
il.append(factory.createInvoke("java.lang.Class", "forName", new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, Constants.INVOKESTATIC));
InstructionHandle ih4 = il.append(InstructionFactory.createReturn(Type.OBJECT));
InstructionHandle ih5 = il.append(InstructionFactory.createStore(Type.OBJECT, 1));
il.append(factory.createNew("java.lang.NoClassDefFoundError"));
il.append(InstructionConstants.DUP);
il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
il.append(factory.createInvoke("java.lang.Throwable", "getMessage", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
il.append(factory.createInvoke("java.lang.NoClassDefFoundError", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL));
il.append(InstructionConstants.ATHROW);
method.addExceptionHandler(ih0, ih4, ih5, new ObjectType("java.lang.ClassNotFoundException"));
method.setMaxStack();
method.setMaxLocals();
classGen.addMethod(method.getMethod());
il.dispose();
}