当前位置: 首页>>代码示例>>Java>>正文


Java Repository.instanceOf方法代码示例

本文整理汇总了Java中org.apache.bcel.Repository.instanceOf方法的典型用法代码示例。如果您正苦于以下问题:Java Repository.instanceOf方法的具体用法?Java Repository.instanceOf怎么用?Java Repository.instanceOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.bcel.Repository的用法示例。


在下文中一共展示了Repository.instanceOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkSuper

import org.apache.bcel.Repository; //导入方法依赖的package包/类
private boolean checkSuper(MyMethod m, HashSet<MyMethod> others) {
	for (Iterator<MyMethod> i = others.iterator(); i.hasNext();) {
		MyMethod m2 = i.next();
		try {
			if (m.confusingMethodNames(m2)
			        && Repository.instanceOf(m.clazz, m2.clazz)) {
				MyMethod m3 = new MyMethod(m.clazz, m2.methodName, m.methodSig);
				boolean r = others.contains(m3);
				if (r) continue;
				bugReporter.reportBug(new BugInstance(this, "NM_VERY_CONFUSING", HIGH_PRIORITY)
				        .addClass(m.getClassName())
				        .addMethod(m.getClassName(), m.methodName, m.methodSig)
				        .addClass(m2.getClassName())
				        .addMethod(m2.getClassName(), m2.methodName, m2.methodSig));
				return true;
			}
		} catch (ClassNotFoundException e) {
		}
	}
	return false;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:22,代码来源:Naming.java

示例2: findNarrowestMethod

import org.apache.bcel.Repository; //导入方法依赖的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;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:34,代码来源:JavaClassDefinition.java

示例3: visit

import org.apache.bcel.Repository; //导入方法依赖的package包/类
public void visit(JavaClass obj) {
	hasNativeMethods = false;
	isSerializable = false;
	if (getSuperclassName().indexOf("$") >= 0
	        || getSuperclassName().indexOf("+") >= 0) {
		// System.out.println("hicfsc: " + betterClassName);
		innerClassCannotBeStatic.add(getDottedClassName());
		// System.out.println("hicfsc: " + betterSuperclassName);
		innerClassCannotBeStatic.add(getDottedSuperclassName());
	}
	// Does this class directly implement Serializable?
	String[] interface_names = obj.getInterfaceNames();
	for (int i = 0; i < interface_names.length; i++) {
		if (interface_names[i].equals("java.io.Externalizable")) {
			isSerializable = true;
		} else if (interface_names[i].equals("java.io.Serializable")) {
			isSerializable = true;
			break;
		}
	}

	// Does this class indirectly implement Serializable?
	if (!isSerializable) {
		try {
			if (Repository.instanceOf(obj, "java.io.Externalizable"))
				isSerializable = true;
			if (Repository.instanceOf(obj, "java.io.Serializable"))
				isSerializable = true;
			if (Repository.instanceOf(obj, "java.rmi.Remote")) {
				isSerializable = true;
			}
		} catch (ClassNotFoundException e) {
			bugReporter.reportMissingClass(e);
		}
	}

	// System.out.println(getDottedClassName() + " is serializable: " + isSerializable);
	super.visit(obj);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:40,代码来源:UnreadFields.java

示例4: hasReference

import org.apache.bcel.Repository; //导入方法依赖的package包/类
/**
 * Determine whether this method definition has a reference from a class or
 * a superclass.
 * @param aJavaClass the JavaClass to check against.
 * @return true if there is a reference to this method definition from a
 * aJavaClass or a superclass of aJavaClass.
 */
public boolean hasReference(JavaClass aJavaClass)
{
    final Iterator it = getReferences().iterator();
    while (it.hasNext()) {
        final InvokeReference invokeRef = (InvokeReference) it.next();
        final String invokeClassName = invokeRef.getClassName();
        if (Repository.instanceOf(aJavaClass, invokeClassName)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:20,代码来源:MethodDefinition.java

示例5: isCashmere

import org.apache.bcel.Repository; //导入方法依赖的package包/类
boolean isCashmere() {
    try {
        return Repository.instanceOf(c, cashmereObjectClass);
    } catch(ClassNotFoundException e) {
        throw new Error(e);
    }
}
 
开发者ID:pieterhijma,项目名称:cashmere,代码行数:8,代码来源:Cashmerec.java

示例6: isSharedObject

import org.apache.bcel.Repository; //导入方法依赖的package包/类
private boolean isSharedObject(Type t) {
    if (t instanceof ObjectType) {
        ObjectType typ = (ObjectType) t;
        try {
            if (Repository.instanceOf(typ.getClassName(),
                "ibis.cashmere.SharedObject")) {
                return true;
            }
        } catch(ClassNotFoundException e) {
            throw new Error(e);
        }
    }
    return false;
}
 
开发者ID:pieterhijma,项目名称:cashmere,代码行数:15,代码来源:Cashmerec.java

示例7: compareTypesOld

import org.apache.bcel.Repository; //导入方法依赖的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;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:41,代码来源:FindUnrelatedTypesInGenericContainer.java

示例8: isBufferedInputStream

import org.apache.bcel.Repository; //导入方法依赖的package包/类
private boolean isBufferedInputStream() {
    try {
        if (lastCallClass.startsWith("["))
            return false;
        return Repository.instanceOf(lastCallClass, "java.io.BufferedInputStream");
    } catch (ClassNotFoundException e) {
        return false;
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:10,代码来源:ReadReturnShouldBeChecked.java

示例9: isImageIOInputStream

import org.apache.bcel.Repository; //导入方法依赖的package包/类
private boolean isImageIOInputStream() {
    try {
        if (lastCallClass.startsWith("["))
            return false;
        return Repository.instanceOf(lastCallClass, "javax.imageio.stream.ImageInputStream");
    } catch (ClassNotFoundException e) {
        return false;
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:10,代码来源:ReadReturnShouldBeChecked.java

示例10: subclassOf

import org.apache.bcel.Repository; //导入方法依赖的package包/类
/**
 * Return true if this type is a subclass of given ObjectType.
 * @throws ClassNotFoundException if any of this class's superclasses
 *  can't be found
 */
public boolean subclassOf( ObjectType superclass ) throws ClassNotFoundException {
    if (this.referencesInterface() || superclass.referencesInterface()) {
        return false;
    }
    return Repository.instanceOf(this.class_name, superclass.class_name);
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:12,代码来源:ObjectType.java

示例11: visit

import org.apache.bcel.Repository; //导入方法依赖的package包/类
public void visit(Field obj) {
	int flags = obj.getAccessFlags();

	if (getClassName().indexOf("ObjectStreamClass") == -1
	        && isSerializable
	        && !isExternalizable
	        && getFieldSig().indexOf("L") >= 0 && !obj.isTransient() && !obj.isStatic()) {
		try {
			String fieldTypeClassName = getFieldSig().substring(getFieldSig().indexOf("L") + 1, getFieldSig().length() - 1).replace('/', '.');
			JavaClass fieldTypeClass = Repository.lookupClass(fieldTypeClassName);

			if (!fieldTypeClassName.equals("java.lang.Object") &&
			        !(Repository.instanceOf(fieldTypeClass, "java.io.Serializable")
			        || Repository.instanceOf(fieldTypeClass, "java.io.Externalizable"))) {


				// Priority is LOW for GUI classes (unless explicitly marked Serializable),
				// HIGH if the class directly implements Serializable,
				// NORMAL otherwise.
				int priority = NORMAL_PRIORITY;
				if (implementsSerializableDirectly || sawSerialVersionUID)
					priority--;
				if (isGUIClass)
					priority++;

				// Lower the priority for fields which are of an interface
				// or abstract type, since the user may know that all subtypes of
				// the interface will be Serializable.
				if (fieldTypeClass.isInterface()
				        || fieldTypeClass.isAbstract()) {
					priority = Math.max(LOW_PRIORITY, priority + 1);
					if (Repository.instanceOf(fieldTypeClass,
					        "java.util.Collection"))
						return;
				}
				// Report is queued until after the entire class has been seen.
				fieldWarningList.add(new BugInstance(this, "SE_BAD_FIELD", priority)
				        .addClass(getThisClass().getClassName())
				        .addField(getDottedClassName(), obj.getName(), getFieldSig(), false));
			}
		} catch (ClassNotFoundException e) {
			bugReporter.reportMissingClass(e);
		}
	}

	if (!getFieldName().startsWith("this")
	        && isSynthetic(obj))
		foundSynthetic = true;
	if (!getFieldName().equals("serialVersionUID")) return;
	int mask = ACC_STATIC | ACC_FINAL;
	if (!getFieldSig().equals("I")
	        && !getFieldSig().equals("J"))
		return;
	if ((flags & mask) == mask
	        && getFieldSig().equals("I")) {
		bugReporter.reportBug(new BugInstance(this, "SE_NONLONG_SERIALVERSIONID", LOW_PRIORITY)
		        .addClass(this)
		        .addVisitedField(this));
		sawSerialVersionUID = true;
		return;
	} else if ((flags & ACC_STATIC) == 0) {
		bugReporter.reportBug(new BugInstance(this, "SE_NONSTATIC_SERIALVERSIONID", NORMAL_PRIORITY)
		        .addClass(this)
		        .addVisitedField(this));
		return;
	} else if ((flags & ACC_FINAL) == 0) {
		bugReporter.reportBug(new BugInstance(this, "SE_NONFINAL_SERIALVERSIONID", NORMAL_PRIORITY)
		        .addClass(this)
		        .addVisitedField(this));
		return;
	}
	sawSerialVersionUID = true;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:74,代码来源:SerializableIdiom.java

示例12: subclassOf

import org.apache.bcel.Repository; //导入方法依赖的package包/类
public boolean subclassOf(ObjectType superclass){
  if (this.referencesInterface() || superclass.referencesInterface())
    return false;

  return Repository.instanceOf(this.class_name, superclass.class_name);
}
 
开发者ID:linchaolong,项目名称:ApkToolPlus,代码行数:7,代码来源:ObjectType.java

示例13: visitINVOKEVIRTUAL

import org.apache.bcel.Repository; //导入方法依赖的package包/类
/**
 * Ensures the specific preconditions of the said instruction.
 */
public void visitINVOKEVIRTUAL(INVOKEVIRTUAL o){
	// the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o).

	Type t = o.getType(cpg);
	if (t instanceof ObjectType){
		String name = ((ObjectType)t).getClassName();
		Verifier v = VerifierFactory.getVerifier( name );
		VerificationResult vr = v.doPass2();
		if (vr.getStatus() != VerificationResult.VERIFIED_OK){
			constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'.");
		}
	}


	Type[] argtypes = o.getArgumentTypes(cpg);
	int nargs = argtypes.length;
	
	for (int i=nargs-1; i>=0; i--){
		Type fromStack = stack().peek( (nargs-1) - i );	// 0 to nargs-1
		Type fromDesc = argtypes[i];
		if (fromDesc == Type.BOOLEAN ||
				fromDesc == Type.BYTE ||
				fromDesc == Type.CHAR ||
				fromDesc == Type.SHORT){
			fromDesc = Type.INT;
		}
		if (! fromStack.equals(fromDesc)){
			if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType){
				ReferenceType rFromStack = (ReferenceType) fromStack;
				ReferenceType rFromDesc = (ReferenceType) fromDesc;
				// TODO: This can possibly only be checked when using Staerk-et-al's "set of object types" instead
				// of a single "wider cast object type" created during verification.
				if ( ! rFromStack.isAssignmentCompatibleWith(rFromDesc) ){
					constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack (which is not assignment compatible).");
				}
			}
			else{
				constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack.");
			}
		}
	}
	
	Type objref = stack().peek(nargs);
	if (objref == Type.NULL){
		return;
	}
	if (! (objref instanceof ReferenceType) ){
		constraintViolated(o, "Expecting a reference type as 'objectref' on the stack, not a '"+objref+"'.");
	}
	referenceTypeIsInitialized(o, (ReferenceType) objref);
	if (!(objref instanceof ObjectType)){
		if (!(objref instanceof ArrayType)){
			constraintViolated(o, "Expecting an ObjectType as 'objectref' on the stack, not a '"+objref+"'."); // could be a ReturnaddressType
		}
		else{
			objref = GENERIC_ARRAY;
		}
	}
	
	String objref_classname = ((ObjectType) objref).getClassName();

	String theClass = o.getClassName(cpg);

	if ( ! Repository.instanceOf(objref_classname, theClass) ){
		constraintViolated(o, "The 'objref' item '"+objref+"' does not implement '"+theClass+"' as expected.");
	}	
}
 
开发者ID:linchaolong,项目名称:ApkToolPlus,代码行数:71,代码来源:InstConstraintVisitor.java

示例14: visitINVOKESPECIAL

import org.apache.bcel.Repository; //导入方法依赖的package包/类
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */
public void visitINVOKESPECIAL(INVOKESPECIAL o){
    try {
	// INVOKESPECIAL is a LoadClass; the Class where the referenced method is declared in,
	// is therefore resolved/verified.
	// INVOKESPECIAL is an InvokeInstruction, the argument and return types are resolved/verified,
	// too. So are the allowed method names.
	String classname = o.getClassName(cpg);
	JavaClass jc = Repository.lookupClass(classname);
	Method[] ms = jc.getMethods();
	Method m = null;
	for (int i=0; i<ms.length; i++){
		if ( (ms[i].getName().equals(o.getMethodName(cpg))) &&
		     (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) &&
		     (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){
			m = ms[i];
			break;
		}
	}
	if (m == null){
		constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature '"+o.getSignature(cpg)+"' not found in class '"+jc.getClassName()+"'. The native verifier does allow the method to be declared in some superclass or implemented interface, which the Java Virtual Machine Specification, Second Edition does not.");
	}
	
	JavaClass current = Repository.lookupClass(myOwner.getClassName());
	if (current.isSuper()){
	
		if ((Repository.instanceOf( current, jc )) && (!current.equals(jc))){
			
			if (! (o.getMethodName(cpg).equals(Constants.CONSTRUCTOR_NAME) )){
				// Special lookup procedure for ACC_SUPER classes.
				
				int supidx = -1;
				
				Method meth = null;
				while (supidx != 0){
					supidx = current.getSuperclassNameIndex();
					current = Repository.lookupClass(current.getSuperclassName());
					
					Method[] meths = current.getMethods();
					for (int i=0; i<meths.length; i++){
						if	( (meths[i].getName().equals(o.getMethodName(cpg))) &&
		     				(Type.getReturnType(meths[i].getSignature()).equals(o.getReturnType(cpg))) &&
		     				(objarrayequals(Type.getArgumentTypes(meths[i].getSignature()), o.getArgumentTypes(cpg))) ){
							meth = meths[i];
							break;
						}
					}
					if (meth != null) {
                              break;
                          }
				}
				if (meth == null){
					constraintViolated(o, "ACC_SUPER special lookup procedure not successful: method '"+o.getMethodName(cpg)+"' with proper signature not declared in superclass hierarchy.");
				}						
			}
		}
	}
	
    } catch (ClassNotFoundException e) {
	// FIXME: maybe not the best way to handle this
	throw new AssertionViolatedException("Missing class: " + e.toString());
    }
	
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:65,代码来源:Pass3aVerifier.java

示例15: visitINVOKEVIRTUAL

import org.apache.bcel.Repository; //导入方法依赖的package包/类
/**
 * Ensures the specific preconditions of the said instruction.
 */
public void visitINVOKEVIRTUAL(INVOKEVIRTUAL o){
    try {
	// the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o).

	Type t = o.getType(cpg);
	if (t instanceof ObjectType){
		String name = ((ObjectType)t).getClassName();
		Verifier v = VerifierFactory.getVerifier( name );
		VerificationResult vr = v.doPass2();
		if (vr.getStatus() != VerificationResult.VERIFIED_OK){
			constraintViolated((Instruction) o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'.");
		}
	}


	Type[] argtypes = o.getArgumentTypes(cpg);
	int nargs = argtypes.length;
	
	for (int i=nargs-1; i>=0; i--){
		Type fromStack = stack().peek( (nargs-1) - i );	// 0 to nargs-1
		Type fromDesc = argtypes[i];
		if (fromDesc == Type.BOOLEAN ||
				fromDesc == Type.BYTE ||
				fromDesc == Type.CHAR ||
				fromDesc == Type.SHORT){
			fromDesc = Type.INT;
		}
		if (! fromStack.equals(fromDesc)){
			if (fromStack instanceof ReferenceType && fromDesc instanceof ReferenceType){
				ReferenceType rFromStack = (ReferenceType) fromStack;
				ReferenceType rFromDesc = (ReferenceType) fromDesc;
				// TODO: This can possibly only be checked when using Staerk-et-al's "set of object types" instead
				// of a single "wider cast object type" created during verification.
				if ( ! rFromStack.isAssignmentCompatibleWith(rFromDesc) ){
					constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack (which is not assignment compatible).");
				}
                   referenceTypeIsInitialized(o, rFromStack);
			}
			else{
				constraintViolated(o, "Expecting a '"+fromDesc+"' but found a '"+fromStack+"' on the stack.");
			}
		}
	}
	
	Type objref = stack().peek(nargs);
	if (objref == Type.NULL){
		return;
	}
	if (! (objref instanceof ReferenceType) ){
		constraintViolated(o, "Expecting a reference type as 'objectref' on the stack, not a '"+objref+"'.");
	}
	referenceTypeIsInitialized(o, (ReferenceType) objref);
	if (!(objref instanceof ObjectType)){
		if (!(objref instanceof ArrayType)){
			constraintViolated(o, "Expecting an ObjectType as 'objectref' on the stack, not a '"+objref+"'."); // could be a ReturnaddressType
		}
		else{
			objref = GENERIC_ARRAY;
		}
	}
	
	String objref_classname = ((ObjectType) objref).getClassName();

	String theClass = o.getClassName(cpg);

	if ( ! Repository.instanceOf(objref_classname, theClass) ){
		constraintViolated(o, "The 'objref' item '"+objref+"' does not implement '"+theClass+"' as expected.");
	}	
    } catch (ClassNotFoundException e) {
	// FIXME: maybe not the best way to handle this
	throw new AssertionViolatedException("Missing class: " + e.toString());
    }
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:77,代码来源:InstConstraintVisitor.java


注:本文中的org.apache.bcel.Repository.instanceOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。