Search in sources :

Example 16 with CoreException

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

the class JavaSearchScopeFactory method addJavaElements.

private void addJavaElements(Set<IJavaElement> javaElements, IResource resource) {
    IJavaElement javaElement = (IJavaElement) resource.getAdapter(IJavaElement.class);
    if (javaElement == null)
        // not a Java resource
        return;
    if (javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
        // add other possible package fragments
        try {
            addJavaElements(javaElements, ((IFolder) resource).members());
        } catch (CoreException ex) {
        // don't add elements
        }
    }
    javaElements.add(javaElement);
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) CoreException(org.eclipse.core.runtime.CoreException)

Example 17 with CoreException

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

the class RefactoringSessionReader method readSession.

/**
	 * Reads a refactoring history descriptor from the specified input object.
	 *
	 * @param source
	 *            the input source
	 * @return a corresponding refactoring history descriptor, or
	 *         <code>null</code>
	 * @throws CoreException
	 *             if an error occurs while reading form the input source
	 */
public RefactoringSessionDescriptor readSession(final InputSource source) throws CoreException {
    fSessionFound = false;
    try {
        //$NON-NLS-1$
        source.setSystemId("/");
        createParser(SAXParserFactory.newInstance()).parse(source, this);
        if (!fSessionFound)
            throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.REFACTORING_HISTORY_FORMAT_ERROR, RefactoringCoreMessages.RefactoringSessionReader_no_session, null));
        if (fRefactoringDescriptors != null) {
            if (//$NON-NLS-1$
            fVersion == null || "".equals(fVersion))
                throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.MISSING_REFACTORING_HISTORY_VERSION, RefactoringCoreMessages.RefactoringSessionReader_missing_version_information, null));
            if (!IRefactoringSerializationConstants.CURRENT_VERSION.equals(fVersion))
                throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.UNSUPPORTED_REFACTORING_HISTORY_VERSION, RefactoringCoreMessages.RefactoringSessionReader_unsupported_version_information, null));
            return new RefactoringSessionDescriptor((RefactoringDescriptor[]) fRefactoringDescriptors.toArray(new RefactoringDescriptor[fRefactoringDescriptors.size()]), fVersion, fComment);
        }
    } catch (IOException exception) {
        throwCoreException(exception, exception.getLocalizedMessage());
    } catch (ParserConfigurationException exception) {
        throwCoreException(exception, exception.getLocalizedMessage());
    } catch (SAXParseException exception) {
        String message = Messages.format(RefactoringCoreMessages.RefactoringSessionReader_invalid_contents_at, new Object[] { Integer.toString(exception.getLineNumber()), Integer.toString(exception.getColumnNumber()) });
        throwCoreException(exception, message);
    } catch (SAXException exception) {
        throwCoreException(exception, exception.getLocalizedMessage());
    } finally {
        fRefactoringDescriptors = null;
        fVersion = null;
        fComment = null;
        fLocator = null;
    }
    return null;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DefaultRefactoringDescriptor(org.eclipse.ltk.internal.core.refactoring.history.DefaultRefactoringDescriptor) RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) CoreException(org.eclipse.core.runtime.CoreException) SAXParseException(org.xml.sax.SAXParseException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) RefactoringSessionDescriptor(org.eclipse.ltk.core.refactoring.RefactoringSessionDescriptor) SAXException(org.xml.sax.SAXException)

Example 18 with CoreException

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

the class RefactoringSessionTransformer method createArgument.

/**
	 * Creates a refactoring argument with the specified name and value.
	 * <p>
	 * If no refactoring is currently processed, this call has no effect.
	 * </p>
	 *
	 * @param name
	 *            the non-empty name of the argument
	 * @param value
	 *            the value of the argument
	 *
	 * @throws CoreException
	 *             if an error occurs while creating a new argument
	 */
public void createArgument(final String name, final String value) throws CoreException {
    Assert.isNotNull(name);
    //$NON-NLS-1$
    Assert.isTrue(!"".equals(name));
    Assert.isNotNull(value);
    if (fDocument != null && fRefactoringArguments != null && value != null) {
        try {
            final Attr attribute = fDocument.createAttribute(name);
            attribute.setValue(value);
            fRefactoringArguments.add(attribute);
        } catch (DOMException exception) {
            throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.REFACTORING_HISTORY_FORMAT_ERROR, exception.getLocalizedMessage(), null));
        }
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) DOMException(org.w3c.dom.DOMException) CoreException(org.eclipse.core.runtime.CoreException) Attr(org.w3c.dom.Attr)

