Search in sources :

Example 26 with IStatus

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

the class JavaConventions method validateCompilationUnitName.

/**
	 * Validate the given compilation unit name for the given source and compliance levels.
	 * <p>
	 * A compilation unit name must obey the following rules:
	 * <ul>
	 * <li> it must not be null
	 * <li> it must be suffixed by a dot ('.') followed by one of the
	 *       {@link org.eclipse.jdt.core.JavaCore#getJavaLikeExtensions() Java-like extensions}
	 * <li> its prefix must be a valid identifier
	 * <li> it must not contain any characters or substrings that are not valid
	 *		   on the file system on which workspace root is located.
	 * </ul>
	 * </p>
	 * @param name the name of a compilation unit
	 * @param sourceLevel the source level
	 * @param complianceLevel the compliance level
	 * @return a status object with code <code>IStatus.OK</code> if
	 *		the given name is valid as a compilation unit name, otherwise a status
	 *		object indicating what is wrong with the name
	 * @since 3.3
	 */
public static IStatus validateCompilationUnitName(String name, String sourceLevel, String complianceLevel) {
    if (name == null) {
        return new Status(IStatus.ERROR, org.eclipse.jdt.core.JavaCore.PLUGIN_ID, -1, Messages.convention_unit_nullName, null);
    }
    if (!org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(name)) {
        return new Status(IStatus.ERROR, org.eclipse.jdt.core.JavaCore.PLUGIN_ID, -1, Messages.convention_unit_notJavaName, null);
    }
    String identifier;
    int index;
    index = name.lastIndexOf('.');
    if (index == -1) {
        return new Status(IStatus.ERROR, org.eclipse.jdt.core.JavaCore.PLUGIN_ID, -1, Messages.convention_unit_notJavaName, null);
    }
    identifier = name.substring(0, index);
    // the package-level spec (replaces package.html)
    if (!identifier.equals(PACKAGE_INFO)) {
        IStatus status = validateIdentifier(identifier, sourceLevel, complianceLevel);
        if (!status.isOK()) {
            return status;
        }
    }
    //		}
    return JavaModelStatus.VERIFIED_OK;
}
Also used : JavaModelStatus(org.eclipse.jdt.internal.core.JavaModelStatus) Status(org.eclipse.core.runtime.Status) IJavaModelStatus(org.eclipse.jdt.core.IJavaModelStatus) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus)

Example 27 with IStatus

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

the class JavaConventions method validateClassFileName.

/**
	 * Validate the given .class file name for the given source and compliance levels.
	 * <p>
	 * A .class file name must obey the following rules:
	 * <ul>
	 * <li> it must not be null
	 * <li> it must include the <code>".class"</code> suffix
	 * <li> its prefix must be a valid identifier
	 * <li> it must not contain any characters or substrings that are not valid
	 *		   on the file system on which workspace root is located.
	 * </ul>
	 * </p>
	 * @param name the name of a .class file
	 * @param sourceLevel the source level
	 * @param complianceLevel the compliance level
	 * @return a status object with code <code>IStatus.OK</code> if
	 *		the given name is valid as a .class file name, otherwise a status
	 *		object indicating what is wrong with the name
	 * @since 3.3
	 */
public static IStatus validateClassFileName(String name, String sourceLevel, String complianceLevel) {
    if (name == null) {
        return new Status(IStatus.ERROR, org.eclipse.jdt.core.JavaCore.PLUGIN_ID, -1, Messages.convention_classFile_nullName, null);
    }
    if (!org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(name)) {
        return new Status(IStatus.ERROR, org.eclipse.jdt.core.JavaCore.PLUGIN_ID, -1, Messages.convention_classFile_notClassFileName, null);
    }
    String identifier;
    int index;
    index = name.lastIndexOf('.');
    if (index == -1) {
        return new Status(IStatus.ERROR, org.eclipse.jdt.core.JavaCore.PLUGIN_ID, -1, Messages.convention_classFile_notClassFileName, null);
    }
    identifier = name.substring(0, index);
    // the package-level spec (replaces package.html)
    if (!identifier.equals(PACKAGE_INFO)) {
        IStatus status = validateIdentifier(identifier, sourceLevel, complianceLevel);
        if (!status.isOK()) {
            return status;
        }
    }
    //		}
    return JavaModelStatus.VERIFIED_OK;
}
Also used : JavaModelStatus(org.eclipse.jdt.internal.core.JavaModelStatus) Status(org.eclipse.core.runtime.Status) IJavaModelStatus(org.eclipse.jdt.core.IJavaModelStatus) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus)

