Search in sources :

Example 71 with CoreException

use of org.eclipse.core.runtime.CoreException in project che by eclipse.

the class MultiStateTextFileChange method isValid.

/*
	 * @see org.eclipse.ltk.core.refactoring.Change#isValid(org.eclipse.core.runtime.IProgressMonitor)
	 */
public final RefactoringStatus isValid(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
    if (monitor == null)
        monitor = new NullProgressMonitor();
    //$NON-NLS-1$
    monitor.beginTask("", 1);
    try {
        if (fValidationState == null)
            //$NON-NLS-1$
            throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), "MultiStateTextFileChange has not been initialialized"));
        final ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
        fDirty = buffer != null && buffer.isDirty();
        final RefactoringStatus status = fValidationState.isValid(needsSaving());
        if (needsSaving()) {
            status.merge(Changes.validateModifiesFiles(new IFile[] { fFile }));
        } else {
            // we are reading the file. So it should be at least in sync
            status.merge(Changes.checkInSync(new IFile[] { fFile }));
        }
        return status;
    } finally {
        monitor.done();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer)

Example 72 with CoreException

use of org.eclipse.core.runtime.CoreException in project che by eclipse.

the class PerformChangeOperation method executeChange.

/**
	 * Actually executes the change.
	 *
	 * @param pm a progress monitor to report progress
	 *
	 * @throws CoreException if an unexpected error occurs during
	 *  change execution
	 */
