• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ConstantValue类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getNativeValue

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
/**
 * Returns a string representation of a given object native value.
 * 
 * @param type - a Class object that wraps a data type.
 * @param value - an object that wraps a value of a primitive data type.
 * @return a string that represents a native data type.
 */
public static String getNativeValue(Type type, ConstantValue value) {
    StringBuffer result = new StringBuffer();

    if (type == Type.INT) {
        result.append(value.toString()).append('L');
    } else if (type == Type.BYTE) {
        result.append(value.toString()).append('L');
    } else if (type == Type.LONG) {
        result.append(value.toString()).append("LL");
    } else if (type == Type.FLOAT) {
        result.append(value.toString()).append('f');
    } else if (type == Type.DOUBLE) {
        result.append(value.toString());
    } else if (type == Type.SHORT) {
        result.append(value.toString()).append('L');
    } else if (type == Type.CHAR) {
        result.append(value.toString()).append('L');
    } else if (type == Type.BOOLEAN) {
        result.append(value.toString()).append('L');
    }

    return result.toString();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:31,代码来源:ClazzField.java


示例2: visit

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


示例3: writeField

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
/**
 * Print field of class.
 *
 * @param field field to print
 * @exception java.io.IOException
 */
private void writeField( Field field ) throws IOException {
    String type = Utility.signatureToString(field.getSignature());
    String name = field.getName();
    String access = Utility.accessToString(field.getAccessFlags());
    Attribute[] attributes;
    access = Utility.replace(access, " ", "&nbsp;");
    file.print("<TR><TD><FONT COLOR=\"#FF0000\">" + access + "</FONT></TD>\n<TD>"
            + Class2HTML.referenceType(type) + "</TD><TD><A NAME=\"field" + name + "\">" + name
            + "</A></TD>");
    attributes = field.getAttributes();
    // Write them to the Attributes.html file with anchor "<name>[<i>]"
    for (int i = 0; i < attributes.length; i++) {
        attribute_html.writeAttribute(attributes[i], name + "@" + i);
    }
    for (int i = 0; i < attributes.length; i++) {
        if (attributes[i].getTag() == ATTR_CONSTANT_VALUE) { // Default value
            String str = ((ConstantValue) attributes[i]).toString();
            // Reference attribute in _attributes.html
            file.print("<TD>= <A HREF=\"" + class_name + "_attributes.html#" + name + "@" + i
                    + "\" TARGET=\"Attributes\">" + str + "</TD>\n");
            break;
        }
    }
    file.println("</TR>");
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:32,代码来源:MethodHTML.java


示例4: getConstants

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
/**
 * Get the constants declared in a file as name=value
 *
 * @param bytes the class as a array of bytes
 * @return a StringBuffer contains the name=value pairs
 * @exception IOException if an error occurs
 */
public static StringBuffer getConstants(final byte[] bytes)
    throws IOException {
    final StringBuffer sb = new StringBuffer();
    final ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
    final ClassParser parser = new ClassParser(bis, "");
    final JavaClass javaClass = parser.parse();
    final Field[] fields = javaClass.getFields();
    for (int i = 0; i < fields.length; i++) {
        final Field field = fields[i];
        if (field != null) {
            final ConstantValue cv = field.getConstantValue();
            if (cv != null) {
                String cvs = cv.toString();
                //Remove start and end quotes if field is a String
                if (cvs.startsWith("\"") && cvs.endsWith("\"")) {
                    cvs = cvs.substring(1, cvs.length() - 1);
                }
                sb.append(field.getName());
                sb.append('=');
                sb.append(cvs);
                sb.append(LS);
            }
        }
    }
    return sb;
}
 
开发者ID:apache,项目名称:ant,代码行数:34,代码来源:JavaClassHelper.java


示例5: visitField

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
@Override
public void visitField(Field field) {
    Element f = new Element("field", nsXMLVM);
    xmlClass.addContent(f);
    addAccessModifiers(f, field.getAccessFlags());
    f.setAttribute("name", field.getName());
    Type t = field.getType();
    f.setAttribute("type", t.toString());
    ConstantValue val = field.getConstantValue();
    if (val != null) {
        f.setAttribute("value", val.toString());
    }
    addAnnotations(f, field.getAnnotationEntries());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:15,代码来源:ClassToXmlvmProcess.java


示例6: visit

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
@Override
public void visit(Field field) {
    ConstantValue value = field.getConstantValue();
    if (value == null) return;
    Constant c = getConstantPool().getConstant(value.getConstantValueIndex());

    if (c instanceof ConstantLong && ((ConstantLong)c).getBytes()  == MICROS_PER_DAY_OVERFLOWED_AS_INT) {
        bugReporter.reportBug( new BugInstance(this, "TESTING", HIGH_PRIORITY).addClass(this).addField(this)
        .addString("Did you mean MICROS_PER_DAY")
        .addInt(MICROS_PER_DAY_OVERFLOWED_AS_INT)
        .describe(IntAnnotation.INT_VALUE));

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


示例7: visit

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
@Override
public void visit(ConstantValue obj) {
    // ConstantValue is an attribute of a field, so the instance variables
    // set during visitation of the Field are still valid here
    XField f = XFactory.createXField(this);
    data.constantFields.add(f);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:8,代码来源:UnreadFields.java


示例8: FieldGen

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
/**
 * Instantiate from existing field.
 *
 * @param field Field object
 * @param cp constant pool (must contain the same entries as the field's constant pool)
 */
public FieldGen(Field field, ConstantPoolGen cp) {
    this(field.getAccessFlags(), Type.getType(field.getSignature()), field.getName(), cp);
    Attribute[] attrs = field.getAttributes();
    for (int i = 0; i < attrs.length; i++) {
        if (attrs[i] instanceof ConstantValue) {
            setValue(((ConstantValue) attrs[i]).getConstantValueIndex());
        } else {
            addAttribute(attrs[i]);
        }
    }
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:18,代码来源:FieldGen.java


示例9: getField

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
/**
 * Get field object after having set up all necessary values.
 */
public Field getField() {
    String signature = getSignature();
    int name_index = cp.addUtf8(name);
    int signature_index = cp.addUtf8(signature);
    if (value != null) {
        checkType(type);
        int index = addConstant();
        addAttribute(new ConstantValue(cp.addUtf8("ConstantValue"), 2, index, cp
                .getConstantPool()));
    }
    return new Field(access_flags, name_index, signature_index, getAttributes(), cp
            .getConstantPool());
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:17,代码来源:FieldGen.java


示例10: visitField

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
public void visitField( Field field ) {
    _out.println();
    _out.println("    field = new FieldGen(" + printFlags(field.getAccessFlags()) + ", "
            + printType(field.getSignature()) + ", \"" + field.getName() + "\", _cp);");
    ConstantValue cv = field.getConstantValue();
    if (cv != null) {
        String value = cv.toString();
        _out.println("    field.setInitValue(" + value + ")");
    }
    _out.println("    _cg.addField(field.getField());");
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:12,代码来源:BCELifier.java


示例11: visitConstantValue

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
public void visitConstantValue(ConstantValue cv) {
  out.println(" = " + cv);
}
 
开发者ID:diana-hep,项目名称:root4j,代码行数:4,代码来源:JasminVisitor.java


示例12: printFields

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
/**
 * Returns some information about the class fields.
 * 
 * @param indent - an indentation.
 * @return an indented string with some information about the class fields.
 */
private String printFields(int indent) {
    StringBuffer result = new StringBuffer();

    Field fields[] = wrappedClass.getFields();
    if (fields.length > 0) {
        // Create the indentation string.
        String indentStr = indentString(indent);

        boolean found = false;
        for (int i = 0; i < fields.length; i++) {
            Field f = fields[i];

            // Skip a field, if we should not print an information about it.
            if (!isPrintable(f)) {
                continue;
            }
            found = true;

            result.append(n);
            result.append(indentStr);

            // Append an access string.
            String access = Utility.accessToString(f.getAccessFlags());
            if (access.length() > 0) {
                result.append(access);
                result.append(' ');
            }
            // Append a field signature and name.
            result.append(Utility.signatureToString(f.getSignature()));
            result.append(' ');
            result.append(f.getName());
            result.append(';');
            result.append(n);

            // Append a type signature.
            if (printTypeSignatures) {
                result.append(indentString(indent * 2, "Signature: "));
                result.append(f.getSignature());
                result.append(n);
            }

            if (verbose) {
                // Append a field constant value, if any.
                ConstantValue cv  = f.getConstantValue();
                if (cv != null) {
                    result.append(indentString(indent * 2,
                            "Constant value: "));
                    result.append(cv);
                    result.append(n);
                }

                Attribute attrs[] = f.getAttributes();
                for (int j = 0; j < attrs.length; j++) {
                    if (attrs[j].getTag() == Constants.ATTR_SYNTHETIC) {
                        result.append(indentString(indent * 2, 
                                "Synthetic: true"));
                        result.append(n);
                        break;
                    }
                }
            }

        }
        if (found) {
            result.append(n);
        }
    }
    return result.toString();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:76,代码来源:Clazz.java


示例13: visitConstantValue

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
@Override
public void visitConstantValue(ConstantValue cv) {
    // System.out.println("**************** = " + cv);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:5,代码来源:ClassToXmlvmProcess.java


示例14: visit

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
public void visit(ConstantValue obj) {
    visit((Attribute) obj);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:4,代码来源:BetterVisitor.java


示例15: visitConstantValue

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
public void visitConstantValue(ConstantValue obj) {
    visit(obj);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:4,代码来源:BetterVisitor.java


示例16: visitField

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
public void visitField(Field obj){

			if (jc.isClass()){
				int maxone=0;
				if (obj.isPrivate()) {
                    maxone++;
                }
				if (obj.isProtected()) {
                    maxone++;
                }
				if (obj.isPublic()) {
                    maxone++;
                }
				if (maxone > 1){
					throw new ClassConstraintException("Field '"+tostring(obj)+"' must only have at most one of its ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC modifiers set.");
				}

				if (obj.isFinal() && obj.isVolatile()){
					throw new ClassConstraintException("Field '"+tostring(obj)+"' must only have at most one of its ACC_FINAL, ACC_VOLATILE modifiers set.");
				}
			}
			else{ // isInterface!
				if (!obj.isPublic()){
					throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_PUBLIC modifier set but hasn't!");
				}
				if (!obj.isStatic()){
					throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_STATIC modifier set but hasn't!");
				}
				if (!obj.isFinal()){
					throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_FINAL modifier set but hasn't!");
				}
			}

			if ((obj.getAccessFlags() & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_STATIC|ACC_FINAL|ACC_VOLATILE|ACC_TRANSIENT)) > 0){
				addMessage("Field '"+tostring(obj)+"' has access flag(s) other than ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_VOLATILE, ACC_TRANSIENT set (ignored).");
			}

			checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

			String name = obj.getName();
			if (! validFieldName(name)){
				throw new ClassConstraintException("Field '"+tostring(obj)+"' has illegal name '"+obj.getName()+"'.");
			}

			// A descriptor is often named signature in BCEL
			checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8);

			String sig  = ((ConstantUtf8) (cp.getConstant(obj.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor)

			try{
				Type.getType(sig);  /* Don't need the return value */
			}
			catch (ClassFormatException cfe){
                throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
			}

			String nameanddesc = (name+sig);
			if (field_names_and_desc.contains(nameanddesc)){
				throw new ClassConstraintException("No two fields (like '"+tostring(obj)+"') are allowed have same names and descriptors!");
			}
			if (field_names.contains(name)){
				addMessage("More than one field of name '"+name+"' detected (but with different type descriptors). This is very unusual.");
			}
			field_names_and_desc.add(nameanddesc);
			field_names.add(name);

			Attribute[] atts = obj.getAttributes();
			for (int i=0; i<atts.length; i++){
				if ((! (atts[i] instanceof ConstantValue)) &&
				    (! (atts[i] instanceof Synthetic))     &&
				    (! (atts[i] instanceof Deprecated))){
					addMessage("Attribute '"+tostring(atts[i])+"' as an attribute of Field '"+tostring(obj)+"' is unknown and will therefore be ignored.");
				}
				if  (! (atts[i] instanceof ConstantValue)){
					addMessage("Attribute '"+tostring(atts[i])+"' as an attribute of Field '"+tostring(obj)+"' is not a ConstantValue and is therefore only of use for debuggers and such.");
				}
			}
		}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:79,代码来源:Pass2Verifier.java


示例17: visitConstantValue

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
public void visitConstantValue(ConstantValue obj){//vmspec2 4.7.2
	// Despite its name, this really is an Attribute,
	// not a constant!
	checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

	String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
	if (! name.equals("ConstantValue")){
		throw new ClassConstraintException("The ConstantValue attribute '"+tostring(obj)+"' is not correctly named 'ConstantValue' but '"+name+"'.");
	}

	Object pred = carrier.predecessor();
	if (pred instanceof Field){ //ConstantValue attributes are quite senseless if the predecessor is not a field.
		Field f = (Field) pred;
		// Field constraints have been checked before -- so we are safe using their type information.
		Type field_type = Type.getType(((ConstantUtf8) (cp.getConstant(f.getSignatureIndex()))).getBytes());

		int index = obj.getConstantValueIndex();
		if ((index < 0) || (index >= cplen)){
			throw new ClassConstraintException("Invalid index '"+index+"' used by '"+tostring(obj)+"'.");
		}
		Constant c = cp.getConstant(index);

		if (CONST_Long.isInstance(c) && field_type.equals(Type.LONG)){
			return;
		}
		if (CONST_Float.isInstance(c) && field_type.equals(Type.FLOAT)){
			return;
		}
		if (CONST_Double.isInstance(c) && field_type.equals(Type.DOUBLE)){
			return;
		}
		if (CONST_Integer.isInstance(c) && (field_type.equals(Type.INT) || field_type.equals(Type.SHORT) || field_type.equals(Type.CHAR) || field_type.equals(Type.BYTE) || field_type.equals(Type.BOOLEAN))){
			return;
		}
		if (CONST_String.isInstance(c) && field_type.equals(Type.STRING)){
			return;
		}

		throw new ClassConstraintException("Illegal type of ConstantValue '"+obj+"' embedding Constant '"+c+"'. It is referenced by field '"+tostring(f)+"' expecting a different type: '"+field_type+"'.");
	}
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:42,代码来源:Pass2Verifier.java


示例18: visitConstantValue

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
public void visitConstantValue(ConstantValue obj) {
    tostring = toString(obj);
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:4,代码来源:StringRepresentation.java


示例19: visitConstantValue

import org.apache.bcel.classfile.ConstantValue; //导入依赖的package包/类
public void visitConstantValue(ConstantValue cv) {
	out.println(" = " + cv);
}
 
开发者ID:jesusc,项目名称:eclectic,代码行数:4,代码来源:DecompilingVisitor.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BitUtil类代码示例发布时间:2022-05-22
下一篇:
Java ServerException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap