/*
(non-Javadoc)

@see
edu.umd.cs.findbugs.classfile.IAnalysisEngine#analyze(edu.umd.cs.findbugs
.classfile.IAnalysisCache, java.lang.Object)
12830
@Override
    public ClassNameAndSuperclassInfo analyze(IAnalysisCache analysisCache, ClassDescriptor descriptor)
            throws CheckedAnalysisException {
        // Get InputStream reading from class data
        ClassData classData = analysisCache.getClassAnalysis(ClassData.class, descriptor);
        DataInputStream classDataIn = new DataInputStream(new ByteArrayInputStream(classData.getData()));

        // Read the class info
        ClassParserInterface parser = new ClassParser(classDataIn, descriptor, classData.getCodeBaseEntry());
        ClassNameAndSuperclassInfo.Builder classInfoBuilder = new ClassNameAndSuperclassInfo.Builder();
        parser.parse(classInfoBuilder);
        ClassNameAndSuperclassInfo classInfo = classInfoBuilder.build();

        if (!classInfo.getClassDescriptor().equals(descriptor)) {
            throw new ClassNameMismatchException(descriptor, classInfo.getClassDescriptor(), classData.getCodeBaseEntry());
        }
        return classInfo;
    }
735716
public static void maybeAnalyze( IParsedElement pe, IParsedElement... other )
  {
    if( !shouldAnalyze() )
    {
      return;
    }

    if( !(pe instanceof IProgram) &&
        (!(pe instanceof IClassFileStatement) ||
         classFileIsNotAnInterface( (IClassFileStatement)pe )) )
    {
//      pe.performUnusedElementAnalysis( other );
    }
  }
407011
public final void analyze(final File classesDir) {

        final FileProcessor fileProcessor = new FileProcessor(new FileHandler() {
            @Override
            public final FileHandlerResult handleFile(final File classFile) {
                if (!classFile.getName().endsWith(".class")) {
                    return FileHandlerResult.CONTINUE;
                }
                try {
                    final ClassInfo classInfo = new ClassInfo(classFile);

                    final Package<DependsOn> allowedPkg = dependencies.findAllowedByName(classInfo.getPackageName());
                    if (allowedPkg == null) {
                        final Package<NotDependsOn> forbiddenPkg = dependencies.findForbiddenByName(classInfo.getPackageName());
                        if (forbiddenPkg == null) {
                            dependencyErrors.addAll(checkAlwaysForbiddenSection(dependencies, classInfo));
                        } else {
                            dependencyErrors.addAll(checkForbiddenSection(dependencies, forbiddenPkg, classInfo));
                        }
                    } else {
                        dependencyErrors.addAll(checkAllowedSection(dependencies, allowedPkg, classInfo));
                    }
                } catch (final IOException ex) {
                    throw new RuntimeException("Error handling file: " + classFile, ex);
                }

                return FileHandlerResult.CONTINUE;

            }
        });

        dependencyErrors.clear();
        fileProcessor.process(classesDir);

    }
1346061
public static void analyzePOM(Dependency dependency, File pomFile) throws AnalysisException {
        final Model pom = PomUtils.readPom(pomFile);
        JarAnalyzer.setPomEvidence(dependency, pom, null, true);
    }
768890
public static void registerBuiltInAnalysisEngines(IAnalysisCache analysisCache) {
        new edu.umd.cs.findbugs.classfile.engine.EngineRegistrar().registerAnalysisEngines(analysisCache);
        new edu.umd.cs.findbugs.classfile.engine.asm.EngineRegistrar().registerAnalysisEngines(analysisCache);
        new edu.umd.cs.findbugs.classfile.engine.bcel.EngineRegistrar().registerAnalysisEngines(analysisCache);
    }
285815
@Override
    public ConstantDataflow analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
        MethodGen methodGen = getMethodGen(analysisCache, descriptor);
        if (methodGen == null) {
            return null;
        }
        ConstantAnalysis analysis = new ConstantAnalysis(methodGen, getDepthFirstSearch(analysisCache, descriptor));
        ConstantDataflow dataflow = new ConstantDataflow(getCFG(analysisCache, descriptor), analysis);
        dataflow.execute();

        return dataflow;
    }
82891
public void analyze(Analyzer analyzer, boolean allowFlow)
    throws Exception
  {
    analyzeImpl(analyzer, allowFlow, new IntArray(), new IntArray());
  }
1207315
@Override
    public ReturnPathTypeDataflow analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor)
            throws CheckedAnalysisException {
        CFG cfg = getCFG(analysisCache, descriptor);
        DepthFirstSearch dfs = getDepthFirstSearch(analysisCache, descriptor);
        ReverseDepthFirstSearch rdfs = getReverseDepthFirstSearch(analysisCache, descriptor);
        ReturnPathTypeAnalysis analysis = new ReturnPathTypeAnalysis(cfg, rdfs, dfs);
        ReturnPathTypeDataflow dataflow = new ReturnPathTypeDataflow(cfg, analysis);

        dataflow.execute();

        return dataflow;
    }
468161
@Override
    public LockDataflow analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
        MethodGen methodGen = getMethodGen(analysisCache, descriptor);
        if (methodGen == null) {
            throw new MethodUnprofitableException(descriptor);
        }
        ValueNumberDataflow vnaDataflow = getValueNumberDataflow(analysisCache, descriptor);
        DepthFirstSearch dfs = getDepthFirstSearch(analysisCache, descriptor);
        CFG cfg = getCFG(analysisCache, descriptor);

        LockAnalysis analysis = new LockAnalysis(methodGen, vnaDataflow, dfs);
        LockDataflow dataflow = new LockDataflow(cfg, analysis);
        dataflow.execute();
        return dataflow;

    }
423835
@Override
    public Void call() {
        if (shouldAnalyze()) {
            LOGGER.debug("Begin Analysis of '{}' ({})", dependency.getActualFilePath(), analyzer.getName());
            try {
                analyzer.analyze(dependency, engine);
            } catch (AnalysisException ex) {
                LOGGER.warn("An error occurred while analyzing '{}' ({}).", dependency.getActualFilePath(), analyzer.getName());
                LOGGER.debug("", ex);
                exceptions.add(ex);
            } catch (Throwable ex) {
                LOGGER.warn("An unexpected error occurred during analysis of '{}' ({}): {}",
                        dependency.getActualFilePath(), analyzer.getName(), ex.getMessage());
                LOGGER.error("", ex);
                exceptions.add(ex);
            }
        }
        return null;
    }
390933
public void analyzeHash(boolean full)
                    throws IOException,
                    EOFException,
                    FileManagerException,
                    ClassNotFoundException,
                    HashtableOnDiskException {
        //
        // Warning: don't call this on a "live" htod or you'll get strange results.
        // This method is intended for quiesced analysis.
        //
        int totalsize = 0;
        long true_location;

        true_location = header.disklocation - SWORDSIZE;
        filemgr.seek(true_location);
        int header_size = filemgr.readInt();

        //println("--------------------------------------------------");
        //println("FileManager information:");
        //println("--------------------------------------------------");
        //filemgr.dump_memory();
        // filemgr.dump_disk_memory(filename);
        //filemgr.show_stats();

        println("\n\n");
        println("--------------------------------------------------");
        println("Header information:\n");
        println("--------------------------------------------------");
        println("Header location = " + true_location);
        println("Header size = " + header_size);
        println("Magic string = " + header.magic);
        println("currentTablePtr = " + header.currentTablePtr);
        println("num_objects = " + header.num_objects());
        println("loadFactor = " + header.loadFactor);
        println("rehashInProgress = " + header.rehashInProgress);
        println("currentTablePtr = " + header.currentTablePtr);

        if (header.tableLocation[0] == 0) {
            println("Hashtable[0] is empty\n");
        } else {
            println("Hashtable[0].tablesize = " + header.tablesize[0]);
            true_location = header.tableLocation[0] - SWORDSIZE;
            filemgr.seek(true_location);
            int physical_size = filemgr.readInt();
            println("Hashtable[0] physical location, size = " +
                    true_location + " " +
                    physical_size);
        }

        if (header.tableLocation[1] == 0) {
            println("Hashtable[1] is empty\n");
        } else {
            println("Hashtable[1].tablesize = " + header.tablesize[1]);
            true_location = header.tableLocation[1] - SWORDSIZE;
            filemgr.seek(true_location);
            int physical_size = filemgr.readInt();
            println("Hashtable[1] physical location, size = " +
                    true_location + " " +
                    physical_size);
        }

        println("--------------------------------------------------");

        if (true) {
            return;
        }

        int tableid = header.currentTableId();
        for (int i = 0; i < header.tablesize(); i++) {

            filemgr.seek(header.calcOffset(i, tableid));
            long location = filemgr.readLong();
            true_location = location - SWORDSIZE;

            //
            // First get true object length
            //
            HashtableEntry e = readEntry(location, 0, RETRIEVE_ALL, !CHECK_EXPIRED, tableid);
            int bucketSize = 0;
            Vector bucketList = new Vector(10, 10);
            println("Bucket " + i + " starts:");
            while (e != null) {

                //
                // First lets peek at actual storage allocation.  The int just before
                // the entry is the buffered size, and the size of the actual object
                // is the size of the object itself.
                //
                filemgr.seek(true_location);
                int bufferedsize = filemgr.readInt();
                filemgr.seek(e.location);
                int objectsize = filemgr.readInt();

                totalsize++;
                bucketSize++;
                // bucketList.add(new AnalyzeStruct(e.key, true_location, bufferedsize, objectsize));

                println(".\t Entry = [loc(" +
                        true_location + ") bufsize(" +
                        bufferedsize + ") objsize(" +
                        objectsize + ") ] " +
                        e.key.toString());
                if (full) {
                    println(" \t Data is class " + e.value.getClass().getName());
                    if (e.value.getClass().getName().equals("[B")) {
                        println(" \t Data = " + new String((byte[]) e.value));
                    } else {
                        println(" \t Data = " + e.value.toString());
                    }
                }
                println(" \t ----------------------------------------------");

                true_location = e.next - SWORDSIZE;
                e = readEntry(e.next, e.location, RETRIEVE_ALL, !CHECK_EXPIRED, tableid);
            }

            println("Bucket " + i + " ends, size= " + bucketSize + "\n");
//             if ( bucketSize > 0 ) {
//                 for (int j = 0; j < bucketSize; j++ ) {
//                     AnalyzeStruct as = (AnalyzeStruct) bucketList.elementAt(j);
//                     println(".\t [loc(" + 
//                                        as.location + ") bufsize(" +
//                                        as.buffersize + ") objsize(" +
//                                        as.objectsize + ") ] " + 
//                                        as.object.toString());
//                 }
//             }

        }

        println("Total objects in the hashtable = " + totalsize);
    }
1072545
@Override
    public void visitClass(ClassDescriptor classDescriptor) throws CheckedAnalysisException {

        // Just get the ClassContext from the analysis cache
        // and apply the detector to it.

        IAnalysisCache analysisCache = Global.getAnalysisCache();
        ClassContext classContext = analysisCache.getClassAnalysis(ClassContext.class, classDescriptor);
        Profiler profiler = analysisCache.getProfiler();
        profiler.start(detector.getClass());
        try {
            detector.visitClassContext(classContext);
        } finally {
            profiler.end(detector.getClass());
        }
    }
444330
@Override
    public BackwardTypeQualifierDataflowFactory analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor)
            throws CheckedAnalysisException {
        return new BackwardTypeQualifierDataflowFactory(descriptor);
    }
376760
@Override
    protected void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
        try {
            final File baseDir = getSettings().getTempDirectory();
            tempFileLocation = File.createTempFile("check", "tmp", baseDir);
            if (!tempFileLocation.delete()) {
                setEnabled(false);
                final String msg = String.format(
                        "Unable to delete temporary file '%s'.",
                        tempFileLocation.getAbsolutePath());
                throw new InitializationException(msg);
            }
            if (!tempFileLocation.mkdirs()) {
                setEnabled(false);
                final String msg = String.format(
                        "Unable to create directory '%s'.",
                        tempFileLocation.getAbsolutePath());
                throw new InitializationException(msg);
            }
        } catch (IOException ex) {
            setEnabled(false);
            throw new InitializationException("Unable to create a temporary file", ex);
        }
    }
870685
@Override
    public void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
        LOGGER.debug("Initializing Nexus Analyzer");
        LOGGER.debug("Nexus Analyzer enabled: {}", isEnabled());
        if (isEnabled()) {
            final boolean useProxy = useProxy();
            LOGGER.debug("Using proxy: {}", useProxy);
            try {
                searcher = new NexusSearch(getSettings(), useProxy);
                if (!searcher.preflightRequest()) {
                    setEnabled(false);
                    throw new InitializationException("There was an issue getting Nexus status. Disabling analyzer.");
                }
            } catch (MalformedURLException mue) {
                setEnabled(false);
                throw new InitializationException("Malformed URL to Nexus", mue);
            }
        }
    }
496084
@Override
    protected void analyzeDependency(Dependency dependency, Engine engine) throws AnalysisException {
        //strip any path information that may get added by ArchiveAnalyzer, etc.
        final File f = dependency.getActualFile();
        final String fileName = FilenameUtils.removeExtension(f.getName());
        final String ext = FilenameUtils.getExtension(f.getName());
        if (!IGNORED_FILES.accept(f) && !"js".equals(ext)) {
            //add version evidence
            final DependencyVersion version = DependencyVersionUtil.parseVersion(fileName);
            final String packageName = DependencyVersionUtil.parsePreVersion(fileName);

            if (version != null) {
                // If the version number is just a number like 2 or 23, reduce the confidence
                // a shade. This should hopefully correct for cases like log4j.jar or
                // struts2-core.jar
                if (version.getVersionParts() == null || version.getVersionParts().size() < 2) {
                    dependency.addEvidence(EvidenceType.VERSION, "file", "version", version.toString(), Confidence.MEDIUM);
                } else {
                    dependency.addEvidence(EvidenceType.VERSION, "file", "version", version.toString(), Confidence.HIGHEST);
                }
                dependency.addEvidence(EvidenceType.VERSION, "file", "name", packageName, Confidence.MEDIUM);
            }

            dependency.addEvidence(EvidenceType.PRODUCT, "file", "name", packageName, Confidence.HIGH);
            dependency.addEvidence(EvidenceType.VENDOR, "file", "name", packageName, Confidence.HIGH);
        }
    }
885151
public FetchedValueAnalysis analyzeFetchedValue(ExecutionContext executionContext, FetchedValue fetchedValue, ExecutionStepInfo executionInfo) throws NonNullableFieldWasNullException {
        return analyzeFetchedValueImpl(executionContext, fetchedValue, fetchedValue.getFetchedValue(), executionInfo);
    }