protected void executeChange(IProgressMonitor pm) throws CoreException {
    fChangeExecuted = false;
    if (!fChange.isEnabled())
        return;
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            boolean undoInitialized = false;
            try {
                //$NON-NLS-1$
                monitor.beginTask("", 10);
                fValidationStatus = fChange.isValid(new SubProgressMonitor(monitor, 1));
                if (fValidationStatus.hasFatalError())
                    return;
                boolean aboutToPerformChangeCalled = false;
                try {
                    if (fUndoManager != null) {
                        ResourcesPlugin.getWorkspace().checkpoint(false);
                        fUndoManager.aboutToPerformChange(fChange);
                        aboutToPerformChangeCalled = true;
                    }
                    fChangeExecutionFailed = true;
                    fUndoChange = fChange.perform(new SubProgressMonitor(monitor, 9));
                    fChangeExecutionFailed = false;
                    fChangeExecuted = true;
                } finally {
                    if (fUndoManager != null) {
                        ResourcesPlugin.getWorkspace().checkpoint(false);
                        if (aboutToPerformChangeCalled)
                            fUndoManager.changePerformed(fChange, !fChangeExecutionFailed);
                    }
                }
                fChange.dispose();
                if (fUndoChange != null) {
                    fUndoChange.initializeValidationData(new NotCancelableProgressMonitor(new SubProgressMonitor(monitor, 1)));
                    undoInitialized = true;
                }
                if (fUndoManager != null) {
                    if (fUndoChange != null) {
                        fUndoManager.addUndo(fUndoName, fUndoChange);
                    } else {
                        fUndoManager.flush();
                    }
                }
            } catch (CoreException e) {
                if (fUndoManager != null)
                    fUndoManager.flush();
                if (fUndoChange != null && undoInitialized) {
                    Change ch = fUndoChange;
                    fUndoChange = null;
                    ch.dispose();
                }
                fUndoChange = null;
                throw e;
            } catch (RuntimeException e) {
                if (fUndoManager != null)
                    fUndoManager.flush();
                if (fUndoChange != null && undoInitialized) {
                    Change ch = fUndoChange;
                    fUndoChange = null;
                    ch.dispose();
                }
                fUndoChange = null;
                throw e;
            } finally {
                monitor.done();
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(runnable, fSchedulingRule, IWorkspace.AVOID_UPDATE, pm);
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) NotCancelableProgressMonitor(org.eclipse.ltk.internal.core.refactoring.NotCancelableProgressMonitor) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 73 with CoreException

use of org.eclipse.core.runtime.CoreException in project che by eclipse.

the class TextEditChangePreviewViewer method setInput.

//	public void createControl(Composite parent) {
//		fViewer = new ComparePreviewer(parent);
//	}
//
//	public Control getControl() {
//		return fViewer;
//	}
public ChangePreview setInput(ChangePreviewViewerInput input) {
    try {
        Change change = input.getChange();
        if (input instanceof TextEditBasedChangeInput) {
            TextEditBasedChangeInput extended = (TextEditBasedChangeInput) input;
            if (extended.group != null && extended.surroundingLines >= 0) {
                TextEditBasedChangeGroup group = extended.group;
                TextEditBasedChange editChange = group.getTextEditChange();
                //					setInput(editChange, editChange.getCurrentContent(group.getRegion(), true, 2, new NullProgressMonitor()),
                //							 editChange.getPreviewContent(new TextEditBasedChangeGroup[]{group}, group.getRegion(), true, 2,
                //														  new NullProgressMonitor()),
                //							 editChange.getTextType());
                ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
                preview.setFileName(getFileName(editChange));
                preview.setOldContent(editChange.getCurrentContent(group.getRegion(), true, 2, new NullProgressMonitor()));
                preview.setNewContent(editChange.getPreviewContent(new TextEditBasedChangeGroup[] { group }, group.getRegion(), true, 2, new NullProgressMonitor()));
                return preview;
            } else if (extended.groups != null && extended.groups.length > 0 && extended.range != null) {
                TextEditBasedChange editChange = extended.groups[0].getTextEditChange();
                TextEditBasedChangeGroup[] groups = extended.groups;
                //					if (extended.groupCategory != null) {
                //
                //					}
                //					setInput(editChange, editChange.getCurrentContent(extended.range, true, 0, new NullProgressMonitor()),
                //							 editChange.getPreviewContent(groups, extended.range, true, 0, new NullProgressMonitor()),
                //							 editChange.getTextType());
                ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
                preview.setFileName(getFileName(editChange));
                preview.setOldContent(editChange.getCurrentContent(extended.range, true, 0, new NullProgressMonitor()));
                preview.setNewContent(editChange.getPreviewContent(groups, extended.range, true, 0, new NullProgressMonitor()));
                return preview;
            }
        } else if (change instanceof TextEditBasedChange) {
            TextEditBasedChange editChange = (TextEditBasedChange) change;
            //				setInput(editChange, editChange.getCurrentContent(new NullProgressMonitor()),
            //						 editChange.getPreviewContent(new NullProgressMonitor()), editChange.getTextType());
            ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
            preview.setFileName(getFileName(editChange));
            preview.setOldContent(editChange.getCurrentContent(new NullProgressMonitor()));
            preview.setNewContent(editChange.getPreviewContent(new NullProgressMonitor()));
            return preview;
        } else {
            //				fViewer.setInput(null);
            return null;
        }
    } catch (CoreException | AssertionFailedException e) {
        JavaPlugin.log(e);
        //			fViewer.setInput(null);
        return null;
    }
    //		}
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ChangePreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) Change(org.eclipse.ltk.core.refactoring.Change) AssertionFailedException(org.eclipse.core.runtime.AssertionFailedException) TextEditBasedChangeGroup(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup)

Example 74 with CoreException

use of org.eclipse.core.runtime.CoreException in project che by eclipse.

the class CompletionProposalCollector method acceptPotentialMethodDeclaration.

private void acceptPotentialMethodDeclaration(CompletionProposal proposal) {
    try {
        IJavaElement enclosingElement = null;
        //			if (getContext().isExtended()) {
        //				enclosingElement= getContext().getEnclosingElement();
        //			} else if (fCompilationUnit != null) {
        // kept for backward compatibility: CU is not reconciled at this moment, information is missing (bug 70005)
        enclosingElement = fCompilationUnit.getElementAt(proposal.getCompletionLocation() + 1);
        //			}
        if (enclosingElement == null)
            return;
        IType type = (IType) enclosingElement.getAncestor(IJavaElement.TYPE);
        if (type != null) {
            String prefix = String.valueOf(proposal.getName());
            int completionStart = proposal.getReplaceStart();
            int completionEnd = proposal.getReplaceEnd();
            int relevance = computeRelevance(proposal);
            GetterSetterCompletionProposal.evaluateProposals(type, prefix, completionStart, completionEnd - completionStart, relevance + 2, fSuggestedMethodNames, fJavaProposals);
            MethodDeclarationCompletionProposal.evaluateProposals(type, prefix, completionStart, completionEnd - completionStart, relevance, fSuggestedMethodNames, fJavaProposals);
        }
    } catch (CoreException e) {
        JavaPlugin.log(e);
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) CoreException(org.eclipse.core.runtime.CoreException) StyledString(org.eclipse.jface.viewers.StyledString) IType(org.eclipse.jdt.core.IType)

Example 75 with CoreException

use of org.eclipse.core.runtime.CoreException in project che by eclipse.

the class FileStoreTextFileBuffer method revert.

/*
	 * @see org.eclipse.core.filebuffers.IFileBuffer#revert(org.eclipse.core.runtime.IProgressMonitor)
	 */
public void revert(IProgressMonitor monitor) throws CoreException {
    if (isDisconnected())
        return;
    IDocument original = null;
    fStatus = null;
    try {
        original = fManager.createEmptyDocument(getLocationOrName(), LocationKind.LOCATION);
        cacheEncodingState();
        setDocumentContent(original, fFileStore, fEncoding, fHasBOM, monitor);
    } catch (CoreException x) {
        fStatus = x.getStatus();
    }
    if (original == null)
        return;
    String originalContents = original.get();
    boolean replaceContents = !originalContents.equals(fDocument.get());
    if (!replaceContents && !fCanBeSaved)
        return;
    fManager.fireStateChanging(this);
    try {
        if (replaceContents) {
            fManager.fireBufferContentAboutToBeReplaced(this);
            fDocument.set(original.get());
        }
        boolean fireDirtyStateChanged = fCanBeSaved;
        if (fCanBeSaved) {
            fCanBeSaved = false;
            addFileBufferContentListeners();
        }
        if (replaceContents)
            fManager.fireBufferContentReplaced(this);
        IFileInfo info = fFileStore.fetchInfo();
        if (info.exists())
            fSynchronizationStamp = fFileStore.fetchInfo().getLastModified();
        if (fireDirtyStateChanged)
            fManager.fireDirtyStateChanged(this, fCanBeSaved);
    } catch (RuntimeException x) {
        fManager.fireStateChangeFailed(this);
        throw x;
    }
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) CoreException(org.eclipse.core.runtime.CoreException) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)987 IStatus (org.eclipse.core.runtime.IStatus)264 Status (org.eclipse.core.runtime.Status)240 IFile (org.eclipse.core.resources.IFile)176 IOException (java.io.IOException)174 IProject (org.eclipse.core.resources.IProject)133 IResource (org.eclipse.core.resources.IResource)132 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)128 IPath (org.eclipse.core.runtime.IPath)126 ArrayList (java.util.ArrayList)125 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)100 File (java.io.File)95 InvocationTargetException (java.lang.reflect.InvocationTargetException)95 InputStream (java.io.InputStream)76 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)67 Path (org.eclipse.core.runtime.Path)61 ByteArrayInputStream (java.io.ByteArrayInputStream)54 IWorkspace (org.eclipse.core.resources.IWorkspace)53 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)52 IFileStore (org.eclipse.core.filesystem.IFileStore)51