Example 28 with IStatus

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

the class Checks method validateModifiesFiles.

//-------- validateEdit checks ----
public static RefactoringStatus validateModifiesFiles(IFile[] filesToModify, Object context) {
    RefactoringStatus result = new RefactoringStatus();
    IStatus status = Resources.checkInSync(filesToModify);
    if (!status.isOK())
        result.merge(RefactoringStatus.create(status));
    status = Resources.makeCommittable(filesToModify, context);
    if (!status.isOK()) {
        result.merge(RefactoringStatus.create(status));
        if (!result.hasFatalError()) {
            result.addFatalError(RefactoringCoreMessages.Checks_validateEdit);
        }
    }
    return result;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus)

Example 29 with IStatus

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

the class FileStoreTextFileBuffer method commitFileBufferContent.

/*
	 * @see org.eclipse.core.internal.filebuffers.FileBuffer#commitFileBufferContent(org.eclipse.core.runtime.IProgressMonitor, boolean)
	 */
protected void commitFileBufferContent(IProgressMonitor monitor, boolean overwrite) throws CoreException {
    //		if (!isSynchronized() && !overwrite)
    //			throw new CoreException(new Status(IStatus.WARNING, FileBuffersPlugin.PLUGIN_ID, IResourceStatus.OUT_OF_SYNC_LOCAL, FileBuffersMessages.FileBuffer_error_outOfSync, null));
    String encoding = computeEncoding();
    Charset charset;
    try {
        charset = Charset.forName(encoding);
    } catch (UnsupportedCharsetException ex) {
        String message = NLSUtility.format(FileBuffersMessages.ResourceTextFileBuffer_error_unsupported_encoding_message_arg, encoding);
        IStatus s = new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, ex);
        throw new CoreException(s);
    } catch (IllegalCharsetNameException ex) {
        String message = NLSUtility.format(FileBuffersMessages.ResourceTextFileBuffer_error_illegal_encoding_message_arg, encoding);
        IStatus s = new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, ex);
        throw new CoreException(s);
    }
    CharsetEncoder encoder = charset.newEncoder();
    encoder.onMalformedInput(CodingErrorAction.REPLACE);
    encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
    byte[] bytes;
    int bytesLength;
    try {
        ByteBuffer byteBuffer = encoder.encode(CharBuffer.wrap(fDocument.get()));
        bytesLength = byteBuffer.limit();
        if (byteBuffer.hasArray())
            bytes = byteBuffer.array();
        else {
            bytes = new byte[bytesLength];
            byteBuffer.get(bytes);
        }
    } catch (CharacterCodingException ex) {
        Assert.isTrue(ex instanceof UnmappableCharacterException);
        String message = NLSUtility.format(FileBuffersMessages.ResourceTextFileBuffer_error_charset_mapping_failed_message_arg, encoding);
        IStatus s = new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IFileBufferStatusCodes.CHARSET_MAPPING_FAILED, message, null);
        throw new CoreException(s);
    }
    IFileInfo fileInfo = fFileStore.fetchInfo();
    if (fileInfo != null && fileInfo.exists()) {
        if (!overwrite)
            checkSynchronizationState();
        InputStream stream = new ByteArrayInputStream(bytes, 0, bytesLength);
        /*
			 * XXX:
			 * This is a workaround for a corresponding bug in Java readers and writer,
			 * see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
			 */
        if (fHasBOM && CHARSET_UTF_8.equals(encoding))
            stream = new SequenceInputStream(new ByteArrayInputStream(IContentDescription.BOM_UTF_8), stream);
        // here the file synchronizer should actually be removed and afterwards added again. However,
        // we are already inside an operation, so the delta is sent AFTER we have added the listener
        setFileContents(stream, monitor);
        // set synchronization stamp to know whether the file synchronizer must become active
        fSynchronizationStamp = fFileStore.fetchInfo().getLastModified();
    //			if (fAnnotationModel instanceof IPersistableAnnotationModel) {
    //				IPersistableAnnotationModel persistableModel= (IPersistableAnnotationModel) fAnnotationModel;
    //				persistableModel.commit(fDocument);
    //			}
    } else {
        fFileStore.getParent().mkdir(EFS.NONE, null);
        OutputStream out = fFileStore.openOutputStream(EFS.NONE, null);
        try {
            /*
				 * XXX:
				 * This is a workaround for a corresponding bug in Java readers and writer,
				 * see http://developer.java.sun.com/developer/bugParade/bugs/4508058.html
				 */
            if (fHasBOM && CHARSET_UTF_8.equals(encoding))
                out.write(IContentDescription.BOM_UTF_8);
            out.write(bytes, 0, bytesLength);
            out.flush();
            out.close();
        } catch (IOException x) {
            IStatus s = new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, x.getLocalizedMessage(), x);
            throw new CoreException(s);
        } finally {
            try {
                out.close();
            } catch (IOException x) {
            }
        }
        // set synchronization stamp to know whether the file synchronizer must become active
        fSynchronizationStamp = fFileStore.fetchInfo().getLastModified();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Charset(java.nio.charset.Charset) CharacterCodingException(java.nio.charset.CharacterCodingException) IOException(java.io.IOException) CharsetEncoder(java.nio.charset.CharsetEncoder) ByteBuffer(java.nio.ByteBuffer) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) IFileInfo(org.eclipse.core.filesystem.IFileInfo) CoreException(org.eclipse.core.runtime.CoreException) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) UnmappableCharacterException(java.nio.charset.UnmappableCharacterException)

