本文整理汇总了Java中org.apache.bcel.classfile.Code类的典型用法代码示例。如果您正苦于以下问题:Java Code类的具体用法?Java Code怎么用?Java Code使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Code类属于org.apache.bcel.classfile包,在下文中一共展示了Code类的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: visit
import org.apache.bcel.classfile.Code; //导入依赖的package包/类
public void visit(Code obj) {
instanceCreated = false;
instanceCreatedWarningGiven = false;
if (!getMethodName().equals("<clinit>")) return;
super.visit(obj);
requires.remove(getDottedClassName());
if (getDottedClassName().equals("java.lang.System")) {
requires.add("java.io.FileInputStream");
requires.add("java.io.FileOutputStream");
requires.add("java.io.BufferedInputStream");
requires.add("java.io.BufferedOutputStream");
requires.add("java.io.PrintStream");
}
if (!requires.isEmpty()) {
classRequires.put(getDottedClassName(), requires);
requires = new TreeSet<String>();
}
}
示例3: 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;
}
示例4: 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);
}
}
示例5: handleCodeFragment
import org.apache.bcel.classfile.Code; //导入依赖的package包/类
/** Handles a single code fragment. */
private void handleCodeFragment(List<String> resultList,
ConstantPoolGen cpg, Code code) {
for (Instruction i : new InstructionList(code.getCode())
.getInstructions()) {
if (i instanceof NEW) {
NEW newInstruction = (NEW) i;
ObjectType ot = newInstruction.getLoadClassType(cpg);
if (ot == null) { // ot is primitive type
continue;
}
String newClassName = ot.getClassName();
if (!resultList.contains(newClassName)
&& !isBlacklisted(newClassName)) {
resultList.add(newClassName);
}
}
}
}
示例6: visit
import org.apache.bcel.classfile.Code; //导入依赖的package包/类
@Override
public void visit(Code obj) {
count_aload_1 = 0;
previousOpcode = -1;
previousPreviousOpcode = -1;
data.nullTested.clear();
seenInvokeStatic = false;
seenMonitorEnter = getMethod().isSynchronized();
data.staticFieldsReadInThisMethod.clear();
super.visit(obj);
if (getMethodName().equals("<init>") && count_aload_1 > 1
&& (getClassName().indexOf('$') >= 0 || getClassName().indexOf('+') >= 0)) {
data.needsOuterObjectInConstructor.add(getDottedClassName());
// System.out.println(betterClassName +
// " needs outer object in constructor");
}
bugAccumulator.reportAccumulatedBugs();
}
示例7: getSurroundingTryBlock
import org.apache.bcel.classfile.Code; //导入依赖的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;
}
示例8: visit
import org.apache.bcel.classfile.Code; //导入依赖的package包/类
@Override
public void visit(Code m) {
applicableApplications = new HashSet<TypeQualifierValue<?>>();
XMethod xMethod = getXMethod();
// Find the direct annotations on this method
updateApplicableAnnotations(xMethod);
// Find direct annotations on called methods and loaded fields
super.visit(m);
if (applicableApplications.size() > 0) {
qualifiers.setDirectlyRelevantTypeQualifiers(getMethodDescriptor(), new ArrayList<TypeQualifierValue<?>>(
applicableApplications));
}
}
示例9: getSourceAnnotationForClass
import org.apache.bcel.classfile.Code; //导入依赖的package包/类
/**
* @param className
* @return
*/
static SourceLineAnnotation getSourceAnnotationForClass(String className, String sourceFileName) {
int lastLine = -1;
int firstLine = Integer.MAX_VALUE;
try {
JavaClass targetClass = AnalysisContext.currentAnalysisContext().lookupClass(className);
for (Method m : targetClass.getMethods()) {
Code c = m.getCode();
if (c != null) {
LineNumberTable table = c.getLineNumberTable();
if (table != null)
for (LineNumber line : table.getLineNumberTable()) {
lastLine = Math.max(lastLine, line.getLineNumber());
firstLine = Math.min(firstLine, line.getLineNumber());
}
}
}
} catch (ClassNotFoundException e) {
AnalysisContext.reportMissingClass(e);
}
if (firstLine < Integer.MAX_VALUE)
return new SourceLineAnnotation(className, sourceFileName, firstLine, lastLine, -1, -1);
return SourceLineAnnotation.createUnknown(className, sourceFileName);
}
示例10: visit
import org.apache.bcel.classfile.Code; //导入依赖的package包/类
@Override
public void visit(Code obj) {
sawWait = false;
sawAwait = false;
waitHasTimeout = false;
sawNotify = false;
earliestJump = 9999999;
super.visit(obj);
if ((sawWait || sawAwait) && waitAt < earliestJump) {
String bugType = sawWait ? "WA_NOT_IN_LOOP" : "WA_AWAIT_NOT_IN_LOOP";
bugReporter.reportBug(new BugInstance(this, bugType, waitHasTimeout ? LOW_PRIORITY : NORMAL_PRIORITY)
.addClassAndMethod(this).addSourceLine(this, waitAt));
}
if (sawNotify)
bugReporter.reportBug(new BugInstance(this, "NO_NOTIFY_NOT_NOTIFYALL", LOW_PRIORITY).addClassAndMethod(this)
.addSourceLine(this, notifyPC));
}
示例11: 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));
}
}
}
示例12: visit
import org.apache.bcel.classfile.Code; //导入依赖的package包/类
@Override
public void visit(Code obj) {
found.clear();
// Solution to sourceforge bug 1765925; returning null is the
// convention used by java.io.File.listFiles()
if (getMethodName().equals("listFiles")) {
return;
}
String returnType = getMethodSig().substring(getMethodSig().indexOf(")") + 1);
if (returnType.startsWith("[")) {
nullOnTOS = false;
super.visit(obj);
if (!found.isEmpty()) {
BugInstance bug = new BugInstance(this, "PZLA_PREFER_ZERO_LENGTH_ARRAYS", LOW_PRIORITY).addClassAndMethod(this);
for (SourceLineAnnotation s : found)
bug.add(s);
bugReporter.reportBug(bug);
found.clear();
}
}
}
示例13: 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();
}
示例14: visit
import org.apache.bcel.classfile.Code; //导入依赖的package包/类
@Override
public void visit(Code obj) {
if (DEBUG)
System.out.printf("%nVisiting %s%n", getMethodDescriptor());
reachable = false;
lastPC = 0;
biggestJumpTarget = -1;
found.clear();
switchHdlr = new SwitchHandler();
clearAllDeadStores();
deadStore = null;
priority = NORMAL_PRIORITY;
fallthroughDistance = 1000;
enumType = null;
super.visit(obj);
enumType = null;
if (!found.isEmpty()) {
if (found.size() >= 4 && priority == NORMAL_PRIORITY)
priority = LOW_PRIORITY;
for (SourceLineAnnotation s : found)
bugAccumulator.accumulateBug(new BugInstance(this, "SF_SWITCH_FALLTHROUGH", priority).addClassAndMethod(this), s);
}
bugAccumulator.reportAccumulatedBugs();
}
示例15: visit
import org.apache.bcel.classfile.Code; //导入依赖的package包/类
@Override
public void visit(Code obj) {
sawSuperFinalize = false;
super.visit(obj);
bugAccumulator.reportAccumulatedBugs();
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) {
if (!getMethod().isFinal())
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));
}