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


Java Repository.getSuperClasses方法代码示例

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


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

示例1: visitJavaClass

import org.apache.bcel.Repository; //导入方法依赖的package包/类
public void visitJavaClass(JavaClass obj) {
	if (obj.isInterface()) return;
	String name = obj.getClassName();
	if (!visited.add(name)) return;
	try {
		JavaClass supers[] = Repository.getSuperClasses(obj);
		for (int i = 0; i < supers.length; i++) {
			visitJavaClass(supers[i]);
		}
	} catch (ClassNotFoundException e) {
		// ignore it
	}
	super.visitJavaClass(obj);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:15,代码来源:Naming.java

示例2: findPrototypeMethod

import org.apache.bcel.Repository; //导入方法依赖的package包/类
/**
	 * Get the method which serves as a "prototype" for the
	 * given InvokeInstruction.  The "prototype" is the method
	 * which defines the contract for the invoked method,
	 * in particular the declared list of exceptions that the
	 * method can throw.
	 * <p/>
	 * <ul>
	 * <li> For invokestatic and invokespecial, this is simply an
	 * exact lookup.
	 * <li> For invokevirtual, the named class is searched,
	 * followed by superclasses  up to the root of the object
	 * hierarchy (java.lang.Object).
	 * <li> For invokeinterface, the named class is searched,
	 * followed by all interfaces transitively declared by the class.
	 * (Question: is the order important here? Maybe the VM spec
	 * requires that the actual interface desired is given,
	 * so the extended lookup will not be required. Should check.)
	 * </ul>
	 *
	 * @param inv the InvokeInstruction
	 * @param cpg the ConstantPoolGen used by the class the InvokeInstruction belongs to
	 * @return the Method, or null if no matching method can be found
	 */
	public static Method findPrototypeMethod(InvokeInstruction inv, ConstantPoolGen cpg)
	        throws ClassNotFoundException {
		Method m = null;

		String className = inv.getClassName(cpg);
		String methodName = inv.getName(cpg);
		String methodSig = inv.getSignature(cpg);

		// Find the method
		if (inv instanceof INVOKESTATIC || inv instanceof INVOKESPECIAL) {
			// Non-virtual dispatch
			m = findExactMethod(inv, cpg);
			if (m == null) {
				// XXX
/*
				System.out.println("Could not resolve " + inv + " in " +
					SignatureConverter.convertMethodSignature(inv, cpg));
*/
			} else if (inv instanceof INVOKESTATIC && !m.isStatic()) {
				m = null;
			}
		} else if (inv instanceof INVOKEVIRTUAL) {
			// Virtual dispatch
			m = findMethod(Repository.lookupClass(className), methodName, methodSig);
			if (m == null) {
				JavaClass[] superClassList = Repository.getSuperClasses(className);
				m = findMethod(superClassList, methodName, methodSig);
			}
		} else if (inv instanceof INVOKEINTERFACE) {
			// Interface dispatch
			m = findMethod(Repository.lookupClass(className), methodName, methodSig);
			if (m == null) {
				JavaClass[] interfaceList = Repository.getInterfaces(className);
				m = findMethod(interfaceList, methodName, methodSig);
			}
		}

		return m;
	}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:64,代码来源:Hierarchy.java

示例3: firstCommonSuperclass

import org.apache.bcel.Repository; //导入方法依赖的package包/类
/**
  * This commutative operation returns the first common superclass (narrowest ReferenceType
  * referencing a class, not an interface).
  * If one of the types is a superclass of the other, the former is returned.
  * If "this" is Type.NULL, then t is returned.
  * If t is Type.NULL, then "this" is returned.
  * If "this" equals t ['this.equals(t)'] "this" is returned.
  * If "this" or t is an ArrayType, then Type.OBJECT is returned.
  * If "this" or t is a ReferenceType referencing an interface, then Type.OBJECT is returned.
  * If not all of the two classes' superclasses cannot be found, "null" is returned.
  * See the JVM specification edition 2, "�4.9.2 The Bytecode Verifier".
  *
  * @deprecated use getFirstCommonSuperclass(ReferenceType t) which has
  *             slightly changed semantics.
  */
 public ReferenceType firstCommonSuperclass(ReferenceType t) {
   if (this.equals(Type.NULL)) return t;
   if (t.equals(Type.NULL)) return this;
   if (this.equals(t)) return this;
   /*
    * TODO: Above sounds a little arbitrary. On the other hand, there is
    * no object referenced by Type.NULL so we can also say all the objects
    * referenced by Type.NULL were derived from java.lang.Object.
    * However, the Java Language's "instanceof" operator proves us wrong:
    * "null" is not referring to an instance of java.lang.Object :)
    */

   if ((this instanceof ArrayType) || (t instanceof ArrayType))
     return Type.OBJECT;
   // TODO: Is there a proof of OBJECT being the direct ancestor of every ArrayType?

   if (((this instanceof ObjectType) && ((ObjectType) this).referencesInterface()) ||
((t instanceof ObjectType) && ((ObjectType) t).referencesInterface()))
     return Type.OBJECT;
   // TODO: The above line is correct comparing to the vmspec2. But one could
   // make class file verification a bit stronger here by using the notion of
   // superinterfaces or even castability or assignment compatibility.


   // this and t are ObjectTypes, see above.
   ObjectType thiz = (ObjectType) this;
   ObjectType other = (ObjectType) t;
   JavaClass[] thiz_sups = Repository.getSuperClasses(thiz.getClassName());
   JavaClass[] other_sups = Repository.getSuperClasses(other.getClassName());

   if ((thiz_sups == null) || (other_sups == null)) {
     return null;
   }

   // Waaahh...
   JavaClass[] this_sups = new JavaClass[thiz_sups.length + 1];
   JavaClass[] t_sups = new JavaClass[other_sups.length + 1];
   System.arraycopy(thiz_sups, 0, this_sups, 1, thiz_sups.length);
   System.arraycopy(other_sups, 0, t_sups, 1, other_sups.length);
   this_sups[0] = Repository.lookupClass(thiz.getClassName());
   t_sups[0] = Repository.lookupClass(other.getClassName());

   for (int i = 0; i < t_sups.length; i++) {
     for (int j = 0; j < this_sups.length; j++) {
if (this_sups[j].equals(t_sups[i])) return new ObjectType(this_sups[j].getClassName());
     }
   }

   // Huh? Did you ask for Type.OBJECT's superclass??
   return null;
 }
 
开发者ID:linchaolong,项目名称:ApkToolPlus,代码行数:67,代码来源:ReferenceType.java

示例4: firstCommonSuperclass

import org.apache.bcel.Repository; //导入方法依赖的package包/类
/**
 * This commutative operation returns the first common superclass (narrowest ReferenceType
 * referencing a class, not an interface).
 * If one of the types is a superclass of the other, the former is returned.
 * If "this" is Type.NULL, then t is returned.
 * If t is Type.NULL, then "this" is returned.
 * If "this" equals t ['this.equals(t)'] "this" is returned.
 * If "this" or t is an ArrayType, then Type.OBJECT is returned.
 * If "this" or t is a ReferenceType referencing an interface, then Type.OBJECT is returned.
 * If not all of the two classes' superclasses cannot be found, "null" is returned.
 * See the JVM specification edition 2, "�4.9.2 The Bytecode Verifier".
 *
 * @deprecated use getFirstCommonSuperclass(ReferenceType t) which has
 *             slightly changed semantics.
 * @throws ClassNotFoundException on failure to find superclasses of this
 *  type, or the type passed as a parameter
 */
public ReferenceType firstCommonSuperclass( ReferenceType t ) throws ClassNotFoundException {
    if (this.equals(Type.NULL)) {
        return t;
    }
    if (t.equals(Type.NULL)) {
        return this;
    }
    if (this.equals(t)) {
        return this;
        /*
         * TODO: Above sounds a little arbitrary. On the other hand, there is
         * no object referenced by Type.NULL so we can also say all the objects
         * referenced by Type.NULL were derived from java.lang.Object.
         * However, the Java Language's "instanceof" operator proves us wrong:
         * "null" is not referring to an instance of java.lang.Object :)
         */
    }
    if ((this instanceof ArrayType) || (t instanceof ArrayType)) {
        return Type.OBJECT;
        // TODO: Is there a proof of OBJECT being the direct ancestor of every ArrayType?
    }
    if (((this instanceof ObjectType) && ((ObjectType) this).referencesInterface())
            || ((t instanceof ObjectType) && ((ObjectType) t).referencesInterface())) {
        return Type.OBJECT;
        // TODO: The above line is correct comparing to the vmspec2. But one could
        // make class file verification a bit stronger here by using the notion of
        // superinterfaces or even castability or assignment compatibility.
    }
    // this and t are ObjectTypes, see above.
    ObjectType thiz = (ObjectType) this;
    ObjectType other = (ObjectType) t;
    JavaClass[] thiz_sups = Repository.getSuperClasses(thiz.getClassName());
    JavaClass[] other_sups = Repository.getSuperClasses(other.getClassName());
    if ((thiz_sups == null) || (other_sups == null)) {
        return null;
    }
    // Waaahh...
    JavaClass[] this_sups = new JavaClass[thiz_sups.length + 1];
    JavaClass[] t_sups = new JavaClass[other_sups.length + 1];
    System.arraycopy(thiz_sups, 0, this_sups, 1, thiz_sups.length);
    System.arraycopy(other_sups, 0, t_sups, 1, other_sups.length);
    this_sups[0] = Repository.lookupClass(thiz.getClassName());
    t_sups[0] = Repository.lookupClass(other.getClassName());
    for (int i = 0; i < t_sups.length; i++) {
        for (int j = 0; j < this_sups.length; j++) {
            if (this_sups[j].equals(t_sups[i])) {
                return new ObjectType(this_sups[j].getClassName());
            }
        }
    }
    // Huh? Did you ask for Type.OBJECT's superclass??
    return null;
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:71,代码来源:ReferenceType.java

示例5: firstCommonSuperclass

import org.apache.bcel.Repository; //导入方法依赖的package包/类
/**
 * This commutative operation returns the first common superclass (narrowest ReferenceType
 * referencing a class, not an interface).
 * If one of the types is a superclass of the other, the former is returned.
 * If "this" is Type.NULL, then t is returned.
 * If t is Type.NULL, then "this" is returned.
 * If "this" equals t ['this.equals(t)'] "this" is returned.
 * If "this" or t is an ArrayType, then Type.OBJECT is returned.
 * If "this" or t is a ReferenceType referencing an interface, then Type.OBJECT is returned.
 * If not all of the two classes' superclasses cannot be found, "null" is returned.
 * See the JVM specification edition 2, "�4.9.2 The Bytecode Verifier".
 *
 * @param t
 * @deprecated use getFirstCommonSuperclass(ReferenceType t) which has
 *             slightly changed semantics.
 */
public ReferenceType firstCommonSuperclass(ReferenceType t) {
    if (this.equals(Type.NULL)) return t;
    if (t.equals(Type.NULL)) return this;
    if (this.equals(t)) return this;
    /*
    * TODO: Above sounds a little arbitrary. On the other hand, there is
    * no object referenced by Type.NULL so we can also say all the objects
    * referenced by Type.NULL were derived from java.lang.Object.
    * However, the Java Language's "instanceof" operator proves us wrong:
    * "null" is not referring to an instance of java.lang.Object :)
    */

    if ((this instanceof ArrayType) || (t instanceof ArrayType))
        return Type.OBJECT;
    // TODO: Is there a proof of OBJECT being the direct ancestor of every ArrayType?

    if (((this instanceof ObjectType) && ((ObjectType) this).referencesInterface()) ||
            ((t instanceof ObjectType) && ((ObjectType) t).referencesInterface()))
        return Type.OBJECT;
    // TODO: The above line is correct comparing to the vmspec2. But one could
    // make class file verification a bit stronger here by using the notion of
    // superinterfaces or even castability or assignment compatibility.


    // this and t are ObjectTypes, see above.
    ObjectType thiz = (ObjectType) this;
    ObjectType other = (ObjectType) t;
    JavaClass[] thiz_sups = Repository.getSuperClasses(thiz.getClassName());
    JavaClass[] other_sups = Repository.getSuperClasses(other.getClassName());

    if ((thiz_sups == null) || (other_sups == null)) {
        return null;
    }

    // Waaahh...
    JavaClass[] this_sups = new JavaClass[thiz_sups.length + 1];
    JavaClass[] t_sups = new JavaClass[other_sups.length + 1];
    System.arraycopy(thiz_sups, 0, this_sups, 1, thiz_sups.length);
    System.arraycopy(other_sups, 0, t_sups, 1, other_sups.length);
    this_sups[0] = Repository.lookupClass(thiz.getClassName());
    t_sups[0] = Repository.lookupClass(other.getClassName());

    for (JavaClass t_sup : t_sups) {
        for (JavaClass this_sup : this_sups) {
            if (this_sup.equals(t_sup)) return new ObjectType(this_sup.getClassName());
        }
    }

    // Huh? Did you ask for Type.OBJECT's superclass??
    return null;
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:68,代码来源:ReferenceType.java


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