本文整理汇总了Java中edu.umd.cs.findbugs.ba.generic.GenericUtilities类的典型用法代码示例。如果您正苦于以下问题:Java GenericUtilities类的具体用法?Java GenericUtilities怎么用?Java GenericUtilities使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GenericUtilities类属于edu.umd.cs.findbugs.ba.generic包,在下文中一共展示了GenericUtilities类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleGetMapView
import edu.umd.cs.findbugs.ba.generic.GenericUtilities; //导入依赖的package包/类
private boolean handleGetMapView(TypeFrame frame, String typeName, int index, int expectedNumberOfTypeParameters) {
try {
Type mapType = frame.getStackValue(0);
if (mapType instanceof GenericObjectType) {
GenericObjectType genericMapType = (GenericObjectType) mapType;
List<? extends ReferenceType> parameters = genericMapType.getParameters();
if (parameters == null)
return false;
if (parameters.size() == expectedNumberOfTypeParameters) {
ReferenceType keyType = parameters.get(index);
frame.popValue();
typesComputedFromGenerics.add(keyType);
GenericObjectType keySetType = GenericUtilities.getType(typeName, Collections.singletonList(keyType));
typesComputedFromGenerics.add(keySetType);
frame.pushValue(keySetType);
return true;
}
}
} catch (DataflowAnalysisException e) {
AnalysisContext.logError("oops", e);
}
return false;
}
示例2: getLocalVariable
import edu.umd.cs.findbugs.ba.generic.GenericUtilities; //导入依赖的package包/类
@CheckForNull
GenericObjectType getLocalVariable(int index, int pos) {
if (genericLocalVariables == null || !genericLocalVariables.get(index))
return null;
for (LocalVariable local : localTypeTable.getLocalVariableTypeTable())
if (local.getIndex() == index && local.getStartPC() <= pos
&& pos < +local.getStartPC() + local.getLength()) {
String signature = local.getSignature();
if (signature.indexOf('<') < 0) continue;
Type t;
try {
t = GenericUtilities.getType(signature);
if (t instanceof GenericObjectType)
return (GenericObjectType) t;
} catch (RuntimeException e) {
AnalysisContext.logError("Bad signature " + signature
+ " for " + local.getName(), e);
}
return null;
}
return null;
}
示例3: handleStoreInstruction
import edu.umd.cs.findbugs.ba.generic.GenericUtilities; //导入依赖的package包/类
@Override
public void handleStoreInstruction(StoreInstruction obj) {
try {
int numConsumed = obj.consumeStack(cpg);
if (numConsumed == 1) {
boolean isExact = isTopOfStackExact();
TypeFrame frame = getFrame();
Type value = frame.popValue();
int index = obj.getIndex();
if (value instanceof ReferenceType && !(value instanceof GenericObjectType)) {
GenericObjectType gType = getLocalVariable(index,
getLocation().getHandle().getPosition());
value = GenericUtilities.merge(gType, value);
}
frame.setValue(index, value);
frame.setExact(index, isExact);
} else
super.handleStoreInstruction(obj);
} catch (DataflowAnalysisException e) {
throw new InvalidBytecodeException(
"error handling store instruction ", e);
}
}
示例4: handleLoadInstruction
import edu.umd.cs.findbugs.ba.generic.GenericUtilities; //导入依赖的package包/类
/**
* Handler for all instructions which load values from a local variable and
* push them on the stack. Note that two locals are loaded for long and
* double loads.
*/
@Override
public void handleLoadInstruction(LoadInstruction obj) {
int numProduced = obj.produceStack(cpg);
if (numProduced == Constants.UNPREDICTABLE)
throw new InvalidBytecodeException("Unpredictable stack production");
if (numProduced != 1) {
super.handleLoadInstruction(obj);
return;
}
int index = obj.getIndex();
TypeFrame frame = getFrame();
Type value = frame.getValue(index);
if (value instanceof ReferenceType && !(value instanceof GenericObjectType)) {
GenericObjectType gType = getLocalVariable(index,
getLocation().getHandle().getPosition());
value = GenericUtilities.merge(gType, value);
}
boolean isExact = frame.isExact(index);
frame.pushValue(value);
if (isExact)
setTopOfStackIsExact();
}
示例5: compareTypesOld
import edu.umd.cs.findbugs.ba.generic.GenericUtilities; //导入依赖的package包/类
private boolean compareTypesOld(Type parmType, Type argType) {
// XXX equality not implemented for GenericObjectType
// if (parmType.equals(argType)) return true;
// Compare type signatures instead
if (GenericUtilities.getString(parmType).equals(GenericUtilities.getString(argType)))
return true;
if (parmType instanceof GenericObjectType) {
GenericObjectType o = (GenericObjectType) parmType;
if (o.getTypeCategory() == GenericUtilities.TypeCategory.WILDCARD_EXTENDS) {
return compareTypesOld(o.getExtension(), argType);
}
}
// ignore type variables for now
if (parmType instanceof GenericObjectType && !((GenericObjectType) parmType).hasParameters())
return true;
if (argType instanceof GenericObjectType && !((GenericObjectType) argType).hasParameters())
return true;
// Case: Both are generic containers
if (parmType instanceof GenericObjectType && argType instanceof GenericObjectType) {
return true;
} else {
// Don't consider non reference types (should not be possible)
if (!(parmType instanceof ReferenceType && argType instanceof ReferenceType))
return true;
// Don't consider non object types (for now)
if (!(parmType instanceof ObjectType && argType instanceof ObjectType))
return true;
// Otherwise, compare base types ignoring generic information
try {
return Repository.instanceOf(((ObjectType) argType).getClassName(), ((ObjectType) parmType).getClassName());
} catch (ClassNotFoundException e) {
}
}
return true;
}
示例6: TypeAnnotation
import edu.umd.cs.findbugs.ba.generic.GenericUtilities; //导入依赖的package包/类
public TypeAnnotation(Type objectType, String roleDescription) {
this(objectType.getSignature(), roleDescription);
if (objectType instanceof GenericObjectType) {
GenericObjectType genericObjectType = (GenericObjectType) objectType;
if (genericObjectType.getTypeCategory() == GenericUtilities.TypeCategory.PARAMETERIZED)
typeParameters = genericObjectType.getGenericParametersAsString();
}
}
示例7: getType
import edu.umd.cs.findbugs.ba.generic.GenericUtilities; //导入依赖的package包/类
/**
* @param xfield
* @return
*/
public static Type getType(XField xfield) {
Type t = Type.getType(xfield.getSignature());
if (!(t instanceof ReferenceType))
return t;
ReferenceType loadType = (ReferenceType) t;
// Check the field store type database to see if we can
// get a more precise type for this load.
useDatabase: {
FieldStoreTypeDatabase database = AnalysisContext
.currentAnalysisContext().getFieldStoreTypeDatabase();
if (database != null) {
FieldStoreType property = database.getProperty(xfield
.getFieldDescriptor());
if (property != null) {
loadType = property.getLoadType(loadType);
break useDatabase;
}
}
FieldSummary fieldSummary = AnalysisContext
.currentAnalysisContext().getFieldSummary();
if (fieldSummary != null) {
Item summary = fieldSummary.getSummary(xfield);
if (summary != null) {
if (xfield.isFinal() && summary.isNull()) {
return TypeFrame.getNullType();
}
if (!summary.getSignature().equals("Ljava/lang/Object;")) {
loadType = (ReferenceType) Type.getType(summary
.getSignature());
}
}
}
}
String sourceSignature = xfield.getSourceSignature();
if (sourceSignature != null && loadType instanceof ObjectType) {
loadType = GenericUtilities.merge(
GenericUtilities.getType(sourceSignature),
(ObjectType) loadType);
}
return loadType;
}
示例8: initEntryFact
import edu.umd.cs.findbugs.ba.generic.GenericUtilities; //导入依赖的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());
}