My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
/*
* Bytecode Analysis Framework
* Copyright (C) 2003-2006 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.ba;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.BitSet;
import java.util.Collection;

import javax.annotation.CheckForNull;

import net.jcip.annotations.NotThreadSafe;

import org.apache.bcel.Repository;
import org.apache.bcel.classfile.JavaClass;

import edu.umd.cs.findbugs.AbstractBugReporter;
import edu.umd.cs.findbugs.AnalysisLocal;
import edu.umd.cs.findbugs.Project;
import edu.umd.cs.findbugs.SourceLineAnnotation;
import edu.umd.cs.findbugs.SystemProperties;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.ba.ch.Subtypes2;
import edu.umd.cs.findbugs.ba.interproc.PropertyDatabase;
import edu.umd.cs.findbugs.ba.interproc.PropertyDatabaseFormatException;
import edu.umd.cs.findbugs.ba.jsr305.DirectlyRelevantTypeQualifiersDatabase;
import edu.umd.cs.findbugs.ba.npe.ParameterNullnessPropertyDatabase;
import edu.umd.cs.findbugs.ba.npe.ReturnValueNullnessPropertyDatabase;
import edu.umd.cs.findbugs.ba.type.FieldStoreTypeDatabase;
import edu.umd.cs.findbugs.classfile.CheckedAnalysisException;
import edu.umd.cs.findbugs.classfile.ClassDescriptor;
import edu.umd.cs.findbugs.classfile.DescriptorFactory;
import edu.umd.cs.findbugs.classfile.FieldOrMethodDescriptor;
import edu.umd.cs.findbugs.classfile.Global;
import edu.umd.cs.findbugs.classfile.IAnalysisCache;
import edu.umd.cs.findbugs.classfile.analysis.ClassData;
import edu.umd.cs.findbugs.detect.UnreadFields;
import edu.umd.cs.findbugs.internalAnnotations.DottedClassName;


/**
* A context for analysis of a complete project.
* This serves as the repository for whole-program information
* and data structures.
*
* <p>
* <b>NOTE</b>: this class is slated to become obsolete.
* New code should use the IAnalysisCache object
* returned by Global.getAnalysisCache() to access all analysis
* information (global databases, class and method analyses, etc.)
* </p>
*
* @author David Hovemeyer
* @see edu.umd.cs.findbugs.classfile.IAnalysisCache
* @see edu.umd.cs.findbugs.classfile.Global
*/
@NotThreadSafe
public abstract class AnalysisContext {
public static final boolean DEBUG = SystemProperties.getBoolean("findbugs.analysiscontext.debug");
public static final boolean IGNORE_BUILTIN_MODELS = SystemProperties.getBoolean("findbugs.ignoreBuiltinModels");

public static final String DEFAULT_NONNULL_PARAM_DATABASE_FILENAME = "nonnullParam.db";


public static final String DEFAULT_CHECK_FOR_NULL_PARAM_DATABASE_FILENAME = "checkForNullParam.db";
public static final String DEFAULT_NULL_RETURN_VALUE_ANNOTATION_DATABASE = "nullReturn.db";

public static final String UNCONDITIONAL_DEREF_DB_FILENAME = "unconditionalDeref.db";
public static final String NONNULL_RETURN_DB_FILENAME = "nonnullReturn.db";

public static final String UNCONDITIONAL_DEREF_DB_RESOURCE = "jdkBaseUnconditionalDeref.db";
public static final String NONNULL_RETURN_DB_RESOURCE = "jdkBaseNonnullReturn.db";

public static final String DEFAULT_NULL_RETURN_VALUE_DB_FILENAME = "mayReturnNull.db";

private static InheritableThreadLocal<AnalysisContext> currentAnalysisContext
= new InheritableThreadLocal<AnalysisContext>() {
@Override
public AnalysisContext initialValue() {
// throw new IllegalStateException("currentAnalysisContext should be set by AnalysisContext.setCurrentAnalysisContext");
return null;
}
};

private static AnalysisLocal<XFactory> currentXFactory
= new AnalysisLocal<XFactory>() {
@Override
public XFactory initialValue() {
throw new IllegalStateException("currentXFactory should be set by AnalysisContext.setCurrentAnalysisContext");
}
};

public abstract INullnessAnnotationDatabase getNullnessAnnotationDatabase();
public abstract CheckReturnAnnotationDatabase getCheckReturnAnnotationDatabase();
public abstract AnnotationRetentionDatabase getAnnotationRetentionDatabase();
public abstract JCIPAnnotationDatabase getJCIPAnnotationDatabase();

/** save the original SyntheticRepository so we may
* obtain JavaClass objects which we can reuse.
* (A URLClassPathRepository gets closed after analysis.) */
private static final org.apache.bcel.util.Repository originalRepository =
Repository.getRepository(); // BCEL SyntheticRepository

/**
* Default maximum number of ClassContext objects to cache.
* FIXME: need to evaluate this parameter. Need to keep stats about accesses.
*/
private static final int DEFAULT_CACHE_SIZE = 3;


// Instance fields
private BitSet boolPropertySet;
private String databaseInputDir;
private String databaseOutputDir;


protected AnalysisContext() {
this.boolPropertySet = new BitSet();
}

private void clear() {
boolPropertySet = null;
databaseInputDir = null;
databaseOutputDir = null;
}

// /**
// * Create a new AnalysisContext.
// *
// * @param lookupFailureCallback the RepositoryLookupFailureCallback that
// * the AnalysisContext should use to report errors
// * @return a new AnalysisContext
// */
// public static AnalysisContext create(RepositoryLookupFailureCallback lookupFailureCallback) {
// AnalysisContext analysisContext = new LegacyAnalysisContext(lookupFailureCallback);
// setCurrentAnalysisContext(analysisContext);
// return analysisContext;
// }

/** Instantiate the CheckReturnAnnotationDatabase.
* Do this after the repository has been set up.
*/
public abstract void initDatabases();


/**
* After a pass has been completed, allow the analysis context to update information.
* @param pass -- the first pass is pass 0
*/
public abstract void updateDatabases(int pass);
/**
* Get the AnalysisContext associated with this thread
*/
static public AnalysisContext currentAnalysisContext() {
return currentAnalysisContext.get();
}

static public XFactory currentXFactory() {
return currentXFactory.get();
}

ClassSummary classSummary;
public ClassSummary getClassSummary() {
if (classSummary == null)
throw new IllegalStateException("ClassSummary not set");
return classSummary;
}
public void setClassSummary(@NonNull ClassSummary classSummary) {
if (this.classSummary != null)
throw new IllegalStateException("ClassSummary already set");
this.classSummary = classSummary;
}



final EqualsKindSummary equalsKindSummary = new EqualsKindSummary();
public EqualsKindSummary getEqualsKindSummary() {
return equalsKindSummary;
}
FieldSummary fieldSummary;

public FieldSummary getFieldSummary() {
if (fieldSummary == null) {
AnalysisContext.logError("Field Summary not set", new IllegalStateException());
fieldSummary = new FieldSummary();
}
return fieldSummary;
}
public void setFieldSummary(@NonNull FieldSummary fieldSummary) {
if (this.fieldSummary != null) {
AnalysisContext.logError("Field Summary already set", new IllegalStateException());
this.fieldSummary = fieldSummary;
}
this.fieldSummary = fieldSummary;
}

UnreadFields unreadFields;
public UnreadFields getUnreadFields() {
if (unreadFields == null) throw new IllegalStateException("UnreadFields detector not set");
return unreadFields;
}
public boolean unreadFieldsAvailable() {
return unreadFields != null;
}
public void setUnreadFields(@NonNull UnreadFields unreadFields) {
if (this.unreadFields != null) throw new IllegalStateException("UnreadFields detector already set");
this.unreadFields = unreadFields;
}

/*
private DirectlyRelevantTypeQualifiersDatabase directlyRelevantTypeQualifiersDatabase;
public DirectlyRelevantTypeQualifiersDatabase getDirectlyRelevantTypeQualifiersDatabase() {
if (directlyRelevantTypeQualifiersDatabase == null) throw new IllegalStateException("DirectlyRelevantTypeQualifiersDatabase not set");
return directlyRelevantTypeQualifiersDatabase;
}
public void setDirectlyRelevantTypeQualifiersDatabase(@NonNull DirectlyRelevantTypeQualifiersDatabase directlyRelevantTypeQualifiersDatabase) {
if (this.directlyRelevantTypeQualifiersDatabase != null) throw new IllegalStateException("DirectlyRelevantTypeQualifiersDatabase already set");
this.directlyRelevantTypeQualifiersDatabase = directlyRelevantTypeQualifiersDatabase;
}
*/

public abstract DirectlyRelevantTypeQualifiersDatabase getDirectlyRelevantTypeQualifiersDatabase();

private static boolean skipReportingMissingClass(String missing) {
return missing.length() == 0 || missing.charAt(0) == '[' || missing.endsWith("package-info");
}
private static @CheckForNull RepositoryLookupFailureCallback getCurrentLookupFailureCallback() {
AnalysisContext currentAnalysisContext2 = currentAnalysisContext();
if (currentAnalysisContext2 == null)
return null;
if (currentAnalysisContext2.missingClassWarningsSuppressed)
return null;
return currentAnalysisContext2.getLookupFailureCallback();
}
/**
* file a ClassNotFoundException with the lookupFailureCallback
* @see #getLookupFailureCallback()
*/
static public void reportMissingClass(ClassNotFoundException e) {
if (e == null)
throw new NullPointerException("argument is null");
String missing = AbstractBugReporter.getMissingClassName(e);
if (skipReportingMissingClass(missing))
return;

RepositoryLookupFailureCallback lookupFailureCallback = getCurrentLookupFailureCallback();
if (lookupFailureCallback != null)
lookupFailureCallback.reportMissingClass(e);
}
static public void reportMissingClass(edu.umd.cs.findbugs.ba.MissingClassException e) {
if (e == null)
throw new NullPointerException("argument is null");
reportMissingClass(e.getClassDescriptor());
}
static public void reportMissingClass(edu.umd.cs.findbugs.classfile.MissingClassException e) {
if (e == null)
throw new NullPointerException("argument is null");
reportMissingClass(e.getClassDescriptor());
}
static public void reportMissingClass(ClassDescriptor c) {
if (c == null)
throw new NullPointerException("argument is null");
String missing = c.getDottedClassName();
if (skipReportingMissingClass(missing))
return;
RepositoryLookupFailureCallback lookupFailureCallback = getCurrentLookupFailureCallback();
if (lookupFailureCallback != null)
lookupFailureCallback.reportMissingClass(c);
}
/**
* Report an error
*/
static public void logError(String msg, Exception e) {
if (e instanceof MissingClassException) {
reportMissingClass(((MissingClassException)e).getClassNotFoundException());
return;
}
if (e instanceof edu.umd.cs.findbugs.classfile.MissingClassException) {
reportMissingClass(((edu.umd.cs.findbugs.classfile.MissingClassException)e).toClassNotFoundException());
return;
}
AnalysisContext currentAnalysisContext2 = currentAnalysisContext();
if (currentAnalysisContext2 == null) return;
RepositoryLookupFailureCallback lookupFailureCallback = currentAnalysisContext2.getLookupFailureCallback();
if (lookupFailureCallback != null) lookupFailureCallback.logError(msg, e);
}
/**
* Report an error
*/
static public void logError(String msg) {
AnalysisContext currentAnalysisContext2 = currentAnalysisContext();
if (currentAnalysisContext2 == null) return;
RepositoryLookupFailureCallback lookupFailureCallback = currentAnalysisContext2.getLookupFailureCallback();
if (lookupFailureCallback != null) lookupFailureCallback.logError(msg);
}

boolean missingClassWarningsSuppressed = false;
protected Project project;

public boolean setMissingClassWarningsSuppressed(boolean value) {
boolean oldValue = missingClassWarningsSuppressed;
missingClassWarningsSuppressed = value;
return oldValue;
}
/**
* Get the lookup failure callback.
*/
public abstract RepositoryLookupFailureCallback getLookupFailureCallback();

/**
* Set the source path.
*/
public final void setProject(Project project) {
this.project = project;
}

/**
* Get the SourceFinder, for finding source files.
*/
public abstract SourceFinder getSourceFinder();

// /**
// * Get the Subtypes database.
// *
// * @return the Subtypes database
// */
// @Deprecated // use Subtypes2 instead
// public abstract Subtypes getSubtypes();

/**
* Clear the BCEL Repository in preparation for analysis.
*/
public abstract void clearRepository();

/**
* Clear the ClassContext cache.
* This should be done between analysis passes.
*/
public abstract void clearClassContextCache();

/**
* Add an entry to the Repository's classpath.
*
* @param url the classpath entry URL
* @throws IOException
*/
public abstract void addClasspathEntry(String url) throws IOException;

// /**
// * Add an application class to the repository.
// *
// * @param appClass the application class
// */
// public abstract void addApplicationClassToRepository(JavaClass appClass);

/**
* Return whether or not the given class is an application class.
*
* @param cls the class to lookup
* @return true if the class is an application class, false if not
* an application class or if the class cannot be located
*/
public boolean isApplicationClass(JavaClass cls) {
//return getSubtypes().isApplicationClass(cls);
return getSubtypes2().isApplicationClass(DescriptorFactory.createClassDescriptor(cls));
}

/**
* Return whether or not the given class is an application class.
*
* @param className name of a class
* @return true if the class is an application class, false if not
* an application class or if the class cannot be located
*/
public boolean isApplicationClass(@DottedClassName String className) {
// try {
// JavaClass javaClass = lookupClass(className);
// return isApplicationClass(javaClass);
// } catch (ClassNotFoundException e) {
// AnalysisContext.reportMissingClass(e);
// return false;
// }
ClassDescriptor classDesc = DescriptorFactory.createClassDescriptorFromDottedClassName(className);
return getSubtypes2().isApplicationClass(classDesc);
}

public boolean isApplicationClass(ClassDescriptor desc) {
return getSubtypes2().isApplicationClass(desc);
}

public boolean isTooBig(ClassDescriptor desc) {
IAnalysisCache analysisCache = Global.getAnalysisCache();

try {
ClassContext classContext = analysisCache.getClassAnalysis(ClassContext.class, desc);
ClassData classData = analysisCache.getClassAnalysis(ClassData.class, desc);
if (classData.getData().length > 1000000) return true;
JavaClass javaClass = classContext.getJavaClass();
if (javaClass.getMethods().length > 1000) return true;

} catch (CheckedAnalysisException e) {
AnalysisContext.logError("Could not get class context", e);
}
return false;

}
/**
* Lookup a class.
* <em>Use this method instead of Repository.lookupClass().</em>
*
* @param className the name of the class
* @return the JavaClass representing the class
* @throws ClassNotFoundException (but not really)
*/
public abstract JavaClass lookupClass(@NonNull @DottedClassName String className) throws ClassNotFoundException;

/**
* Lookup a class.
* <em>Use this method instead of Repository.lookupClass().</em>
*
* @param classDescriptor descriptor specifying the class to look up
* @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 dottedClassName the name of the class
* @return the source file for the class, or {@link SourceLineAnnotation#UNKNOWN_SOURCE_FILE} if unable to determine
*/
public final String lookupSourceFile(@NonNull @DottedClassName String dottedClassName) {
if (dottedClassName == null)
throw new IllegalArgumentException("className is null");
try {
XClass xClass = Global.getAnalysisCache().getClassAnalysis(XClass.class, DescriptorFactory.createClassDescriptorFromDottedClassName(dottedClassName));
String name = xClass.getSource();
if (name == null) {
return SourceLineAnnotation.UNKNOWN_SOURCE_FILE;
}
return name;
} catch (CheckedAnalysisException e) {
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 FieldOrMethodDescriptor,
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 FieldOrMethodDescriptor,
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 FieldOrMethodDescriptor,
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);
}
}




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);
currentXFactory.set(new XFactory());
}

