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


Java ConstantClass类代码示例

本文整理汇总了Java中org.apache.bcel.classfile.ConstantClass的典型用法代码示例。如果您正苦于以下问题:Java ConstantClass类的具体用法?Java ConstantClass怎么用?Java ConstantClass使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: visitCHECKCAST

import org.apache.bcel.classfile.ConstantClass; //导入依赖的package包/类
/**
 * Ensures the specific preconditions of the said instruction.
 */
public void visitCHECKCAST(CHECKCAST o){
	// The objectref must be of type reference.
	Type objectref = stack().peek(0);
	if (!(objectref instanceof ReferenceType)){
		constraintViolated(o, "The 'objectref' is not of a ReferenceType but of type "+objectref+".");
	}
	else{
		referenceTypeIsInitialized(o, (ReferenceType) objectref);
	}
	// The unsigned indexbyte1 and indexbyte2 are used to construct an index into the runtime constant pool of the
	// current class (�3.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant
	// pool item at the index must be a symbolic reference to a class, array, or interface type.
	Constant c = cpg.getConstant(o.getIndex());
	if (! (c instanceof ConstantClass)){
		constraintViolated(o, "The Constant at 'index' is not a ConstantClass, but '"+c+"'.");
	}
}
 
开发者ID:linchaolong,项目名称:ApkToolPlus,代码行数:21,代码来源:InstConstraintVisitor.java

示例2: visitINSTANCEOF

import org.apache.bcel.classfile.ConstantClass; //导入依赖的package包/类
/**
 * Ensures the specific preconditions of the said instruction.
 */
public void visitINSTANCEOF(INSTANCEOF o){
	// The objectref must be of type reference.
	Type objectref = stack().peek(0);
	if (!(objectref instanceof ReferenceType)){
		constraintViolated(o, "The 'objectref' is not of a ReferenceType but of type "+objectref+".");
	}
	else{
		referenceTypeIsInitialized(o, (ReferenceType) objectref);
	}
	// The unsigned indexbyte1 and indexbyte2 are used to construct an index into the runtime constant pool of the
	// current class (�3.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant
	// pool item at the index must be a symbolic reference to a class, array, or interface type.
	Constant c = cpg.getConstant(o.getIndex());
	if (! (c instanceof ConstantClass)){
		constraintViolated(o, "The Constant at 'index' is not a ConstantClass, but '"+c+"'.");
	}
}
 
开发者ID:linchaolong,项目名称:ApkToolPlus,代码行数:21,代码来源:InstConstraintVisitor.java

示例3: processConstant

import org.apache.bcel.classfile.ConstantClass; //导入依赖的package包/类
private void processConstant(ConstantPool pool, Constant c, int i) {
	if (c == null) // don't know why, but constant[0] seems to be always
					// null.
		return;

	log("      const[" + i + "]=" + pool.constantToString(c) + " inst=" + c.getClass().getName(),
			Project.MSG_DEBUG);
	byte tag = c.getTag();
	switch (tag) {
	// reverse engineered from ConstantPool.constantToString..
	case Constants.CONSTANT_Class:
		int ind = ((ConstantClass) c).getNameIndex();
		c = pool.getConstant(ind, Constants.CONSTANT_Utf8);
		String className = Utility.compactClassName(((ConstantUtf8) c).getBytes(), false);
		log("      classNamePre=" + className, Project.MSG_DEBUG);
		className = getRidOfArray(className);
		String firstLetter = className.charAt(0) + "";
		if (primitives.contains(firstLetter))
			return;
		log("      className=" + className, Project.MSG_VERBOSE);
		design.checkClass(className);
		break;
	default:

	}
}
 
开发者ID:cniweb,项目名称:ant-contrib,代码行数:27,代码来源:VerifyDesignDelegate.java

示例4: createDependencyList

import org.apache.bcel.classfile.ConstantClass; //导入依赖的package包/类
/**
 * Create a list containing all referenced classes.
 * 
 * @return the list of all classes the given class depends on.
 */
