anymethodreturnvaluestreamfactory.java

来自「一个查找java程序里bug的程序的源代码,该程序本身也是java写的,对提高j」· Java 代码 · 共 80 行

JAVA
80
字号
/* * FindBugs - Find bugs in Java programs * Copyright (C) 2004, University of Maryland *  * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. *  * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. *  * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package edu.umd.cs.findbugs.detect;import edu.umd.cs.findbugs.ba.Hierarchy;import edu.umd.cs.findbugs.ba.Location;import edu.umd.cs.findbugs.ba.RepositoryLookupFailureCallback;import org.apache.bcel.generic.ConstantPoolGen;import org.apache.bcel.generic.Instruction;import org.apache.bcel.generic.InvokeInstruction;import org.apache.bcel.generic.ObjectType;/** * Factory for stream objects of a particular * base class type returned by any method. * This factory helps us keep track of streams returned * by methods; we don't want to report them, but we do * want to keep track of whether or not they are closed, * to avoid reporting unclosed streams in the same * equivalence class. */public class AnyMethodReturnValueStreamFactory implements StreamFactory {	private ObjectType baseClassType;	private String bugType;	public AnyMethodReturnValueStreamFactory(String streamBase) {		this.baseClassType = new ObjectType(streamBase);		this.bugType = null;	}	public AnyMethodReturnValueStreamFactory setBugType(String bugType) {		this.bugType = bugType;		return this;	}	public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg,	                           RepositoryLookupFailureCallback lookupFailureCallback) {		Instruction ins = location.getHandle().getInstruction();		try {			if (ins instanceof InvokeInstruction) {				if (!Hierarchy.isSubtype(type, baseClassType))					return null;				Stream stream = new Stream(location, type.getClassName(), baseClassType.getClassName())				        .setIsOpenOnCreation(true)				        .setIgnoreImplicitExceptions(true);				if (bugType != null)					stream.setInteresting(bugType);				return stream;			}		} catch (ClassNotFoundException e) {			lookupFailureCallback.reportMissingClass(e);		}		return null;	}}// vim:ts=4

⌨️ 快捷键说明

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