Search in sources :

Example 21 with CoreException

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

the class RefactoringHistoryManager method getCachedSession.

/**
	 * Returns the cached refactoring session descriptor.
	 *
	 * @param store
	 *            the file store of the descriptor
	 * @param projectName
	 *            project name, or <code>null</code> for the workspace
	 * @param input
	 *            the input stream where to read the descriptor
	 * @return the cached refactoring session descriptor
	 * @throws CoreException
	 *             if an error occurs while reading the session
	 */
private RefactoringSessionDescriptor getCachedSession(final IFileStore store, String projectName, final InputStream input) throws CoreException {
    if (store.equals(fCachedStore) && fCachedDescriptor != null)
        return fCachedDescriptor;
    final RefactoringSessionDescriptor descriptor;
    try {
        descriptor = new RefactoringSessionReader(false, projectName).readSession(new InputSource(input));
        fCachedDescriptor = descriptor;
        fCachedStore = store;
        return descriptor;
    } catch (CoreException e) {
        throw new CoreException(new MultiStatus(RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.REFACTORING_HISTORY_IO_ERROR, new IStatus[] { e.getStatus() }, Messages.format(RefactoringCoreMessages.RefactoringHistoryManager_error_reading_file, BasicElementLabels.getURLPart(store.toURI().toString())), null));
    }
}
Also used : InputSource(org.xml.sax.InputSource) RefactoringSessionReader(org.eclipse.ltk.internal.core.refactoring.RefactoringSessionReader) CoreException(org.eclipse.core.runtime.CoreException) MultiStatus(org.eclipse.core.runtime.MultiStatus) RefactoringSessionDescriptor(org.eclipse.ltk.core.refactoring.RefactoringSessionDescriptor)

Example 22 with CoreException

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

the class DeleteResourcesProcessor method checkDirtyResources.

private void checkDirtyResources(final RefactoringStatus result) throws CoreException {
    for (int i = 0; i < fResources.length; i++) {
        IResource resource = fResources[i];
        if (resource instanceof IProject && !((IProject) resource).isOpen())
            continue;
        resource.accept(new IResourceVisitor() {

            public boolean visit(IResource visitedResource) throws CoreException {
                if (visitedResource instanceof IFile) {
                    checkDirtyFile(result, (IFile) visitedResource);
                }
                return true;
            }
        }, IResource.DEPTH_INFINITE, false);
    }
}
Also used : IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 23 with CoreException

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

the class MultiStateUndoChange method isValid.

/**
	 * {@inheritDoc}
	 */
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
    if (pm == null)
        pm = new NullProgressMonitor();
    //$NON-NLS-1$
    pm.beginTask("", 1);
    try {
        if (fValidationState == null)
            //$NON-NLS-1$
            throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), "MultiStateUndoChange has not been initialialized"));
        ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
        fDirty = buffer != null && buffer.isDirty();
        return fValidationState.isValid(needsSaving(), true);
    } finally {
        pm.done();
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer)

Example 24 with CoreException

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

the class UndoTextFileChange method performEdits.

private UndoEdit performEdits(ITextFileBuffer buffer, final IDocument document, final boolean[] setContentStampSuccess) throws MalformedTreeException, BadLocationException, CoreException {
    if (!buffer.isSynchronizationContextRequested()) {
        return doPerformEdits(document, setContentStampSuccess);
    }
    ITextFileBufferManager fileBufferManager = FileBuffers.getTextFileBufferManager();
    /** The lock for waiting for computation in the UI thread to complete. */
    final Lock completionLock = new Lock();
    final UndoEdit[] result = new UndoEdit[1];
    final BadLocationException[] badLocationException = new BadLocationException[1];
    final MalformedTreeException[] malformedTreeException = new MalformedTreeException[1];
    final CoreException[] coreException = new CoreException[1];
    Runnable runnable = new Runnable() {

        public void run() {
            synchronized (completionLock) {
                try {
                    result[0] = doPerformEdits(document, setContentStampSuccess);
                } catch (BadLocationException e) {
                    badLocationException[0] = e;
                } catch (MalformedTreeException e) {
                    malformedTreeException[0] = e;
                } catch (CoreException e) {
                    coreException[0] = e;
                } finally {
                    completionLock.fDone = true;
                    completionLock.notifyAll();
                }
            }
        }
    };
    synchronized (completionLock) {
        fileBufferManager.execute(runnable);
        while (!completionLock.fDone) {
            try {
                completionLock.wait(500);
            } catch (InterruptedException x) {
            }
        }
    }
    if (badLocationException[0] != null) {
        throw badLocationException[0];
    } else if (malformedTreeException[0] != null) {
        throw malformedTreeException[0];
    } else if (coreException[0] != null) {
        throw coreException[0];
    }
    return result[0];
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) UndoEdit(org.eclipse.text.edits.UndoEdit) BadLocationException(org.eclipse.jface.text.BadLocationException) Lock(org.eclipse.ltk.internal.core.refactoring.Lock)

