001: /*
002: * FindBugs - Find Bugs in Java programs
003: * Copyright (C) 2006-2007 University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs.classfile;
021:
022: import java.util.Map;
023:
024: import javax.annotation.Nonnull;
025:
026: /**
027: * The analysis cache performs analyses on classes and methods
028: * and caches the results.
029: *
030: * @author David Hovemeyer
031: */
032: public interface IAnalysisCache {
033: /**
034: * Register the given class analysis engine as producing the
035: * analysis result type whose Class is given.
036: *
037: * @param <E> analysis result type
038: * @param analysisResultType analysis result type Class object
039: * @param classAnalysisEngine the class analysis engine to register
040: */
041: public <E> void registerClassAnalysisEngine(
042: Class<E> analysisResultType,
043: IClassAnalysisEngine<E> classAnalysisEngine);
044:
045: /**
046: * Register the given method analysis engine as producing the
047: * analysis result type whose Class is given.
048: *
049: * @param <E> analysis result type
050: * @param analysisResultType analysis result type Class object
051: * @param methodAnalysisEngine the method analysis engine to register
052: */
053: public <E> void registerMethodAnalysisEngine(
054: Class<E> analysisResultType,
055: IMethodAnalysisEngine<E> methodAnalysisEngine);
056:
057: /**
058: * Get an analysis of the given class.
059: *
060: * @param <E> the type of the analysis (e.g., FoobarAnalysis)
061: * @param analysisClass the analysis class object (e.g., FoobarAnalysis.class)
062: * @param classDescriptor the descriptor of the class to analyze
063: * @return the analysis object (e.g., instance of FoobarAnalysis for the class)
064: * @throws CheckedAnalysisException if an error occurs performing the analysis
065: */
066: public <E> E getClassAnalysis(Class<E> analysisClass, @Nonnull
067: ClassDescriptor classDescriptor) throws CheckedAnalysisException;
068:
069: /**
070: * See if the cache contains a cached class analysis result
071: * for given class descriptor.
072: *
073: * @param analysisClass analysis result class
074: * @param classDescriptor the class descriptor
075: * @return a cached analysis result, or null if there is no cached analysis result
076: */
077: public <E> E probeClassAnalysis(Class<E> analysisClass, @Nonnull
078: ClassDescriptor classDescriptor);
079:
080: /**
081: * Get an analysis of the given method.
082: *
083: * @param <E> the type of the analysis (e.g., FoobarAnalysis)
084: * @param analysisClass the analysis class object (e.g., FoobarAnalysis.class)
085: * @param methodDescriptor the descriptor of the method to analyze
086: * @return the analysis object (e.g., instance of FoobarAnalysis for the method)
087: * @throws CheckedAnalysisException if an error occurs performing the analysis
088: */
089: public <E> E getMethodAnalysis(Class<E> analysisClass, @Nonnull
090: MethodDescriptor methodDescriptor) throws CheckedAnalysisException;
091:
092: /**
093: * Eagerly put a method analysis object in the cache.
094: * This can be necessary if an method analysis engine invokes other
095: * analysis engines that might recursively require the analysis
096: * being produced.
097: *
098: * @param <E> the type of the analysis (e.g., FoobarAnalysis)
099: * @param analysisClass the analysis class object (e.g., FoobarAnalysis.class)
100: * @param methodDescriptor the descriptor of the method to analyze
101: * @param analysisObject
102: */
103: public <E> void eagerlyPutMethodAnalysis(Class<E> analysisClass,
104: @Nonnull
105: MethodDescriptor methodDescriptor, Object analysisObject);
106:
107: /**
108: * Purge all analysis results for given method.
109: * This can be called when a CFG is pruned and we want to
110: * compute more accurate analysis results on the new CFG.
111: *
112: * @param methodDescriptor method whose analysis results should be purged
113: */
114: public void purgeMethodAnalyses(@Nonnull
115: MethodDescriptor methodDescriptor);
116:
117: public void purgeAllMethodAnalysis();
118:
119: /**
120: * Register a database factory.
121: *
122: * @param <E> type of database
123: * @param databaseClass Class of database
124: * @param databaseFactory the database factory
125: */
126: public <E> void registerDatabaseFactory(Class<E> databaseClass,
127: IDatabaseFactory<E> databaseFactory);
128:
129: /**
130: * Get a database.
131: *
132: * @param <E> type of database
133: * @param databaseClass Class of database
134: * @return the database (which is created by a database factory if required)
135: * @throws CheckedAnalysisException
136: */
137: public <E> E getDatabase(Class<E> databaseClass)
138: throws CheckedAnalysisException;
139:
140: /**
141: * Eagerly install a database.
142: * This avoids the need to register a database factory.
143: *
144: * @param <E> type of database
145: * @param databaseClass Class of database
146: * @param database database object
147: */
148: public <E> void eagerlyPutDatabase(Class<E> databaseClass,
149: E database);
150:
151: /**
152: * Get the classpath from which classes are loaded.
153: *
154: * @return the classpath
155: */
156: public IClassPath getClassPath();
157:
158: /**
159: * Get the error logger.
160: *
161: * @return the error logger
162: */
163: public IErrorLogger getErrorLogger();
164:
165: /**
166: * @return
167: */
168: public Map<?, ?> getAnalysisLocals();
169: }
|