⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buginstance.java

📁 A static analysis tool to find bugs in Java programs
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	}	public BugInstance addFoundAndExpectedType(String foundType, String expectedType) {		add( new TypeAnnotation(foundType)).describe(TypeAnnotation.FOUND_ROLE);		add( new TypeAnnotation(expectedType)).describe(TypeAnnotation.EXPECTED_ROLE);		return this;	}	public BugInstance addTypeOfNamedClass(String typeName) {		TypeAnnotation typeAnnotation = new TypeAnnotation("L" + typeName.replace('.','/')+";");		add(typeAnnotation);		return this;	}	/* ----------------------------------------------------------------------	 * Field annotation adders	 * ---------------------------------------------------------------------- */	/**	 * Add a field annotation.	 *	 * @param className name of the class containing the field	 * @param fieldName the name of the field	 * @param fieldSig  type signature of the field	 * @param isStatic  whether or not the field is static	 * @return this object	 */	public BugInstance addField(String className, String fieldName, String fieldSig, boolean isStatic) {		addField(new FieldAnnotation(className, fieldName, fieldSig, isStatic));		return this;	}	/**	 * Add a field annotation.	 *	 * @param className name of the class containing the field	 * @param fieldName the name of the field	 * @param fieldSig  type signature of the field	 * @param isStatic  whether or not the field is static	 * @return this object	 */	public BugInstance addField(String className, String fieldName, String fieldSig, int accessFlags) {		addField(new FieldAnnotation(className, fieldName, fieldSig, accessFlags));		return this;	}	public BugInstance addField(PreorderVisitor visitor) {		FieldAnnotation fieldAnnotation = FieldAnnotation.fromVisitedField(visitor);		return addField(fieldAnnotation);	}	/**	 * Add a field annotation	 *	 * @param fieldAnnotation the field annotation	 * @return this object	 */	public BugInstance addField(FieldAnnotation fieldAnnotation) {		add(fieldAnnotation);		return this;	}	/**	 * Add a field annotation for a FieldVariable matched in a ByteCodePattern.	 *	 * @param field the FieldVariable	 * @return this object	 */	public BugInstance addField(FieldVariable field) {		return addField(field.getClassName(), field.getFieldName(), field.getFieldSig(), field.isStatic());	}	/**	 * Add a field annotation for an XField.	 *	 * @param xfield the XField	 * @return this object	 */	public BugInstance addOptionalField(@CheckForNull XField xfield) {		if (xfield == null) return this;		return addField(xfield.getClassName(), xfield.getName(), xfield.getSignature(), xfield.isStatic());	}	/**	 * Add a field annotation for an XField.	 *	 * @param xfield the XField	 * @return this object	 */	public BugInstance addField(XField xfield) {		return addField(xfield.getClassName(), xfield.getName(), xfield.getSignature(), xfield.isStatic());	}	/**	 * Add a field annotation for a FieldDescriptor.	 * 	 * @param fieldDescriptor the FieldDescriptor	 * @return this object	 */	public BugInstance addField(FieldDescriptor fieldDescriptor) {		FieldAnnotation fieldAnnotation = FieldAnnotation.fromFieldDescriptor(fieldDescriptor);		add(fieldAnnotation);		return this;	}	/**	 * Add a field annotation for the field which has just been accessed	 * by the method currently being visited by given visitor.	 * Assumes that a getfield/putfield or getstatic/putstatic	 * has just been seen.	 *	 * @param visitor the DismantleBytecode object	 * @return this object	 */	public BugInstance addReferencedField(DismantleBytecode visitor) {		FieldAnnotation f = FieldAnnotation.fromReferencedField(visitor);		addField(f);		return this;	}	/**	 * Add a field annotation for the field referenced by the FieldAnnotation parameter	 */	public BugInstance addReferencedField(FieldAnnotation fa) {		addField(fa);		return this;	}	/**	 * Add a field annotation for the field which is being visited by	 * given visitor.	 *	 * @param visitor the visitor	 * @return this object	 */	public BugInstance addVisitedField(PreorderVisitor visitor) {		FieldAnnotation f = FieldAnnotation.fromVisitedField(visitor);		addField(f);		return this;	}	/* ----------------------------------------------------------------------	 * Method annotation adders	 * ---------------------------------------------------------------------- */	/**	 * Add a method annotation.  If this is the first method annotation added,	 * it becomes the primary method annotation.	 *	 * @param className  name of the class containing the method	 * @param methodName name of the method	 * @param methodSig  type signature of the method	 * @param isStatic   true if the method is static, false otherwise	 * @return this object	 */	public BugInstance addMethod(String className, String methodName, String methodSig, boolean isStatic) {		addMethod(MethodAnnotation.fromForeignMethod(className, methodName, methodSig, isStatic));		return this;	}	/**	 * Add a method annotation.  If this is the first method annotation added,	 * it becomes the primary method annotation.	 *	 * @param className  name of the class containing the method	 * @param methodName name of the method	 * @param methodSig  type signature of the method	 * @param accessFlags   accessFlags for the method	 * @return this object	 */	public BugInstance addMethod(String className, String methodName, String methodSig, int accessFlags) {		addMethod(MethodAnnotation.fromForeignMethod(className, methodName, methodSig, accessFlags));		return this;	}	/**	 * Add a method annotation.  If this is the first method annotation added,	 * it becomes the primary method annotation.	 * If the method has source line information, then a SourceLineAnnotation	 * is added to the method.	 *	 * @param methodGen  the MethodGen object for the method	 * @param sourceFile source file method is defined in	 * @return this object	 */	public BugInstance addMethod(MethodGen methodGen, String sourceFile) {		String className = methodGen.getClassName();		MethodAnnotation methodAnnotation =				new MethodAnnotation(className, methodGen.getName(), methodGen.getSignature(), methodGen.isStatic());		addMethod(methodAnnotation);		addSourceLinesForMethod(methodAnnotation, SourceLineAnnotation.fromVisitedMethod(methodGen, sourceFile));		return this;	}	/**	 * Add a method annotation.  If this is the first method annotation added,	 * it becomes the primary method annotation.	 * If the method has source line information, then a SourceLineAnnotation	 * is added to the method.	 *	 * @param javaClass the class the method is defined in	 * @param method    the method	 * @return this object	 */	public BugInstance addMethod(JavaClass javaClass, Method method) {		MethodAnnotation methodAnnotation =			new MethodAnnotation(javaClass.getClassName(), method.getName(), method.getSignature(), method.isStatic());		SourceLineAnnotation methodSourceLines = SourceLineAnnotation.forEntireMethod(				javaClass,				method);		methodAnnotation.setSourceLines(methodSourceLines);		addMethod(methodAnnotation);		return this;	}	/**	 * Add a method annotation.  If this is the first method annotation added,	 * it becomes the primary method annotation.	 * If the method has source line information, then a SourceLineAnnotation	 * is added to the method.	 *	 * @param classAndMethod JavaClassAndMethod identifying the method to add	 * @return this object	 */	public BugInstance addMethod(JavaClassAndMethod classAndMethod) {		return addMethod(classAndMethod.getJavaClass(), classAndMethod.getMethod());	}	/**	 * Add a method annotation for the method which the given visitor is currently visiting.	 * If the method has source line information, then a SourceLineAnnotation	 * is added to the method.	 *	 * @param visitor the BetterVisitor	 * @return this object	 */	public BugInstance addMethod(PreorderVisitor visitor) {		MethodAnnotation methodAnnotation = MethodAnnotation.fromVisitedMethod(visitor);		addMethod(methodAnnotation);		addSourceLinesForMethod(methodAnnotation, SourceLineAnnotation.fromVisitedMethod(visitor));		return this;	}	/**	 * Add a method annotation for the method which has been called	 * by the method currently being visited by given visitor.	 * Assumes that the visitor has just looked at an invoke instruction	 * of some kind.	 *	 * @param visitor the DismantleBytecode object	 * @return this object	 */	public BugInstance addCalledMethod(DismantleBytecode visitor) {		return addMethod(MethodAnnotation.fromCalledMethod(visitor)).describe("METHOD_CALLED");	}	/**	 * Add a method annotation.	 *	 * @param className  name of class containing called method	 * @param methodName name of called method	 * @param methodSig  signature of called method	 * @param isStatic   true if called method is static, false if not	 * @return this object	 */	public BugInstance addCalledMethod(String className, String methodName, String methodSig, boolean isStatic) {		return addMethod(MethodAnnotation.fromCalledMethod(className, methodName, methodSig, isStatic)).describe("METHOD_CALLED");	}	/**	 * Add a method annotation for the method which is called by given	 * instruction.	 *	 * @param methodGen the method containing the call	 * @param inv       the InvokeInstruction	 * @return this object	 */	public BugInstance addCalledMethod(MethodGen methodGen, InvokeInstruction inv) {		ConstantPoolGen cpg = methodGen.getConstantPool();		String className = inv.getClassName(cpg);		String methodName = inv.getMethodName(cpg);		String methodSig = inv.getSignature(cpg);		addMethod(className, methodName, methodSig, inv.getOpcode() == Constants.INVOKESTATIC);		describe("METHOD_CALLED");		return this;	}	/**	 * Add a MethodAnnotation from an XMethod.	 * 	 * @param xmethod the XMethod	 * @return this object	 */	public BugInstance addMethod(XMethod xmethod) {		addMethod(MethodAnnotation.fromXMethod(xmethod));		return this;	}	/**	 * Add a method annotation.  If this is the first method annotation added,	 * it becomes the primary method annotation.	 *	 * @param methodAnnotation the method annotation	 * @return this object	 */	public BugInstance addMethod(MethodAnnotation methodAnnotation) {		add(methodAnnotation);		return this;	}	/* ----------------------------------------------------------------------	 * Integer annotation adders	 * ---------------------------------------------------------------------- */	/**	 * Add an integer annotation.	 *	 * @param value the integer value	 * @return this object	 */	public BugInstance addInt(int value) {		add(new IntAnnotation(value));		return this;	}	/**	 * Add a String annotation.	 *	 * @param value the String value	 * @return this object	 */	public BugInstance addString(String value) {		add(new StringAnnotation(value));		return this;	}	/* ----------------------------------------------------------------------	 * Source line annotation adders	 * ---------------------------------------------------------------------- */	/**	 * Add a source line annotation.	 *	 * @param sourceLine the source line annotation	 * @return this object	 */	public BugInstance addSourceLine(SourceLineAnnotation sourceLine) {		add(sourceLine);		return this;	}	/**	 * Add a source line annotation for instruction whose PC is given	 * in the method that the given visitor is currently visiting.	 * Note that if the method does not have line number information, then	 * no source line annotation will be added.	 *	 * @param visitor a BytecodeScanningDetector that is currently visiting the method	 * @param pc      bytecode offset of the instruction	 * @return this object	 */	public BugInstance addSourceLine(BytecodeScanningDetector visitor, int pc) {		SourceLineAnnotation sourceLineAnnotation =			SourceLineAnnotation.fromVisitedInstruction(visitor.getClassContext(), visitor, pc);		if (sourceLineAnnotation != null)			add(sourceLineAnnotation);		return this;	}	/**	 * Add a source line annotation for instruction whose PC is given	 * in the method that the given visitor is currently visiting.	 * Note that if the method does not have line number information, then	 * no source line annotation will be added.	 *	 * @param classContext the ClassContext	 * @param visitor a PreorderVisitor that is currently visiting the method	 * @param pc      bytecode offset of the instruction	 * @return this object	 */	public BugInstance addSourceLine(ClassContext classContext, PreorderVisitor visitor, int pc) {		SourceLineAnnotation sourceLineAnnotation =			SourceLineAnnotation.fromVisitedInstruction(classContext, visitor, pc);		if (sourceLineAnnotation != null)			add(sourceLineAnnotation);		return this;	}	/**	 * Add a source line annotation for the given instruction in the given method.	 * Note that if the method does not have line number information, then	 * no source line annotation will be added.	 *	 * @param classContext the ClassContext	 * @param methodGen  the method being visited	 * @param sourceFile source file the method is defined in	 * @param handle     the InstructionHandle containing the visited instruction	 * @return this object	 */	public BugInstance addSourceLine(ClassContext classContext, MethodGen methodGen, String sourceFile, @NonNull InstructionHandle handle) {		SourceLineAnnotation sourceLineAnnotation =			SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile, handle);		if (sourceLineAnnotation != null)			add(sourceLineAnnotation);		return this;	}	/**	 * Add a source line annotation describing a range of instructions.	 *	 * @param classContext the ClassContext	 * @param methodGen  the method	 * @param sourceFile source file the method is defined in	 * @param start      the start instruction in the range	 * @param end        the end instruction in the range (inclusive)	 * @return this object	 */	public BugInstance addSourceLine(ClassContext classContext, MethodGen methodGen, String sourceFile, InstructionHandle start, InstructionHandle end) {		// Make sure start and end are really in the right order.		if (start.getPosition() > end.getPosition()) {			InstructionHandle tmp = start;			start = end;			end = tmp;		}		SourceLineAnnotation sourceLineAnnotation =			SourceLineAnnotation.fromVisitedInstructionRange(classContext, methodGen, sourceFile, start, end);		if (sourceLineAnnotation != null)			add(sourceLineAnnotation);		return this;	}	/**	 * Add source line annotation for given Location in a method. 	 * 	 * @param classContext the ClassContext	 * @param method       the Method	 * @param location     the Location in the method	 * @return this BugInstance	 */	public BugInstance addSourceLine(ClassContext classContext, Method method, Location location) {		return addSourceLine(classContext, method, location.getHandle());	}	/**	 * Add source line annotation for given Location in a method. 	 * 	 * @param classContext the ClassContext	 * @param method       the Method	 * @param location     the Location in the method	 * @return this BugInstance	 */	public BugInstance addSourceLine(ClassContext classContext, Method method, InstructionHandle handle) {		SourceLineAnnotation sourceLineAnnotation =			SourceLineAnnotation.fromVisitedInstruction(classContext, method, handle.getPosition());		if (sourceLineAnnotation != null)			add(sourceLineAnnotation);		return this;	}	/**	 * Add a source line annotation describing the	 * source line numbers for a range of instructions in the method being	 * visited by the given visitor.	 * Note that if the method does not have line number information, then	 * no source line annotation will be added.	 *	 * @param visitor a BetterVisitor which is visiting the method	 * @param startPC the bytecode offset of the start instruction in the range	 * @param endPC   the bytecode offset of the end instruction in the range	 * @return this object	 */	public BugInstance addSourceLineRange(BytecodeScanningDetector visitor, int startPC, int endPC) {		SourceLineAnnotation sourceLineAnnotation =			SourceLineAnnotation.fromVisitedInstructionRange(visitor.getClassContext(), visitor, startPC, endPC);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -