/** * Creates the text change for this proposal. This method is only called once and only when no * text change has been passed in {@link #TUCorrectionProposal(String, ITranslationUnit, * TextChange, int, Image)}. * * @return returns the created text change. * @throws CoreException thrown if the creation of the text change failed. */ protected TextChange createTextChange() throws CoreException { ITranslationUnit tu = getTranslationUnit(); String name = getName(); TextChange change; if (!tu.getResource().exists()) { String source; try { source = tu.getSource(); } catch (CModelException e) { CUIPlugin.log(e); source = ""; // $NON-NLS-1$ } Document document = new Document(source); document.setInitialLineDelimiter(StubUtility.getLineDelimiterUsed(tu)); change = new DocumentChange(name, document); } else { CTextFileChange tuChange = new CTextFileChange(name, tu); tuChange.setSaveMode(TextFileChange.LEAVE_DIRTY); change = tuChange; } TextEdit rootEdit = new MultiTextEdit(); change.setEdit(rootEdit); // Initialize text change. IDocument document = change.getCurrentDocument(new NullProgressMonitor()); addEdits(document, rootEdit); return change; }
@Override public void apply(IDocument document) { try { ITranslationUnit unit = getTranslationUnit(); IEditorPart part = null; if (unit.getResource().exists()) { boolean canEdit = performValidateEdit(unit); if (!canEdit) { return; } part = EditorUtility.isOpenInEditor(unit); if (part == null) { part = EditorUtility.openInEditor(unit); if (part != null) { document = CUIPlugin.getDefault().getDocumentProvider().getDocument(part.getEditorInput()); } } IWorkbenchPage page = CUIPlugin.getActivePage(); if (page != null && part != null) { page.bringToTop(part); } if (part != null) { part.setFocus(); } } performChange(part, document); } catch (CoreException e) { ExceptionHandler.handle( e, CorrectionMessages.TUCorrectionProposal_error_title, CorrectionMessages.TUCorrectionProposal_error_message); } }
private boolean performValidateEdit(ITranslationUnit unit) { IStatus status = Resources.makeCommittable(unit.getResource(), CUIPlugin.getActiveWorkbenchShell()); if (!status.isOK()) { String label = CorrectionMessages.TUCorrectionProposal_error_title; String message = CorrectionMessages.TUCorrectionProposal_error_message; ErrorDialog.openError(CUIPlugin.getActiveWorkbenchShell(), label, message, status); return false; } return true; }
public ScanReturn analyse(IProgressMonitor monitor, ITranslationUnit tu, List<String> includes) { if (traceOn) { println("RunAnalyseBase.analyse()..."); // $NON-NLS-1$ } // ScanReturn nr = null; String errMsg = null; monitor.subTask(Messages.RunAnalyseHandlerBase_42); String rawPath = tu.getLocationURI().toString(); if (traceOn) { println("RunAnalyseBase: file = " + rawPath); // $NON-NLS-1$ } monitor.subTask(Messages.RunAnalyseHandlerBase_on + rawPath); ScanReturn scanReturn = doArtifactAnalysis(tu, includes); monitor.worked(1); if (traceOn) { println("Artifact analysis complete..."); // $NON-NLS-1$ } int numArtifacts = scanReturn.getArtifactList().size(); cumulativeArtifacts = cumulativeArtifacts + numArtifacts; if (traceOn) { System.out.println( "Artifacts found for " //$NON-NLS-1$ + tu.getResource().getProjectRelativePath() + ": " + numArtifacts); //$NON-NLS-1$ } if (traceOn) { System.out.println(" Total # found: " + cumulativeArtifacts); // $NON-NLS-1$ } if (scanReturn == null) { System.out.println( "ScanReturn result is NULL. No results for " //$NON-NLS-1$ + tu.getResource().getProjectRelativePath()); errMsg = "Error: No results were returned from analysis of " //$NON-NLS-1$ + tu.getResource().getProjectRelativePath(); MessageDialog.openError(shell, "Error in Analysis", errMsg); // $NON-NLS-1$ } else { if (traceOn) { System.out.println( "RunAnalyzeBase: ScanReturn received for " //$NON-NLS-1$ + tu.getElementName()); } } if (scanReturn != null) { boolean wasError = scanReturn.wasError(); if (traceOn) { System.out.println("error occurred =" + wasError); // $NON-NLS-1$ } if (wasError) { System.out.println("RunAnalyseBase.analyse...Error..."); // $NON-NLS-1$ } } return scanReturn; }
public CodeReader createCodeReaderForTranslationUnit(ITranslationUnit tu) { return new CodeReader(tu.getResource().getLocation().toOSString(), tu.getContents()); }