private List<String> createDependencyList(JavaClass clazz) {
	Set<String> result = new HashSet<String>();
	ConstantPool cp = clazz.getConstantPool();
	String className = clazz.getClassName();
	for (Constant c : cp.getConstantPool()) {
		if (c instanceof ConstantClass) {
			String usedClassName = cp.constantToString(c);

			usedClassName = JavaLibrary
					.ignoreArtificialPrefix(usedClassName);
			if (!usedClassName.equals("") && !isBlacklisted(usedClassName)
					&& !className.equals(usedClassName)) {
				result.add(usedClassName);
			}
		}
	}
	return new ArrayList<String>(result);
}
 
开发者ID:vimaier,项目名称:conqat,代码行数:24,代码来源:ImportListBuilder.java

示例5: createDependencyList

import org.apache.bcel.classfile.ConstantClass; //导入依赖的package包/类
/** Create a list of dependencies for a given class. */
private ArrayList<String> createDependencyList(JavaClass clazz) {

	ArrayList<String> depList = new ArrayList<String>();
	ConstantPool cp = clazz.getConstantPool();
	String className = clazz.getClassName();

	for (Constant constant : cp.getConstantPool()) {
		if (constant instanceof ConstantClass) {

			String usedClassName = cp.constantToString(constant);

			// don't include self-reference
			if (!className.equals(usedClassName)) {
				depList.add(usedClassName);
			}
		}
	}
	return depList;
}
 
开发者ID:vimaier,项目名称:conqat,代码行数:21,代码来源:ClassFanInCounter.java

示例6: setupVisitorForClass

