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


Java Constant类代码示例

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


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

示例1: pushByConstant

import org.apache.bcel.classfile.Constant; //导入依赖的package包/类
private void pushByConstant(DismantleBytecode dbc, Constant c) {
	
if (c instanceof ConstantInteger)
	push(new Item("I", new Integer(((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", new Float(((ConstantInteger) c).getBytes())));
else if (c instanceof ConstantDouble)
	push(new Item("D", new Double(((ConstantDouble) c).getBytes())));
else if (c instanceof ConstantLong)
	push(new Item("J", new Long(((ConstantLong) c).getBytes())));
else
	throw new UnsupportedOperationException("Constant type not expected" );
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:18,代码来源:OpcodeStack.java

示例2: visitFieldInstruction

import org.apache.bcel.classfile.Constant; //导入依赖的package包/类
/**
* Ensures the general preconditions of a FieldInstruction instance.
*/
public void visitFieldInstruction(FieldInstruction o){
	// visitLoadClass(o) has been called before: Every FieldOrMethod
	// implements LoadClass.
	// visitCPInstruction(o) has been called before.
// A FieldInstruction may be: GETFIELD, GETSTATIC, PUTFIELD, PUTSTATIC 
	Constant c = cpg.getConstant(o.getIndex());
	if (!(c instanceof ConstantFieldref)){
		constraintViolated(o, "Index '"+o.getIndex()+"' should refer to a CONSTANT_Fieldref_info structure, but refers to '"+c+"'.");
	}
	// 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+"'.");
		}
	}
}
 
开发者ID:linchaolong,项目名称:ApkToolPlus,代码行数:24,代码来源:InstConstraintVisitor.java

示例3: visitCHECKCAST

import org.apache.bcel.classfile.Constant; //导入依赖的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

示例4: visitINSTANCEOF

import org.apache.bcel.classfile.Constant; //导入依赖的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

示例5: processConstant

import org.apache.bcel.classfile.Constant; //导入依赖的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

示例6: checkCode

import org.apache.bcel.classfile.Constant; //导入依赖的package包/类
public boolean checkCode(InstructionHandle[] match)
{
    InstructionHandle ih = match[0];
    CPInstruction ldc_w = (CPInstruction) ih.getInstruction();
    Constant cc = cpool.getConstant(ldc_w.getIndex());
    if (cc.getTag() != CONSTANT_Class)
        return false;

    ih = match[1];
    CPInstruction invokevirtual = (CPInstruction) ih.getInstruction();
    ConstantMethodref cm = (ConstantMethodref) cpool.getConstant(invokevirtual.getIndex());
    ConstantNameAndType cnt = (ConstantNameAndType) cpool.getConstant(cm.getNameAndTypeIndex());
    if (!cnt.getName(cpool.getConstantPool()).equals("desiredAssertionStatus"))
        return false;
    return true;
}
 
开发者ID:BowlerHatLLC,项目名称:feathers-sdk,代码行数:17,代码来源:Downgrader.java

示例7: createDependencyList

import org.apache.bcel.classfile.Constant; //导入依赖的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

示例8: createDependencyList

import org.apache.bcel.classfile.Constant; //导入依赖的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

示例9: getSurroundingCaughtExceptions

import org.apache.bcel.classfile.Constant; //导入依赖的package包/类
public Set<String> getSurroundingCaughtExceptions(int pc, int maxTryBlockSize) {
    HashSet<String> result = new HashSet<String>();
    if (code == null)
        throw new IllegalStateException("Not visiting Code");
    int size = maxTryBlockSize;
    if (code.getExceptionTable() == null)
        return result;
    for (CodeException catchBlock : code.getExceptionTable()) {
        int startPC = catchBlock.getStartPC();
        int endPC = catchBlock.getEndPC();
        if (pc >= startPC && pc <= endPC) {
            int thisSize = endPC - startPC;
            if (size > thisSize) {
                result.clear();
                size = thisSize;
                Constant kind = constantPool.getConstant(catchBlock.getCatchType());
                result.add("C" + catchBlock.getCatchType());
            } else if (size == thisSize)
                result.add("C" + catchBlock.getCatchType());
        }
    }
    return result;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:24,代码来源:PreorderVisitor.java

示例10: getSurroundingTryBlock

import org.apache.bcel.classfile.Constant; //导入依赖的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

示例11: visit

import org.apache.bcel.classfile.Constant; //导入依赖的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

示例12: visitClass

import org.apache.bcel.classfile.Constant; //导入依赖的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

示例13: visitClassContext

import org.apache.bcel.classfile.Constant; //导入依赖的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

示例14: visit

import org.apache.bcel.classfile.Constant; //导入依赖的package包/类
@Override
public void visit(ConstantValue s) {
    if (!visitingField())
        return;
    int i = s.getConstantValueIndex();
    Constant c = getConstantPool().getConstant(i);
    if (c instanceof ConstantString) {
        String value = ((ConstantString) c).getBytes(getConstantPool());
        if (value.length() < SIZE_OF_HUGE_CONSTANT)
            return;
        String key = getStringKey(value);
        definition.put(key, XFactory.createXField(this));
        stringSize.put(key, value.length());
    }

}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:17,代码来源:HugeSharedStringConstants.java

示例15: pushByConstant

import org.apache.bcel.classfile.Constant; //导入依赖的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


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