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

📄 filter.java

📁 A static analysis tool to find bugs in Java programs
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				return false;			if (presentAsString != null && !bugLiveAt(bug, present))				return false;			if (absentAsString != null && bugLiveAt(bug, absent))				return false;			if (hasFieldSpecified && (hasField != (bug.getPrimaryField() != null)))					return false;			if (hasLocalSpecified && (hasLocal != (bug.getPrimaryLocalVariableAnnotation() != null)))					return false;			if (activeSpecified && active != (bug.getLastVersion() == -1))				return false;			if (removedByChangeSpecified					&& bug.isRemovedByChangeOfPersistingClass() != removedByChange)				return false;			if (introducedByChangeSpecified					&& bug.isIntroducedByChangeOfExistingClass() != introducedByChange)				return false;			if (newCodeSpecified && newCode != (!bug.isIntroducedByChangeOfExistingClass() && bug.getFirstVersion() != 0))				return false;			if (removedCodeSpecified && removedCode != (!bug.isRemovedByChangeOfPersistingClass() && bug.getLastVersion() != -1))				return false;			if (bugPattern != null && !bugPattern.matcher(bug.getType()).find())					return false;			if (className != null && !className.matcher(bug.getPrimaryClass().getClassName()).find())					return false;			BugPattern thisBugPattern = bug.getBugPattern();			if (categoryKey != null && thisBugPattern != null && !categoryKey.equals(thisBugPattern.getCategory()))				return false;			if (designationKey != null && !designationKey.equals(bug.getUserDesignationKey()))				return false;			if (withSourceSpecified) {				if (sourceSearcher.findSource(bug.getPrimarySourceLineAnnotation()) != withSource) 					return false;			}			if (hashChangedSpecified) {				if (bug.isInstanceHashConsistent()  == hashChanged) 					return false;			}			if (classifiedSpecified && classified != isClassified(bug)) {				return false;			}			if (seriousSpecified) {				Set<String> words = bug.getTextAnnotationWords();				boolean thisOneIsSerious = words.contains("BUG")				&& !(words.contains("NOT_BUG") || words.contains("HARMLESS"));				if (serious != thisOneIsSerious) return false;			}			return true;		}		private boolean isClassified(BugInstance bug) {			Set<String> words = bug.getTextAnnotationWords();			return words.contains("BUG") || words.contains("NOT_BUG");		}		private boolean bugLiveAt(BugInstance bug, long now) {			if (now < bug.getFirstVersion())				return false;			if (bug.getLastVersion() != -1 && bug.getLastVersion() < now)				return false;			return true;		}		@Override		protected void handleOption(String option, String optionExtraPart) throws IOException {			option = option.substring(1);			if (optionExtraPart.length() == 0)				setField(option, true);			else				setField(option, TigerSubstitutes.parseBoolean(optionExtraPart));			setField(option+"Specified", true);		}		private void setField(String fieldName, boolean value) {			try {			Field f = FilterCommandLine.class.getField(fieldName);			f.setBoolean(this, value);			} catch (RuntimeException e) {				throw e;			} catch (Exception e) {				throw new RuntimeException(e);			}		}		@Override		protected void handleOptionWithArgument(String option, String argument) throws IOException {			if (option.equals("-priority")) {				priority = parsePriority(argument);			}			else if (option.equals("-first")) 				firstAsString = argument;			else if (option.equals("-last")) 				lastAsString = argument;			else if (option.equals("-fixed")) 				fixedAsString = argument;			else if (option.equals("-after")) 				afterAsString = argument;			else if (option.equals("-before")) 				beforeAsString = argument;			else if (option.equals("-present")) 				presentAsString = argument;			else if (option.equals("-absent")) 				absentAsString = argument;			else if (option.equals("-category"))				categoryString = argument;			else if (option.equals("-designation"))				designationString = argument;			else if (option.equals("-class"))					className = Pattern.compile(argument);			else if (option.equals("-bugPattern"))					bugPattern = Pattern.compile(argument);			else if (option.equals("-annotation"))				annotation = argument;			else if (option.equals("-include")) {				try {					includeFilter = new edu.umd.cs.findbugs.filter.Filter(argument);				} catch (FilterException e) {					throw new IllegalArgumentException("Error processing include file: " + argument, e);				}			} else if (option.equals("-exclude")) {				try {					excludeFilter = new edu.umd.cs.findbugs.filter.Filter(argument);				} catch (FilterException e) {					throw new IllegalArgumentException("Error processing include file: " + argument, e);				}			} else throw new IllegalArgumentException("can't handle command line argument of " + option);		}	}	public static int parsePriority(String argument) {		int i = " HMLE".indexOf(argument);		if (i == -1)			i = " 1234".indexOf(argument);		if (i == -1)			throw new IllegalArgumentException("Bad priority: " + argument);		return i;	}	static SourceSearcher sourceSearcher;	public static void main(String[] args) throws Exception {		DetectorFactoryCollection.instance();		final FilterCommandLine commandLine = new FilterCommandLine();		int argCount = commandLine.parse(args, 0, 2, "Usage: " + Filter.class.getName()				+ " [options] [<orig results> [<new results]] ");		Project project = new Project();		SortedBugCollection origCollection = new SortedBugCollection();		if (argCount == args.length)			origCollection.readXML(System.in, project);		else			origCollection.readXML(args[argCount++], project);		boolean verbose = argCount < args.length;		I18N i18n = I18N.instance();		if (commandLine.categoryString != null) {			for (BugCategory bugCategory : i18n					.getBugCategoryObjects())				if (bugCategory.getAbbrev().equals(commandLine.categoryString)) {					commandLine.categoryKey = bugCategory.getCategory();					break;				}			if (commandLine.categoryKey == null)				for (BugCategory bugCategory : i18n						.getBugCategoryObjects())					if (bugCategory.getAbbrev().startsWith(							commandLine.categoryString)) {						commandLine.categoryKey = bugCategory.getCategory();						break;					}		}		if (commandLine.designationString != null) {			for (String designationKey : i18n.getUserDesignationKeys()) {				if (designationKey.startsWith(commandLine.designationString) 						|| i18n.getUserDesignation(designationKey).startsWith(commandLine.designationString)) {					commandLine.designationKey = designationKey;					break;				}			}		}				SortedBugCollection resultCollection = origCollection.createEmptyCollectionWithMetadata();		int passed = 0;		int dropped = 0;		resultCollection.setWithMessages(commandLine.withMessages);		if (commandLine.hashChangedSpecified)			origCollection.computeBugHashes();		commandLine.adjustFilter(resultCollection);		resultCollection.getProjectStats().clearBugCounts();		sourceSearcher = new SourceSearcher(project);		for (BugInstance bug : origCollection.getCollection())			if (commandLine.accept(bug)) {				resultCollection.add(bug, false);				if (bug.getLastVersion() == -1 )					resultCollection.getProjectStats().addBug(bug);				passed++;			} else				dropped++;						if (verbose)			System.out.println(passed + " warnings passed through, " + dropped				+ " warnings dropped");		if (commandLine.withSourceSpecified && commandLine.withSource) {			for(PackageStats stats : resultCollection.getProjectStats().getPackageStats()) {				Iterator<ClassStats> i = stats.getClassStats().iterator();				while (i.hasNext()) {					String className = i.next().getName();					if (sourceSearcher.sourceNotFound.contains(className) || !sourceSearcher.sourceFound.contains(className) 							&& !sourceSearcher.findSource(SourceLineAnnotation.createReallyUnknown(className)									)) 						i.remove();				}			}			resultCollection.getProjectStats().recomputeFromClassStats();		}		if (argCount == args.length) {			assert !verbose;			resultCollection.writeXML(System.out, project);		}		else {			resultCollection.writeXML(args[argCount++], project);		}	}}// vim:ts=4

⌨️ 快捷键说明

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