Example 19 with CoreException

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

the class RefactoringHistoryManager method readRefactoringHistory.

/**
	 * Reads the refactoring history from disk.
	 *
	 * @param start
	 *            the start time stamp, inclusive
	 * @param end
	 *            the end time stamp, inclusive
	 * @param monitor
	 *            the progress monitor to use
	 * @return the refactoring history
	 */
RefactoringHistory readRefactoringHistory(final long start, final long end, final IProgressMonitor monitor) {
    try {
        monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_retrieving_history, 200);
        final Set set = new HashSet();
        try {
            if (fHistoryStore.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 20, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists())
                readRefactoringDescriptorProxies(fHistoryStore, fProjectName, set, start, end, new SubProgressMonitor(monitor, 80), RefactoringCoreMessages.RefactoringHistoryService_retrieving_history);
            final IFileStore store = EFS.getLocalFileSystem().getStore(RefactoringCorePlugin.getDefault().getStateLocation()).getChild(RefactoringHistoryService.NAME_HISTORY_FOLDER).getChild(RefactoringHistoryService.NAME_WORKSPACE_PROJECT);
            if (store.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 20, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists())
                readRefactoringDescriptorProxies(store, null, set, start, end, new SubProgressMonitor(monitor, 80), RefactoringCoreMessages.RefactoringHistoryService_retrieving_history);
        } catch (CoreException exception) {
            RefactoringCorePlugin.log(exception);
        }
        final RefactoringDescriptorProxy[] proxies = new RefactoringDescriptorProxy[set.size()];
        set.toArray(proxies);
        return new RefactoringHistoryImplementation(proxies);
    } finally {
        monitor.done();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CoreException(org.eclipse.core.runtime.CoreException) RefactoringDescriptorProxy(org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy) IFileStore(org.eclipse.core.filesystem.IFileStore) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) HashSet(java.util.HashSet)

Example 20 with CoreException

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

the class RefactoringHistoryManager method checkArgumentMap.

/**
	 * Checks whether the argument map is well-formed.
	 * <p>
	 * All arguments contained in the map are checked according to the rules of
	 * {@link RefactoringDescriptor}.
	 * </p>
	 *
	 * @param arguments
	 *            the argument map
	 * @throws CoreException
	 *             if the argument violates any of the constraints
	 */
public static void checkArgumentMap(final Map arguments) throws CoreException {
    Assert.isNotNull(arguments);
    for (final Iterator iterator = arguments.entrySet().iterator(); iterator.hasNext(); ) {
        final Map.Entry entry = (Map.Entry) iterator.next();
        if (entry.getKey() instanceof String) {
            final String string = (String) entry.getKey();
            final char[] characters = string.toCharArray();
            if (characters.length == 0) {
                throw new CoreException(new Status(IStatus.ERROR, RefactoringCore.ID_PLUGIN, IRefactoringCoreStatusCodes.REFACTORING_HISTORY_FORMAT_ERROR, RefactoringCoreMessages.RefactoringHistoryManager_empty_argument, null));
            }
            for (int index = 0; index < characters.length; index++) {
                if (Character.isWhitespace(characters[index]))
                    throw new CoreException(new Status(IStatus.ERROR, RefactoringCore.ID_PLUGIN, IRefactoringCoreStatusCodes.REFACTORING_HISTORY_FORMAT_ERROR, RefactoringCoreMessages.RefactoringHistoryManager_whitespace_argument_key, null));
            }
        } else {
            throw new CoreException(new Status(IStatus.ERROR, RefactoringCore.ID_PLUGIN, IRefactoringCoreStatusCodes.REFACTORING_HISTORY_FORMAT_ERROR, Messages.format(RefactoringCoreMessages.RefactoringHistoryManager_non_string_argument, entry.getKey()), null));
        }
        if (!(entry.getValue() instanceof String)) {
            throw new CoreException(new Status(IStatus.ERROR, RefactoringCore.ID_PLUGIN, IRefactoringCoreStatusCodes.REFACTORING_HISTORY_FORMAT_ERROR, Messages.format(RefactoringCoreMessages.RefactoringHistoryManager_non_string_value, entry.getKey()), null));
        }
    }
}
Also used : Entry(java.util.Map.Entry) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Entry(java.util.Map.Entry) CoreException(org.eclipse.core.runtime.CoreException) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap)

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