Example usage for org.eclipse.jdt.core IJavaModelStatusConstants NO_ELEMENTS_TO_PROCESS

List of usage examples for org.eclipse.jdt.core IJavaModelStatusConstants NO_ELEMENTS_TO_PROCESS

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaModelStatusConstants NO_ELEMENTS_TO_PROCESS.

Prototype

int NO_ELEMENTS_TO_PROCESS

To view the source code for org.eclipse.jdt.core IJavaModelStatusConstants NO_ELEMENTS_TO_PROCESS.

Click Source Link

Document

Status constant indicating that no elements were provided to the operation for processing.

Usage

From source file:com.github.parzonka.ccms.engine.SortElementsOperation.java

License:Open Source License

/**
 * Calculates the required text edits to sort the <code>unit</code>
 *
 * @param group// www  . j ava 2  s. c  o m
 * @return the edit or null if no sorting is required
 */
public TextEdit calculateEdit(org.eclipse.jdt.core.dom.CompilationUnit unit, TextEditGroup group)
        throws JavaModelException {
    if (this.elementsToProcess.length != 1)
        throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.NO_ELEMENTS_TO_PROCESS));

    if (!(this.elementsToProcess[0] instanceof ICompilationUnit))
        throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES,
                this.elementsToProcess[0]));

    try {
        beginTask(Messages.operation_sortelements, getMainAmountOfWork());

        final ICompilationUnit cu = (ICompilationUnit) this.elementsToProcess[0];
        final String content = cu.getBuffer().getContents();
        final ASTRewrite rewrite = sortCompilationUnit(unit, group);
        if (rewrite == null) {
            return null;
        }

        final Document document = new Document(content);
        return rewrite.rewriteAST(document, cu.getJavaProject().getOptions(true));
    } finally {
        done();
    }
}

From source file:com.github.parzonka.ccms.engine.SortElementsOperation.java

License:Open Source License

/**
 * Possible failures:/* w  ww .  ja  v a 2  s.  c  o m*/
 * <ul>
 * <li>NO_ELEMENTS_TO_PROCESS - the compilation unit supplied to the
 * operation is <code>null</code></li>.
 * <li>INVALID_ELEMENT_TYPES - the supplied elements are not an instance of
 * IWorkingCopy</li>.
 * </ul>
 *
 * @return IJavaModelStatus
 */
@Override
public IJavaModelStatus verify() {
    if (this.elementsToProcess.length != 1) {
        return new JavaModelStatus(IJavaModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
    }
    if (this.elementsToProcess[0] == null) {
        return new JavaModelStatus(IJavaModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
    }
    if (!(this.elementsToProcess[0] instanceof ICompilationUnit)
            || !((ICompilationUnit) this.elementsToProcess[0]).isWorkingCopy()) {
        return new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, this.elementsToProcess[0]);
    }
    return JavaModelStatus.VERIFIED_OK;
}