import org.apache.bcel.classfile.ConstantClass; //导入依赖的package包/类
public void setupVisitorForClass(JavaClass obj) {
    constantPool = obj.getConstantPool();
    thisClass = obj;
    ConstantClass c = (ConstantClass) constantPool.getConstant(obj.getClassNameIndex());
    className = getStringFromIndex(c.getNameIndex());
    dottedClassName = className.replace('/', '.');
    packageName = obj.getPackageName();
    sourceFile = obj.getSourceFileName();
    dottedSuperclassName = obj.getSuperclassName();
    superclassName = dottedSuperclassName.replace('.', '/');

    ClassDescriptor cDesc = DescriptorFactory.createClassDescriptor(className);
    if (!FindBugs.isNoAnalysis())
    try {
        thisClassInfo = (ClassInfo) Global.getAnalysisCache().getClassAnalysis(XClass.class, cDesc);
    } catch (CheckedAnalysisException e) {
        throw new AssertionError("Can't find ClassInfo for " + cDesc);
    }

    super.visitJavaClass(obj);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:22,代码来源:PreorderVisitor.java

示例7: getOuterClass

import org.apache.bcel.classfile.ConstantClass; //导入依赖的package包/类
/**
 * Determine the outer class of obj.
 * 
 * @param obj
 * @return JavaClass for outer class, or null if obj is not an outer class
 * @throws ClassNotFoundException
 */

@CheckForNull
public static JavaClass getOuterClass(JavaClass obj) throws ClassNotFoundException {
    for (Attribute a : obj.getAttributes())
        if (a instanceof InnerClasses) {
            for (InnerClass ic : ((InnerClasses) a).getInnerClasses()) {
                if (obj.getClassNameIndex() == ic.getInnerClassIndex()) {
                    // System.out.println("Outer class is " +
                    // ic.getOuterClassIndex());
                    ConstantClass oc = (ConstantClass) obj.getConstantPool().getConstant(ic.getOuterClassIndex());
                    String ocName = oc.getBytes(obj.getConstantPool());
                    return Repository.lookupClass(ocName);
                }
            }
        }
    return null;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:25,代码来源:Util.java

示例8: getSurroundingTryBlock

import org.apache.bcel.classfile.ConstantClass; //导入依赖的package包/类
public static @CheckForNull
CodeException getSurroundingTryBlock(ConstantPool constantPool, Code code, @CheckForNull String vmNameOfExceptionClass, int pc) {
    int size = Integer.MAX_VALUE;
    if (code.getExceptionTable() == null)
        return null;
    CodeException result = null;
    for (CodeException catchBlock : code.getExceptionTable()) {
        if (vmNameOfExceptionClass != null) {
            Constant catchType = constantPool.getConstant(catchBlock.getCatchType());
            if (catchType == null || catchType instanceof ConstantClass
                    && !((ConstantClass) catchType).getBytes(constantPool).equals(vmNameOfExceptionClass))
                continue;
        }
        int startPC = catchBlock.getStartPC();
        int endPC = catchBlock.getEndPC();
        if (pc >= startPC && pc <= endPC) {
            int thisSize = endPC - startPC;
            if (size > thisSize) {
                size = thisSize;
                result = catchBlock;
            }
        }
    }
    return result;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:26,代码来源:Util.java

示例9: visit

import org.apache.bcel.classfile.ConstantClass; //导入依赖的package包/类
@Override
public void visit(ConstantPool pool) {
    for (Constant constant : pool.getConstantPool()) {
        if (constant instanceof ConstantClass) {
            ConstantClass cc = (ConstantClass) constant;
            @SlashedClassName String className = cc.getBytes(pool);
            if (className.equals("java/util/Calendar") || className.equals("java/text/DateFormat")) {
                sawDateClass = true;
                break;
            }
            try {
                ClassDescriptor cDesc = DescriptorFactory.createClassDescriptor(className);
                
                if (subtypes2.isSubtype(cDesc, calendarType) || subtypes2.isSubtype(cDesc, dateFormatType)) {
                    sawDateClass = true;
                    break;
                }
            } catch (ClassNotFoundException e) {
              reporter.reportMissingClass(e);
            }
          
              
        }
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:26,代码来源:StaticCalendarDetector.java

示例10: visitClass

import org.apache.bcel.classfile.ConstantClass; //导入依赖的package包/类
@Override
public void visitClass(ClassDescriptor classDescriptor) throws CheckedAnalysisException {
    IAnalysisCache analysisCache = Global.getAnalysisCache();

    ObligationFactory factory = database.getFactory();

    JavaClass jclass = analysisCache.getClassAnalysis(JavaClass.class, classDescriptor);
    for (Constant c : jclass.getConstantPool().getConstantPool()) {
        if (c instanceof ConstantNameAndType) {
            ConstantNameAndType cnt = (ConstantNameAndType) c;
            String signature = cnt.getSignature(jclass.getConstantPool());
            if (factory.signatureInvolvesObligations(signature)) {
                super.visitClass(classDescriptor);
                return;
            }
        } else if (c instanceof ConstantClass) {
            String className = ((ConstantClass) c).getBytes(jclass.getConstantPool());
            if (factory.signatureInvolvesObligations(className)) {
                super.visitClass(classDescriptor);
                return;
            }
        }
    }
    if (DEBUG)
        System.out.println(classDescriptor + " isn't interesting for obligation analysis");
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:27,代码来源:FindUnsatisfiedObligation.java

示例11: visitClassContext

import org.apache.bcel.classfile.ConstantClass; //导入依赖的package包/类
@Override
public void visitClassContext(ClassContext classContext) {
    JavaClass jclass = classContext.getJavaClass();

    // We can ignore classes that were compiled for anything
    // less than JDK 1.5. This should avoid lots of unnecessary work
    // when analyzing code for older VM targets.
    if (BCELUtil.preTiger(jclass))
        return;

    boolean sawUtilConcurrentLocks = false;
    for (Constant c : jclass.getConstantPool().getConstantPool())
        if (c instanceof ConstantMethodref) {
            ConstantMethodref m = (ConstantMethodref) c;
            ConstantClass cl = (ConstantClass) jclass.getConstantPool().getConstant(m.getClassIndex());
            ConstantUtf8 name = (ConstantUtf8) jclass.getConstantPool().getConstant(cl.getNameIndex());
            String nameAsString = name.getBytes();
            if (nameAsString.startsWith("java/util/concurrent/locks"))
                sawUtilConcurrentLocks = true;

        }
    if (sawUtilConcurrentLocks)
        super.visitClassContext(classContext);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:25,代码来源:FindUnreleasedLock.java

示例12: pushByConstant

import org.apache.bcel.classfile.ConstantClass; //导入依赖的package包/类
private void pushByConstant(DismantleBytecode dbc, Constant c) {

        if (c instanceof ConstantClass)
            push(new Item("Ljava/lang/Class;", ((ConstantClass) c).getConstantValue(dbc.getConstantPool())));
        else if (c instanceof ConstantInteger)
            push(new Item("I", Integer.valueOf(((ConstantInteger) c).getBytes())));
        else if (c instanceof ConstantString) {
            int s = ((ConstantString) c).getStringIndex();
            push(new Item("Ljava/lang/String;", getStringFromIndex(dbc, s)));
        } else if (c instanceof ConstantFloat)
            push(new Item("F", Float.valueOf(((ConstantFloat) c).getBytes())));
        else if (c instanceof ConstantDouble)
            push(new Item("D", Double.valueOf(((ConstantDouble) c).getBytes())));
        else if (c instanceof ConstantLong)
            push(new Item("J", Long.valueOf(((ConstantLong) c).getBytes())));
        else
            throw new UnsupportedOperationException("Constant type not expected");
    }
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:19,代码来源:OpcodeStack.java

示例13: setField

import org.apache.bcel.classfile.ConstantClass; //导入依赖的package包/类
/**
 * Called to indicate that a field load or store was encountered.
 *
 * @param cpIndex
 *            the constant pool index of the fieldref
 * @param isStatic
 *            true if it is a static field access
 * @param isLoad
 *            true if the access is a load
 */
private void setField(int cpIndex, boolean isStatic, boolean isLoad) {
    // We only allow one field access for an accessor method.
    accessCount++;
    if (accessCount != 1) {
        access = null;
        return;
    }

    ConstantPool cp = javaClass.getConstantPool();
    ConstantFieldref fieldref = (ConstantFieldref) cp.getConstant(cpIndex);

    ConstantClass cls = (ConstantClass) cp.getConstant(fieldref.getClassIndex());
    String className = cls.getBytes(cp).replace('/', '.');

    ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(fieldref.getNameAndTypeIndex());
    String fieldName = nameAndType.getName(cp);
    String fieldSig = nameAndType.getSignature(cp);


        XField xfield = Hierarchy.findXField(className, fieldName, fieldSig, isStatic);
        if (xfield != null && xfield.isStatic() == isStatic && isValidAccessMethod(methodSig, xfield, isLoad)) {
            access = new InnerClassAccess(methodName, methodSig, xfield, isLoad);
        }
   
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:36,代码来源:InnerClassAccessMap.java

示例14: visitLDC

import org.apache.bcel.classfile.ConstantClass; //导入依赖的package包/类
@Override
public void visitLDC(LDC obj) {
    Object constantValue = obj.getValue(cpg);
    ValueNumber value;
    if (constantValue instanceof ConstantClass) {
        ConstantClass constantClass = (ConstantClass) constantValue;
        String className = constantClass.getBytes(cpg.getConstantPool());
        value = factory.getClassObjectValue(className);
    } else {
        value = constantValueMap.get(constantValue);
        if (value == null) {
            value = factory.createFreshValue(ValueNumber.CONSTANT_VALUE);
            constantValueMap.put(constantValue, value);

            // Keep track of String constants

            if (constantValue instanceof String) {
                stringConstantMap.put(value, (String) constantValue);
            }
        }
    }
    getFrame().pushValue(value);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:24,代码来源:ValueNumberFrameModelingVisitor.java

示例15: getOuterClass

import org.apache.bcel.classfile.ConstantClass; //导入依赖的package包/类
/**
 * Determine the outer class of obj.
 *
 * @param obj
 * @return JavaClass for outer class, or null if obj is not an outer class
 * @throws ClassNotFoundException
 */

@CheckForNull
public static JavaClass getOuterClass(JavaClass obj) throws ClassNotFoundException {
    for (Attribute a : obj.getAttributes())
        if (a instanceof InnerClasses) {
            for (InnerClass ic : ((InnerClasses) a).getInnerClasses()) {
                if (obj.getClassNameIndex() == ic.getInnerClassIndex()) {
                    // System.out.println("Outer class is " +
                    // ic.getOuterClassIndex());
                    ConstantClass oc = (ConstantClass) obj.getConstantPool().getConstant(ic.getOuterClassIndex());
                    String ocName = oc.getBytes(obj.getConstantPool());
                    return Repository.lookupClass(ocName);
                }
            }
        }
    return null;
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:25,代码来源:Util.java


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