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


Java Utility类代码示例

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


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

示例1: visitJavaClass

import org.apache.bcel.classfile.Utility; //导入依赖的package包/类
public void visitJavaClass(JavaClass clazz) {
  out.println(";; Produced by JasminVisitor (BCEL)");
  out.println(";; http://bcel.sourceforge.net/");
  out.println(";; " + new Date() + "\n");

  out.println(".source " + clazz.getSourceFileName());
  out.println("." + Utility.classOrInterface(clazz.getAccessFlags()) + " " +
Utility.accessToString(clazz.getAccessFlags(), true) +
" " + clazz.getClassName().replace('.', '/'));
  out.println(".super " + clazz.getSuperclassName().replace('.', '/'));

  String[] interfaces = clazz.getInterfaceNames();

  for(int i=0; i < interfaces.length; i++)
    out.println(".implements " + interfaces[i].replace('.', '/'));

  out.print("\n");
}
 
开发者ID:diana-hep,项目名称:root4j,代码行数:19,代码来源:JasminVisitor.java

示例2: processConstant

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

示例3: visitMethod

import org.apache.bcel.classfile.Utility; //导入依赖的package包/类
/**
 * @see org.apache.bcel.classfile.Visitor#visitMethod(org.apache.bcel.classfile.Method)
 */
public void visitMethod(Method m) {
	log("      method=" + m.getName(), Project.MSG_VERBOSE);
	String retType = Utility.methodSignatureReturnType(m.getSignature());
	log("         method ret type=" + retType, Project.MSG_VERBOSE);
	if (!"void".equals(retType))
		design.checkClass(retType);

	String[] types = Utility.methodSignatureArgumentTypes(m.getSignature());
	for (int i = 0; i < types.length; i++) {
		log("         method param[" + i + "]=" + types[i], Project.MSG_VERBOSE);
		design.checkClass(types[i]);
	}

	ExceptionTable excs = m.getExceptionTable();
	if (excs != null) {
		types = excs.getExceptionNames();
		for (int i = 0; i < types.length; i++) {
			log("         exc=" + types[i], Project.MSG_VERBOSE);
			design.checkClass(types[i]);
		}
	}

	processInstructions(m);
}
 
开发者ID:cniweb,项目名称:ant-contrib,代码行数:28,代码来源:VisitorImpl.java

示例4: referenceType

import org.apache.bcel.classfile.Utility; //导入依赖的package包/类
static final String referenceType( String type ) {
    String short_type = Utility.compactClassName(type);
    short_type = Utility.compactClassName(short_type, class_package + ".", true);
    int index = type.indexOf('['); // Type is an array?
    String base_type = type;
    if (index > -1) {
        base_type = type.substring(0, index); // Tack of the `['  		
    }
    // test for basic type
    if (base_type.equals("int") || base_type.equals("short") || base_type.equals("boolean")
            || base_type.equals("void") || base_type.equals("char") || base_type.equals("byte")
            || base_type.equals("long") || base_type.equals("double")
            || base_type.equals("float")) {
        return "<FONT COLOR=\"#00FF00\">" + type + "</FONT>";
    } else {
        return "<A HREF=\"" + base_type + ".html\" TARGET=_top>" + short_type + "</A>";
    }
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:19,代码来源:Class2HTML.java

示例5: createClass

import org.apache.bcel.classfile.Utility; //导入依赖的package包/类
/** 
 * Override this method to create you own classes on the fly. The
 * name contains the special token $$BCEL$$. Everything before that
 * token is consddered to be a package name. You can encode you own
 * arguments into the subsequent string. You must regard however not
 * to use any "illegal" characters, i.e., characters that may not
 * appear in a Java class name too<br>
 *
 * The default implementation interprets the string as a encoded compressed
 * Java class, unpacks and decodes it with the Utility.decode() method, and
 * parses the resulting byte array and returns the resulting JavaClass object.
 *
 * @param class_name compressed byte code with "$$BCEL$$" in it
 */
protected JavaClass createClass( String class_name ) {
    int index = class_name.indexOf("$$BCEL$$");
    String real_name = class_name.substring(index + 8);
    JavaClass clazz = null;
    try {
        byte[] bytes = Utility.decode(real_name, true);
        ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes), "foo");
        clazz = parser.parse();
    } catch (Throwable e) {
        e.printStackTrace();
        return null;
    }
    // Adapt the class name to the passed value
    ConstantPool cp = clazz.getConstantPool();
    ConstantClass cl = (ConstantClass) cp.getConstant(clazz.getClassNameIndex(),
            Constants.CONSTANT_Class);
    ConstantUtf8 name = (ConstantUtf8) cp.getConstant(cl.getNameIndex(),
            Constants.CONSTANT_Utf8);
    name.setBytes(class_name.replace('.', '/'));
    return clazz;
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:36,代码来源:ClassLoader.java

示例6: writeField

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

示例7: visitMethod

