Example usage for org.eclipse.jdt.internal.core JavaModelStatus JavaModelStatus

List of usage examples for org.eclipse.jdt.internal.core JavaModelStatus JavaModelStatus

Introduction

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

Prototype

public JavaModelStatus(CoreException coreException) 

Source Link

Document

Constructs an Java model status with no corresponding elements.

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnit.java

License:Open Source License

protected void updateTimeStamp(CompilationUnit original) throws JavaModelException {
    long timeStamp = ((IFile) original.getResource()).getModificationStamp();
    if (timeStamp == IResource.NULL_STAMP) {
        throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_RESOURCE));
    }//  w w  w. j av a  2 s .  com
    ((CompilationUnitElementInfo) getElementInfo()).timestamp = timeStamp;
}

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//w ww  .  j a  v  a 2s  . com
 * @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 w  w.j  av  a  2s  .  co 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;
}

From source file:org.eclipse.ajdt.core.javaelements.AJCompilationUnit.java

License:Open Source License

/**
* this method is a copy of {@link Openable#codeComplete(org.eclipse.jdt.internal.compiler.env.ICompilationUnit, org.eclipse.jdt.internal.compiler.env.ICompilationUnit, int, CompletionRequestor, WorkingCopyOwner, ITypeRoot)}
* The only change is that we need to create an {@link ITDAwareNameEnvironment}, not  standard {@link SearchableEnvironment}.
 * //from  w  w w.  j  ava2s .co  m
* @param cu
* @param unitToSkip
* @param position
* @param requestor
* @param owner
* @param typeRoot
* @throws JavaModelException
*/
private void internalCodeComplete(org.eclipse.jdt.internal.compiler.env.ICompilationUnit cu,
        org.eclipse.jdt.internal.compiler.env.ICompilationUnit unitToSkip, int position,
        CompletionRequestor requestor, WorkingCopyOwner owner, ITypeRoot typeRoot,
        /* AJDT 1.7 */
        IProgressMonitor monitor) throws JavaModelException {

    if (requestor == null) {
        throw new IllegalArgumentException("Completion requestor cannot be null"); //$NON-NLS-1$
    }
    PerformanceStats performanceStats = CompletionEngine.PERF
            ? PerformanceStats.getStats(JavaModelManager.COMPLETION_PERF, this)
            : null;
    if (performanceStats != null) {
        performanceStats.startRun(new String(cu.getFileName()) + " at " + position); //$NON-NLS-1$
    }
    IBuffer buffer = getBuffer();
    if (buffer == null) {
        return;
    }
    if (position < -1 || position > buffer.getLength()) {
        throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INDEX_OUT_OF_BOUNDS));
    }
    JavaProject project = (JavaProject) getJavaProject();
    /* AJDT 1.7 */
    ITDAwareNameEnvironment environment = new ITDAwareNameEnvironment(project, owner, monitor);

    environment.setUnitToSkip(unitToSkip);

    // code complete
    /* AJDT 1.7 */
    CompletionEngine engine = new CompletionEngine(environment, requestor, project.getOptions(true), project,
            owner, monitor);
    engine.complete(cu, position, 0, typeRoot);
    if (performanceStats != null) {
        performanceStats.endRun();
    }
    if (NameLookup.VERBOSE) {
        AJLog.log(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " //$NON-NLS-1$
                + environment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms"); //$NON-NLS-1$
        AJLog.log(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " //$NON-NLS-1$
                + environment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms"); //$NON-NLS-1$
    }

}

From source file:org.eclipse.ajdt.internal.core.contentassist.ContentAssistProvider.java

License:Open Source License

public boolean doContentAssist(ICompilationUnit cu, ICompilationUnit unitToSkip, int position,
        CompletionRequestor requestor, WorkingCopyOwner owner,
        /* AJDT 1.7 */
        ITypeRoot typeRoot, Openable target, IProgressMonitor monitor) throws Exception {
    JavaProject project = (JavaProject) target.getJavaProject();
    if (!AspectJPlugin.isAJProject(project.getProject())) {
        return false;
    }//from  w ww .ja  va 2 s . c  om
    if (target instanceof AJCompilationUnit) {
        // already handled by the compilation unit
        return false;
    }
    if (!(target instanceof CompilationUnit)) {
        return false;
    }
    IBuffer buffer = target.getBuffer();
    if (buffer == null) {
        return false;
    }

    if (requestor == null) {
        throw new IllegalArgumentException("Completion requestor cannot be null"); //$NON-NLS-1$
    }

    MockCompilationUnit mcu = new MockCompilationUnit((CompilationUnit) target);
    ProposalRequestorWrapper wrapped = new ProposalRequestorWrapper(requestor, mcu, mcu.insertionTable);
    int transformedPos = mcu.translatePositionToFake(position);
    if (transformedPos < -1 || transformedPos > mcu.getContents().length) {
        throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INDEX_OUT_OF_BOUNDS));
    }

    /* AJDT 1.7 */
    ITDAwareNameEnvironment environment = new ITDAwareNameEnvironment(project, owner, monitor);
    environment.setUnitToSkip(unitToSkip);

    // code complete
    /* AJDT 1.7 */
    CompletionEngine engine = new CompletionEngine(environment, wrapped, project.getOptions(true), project,
            owner, monitor);
    engine.lookupEnvironment = new ITDAwareLookupEnvironment(engine.lookupEnvironment, environment);
    engine.complete(mcu, transformedPos, 0, typeRoot);

    return true;
}

From source file:org.eclipse.jdt.internal.core.CopyResourceElementsOperation.java

License:Open Source License

/**
 * Possible failures://from  w  w  w  .j av a 2s .c  o m
 * <ul>
 *  <li>NO_ELEMENTS_TO_PROCESS - no elements supplied to the operation
 *   <li>INDEX_OUT_OF_BOUNDS - the number of renamings supplied to the operation
 *      does not match the number of elements that were supplied.
 * </ul>
 */
protected IJavaModelStatus verify() {
    IJavaModelStatus status = super.verify();
    if (!status.isOK()) {
        return status;
    }

    if (this.renamingsList != null && this.renamingsList.length != this.elementsToProcess.length) {
        return new JavaModelStatus(IJavaModelStatusConstants.INDEX_OUT_OF_BOUNDS);
    }
    return JavaModelStatus.VERIFIED_OK;
}