Example 25 with CoreException

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

the class ParticipantExtensionPoint method getParticipants.

/**
	 * Returns all participants for a given element.
	 *
	 * @param status a refactoring status to report status if problems occurred while
	 *  loading the participants
	 * @param processor the processor that will own the participants
	 * @param element the element to be copied or a corresponding descriptor
	 * @param arguments the arguments for the participants
	 * @param filter a participant filter to exclude certain participants, or <code>null</code>
	 *  if no filtering is desired
	 * @param affectedNatures an array of project natures affected by the refactoring
	 * @param shared a list of shared participants
	 *
	 * @return an array of participants
	 */
public RefactoringParticipant[] getParticipants(RefactoringStatus status, RefactoringProcessor processor, Object element, RefactoringArguments arguments, IParticipantDescriptorFilter filter, String[] affectedNatures, SharableParticipants shared) {
    if (fParticipants == null)
        init();
    EvaluationContext evalContext = createEvaluationContext(processor, element, affectedNatures);
    List result = new ArrayList();
    for (Iterator iter = fParticipants.iterator(); iter.hasNext(); ) {
        ParticipantDescriptor descriptor = (ParticipantDescriptor) iter.next();
        if (!descriptor.isEnabled()) {
            iter.remove();
        } else {
            try {
                RefactoringStatus filterStatus = new RefactoringStatus();
                if (descriptor.matches(evalContext, filter, filterStatus)) {
                    RefactoringParticipant participant = shared.get(descriptor);
                    if (participant != null) {
                        ((ISharableParticipant) participant).addElement(element, arguments);
                    } else {
                        participant = descriptor.createParticipant();
                        if (fParticipantClass.isInstance(participant)) {
                            if (participant.initialize(processor, element, arguments)) {
                                participant.setDescriptor(descriptor);
                                result.add(participant);
                                if (participant instanceof ISharableParticipant)
                                    shared.put(descriptor, participant);
                            }
                        } else {
                            status.addError(Messages.format(RefactoringCoreMessages.ParticipantExtensionPoint_participant_removed, descriptor.getName()));
                            RefactoringCorePlugin.logErrorMessage(Messages.format(RefactoringCoreMessages.ParticipantExtensionPoint_wrong_type, new String[] { descriptor.getName(), fParticipantClass.getName() }));
                            iter.remove();
                        }
                    }
                } else {
                    status.merge(filterStatus);
                }
            } catch (CoreException e) {
                logMalfunctioningParticipant(status, descriptor, e);
                iter.remove();
            } catch (RuntimeException e) {
                logMalfunctioningParticipant(status, descriptor, e);
                iter.remove();
            }
        }
    }
    return (RefactoringParticipant[]) result.toArray(new RefactoringParticipant[result.size()]);
}
Also used : ParticipantDescriptor(org.eclipse.ltk.internal.core.refactoring.ParticipantDescriptor) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ArrayList(java.util.ArrayList) List(java.util.List) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)569 IStatus (org.eclipse.core.runtime.IStatus)127 Status (org.eclipse.core.runtime.Status)124 IFile (org.eclipse.core.resources.IFile)119 IOException (java.io.IOException)96 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)93 IProject (org.eclipse.core.resources.IProject)90 IResource (org.eclipse.core.resources.IResource)84 ArrayList (java.util.ArrayList)71 InvocationTargetException (java.lang.reflect.InvocationTargetException)63 IPath (org.eclipse.core.runtime.IPath)63 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)60 File (java.io.File)56 IFolder (org.eclipse.core.resources.IFolder)45 InputStream (java.io.InputStream)42 IWorkspace (org.eclipse.core.resources.IWorkspace)40 PersistenceException (org.talend.commons.exception.PersistenceException)39 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)37 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)36 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)34