import org.apache.bcel.classfile.Utility; //导入依赖的package包/类
public void visitMethod( Method method ) {
    MethodGen mg = new MethodGen(method, _clazz.getClassName(), _cp);
    Type result_type = mg.getReturnType();
    Type[] arg_types = mg.getArgumentTypes();
    _out.println("    InstructionList il = new InstructionList();");
    _out.println("    MethodGen method = new MethodGen("
            + printFlags(method.getAccessFlags(), FLAG_FOR_METHOD) + ", "
            + printType(result_type) + ", " + printArgumentTypes(arg_types) + ", "
            + "new String[] { " + Utility.printArray(mg.getArgumentNames(), false, true)
            + " }, \"" + method.getName() + "\", \"" + _clazz.getClassName() + "\", il, _cp);");
    _out.println();
    BCELFactory factory = new BCELFactory(mg, _out);
    factory.start();
    _out.println("    method.setMaxStack();");
    _out.println("    method.setMaxLocals();");
    _out.println("    _cg.addMethod(method.getMethod());");
    _out.println("    il.dispose();");
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:19,代码来源:BCELifier.java

示例8: printType

import org.apache.bcel.classfile.Utility; //导入依赖的package包/类
static String printType( String signature ) {
    Type type = Type.getType(signature);
    byte t = type.getType();
    if (t <= Constants.T_VOID) {
        return "Type." + Constants.TYPE_NAMES[t].toUpperCase(Locale.ENGLISH);
    } else if (type.toString().equals("java.lang.String")) {
        return "Type.STRING";
    } else if (type.toString().equals("java.lang.Object")) {
        return "Type.OBJECT";
    } else if (type.toString().equals("java.lang.StringBuffer")) {
        return "Type.STRINGBUFFER";
    } else if (type instanceof ArrayType) {
        ArrayType at = (ArrayType) type;
        return "new ArrayType(" + printType(at.getBasicType()) + ", " + at.getDimensions()
                + ")";
    } else {
        return "new ObjectType(\"" + Utility.signatureToString(signature, false) + "\")";
    }
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:20,代码来源:BCELifier.java

示例9: visitJavaClass

import org.apache.bcel.classfile.Utility; //导入依赖的package包/类
public void visitJavaClass(JavaClass clazz) {

		out.println("// source " + clazz.getSourceFileName());
		out.println(Utility.accessToString(clazz.getAccessFlags(), true) + " "
				+ Utility.classOrInterface(clazz.getAccessFlags()) + " "
				+ clazz.getClassName().replace('.', '/'));
		out.println("  extends " + clazz.getSuperclassName().replace('.', '/'));

		String[] interfaces = clazz.getInterfaceNames();

		if (interfaces.length > 0) {
			out.print("  implements");
			for (int i = 0; i < interfaces.length; i++)
				out.print(" " + interfaces[i].replace('.', '/'));
			out.println();
		}
		out.println();
	}
 
开发者ID:jesusc,项目名称:eclectic,代码行数:19,代码来源:DecompilingVisitor.java

示例10: createConstant

import org.apache.bcel.classfile.Utility; //导入依赖的package包/类
private void createConstant(Object value) {
  String embed = value.toString();

  if(value instanceof String)
    embed = '"' + Utility.convertString(value.toString()) + '"';
  else if(value instanceof Character)
    embed = "(char)0x" + Integer.toHexString(((Character)value).charValue());

  _out.println("il.append(new PUSH(_cp, " + embed + "));");
}
 
开发者ID:linchaolong,项目名称:ApkToolPlus,代码行数:11,代码来源:BCELFactory.java

示例11: visitMethod

import org.apache.bcel.classfile.Utility; //导入依赖的package包/类
public void visitMethod(Method method) {
  out.println("\n.method " + Utility.accessToString(method.getAccessFlags()) +
" " + method.getName() + method.getSignature());

  this.method = method; // Remember for use in subsequent visitXXX calls

  Attribute[] attributes = method.getAttributes();
  if((attributes == null) || (attributes.length == 0))
    out.println(".end method");
}
 
开发者ID:diana-hep,项目名称:root4j,代码行数:11,代码来源:JasminVisitor.java

示例12: visitField

import org.apache.bcel.classfile.Utility; //导入依赖的package包/类
/**
 * @see org.apache.bcel.classfile.Visitor#visitField(org.apache.bcel.classfile.Field)
 */
public void visitField(Field f) {
	String type = Utility.methodSignatureReturnType(f.getSignature());
	log("      field type=" + type, Project.MSG_VERBOSE);
	design.checkClass(type);

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

示例13: visitCodeException

import org.apache.bcel.classfile.Utility; //导入依赖的package包/类
public void visitCodeException(CodeException c) {
	c.toString(pool, false);

	int catch_type = c.getCatchType();

	if (catch_type == 0)
		return;

	String temp = pool.getConstantString(catch_type, Constants.CONSTANT_Class);
	String str = Utility.compactClassName(temp, false);

	log("         catch=" + str, Project.MSG_DEBUG);
	design.checkClass(str);
}
 
开发者ID:cniweb,项目名称:ant-contrib,代码行数:15,代码来源:VisitorImpl.java

示例14: assess

import org.apache.bcel.classfile.Utility; //导入依赖的package包/类
/**
 * Checks if method return type is discouraged. This works plainly on names,
 * type hierarchy is not taken into consideration.
 */
@Override
protected String assess(Method method) {
	Type type = method.getReturnType();
	String returnTypeName = Utility.signatureToString(type.getSignature());
	if (discouragedTypes.contains(returnTypeName)) {
		return "Discouraged return type '" + returnTypeName + "'";
	}
	return null;
}
 
开发者ID:vimaier,项目名称:conqat,代码行数:14,代码来源:ReturnTypeAssessor.java

示例15: parseSignature

import org.apache.bcel.classfile.Utility; //导入依赖的package包/类
private Element parseSignature(String signature) {
    org.jdom.Element sgn = new Element("signature", nsXMLVM);
    String[] params = Utility.methodSignatureArgumentTypes(signature, false);

    Element ret = new Element("return", nsXMLVM);
    ret.setAttribute("type", Utility.methodSignatureReturnType(signature, false));
    sgn.addContent(ret);

    for (int i = 0; i < params.length; i++) {
        Element param = new Element("parameter", nsXMLVM);
        param.setAttribute("type", params[i]);
        sgn.addContent(param);
    }
    return sgn;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:16,代码来源:ClassToXmlvmProcess.java


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