Example usage for org.eclipse.jdt.internal.core.util Messages operation_sortelements

List of usage examples for org.eclipse.jdt.internal.core.util Messages operation_sortelements

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.util Messages operation_sortelements.

Prototype

String operation_sortelements

To view the source code for org.eclipse.jdt.internal.core.util Messages operation_sortelements.

Click Source Link

Usage

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

License:Open Source License

/**
 * @see org.eclipse.jdt.internal.core.JavaModelOperation#executeOperation()
 */// www .  j  a va 2s  . c om
@Override
protected void executeOperation() throws JavaModelException {
    try {
        beginTask(Messages.operation_sortelements, getMainAmountOfWork());
        final CompilationUnit copy = (CompilationUnit) this.elementsToProcess[0];
        final ICompilationUnit unit = copy.getPrimary();
        final IBuffer buffer = copy.getBuffer();
        if (buffer == null) {
            return;
        }
        final char[] bufferContents = buffer.getCharacters();
        final String result = processElement(unit, bufferContents);
        if (!CharOperation.equals(result.toCharArray(), bufferContents)) {
            copy.getBuffer().setContents(result);
        }
        worked(1);
    } finally {
        done();
    }
}

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/*from   www .j  a v a2 s  .co 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();
    }
}