本文整理汇总了Java中org.apache.bcel.classfile.Code.getCode方法的典型用法代码示例。如果您正苦于以下问题:Java Code.getCode方法的具体用法?Java Code.getCode怎么用?Java Code.getCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.classfile.Code
的用法示例。
在下文中一共展示了Code.getCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import org.apache.bcel.classfile.Code; //导入方法依赖的package包/类
public void visit(Code obj) {
sawSuperFinalize = false;
super.visit(obj);
if (!getMethodName().equals("finalize")
|| !getMethodSig().equals("()V"))
return;
String overridesFinalizeIn
= Lookup.findSuperImplementor(getDottedClassName(),
"finalize",
"()V",
bugReporter);
boolean superHasNoFinalizer = overridesFinalizeIn.equals("java.lang.Object");
// System.out.println("superclass: " + superclassName);
if (obj.getCode().length == 1) {
if (superHasNoFinalizer)
bugReporter.reportBug(new BugInstance(this, "FI_EMPTY", NORMAL_PRIORITY).addClassAndMethod(this));
else
bugReporter.reportBug(new BugInstance(this, "FI_NULLIFY_SUPER", NORMAL_PRIORITY)
.addClassAndMethod(this)
.addClass(overridesFinalizeIn));
} else if (obj.getCode().length == 5 && sawSuperFinalize)
bugReporter.reportBug(new BugInstance(this, "FI_USELESS", NORMAL_PRIORITY).addClassAndMethod(this));
else if (!sawSuperFinalize && !superHasNoFinalizer)
bugReporter.reportBug(new BugInstance(this, "FI_MISSING_SUPER_CALL", NORMAL_PRIORITY).addClassAndMethod(this)
.addClass(overridesFinalizeIn));
}
示例2: analyze
import org.apache.bcel.classfile.Code; //导入方法依赖的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;
}
示例3: visitCode
import org.apache.bcel.classfile.Code; //导入方法依赖的package包/类
/**
* @see org.apache.bcel.classfile.Visitor#visitCode
*/
public void visitCode(Code aCode)
{
for (Iterator iter = mVisitors.iterator(); iter.hasNext();) {
IDeepVisitor visitor = (IDeepVisitor) iter.next();
Visitor v = visitor.getClassFileVisitor();
aCode.accept(v);
}
// perform a deep visit
final byte[] code = aCode.getCode();
final InstructionList list = new InstructionList(code);
final Iterator it = list.iterator();
for (Iterator iter = list.iterator(); iter.hasNext();) {
InstructionHandle instruction = (InstructionHandle) iter.next();
visitInstructionHandle(instruction);
}
}
示例4: markedAsNotUsable
import org.apache.bcel.classfile.Code; //导入方法依赖的package包/类
private boolean markedAsNotUsable(Method obj) {
for (Attribute a : obj.getAttributes())
if (a instanceof Deprecated)
return true;
Code code = obj.getCode();
if (code == null)
return false;
byte[] codeBytes = code.getCode();
if (codeBytes.length > 1 && codeBytes.length < 10) {
int lastOpcode = codeBytes[codeBytes.length - 1] & 0xff;
if (lastOpcode != ATHROW)
return false;
for (int b : codeBytes)
if ((b & 0xff) == RETURN)
return false;
return true;
}
return false;
}
示例5: visit
import org.apache.bcel.classfile.Code; //导入方法依赖的package包/类
@Override
public void visit(Code obj) {
if (!directChildOfTestCase && (getMethodName().equals("setUp") || getMethodName().equals("tearDown"))
&& !getMethod().isPrivate() && getMethodSig().equals("()V")) {
sawSuperCall = false;
super.visit(obj);
if (sawSuperCall)
return;
JavaClass we = Lookup.findSuperImplementor(getThisClass(), getMethodName(), "()V", bugReporter);
if (we != null && !we.getClassName().equals("junit.framework.TestCase")) {
// OK, got a bug
int offset = 0;
if (getMethodName().equals("tearDown"))
offset = obj.getCode().length - 1;
Method superMethod = Lookup.findImplementation(we, getMethodName(), "()V");
Code superCode = superMethod.getCode();
if (superCode != null && superCode.getCode().length > 3)
bugReporter.reportBug(new BugInstance(this, getMethodName().equals("setUp") ? "IJU_SETUP_NO_SUPER"
: "IJU_TEARDOWN_NO_SUPER", NORMAL_PRIORITY).addClassAndMethod(this).addMethod(we, superMethod)
.describe(MethodAnnotation.METHOD_OVERRIDDEN).addSourceLine(this, offset));
}
}
}
示例6: analyze
import org.apache.bcel.classfile.Code; //导入方法依赖的package包/类
public UnpackedCode analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
Method method = getMethod(analysisCache, descriptor);
Code code = method.getCode();
if (code == null)
return null;
byte[] instructionList = code.getCode();
// Create callback
UnpackedBytecodeCallback callback = new UnpackedBytecodeCallback(instructionList.length);
// Scan the method.
BytecodeScanner scanner = new BytecodeScanner();
scanner.scan(instructionList, callback);
return callback.getUnpackedCode();
}
示例7: analyze
import org.apache.bcel.classfile.Code; //导入方法依赖的package包/类
public MethodBytecodeSet analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
Method method = analysisCache.getMethodAnalysis(Method.class, descriptor);
Code code = method.getCode();
if (code == null) {
return null;
}
byte[] instructionList = code.getCode();
// Create callback
UnpackedBytecodeCallback callback = new UnpackedBytecodeCallback(instructionList.length);
// Scan the method.
BytecodeScanner scanner = new BytecodeScanner();
scanner.scan(instructionList, callback);
UnpackedCode unpackedCode = callback.getUnpackedCode();
MethodBytecodeSet result = null;
if (unpackedCode != null) {
result = unpackedCode.getBytecodeSet();
}
return result;
}
示例8: fromVisitedMethod
import org.apache.bcel.classfile.Code; //导入方法依赖的package包/类
/**
* Factory method for creating a source line annotation describing
* an entire method.
*
* @param visitor a BetterVisitor which is visiting the method
* @return the SourceLineAnnotation
*/
public static SourceLineAnnotation fromVisitedMethod(PreorderVisitor visitor) {
LineNumberTable lineNumberTable = getLineNumberTable(visitor);
String className = visitor.getDottedClassName();
String sourceFile = visitor.getSourceFile();
Code code = visitor.getMethod().getCode();
int codeSize = (code != null) ? code.getCode().length : 0;
if (lineNumberTable == null)
return createUnknown(className, sourceFile, 0, codeSize - 1);
return forEntireMethod(className, sourceFile, lineNumberTable, codeSize);
}
示例9: visit
import org.apache.bcel.classfile.Code; //导入方法依赖的package包/类
public void visit(Code obj) {
if (inConstructor) return;
thisOnTopOfStack = false;
thisLocked = false;
super.visit(obj);
// System.out.println("End of method, state = " + state);
if (state == 1) {
updateStats(fieldsWritten, WRITTEN_LOCKED);
updateStats(fieldsRead, READ_LOCKED);
} else if (obj.getCode().length > 6) {
updateStats(fieldsWritten, WRITTEN_UNLOCKED);
updateStats(fieldsRead, READ_UNLOCKED);
}
}
示例10: prescreen
import org.apache.bcel.classfile.Code; //导入方法依赖的package包/类
@Override
public boolean prescreen(Method method, ClassContext classContext) {
if (method.getName().equals("<clinit>"))
return false;
Code code = method.getCode();
if (code.getCode().length > 5000)
return false;
BitSet bytecodeSet = classContext.getBytecodeSet(method);
if (bytecodeSet == null)
return false;
// The pattern requires a get/put pair accessing the same field.
boolean hasGetStatic = bytecodeSet.get(Constants.GETSTATIC);
boolean hasPutStatic = bytecodeSet.get(Constants.PUTSTATIC);
if (!hasGetStatic || !hasPutStatic)
return false;
// If the method is synchronized, then we'll assume that
// things are properly synchronized
if (method.isSynchronized())
return false;
reported.clear();
return true;
}
示例11: initialize
import org.apache.bcel.classfile.Code; //导入方法依赖的package包/类
/**
* Initialize from given JavaClass.
*
* @param javaClass
* the JavaClass
* @return this object
*/
public ClassFeatureSet initialize(JavaClass javaClass) {
this.className = javaClass.getClassName();
this.isInterface = javaClass.isInterface();
addFeature(CLASS_NAME_KEY + transformClassName(javaClass.getClassName()));
for (Method method : javaClass.getMethods()) {
if (!isSynthetic(method)) {
String transformedMethodSignature = transformMethodSignature(method.getSignature());
if (method.isStatic() || !overridesSuperclassMethod(javaClass, method)) {
addFeature(METHOD_NAME_KEY + method.getName() + ":" + transformedMethodSignature);
}
Code code = method.getCode();
if (code != null && code.getCode() != null && code.getCode().length >= MIN_CODE_LENGTH) {
addFeature(CODE_LENGTH_KEY + method.getName() + ":" + transformedMethodSignature + ":"
+ code.getCode().length);
}
}
}
for (Field field : javaClass.getFields()) {
if (!isSynthetic(field)) {
addFeature(FIELD_NAME_KEY + field.getName() + ":" + transformSignature(field.getSignature()));
}
}
return this;
}
示例12: getBytecodeSet
import org.apache.bcel.classfile.Code; //导入方法依赖的package包/类
/**
* Get a BitSet representing the bytecodes that are used in the given
* method. This is useful for prescreening a method for the existence of
* particular instructions. Because this step doesn't require building a
* MethodGen, it is very fast and memory-efficient. It may allow a Detector
* to avoid some very expensive analysis, which is a Big Win for the user.
*
* @param method
* the method
* @return the BitSet containing the opcodes which appear in the method, or
* null if the method has no code
*/
@CheckForNull
static public BitSet getBytecodeSet(JavaClass clazz, Method method) {
XMethod xmethod = XFactory.createXMethod(clazz, method);
if (cachedBitsets().containsKey(xmethod)) {
return cachedBitsets().get(xmethod);
}
Code code = method.getCode();
if (code == null)
return null;
byte[] instructionList = code.getCode();
// Create callback
UnpackedBytecodeCallback callback = new UnpackedBytecodeCallback(instructionList.length);
// Scan the method.
BytecodeScanner scanner = new BytecodeScanner();
scanner.scan(instructionList, callback);
UnpackedCode unpackedCode = callback.getUnpackedCode();
BitSet result = null;
if (unpackedCode != null)
result = unpackedCode.getBytecodeSet();
cachedBitsets().put(xmethod, result);
return result;
}
示例13: isStaticOnlyClass
import org.apache.bcel.classfile.Code; //导入方法依赖的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;
}
示例14: visit
import org.apache.bcel.classfile.Code; //导入方法依赖的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;
}
}
示例15: visit
import org.apache.bcel.classfile.Code; //导入方法依赖的package包/类
@Override
public void visit(Code obj) {
classCodeSize += obj.getCode().length;
}