Example 30 with IStatus

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

the class ProposalSorterHandle method sortProposals.

/**
	 * Safely computes completion proposals through the described extension. If the extension throws
	 * an exception or otherwise does not adhere to the contract described in
	 * {@link AbstractProposalSorter}, the list is returned as is.
	 *
	 * @param context the invocation context passed on to the extension
	 * @param proposals the list of computed completion proposals to be sorted (element type:
	 *        {@link ICompletionProposal}), must be writable
	 */
public void sortProposals(ContentAssistInvocationContext context, List<ICompletionProposal> proposals) {
    IStatus status;
    try {
        AbstractProposalSorter sorter = getSorter();
        PerformanceStats stats = startMeter(SORT, sorter);
        sorter.beginSorting(context);
        Collections.sort(proposals, sorter);
        sorter.endSorting();
        status = stopMeter(stats, SORT);
        // valid result
        if (status == null)
            return;
        status = createAPIViolationStatus(SORT);
    } catch (InvalidRegistryObjectException x) {
        status = createExceptionStatus(x);
    } catch (CoreException x) {
        status = createExceptionStatus(x);
    } catch (RuntimeException x) {
        status = createExceptionStatus(x);
    }
    JavaPlugin.log(status);
    return;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) AbstractProposalSorter(org.eclipse.jdt.ui.text.java.AbstractProposalSorter) PerformanceStats(org.eclipse.core.runtime.PerformanceStats) CoreException(org.eclipse.core.runtime.CoreException) InvalidRegistryObjectException(org.eclipse.core.runtime.InvalidRegistryObjectException)

Aggregations

IStatus (org.eclipse.core.runtime.IStatus)417 Status (org.eclipse.core.runtime.Status)195 CoreException (org.eclipse.core.runtime.CoreException)103 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)81 IOException (java.io.IOException)48 ArrayList (java.util.ArrayList)46 File (java.io.File)40 InvocationTargetException (java.lang.reflect.InvocationTargetException)39 ITask (com.cubrid.common.core.task.ITask)37 Job (org.eclipse.core.runtime.jobs.Job)32 IFile (org.eclipse.core.resources.IFile)31 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)29 IPath (org.eclipse.core.runtime.IPath)29 List (java.util.List)23 IResource (org.eclipse.core.resources.IResource)22 MultiStatus (org.eclipse.core.runtime.MultiStatus)22 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)19 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)19 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)18 InputStream (java.io.InputStream)17