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

📄 analysiscontext.java

📁 A static analysis tool to find bugs in Java programs
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * @return the class	 * @throws ClassNotFoundException if the class can't be found	 */	public JavaClass lookupClass(@NonNull ClassDescriptor classDescriptor) throws ClassNotFoundException {		return lookupClass(classDescriptor.toDottedClassName());	}	/**	 * This is equivalent to Repository.lookupClass() or this.lookupClass(),	 * except it uses the original Repository instead of the current one.	 * 	 * This can be important because URLClassPathRepository objects are	 * closed after an analysis, so JavaClass objects obtained from them	 * are no good on subsequent runs.	 * 	 * @param className the name of the class	 * @return the JavaClass representing the class	 * @throws ClassNotFoundException	 */	public static JavaClass lookupSystemClass(@NonNull String className) throws ClassNotFoundException {		// TODO: eventually we should move to our own thread-safe repository implementation		if (className == null) throw new IllegalArgumentException("className is null");		if (originalRepository == null) throw new IllegalStateException("originalRepository is null");		JavaClass clazz = originalRepository.findClass(className);		return (clazz==null ? originalRepository.loadClass(className) : clazz);	}	/**	 * Lookup a class's source file	 * 	 * @param className the name of the class	 * @return the source file for the class, or SourceLineAnnotation.UNKNOWN_SOURCE_FILE if unable to determine	 */	public final String lookupSourceFile(@NonNull String className) {		if (className == null) 			throw new IllegalArgumentException("className is null");		try {			JavaClass jc = this.lookupClass(className);			String name = jc.getSourceFileName();			if (name == null) {				System.out.println("No sourcefile for " + className);				return SourceLineAnnotation.UNKNOWN_SOURCE_FILE;			}			return name;		} catch (ClassNotFoundException cnfe) {		  return SourceLineAnnotation.UNKNOWN_SOURCE_FILE;		}	}	/**	 * Get the ClassContext for a class.	 *	 * @param javaClass the class	 * @return the ClassContext for that class	 */	public abstract ClassContext getClassContext(JavaClass javaClass);	/**	 * Get stats about hit rate for ClassContext cache.	 * 	 * @return stats about hit rate for ClassContext cache	 */	public abstract String getClassContextStats();	/**	 * If possible, load interprocedural property databases.	 */	public final void loadInterproceduralDatabases() {		loadPropertyDatabase(				getFieldStoreTypeDatabase(),				FieldStoreTypeDatabase.DEFAULT_FILENAME,				"field store type database");		loadPropertyDatabase(				getUnconditionalDerefParamDatabase(),				UNCONDITIONAL_DEREF_DB_FILENAME,				"unconditional param deref database");		loadPropertyDatabase(				getReturnValueNullnessPropertyDatabase(),				NONNULL_RETURN_DB_FILENAME,				"nonnull return db database");	}	/**	 * If possible, load default (built-in) interprocedural property databases.	 * These are the databases for things like Java core APIs that	 * unconditional dereference parameters.	 */	public final void loadDefaultInterproceduralDatabases() {		if (IGNORE_BUILTIN_MODELS) return;		loadPropertyDatabaseFromResource(				getUnconditionalDerefParamDatabase(),				UNCONDITIONAL_DEREF_DB_RESOURCE,				"unconditional param deref database");		loadPropertyDatabaseFromResource(				getReturnValueNullnessPropertyDatabase(),				NONNULL_RETURN_DB_RESOURCE,				"nonnull return db database");	}	/**	 * Set a boolean property.	 * 	 * @param prop  the property to set	 * @param value the value of the property	 */	public final void setBoolProperty(int prop, boolean value) {		boolPropertySet.set(prop, value);	}	/**	 * Get a boolean property.	 * 	 * @param prop the property	 * @return value of the property; defaults to false if the property	 *         has not had a value assigned explicitly	 */	public final boolean getBoolProperty(int prop) {		return boolPropertySet.get(prop);	}	/**	 * Get the SourceInfoMap.	 */	public abstract SourceInfoMap getSourceInfoMap();	/**	 * Set the interprocedural database input directory.	 * 	 * @param databaseInputDir the interprocedural database input directory	 */	public final void setDatabaseInputDir(String databaseInputDir) {		if (DEBUG) System.out.println("Setting database input directory: " + databaseInputDir);		this.databaseInputDir = databaseInputDir;	}	/**	 * Get the interprocedural database input directory.	 * 	 * @return the interprocedural database input directory	 */	public final String getDatabaseInputDir() {		return databaseInputDir;	}	/**	 * Set the interprocedural database output directory.	 * 	 * @param databaseOutputDir the interprocedural database output directory	 */	public final void setDatabaseOutputDir(String databaseOutputDir) {		if (DEBUG) System.out.println("Setting database output directory: " + databaseOutputDir);		this.databaseOutputDir = databaseOutputDir;	}	/**	 * Get the interprocedural database output directory.	 * 	 * @return the interprocedural database output directory	 */	public final String getDatabaseOutputDir() {		return databaseOutputDir;	}	/**	 * Get the property database recording the types of values stored	 * into fields.	 * 	 * @return the database, or null if there is no database available	 */	public abstract FieldStoreTypeDatabase getFieldStoreTypeDatabase();	/**	 * Get the property database recording which methods unconditionally	 * dereference parameters.	 * 	 * @return the database, or null if there is no database available	 */	public abstract ParameterNullnessPropertyDatabase getUnconditionalDerefParamDatabase();	/**	 * Get the property database recording which methods always return nonnull values	 * 	 * @return the database, or null if there is no database available	 */	public abstract ReturnValueNullnessPropertyDatabase getReturnValueNullnessPropertyDatabase();	/**	 * Load an interprocedural property database.	 * 	 * @param <DatabaseType> actual type of the database	 * @param <KeyType>      type of key (e.g., method or field)	 * @param <Property>     type of properties stored in the database	 * @param database       the empty database object	 * @param fileName       file to load database from	 * @param description    description of the database (for diagnostics)	 * @return the database object, or null if the database couldn't be loaded	 */	public<		DatabaseType extends PropertyDatabase<KeyType,Property>,		KeyType extends ClassMember,		Property		> DatabaseType loadPropertyDatabase(			DatabaseType database,			String fileName,			String description) {		try {			File dbFile = new File(getDatabaseInputDir(), fileName);			if (DEBUG) System.out.println("Loading " + description + " from " + dbFile.getPath() + "...");			database.readFromFile(dbFile.getPath());			return database;		} catch (IOException e) {			getLookupFailureCallback().logError("Error loading " + description, e);		} catch (PropertyDatabaseFormatException e) {			getLookupFailureCallback().logError("Invalid " + description, e);		}		return null;	}	/**	 * Load an interprocedural property database.	 * 	 * @param <DatabaseType> actual type of the database	 * @param <KeyType>      type of key (e.g., method or field)	 * @param <Property>     type of properties stored in the database	 * @param database       the empty database object	 * @param resourceName   name of resource to load the database from	 * @param description    description of the database (for diagnostics)	 * @return the database object, or null if the database couldn't be loaded	 */	public<		DatabaseType extends PropertyDatabase<KeyType,Property>,		KeyType extends ClassMember,		Property		> DatabaseType loadPropertyDatabaseFromResource(			DatabaseType database,			String resourceName,			String description) {		try {			if (DEBUG) System.out.println("Loading default " + description + " from " 					+ resourceName + " @ "			 + PropertyDatabase.class.getResource(resourceName) + " ... ");			InputStream in = PropertyDatabase.class.getResourceAsStream(resourceName);			database.read(in);			in.close();			return database;		} catch (IOException e) {			getLookupFailureCallback().logError("Error loading " + description, e);		} catch (PropertyDatabaseFormatException e) {			getLookupFailureCallback().logError("Invalid " + description, e);		}		return null;	}	/**	 * Write an interprocedural property database.	 * 	 * @param <DatabaseType> actual type of the database	 * @param <KeyType>      type of key (e.g., method or field)	 * @param <Property>     type of properties stored in the database	 * @param database    the database	 * @param fileName    name of database file	 * @param description description of the database	 */	public<		DatabaseType extends PropertyDatabase<KeyType,Property>,		KeyType extends ClassMember,		Property		> void storePropertyDatabase(DatabaseType database, String fileName, String description) {		try {			File dbFile = new File(getDatabaseOutputDir(), fileName);			if (DEBUG) System.out.println("Writing " + description + " to " + dbFile.getPath() + "...");			database.writeToFile(dbFile.getPath());		} catch (IOException e) {			getLookupFailureCallback().logError("Error writing " + description, e);		}	}	/* (non-Javadoc)	 * @see edu.umd.cs.findbugs.ba.AnalysisContext#getAnalyisLocals()	 */	public final Map<Object, Object> getAnalysisLocals() {		return analysisLocals;	}	public abstract InnerClassAccessMap getInnerClassAccessMap();	/**	 * Set the current analysis context for this thread.	 * 	 * @param analysisContext the current analysis context for this thread	 */	public static void setCurrentAnalysisContext(AnalysisContext analysisContext) {		currentAnalysisContext.set(analysisContext);	}}// vim:ts=4

⌨️ 快捷键说明

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