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


Java Method.getCode方法代码示例

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


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

示例1: analyze

import org.apache.bcel.classfile.Method; //导入方法依赖的package包/类
protected BitSet analyze(Method method) {
 final BitSet result = new BitSet();

 Code code = method.getCode();
 if (code != null) {
  byte[] instructionList = code.getCode();

  // Create a callback to put the opcodes of the method's
  // bytecode instructions into the BitSet.
  BytecodeScanner.Callback callback = new BytecodeScanner.Callback() {
   public void handleInstruction(int opcode, int index) {
    result.set(opcode, true);
   }
  };

  // Scan the method.
  BytecodeScanner scanner = new BytecodeScanner();
  scanner.scan(instructionList, callback);
 }

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

示例2: visitClassContext

import org.apache.bcel.classfile.Method; //导入方法依赖的package包/类
public void visitClassContext(ClassContext classContext) {
	JavaClass jclass = classContext.getJavaClass();
	Method[] methodList = jclass.getMethods();

	for (int i = 0; i < methodList.length; ++i) {
		Method method = methodList[i];
		if (method.getCode() == null)
			continue;

		analyzeMethod(classContext, method);
	}
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:13,代码来源:FindJSR166LockMonitorenter.java

示例3: isStaticOnlyClass

import org.apache.bcel.classfile.Method; //导入方法依赖的package包/类
private boolean isStaticOnlyClass(String clsName) throws ClassNotFoundException {
JavaClass cls = Repository.lookupClass(clsName);
if (cls.getInterfaceNames().length > 0)
	return false;
String superClassName = cls.getSuperclassName();
if (!superClassName.equals("java.lang.Object"))
	return false;

Method[] methods = cls.getMethods();
int staticCount = 0;
for (int i = 0; i < methods.length; i++) {
	Method m = methods[i];
	if (m.isStatic()) {
		staticCount++;
		continue;
		}
	
	if (m.getName().equals("<init>")) {
		if (!m.getSignature().equals("()V"))
			return false;
		
		Code c = m.getCode();

		if (c.getCode().length > 5)
			return false;
	} else {
		return false;
	}
}

Field[] fields = cls.getFields();
for (int i = 0; i < fields.length; i++) {
	Field f = fields[i];
	if (f.isStatic()) {
		staticCount++;
		continue;
		}
	
	if (!f.isPrivate())
		return false;
}

if (staticCount == 0) return false;
return true;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:46,代码来源:InstantiateStaticClass.java

示例4: visit

import org.apache.bcel.classfile.Method; //导入方法依赖的package包/类
public void visit(Method obj) {
	int accessFlags = obj.getAccessFlags();
	if ((accessFlags & ACC_STATIC) != 0) return;
	String name = obj.getName();
	String sig = obj.getSignature();
	if ((accessFlags & ACC_ABSTRACT) != 0) {
		if (name.equals("equals")
		        && sig.equals("(L" + getClassName() + ";)Z")) {
			bugReporter.reportBug(new BugInstance(this, "EQ_ABSTRACT_SELF", LOW_PRIORITY).addClass(getDottedClassName()));
			return;
		} else if (name.equals("compareTo")
		        && sig.equals("(L" + getClassName() + ";)I")) {
			bugReporter.reportBug(new BugInstance(this, "CO_ABSTRACT_SELF", LOW_PRIORITY).addClass(getDottedClassName()));
			return;
		}
	}
	boolean sigIsObject = sig.equals("(Ljava/lang/Object;)Z");
	if (name.equals("hashCode")
	        && sig.equals("()I")) {
		hasHashCode = true;
		if (obj.isAbstract()) hashCodeIsAbstract = true;
		// System.out.println("Found hashCode for " + betterClassName);
	} else if (name.equals("equals")) {
		if (sigIsObject) {
			hasEqualsObject = true;
			if (obj.isAbstract())
				equalsObjectIsAbstract = true;
			else {
				Code code = obj.getCode();
				byte[] codeBytes = code.getCode();

				if ((codeBytes.length == 5 &&
				        (codeBytes[1] & 0xff) == INSTANCEOF)
				        || (codeBytes.length == 15 &&
				        (codeBytes[1] & 0xff) == INSTANCEOF &&
				        (codeBytes[11] & 0xff) == INVOKESPECIAL)) {
					equalsMethodIsInstanceOfEquals = true;
				}
			}
		} else if (sig.equals("(L" + getClassName() + ";)Z"))
			hasEqualsSelf = true;
	} else if (name.equals("compareTo")) {
		if (sig.equals("(Ljava/lang/Object;)I"))
			hasCompareToObject = true;
		else if (sig.equals("(L" + getClassName() + ";)I"))
			hasCompareToSelf = true;
	}
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:49,代码来源:FindHEmismatch.java


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