public static void removeCurrentAnalysisContext() {
AnalysisContext context = currentAnalysisContext();
if (context != null)
context.clear();
currentAnalysisContext.remove();
}


/**
* Get the Subtypes2 inheritance hierarchy database.
*/
public abstract Subtypes2 getSubtypes2();

/**
* Get Collection of all XClass objects seen so far.
*
* @return Collection of all XClass objects seen so far
*/
public Collection<XClass> getXClassCollection() {
return getSubtypes2().getXClassCollection();
}
}

// vim:ts=4
Show details Hide details

Change log

r11600 by bill.pugh on Oct 13, 2009   Diff
centralize reporting of missing classes
Go to: 
Project members, sign in to write a code review

Older revisions

r11518 by bill.pugh on Aug 02, 2009   Diff
refactoring to separate GUI, cloud and
core FindBugs code
r11068 by bill.pugh on May 01, 2009   Diff
various adjustments to handle
mergeSummarizeAndView
and multiple current working
directories
r10867 by iloveeclipse on Apr 02, 2009   Diff
- Fix for broken FB Eclipse build:
bugrank.txt file was not deployed
- added jdepend package dependency
test contributed by Tomas Pollak
- Fix for bug 2718970:
...
All revisions of this file

File info

Size: 27175 bytes, 760 lines
Hosted by Google Code