本文整理汇总了Java中org.apache.bcel.generic.Type.getType方法的典型用法代码示例。如果您正苦于以下问题:Java Type.getType方法的具体用法?Java Type.getType怎么用?Java Type.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.generic.Type
的用法示例。
在下文中一共展示了Type.getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: mergeTypes
import org.apache.bcel.generic.Type; //导入方法依赖的package包/类
public Type mergeTypes(Type a, Type b) throws DataflowAnalysisException {
byte aType = a.getType(), bType = b.getType();
if (aType == T_TOP) // Top is the identity element
return b;
else if (bType == T_TOP) // Top is the identity element
return a;
else if (aType == T_BOTTOM || bType == T_BOTTOM) // Bottom meet anything is bottom
return BottomType.instance();
else if (isReferenceType(aType) && isReferenceType(bType)) { // Two object types!
// Handle the Null type, which serves as a special "top"
// value for reference types.
if (aType == T_NULL)
return b;
else if (bType == T_NULL)
return a;
ReferenceType aRef = (ReferenceType) a;
ReferenceType bRef = (ReferenceType) b;
return mergeReferenceTypes(aRef, bRef);
} else if (isReferenceType(aType) || isReferenceType(bType)) // Object meet non-object is bottom
return BottomType.instance();
else if (aType == bType) // Same non-object type?
return a;
else if (isIntegerType(aType) && isIntegerType(bType)) // Two different integer types - use T_INT
return Type.INT;
else // Default - types are incompatible
return BottomType.instance();
}
示例3: fromExceptionSet
import org.apache.bcel.generic.Type; //导入方法依赖的package包/类
/**
* Initialize object from an exception set.
*
* @param exceptionSet the exception set
* @return a Type that is a supertype of all of the exceptions in
* the exception set
*/
public static Type fromExceptionSet(ExceptionSet exceptionSet) throws ClassNotFoundException {
Type commonSupertype = exceptionSet.getCommonSupertype();
if (commonSupertype.getType() != T_OBJECT)
return commonSupertype;
ObjectType exceptionSupertype = (ObjectType) commonSupertype;
return new ExceptionObjectType(exceptionSupertype.getClassName(), exceptionSet);
}
示例4: getAllLocalTypes
import org.apache.bcel.generic.Type; //导入方法依赖的package包/类
static Type[] getAllLocalTypes(Method m) {
LocalVariable[] lt = getLocalTable(m).getLocalVariableTable();
Type[] result = new Type[lt.length];
for (int i = 0; i < lt.length; i++) {
LocalVariable l = lt[i];
Type tp = Type.getType(l.getSignature());
result[i] = tp;
}
return result;
}
示例5: getAllLocalNames
import org.apache.bcel.generic.Type; //导入方法依赖的package包/类
static String[] getAllLocalNames(Method m) {
LocalVariable[] lt = getLocalTable(m).getLocalVariableTable();
String[] result = new String[lt.length];
for (int i = 0; i < lt.length; i++) {
LocalVariable l = lt[i];
Type tp = Type.getType(l.getSignature());
String e = generatedLocalName(tp, l.getName());
result[i] = e;
}
return result;
}
示例6: className
import org.apache.bcel.generic.Type; //导入方法依赖的package包/类
private static String className(Type type) {
if (type.getType() <= Constants.T_VOID) {
return PRIMITIVE_NAME;
} else if (type instanceof ArrayType) {
return className(((ArrayType) type).getBasicType());
} else {
return type.toString();
}
}
示例7: mergeSummary
import org.apache.bcel.generic.Type; //导入方法依赖的package包/类
public void mergeSummary(XField fieldOperand, OpcodeStack.Item mergeValue) {
if (SystemProperties.ASSERTIONS_ENABLED) {
String mSignature = mergeValue.getSignature();
Type mergeType = Type.getType(mSignature);
Type fieldType = Type.getType(fieldOperand.getSignature());
IncompatibleTypes check = IncompatibleTypes.getPriorityForAssumingCompatible(mergeType, fieldType, false);
if (check.getPriority() <= Priorities.NORMAL_PRIORITY) {
AnalysisContext.logError(fieldOperand + " not compatible with " + mergeValue,
new IllegalArgumentException(check.toString()));
}
}
OpcodeStack.Item oldSummary = summary.get(fieldOperand);
if (oldSummary != null) {
Item newValue = OpcodeStack.Item.merge(mergeValue, oldSummary);
newValue.clearNewlyAllocated();
summary.put(fieldOperand, newValue);
} else {
if (mergeValue.isNewlyAllocated()) {
mergeValue = new OpcodeStack.Item(mergeValue);
mergeValue.clearNewlyAllocated();
}
summary.put(fieldOperand, mergeValue);
}
}
示例8: purgeBoringEntries
import org.apache.bcel.generic.Type; //导入方法依赖的package包/类
public void purgeBoringEntries() {
Collection<FieldDescriptor> keys = new ArrayList<FieldDescriptor>(getKeys());
for (FieldDescriptor f : keys) {
String s = f.getSignature();
FieldStoreType type = getProperty(f);
Type fieldType = Type.getType(f.getSignature());
if (!(fieldType instanceof ReferenceType)) {
removeProperty(f);
continue;
}
ReferenceType storeType = type.getLoadType((ReferenceType) fieldType);
if (storeType.equals(fieldType))
removeProperty(f);
}
}
示例9: mergeTypes
import org.apache.bcel.generic.Type; //导入方法依赖的package包/类
public Type mergeTypes(Type a, Type b) throws DataflowAnalysisException {
byte aType = a.getType(), bType = b.getType();
if (aType == T_TOP) // Top is the identity element
return b;
else if (bType == T_TOP) // Top is the identity element
return a;
else if (aType == T_BOTTOM || bType == T_BOTTOM) // Bottom meet anything
// is bottom
return BottomType.instance();
else if (isReferenceType(aType) && isReferenceType(bType)) { // Two
// object
// types!
// Handle the Null type, which serves as a special "top"
// value for reference types.
if (aType == T_NULL)
return b;
else if (bType == T_NULL)
return a;
ReferenceType aRef = (ReferenceType) a;
ReferenceType bRef = (ReferenceType) b;
return mergeReferenceTypes(aRef, bRef);
} else if (isReferenceType(aType) || isReferenceType(bType)) // Object
// meet
// non-object
// is
// bottom
return BottomType.instance();
else if (aType == bType) // Same non-object type?
return a;
else if (isIntegerType(aType) && isIntegerType(bType)) // Two different
// integer types
// - use T_INT
return Type.INT;
else
// Default - types are incompatible
return BottomType.instance();
}
示例10: fromExceptionSet
import org.apache.bcel.generic.Type; //导入方法依赖的package包/类
/**
* Initialize object from an exception set.
*
* @param exceptionSet
* the exception set
* @return a Type that is a supertype of all of the exceptions in the
* exception set
*/
public static Type fromExceptionSet(ExceptionSet exceptionSet) throws ClassNotFoundException {
Type commonSupertype = exceptionSet.getCommonSupertype();
if (commonSupertype.getType() != T_OBJECT)
return commonSupertype;
ObjectType exceptionSupertype = (ObjectType) commonSupertype;
String className = exceptionSupertype.getClassName();
if (className.equals("java.lang.Throwable"))
return exceptionSupertype;
return new ExceptionObjectType(className, exceptionSet);
}
示例11: generateMethods
import org.apache.bcel.generic.Type; //导入方法依赖的package包/类
private static void generateMethods(RootClass k, ConstantPoolGen cp, InstructionList il, InstructionFactory factory, ClassGen cg, String className, Class implementedInterface)
{
RootMember[] members = k.getMembers();
for (int i = 0; i < members.length; i++)
{
Type type = ((BasicMember) members[i]).getJavaType();
Type returnType = type;
try
{
if (implementedInterface != null) returnType = Type.getType(implementedInterface.getMethod(nameMangler.mangleMember(members[i].getName()),(Class[]) null).getReturnType());
if (!returnType.equals(type) && debugRoot)
{
System.err.println("Warning: Interface type mismatch "+implementedInterface.getName()+"."+nameMangler.mangleMember(members[i].getName())+" "+returnType+" "+type);
}
}
catch (NoSuchMethodException x)
{
}
if (cg.containsMethod(nameMangler.mangleMember(members[i].getName()), "()" + returnType.getSignature()) == null)
{
MethodGen mg = new MethodGen(ACC_PUBLIC, returnType, null, null, nameMangler.mangleMember(members[i].getName()), null, il, cp);
if (members[i].getType() == null) // Dummy object
{
il.append(new PUSH(cp, "<<Unreadable>>"));
}
else
{
il.append(InstructionConstants.ALOAD_0);
il.append(factory.createGetField(className, members[i].getName(), type));
}
if (!returnType.equals(type) && !(returnType == Type.INT && (type == Type.BYTE || type == Type.CHAR || type == Type.SHORT)))
il.append(factory.createCast(type,returnType));
il.append(InstructionFactory.createReturn(returnType));
mg.setMaxStack();
mg.setMaxLocals();
cg.addMethod(mg.getMethod());
il.dispose();
}
}
}
示例12: counterAdaptClass
import org.apache.bcel.generic.Type; //导入方法依赖的package包/类
byte[] counterAdaptClass(final InputStream is, final String name)
throws Exception
{
JavaClass jc = new ClassParser(is, name + ".class").parse();
ClassGen cg = new ClassGen(jc);
ConstantPoolGen cp = cg.getConstantPool();
if (!cg.isInterface()) {
FieldGen fg = new FieldGen(ACC_PUBLIC,
Type.getType("I"),
"_counter",
cp);
cg.addField(fg.getField());
}
Method[] ms = cg.getMethods();
for (int j = 0; j < ms.length; ++j) {
MethodGen mg = new MethodGen(ms[j], cg.getClassName(), cp);
if (!mg.getName().equals("<init>") && !mg.isStatic()
&& !mg.isAbstract() && !mg.isNative())
{
if (mg.getInstructionList() != null) {
InstructionList il = new InstructionList();
il.append(new ALOAD(0));
il.append(new ALOAD(0));
il.append(new GETFIELD(cp.addFieldref(name, "_counter", "I")));
il.append(new ICONST(1));
il.append(new IADD());
il.append(new PUTFIELD(cp.addFieldref(name, "_counter", "I")));
mg.getInstructionList().insert(il);
mg.setMaxStack(Math.max(mg.getMaxStack(), 2));
boolean lv = ms[j].getLocalVariableTable() == null;
boolean ln = ms[j].getLineNumberTable() == null;
if (lv) {
mg.removeLocalVariables();
}
if (ln) {
mg.removeLineNumbers();
}
cg.replaceMethod(ms[j], mg.getMethod());
}
}
}
return cg.getJavaClass().getBytes();
}
示例13: handleStringComparison
import org.apache.bcel.generic.Type; //导入方法依赖的package包/类
private void handleStringComparison(JavaClass jclass, Method method, MethodGen methodGen,
RefComparisonTypeFrameModelingVisitor visitor, List<WarningWithProperties> stringComparisonList, Location location,
Type lhsType, Type rhsType) {
if (DEBUG) {
System.out.println("String/String comparison at " + location.getHandle());
}
// Compute the priority:
// - two static strings => do not report
// - dynamic string and anything => high
// - static string and unknown => medium
// - all other cases => low
// System.out.println("Compare " + lhsType + " == " + rhsType);
byte type1 = lhsType.getType();
byte type2 = rhsType.getType();
String bugPattern = "ES_COMPARING_STRINGS_WITH_EQ";
// T1 T2 result
// S S no-op
// D ? high
// ? D high
// S ? normal
// ? S normal
WarningPropertySet<WarningProperty> propertySet = new WarningPropertySet<WarningProperty>();
if (type1 == T_STATIC_STRING && type2 == T_STATIC_STRING) {
propertySet.addProperty(RefComparisonWarningProperty.COMPARE_STATIC_STRINGS);
} else if (type1 == T_DYNAMIC_STRING || type2 == T_DYNAMIC_STRING) {
propertySet.addProperty(RefComparisonWarningProperty.DYNAMIC_AND_UNKNOWN);
} else if (type2 == T_PARAMETER_STRING || type1 == T_PARAMETER_STRING) {
bugPattern = "ES_COMPARING_PARAMETER_STRING_WITH_EQ";
if (methodGen.isPublic() || methodGen.isProtected()) {
propertySet.addProperty(RefComparisonWarningProperty.STRING_PARAMETER_IN_PUBLIC_METHOD);
} else {
propertySet.addProperty(RefComparisonWarningProperty.STRING_PARAMETER);
}
} else if (type1 == T_STATIC_STRING || type2 == T_STATIC_STRING) {
if (lhsType instanceof EmptyStringType || rhsType instanceof EmptyStringType)
propertySet.addProperty(RefComparisonWarningProperty.EMPTY_AND_UNKNOWN);
else
propertySet.addProperty(RefComparisonWarningProperty.STATIC_AND_UNKNOWN);
} else if (visitor.sawStringIntern()) {
propertySet.addProperty(RefComparisonWarningProperty.SAW_INTERN);
}
String sourceFile = jclass.getSourceFileName();
BugInstance instance = new BugInstance(this, bugPattern, BASE_ES_PRIORITY).addClassAndMethod(methodGen, sourceFile)
.addType("Ljava/lang/String;").describe(TypeAnnotation.FOUND_ROLE).addSomeSourceForTopTwoStackValues(classContext, method, location);
SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen,
sourceFile, location.getHandle());
if (sourceLineAnnotation != null) {
WarningWithProperties warn = new WarningWithProperties(instance, propertySet, sourceLineAnnotation, location);
stringComparisonList.add(warn);
}
}
示例14: initEntryFact
import org.apache.bcel.generic.Type; //导入方法依赖的package包/类
public void initEntryFact(TypeFrame result) {
// Make the frame valid
result.setValid();
int slot = 0;
// Clear the stack slots in the frame
result.clearStack();
// Add local for "this" pointer, if present
if (!methodGen.isStatic())
result.setValue(slot++, ObjectTypeFactory.getInstance(methodGen.getClassName()));
// [Added: Support for Generics]
// Get a parser that reads the generic signature of the method and
// can be used to get the correct GenericObjectType if an argument
// has a class type
Iterator<String> iter = GenericSignatureParser.getGenericSignatureIterator(method);
// Add locals for parameters.
// Note that long and double parameters need to be handled
// specially because they occupy two locals.
Type[] argumentTypes = methodGen.getArgumentTypes();
for (Type argType : argumentTypes) {
// Add special "extra" type for long or double params.
// These occupy the slot before the "plain" type.
if (argType.getType() == Constants.T_LONG) {
result.setValue(slot++, TypeFrame.getLongExtraType());
} else if (argType.getType() == Constants.T_DOUBLE) {
result.setValue(slot++, TypeFrame.getDoubleExtraType());
}
// [Added: Support for Generics]
String s = (iter == null || !iter.hasNext()) ? null : iter.next();
if (s != null && (argType instanceof ObjectType || argType instanceof ArrayType)
&& !(argType instanceof ExceptionObjectType)) {
// replace with a generic version of the type
try {
Type t = GenericUtilities.getType(s);
if (t != null)
argType = t;
} catch (RuntimeException e) {
} // degrade gracefully
}
// Add the plain parameter type.
result.setValue(slot++, argType);
}
// Set remaining locals to BOTTOM; this will cause any
// uses of them to be flagged
while (slot < methodGen.getMaxLocals())
result.setValue(slot++, TypeFrame.getBottomType());
}
示例15: mergeTypes
import org.apache.bcel.generic.Type; //导入方法依赖的package包/类
public Type mergeTypes(Type a, Type b) throws DataflowAnalysisException {
if (a == null) return b;
if (b == null) return a;
byte aType = a.getType(), bType = b.getType();
if (aType == T_TOP) // Top is the identity element
return b;
else if (bType == T_TOP) // Top is the identity element
return a;
else if (aType == T_BOTTOM || bType == T_BOTTOM) // Bottom meet anything
// is bottom
return BottomType.instance();
else if (isReferenceType(aType) && isReferenceType(bType)) { // Two
// object
// types!
// Handle the Null type, which serves as a special "top"
// value for reference types.
if (aType == T_NULL)
return b;
else if (bType == T_NULL)
return a;
ReferenceType aRef = (ReferenceType) a;
ReferenceType bRef = (ReferenceType) b;
return mergeReferenceTypes(aRef, bRef);
} else if (isReferenceType(aType) || isReferenceType(bType)) // Object
// meet
// non-object
// is
// bottom
return BottomType.instance();
else if (aType == bType) // Same non-object type?
return a;
else if (isIntegerType(aType) && isIntegerType(bType)) // Two different
// integer types
// - use T_INT
return Type.INT;
else
// Default - types are incompatible
return BottomType.instance();
}