/** * Run analysis on a resource (e.g. File or Folder) Will descend to members of folder * * @param atu the resource * @param indent number of levels of nesting/recursion for prettyprinting * @param includes contains header files include paths from the Preference page * @return true if an error was encountered * @throws InterruptedException */ public boolean runResource( IProgressMonitor monitor, ICElement ce, int indent, List<String> includes) throws InterruptedException { indent += INDENT_INCR; ScanReturn results; boolean foundError = false; if (!monitor.isCanceled()) { if (ce instanceof ITranslationUnit) { IResource res = ce.getResource(); // null if not part of C // project in ws // cdt40: eventually shd be able to deal with just tu; // tu.getResource() can always work later... if (res instanceof IFile) { // shd always be true (but might be // null) IFile file = (IFile) res; String filename = file.getName(); // String fn2 = ce.getElementName();// shd be filename too // cdt40 boolean cpp = isCPPproject(ce); // if (AnalysisUtil.validForAnalysis(filename,cpp)) { if (validForAnalysis(filename, cpp)) { if (traceOn) { println(getSpaces(indent) + "file: " + filename); // $NON-NLS-1$ } results = analyse(monitor, (ITranslationUnit) ce, includes); foundError = foundError || results == null || results.wasError(); if (foundError) { int stopHere = 0; System.out.println( "found error on " //$NON-NLS-1$ + file.getName() + " " + stopHere); //$NON-NLS-1$ } if (traceOn) { println( "******** RunAnalyseBase, analysis complete; ScanReturn=" //$NON-NLS-1$ + results); } if (results != null) { // apply markers to the file processResults(results, file); } } else { if (traceOn) { println(getSpaces(indent) + "---omit: not valid file: " + filename); // $NON-NLS-1$ } } return foundError; } } else if (ce instanceof ICContainer) { ICContainer container = (ICContainer) ce; try { ICElement[] mems = container.getChildren(); for (int i = 0; i < mems.length; i++) { if (monitor.isCanceled()) { // this is usually hit while processing normal // analysis of e.g. container throw new InterruptedException(); } boolean err = runResource(monitor, mems[i], indent, includes); foundError = foundError || err; } } catch (CoreException e) { e.printStackTrace(); } } else if (ce instanceof ICProject) { ICProject proj = (ICProject) ce; try { ICElement[] mems = proj.getChildren(); for (int i = 0; i < mems.length; i++) { if (monitor.isCanceled()) { // this is usually hit while processing normal // analysis of e.g. container throw new InterruptedException(); } boolean err = runResource(monitor, mems[i], indent, includes); foundError = foundError || err; } } catch (CoreException e) { e.printStackTrace(); } } // container could be project or folder } // end if !monitor.isCanceled() else { String name = ""; // $NON-NLS-1$ // cdt40 name = ce.getElementName(); // String p=ce.getPath().toString(); System.out.println( "Cancelled by User, aborting analysis on subsequent files... " //$NON-NLS-1$ + name); throw new InterruptedException(); } return foundError; }