Search in sources :

Example 1 with IProgressMonitor

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

the class JavaProjectHelper method delete.

/**
     * Removes an IJavaElement's resource. Retries if deletion failed (e.g. because the indexer
     * still locks the file).
     *
     * @param elem the element to delete
     * @throws CoreException if operation failed
     * @see #ASSERT_NO_MIXED_LINE_DELIMIERS
     */
public static void delete(final IJavaElement elem) throws CoreException {
    //			MixedLineDelimiterDetector.assertNoMixedLineDelimiters(elem);
    if (elem instanceof JavaProject) {
        ((JavaProject) elem).close();
        JavaModelManager.getJavaModelManager().removePerProjectInfo((JavaProject) elem, true);
    }
    JavaModelManager.getJavaModelManager().resetTemporaryCache();
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            //				performDummySearch();
            if (elem instanceof IJavaProject) {
                IJavaProject jproject = (IJavaProject) elem;
                jproject.setRawClasspath(new IClasspathEntry[0], jproject.getProject().getFullPath(), null);
            }
            delete(elem.getResource());
        }
    };
    ResourcesPlugin.getWorkspace().run(runnable, null);
//		emptyDisplayLoop();
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) JavaProject(org.eclipse.jdt.internal.core.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject)

Example 2 with IProgressMonitor

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

the class InlineMethodRefactoring method checkFinalConditions.

@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
    //$NON-NLS-1$
    pm.beginTask("", 20);
    fChangeManager = new TextChangeManager();
    RefactoringStatus result = new RefactoringStatus();
    fSourceProvider.initialize();
    fTargetProvider.initialize();
    pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_searching);
    RefactoringStatus searchStatus = new RefactoringStatus();
    String binaryRefsDescription = Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description, BasicElementLabels.getJavaElementName(fSourceProvider.getMethodName()));
    ReferencesInBinaryContext binaryRefs = new ReferencesInBinaryContext(binaryRefsDescription);
    ICompilationUnit[] units = fTargetProvider.getAffectedCompilationUnits(searchStatus, binaryRefs, new SubProgressMonitor(pm, 1));
    binaryRefs.addErrorIfNecessary(searchStatus);
    if (searchStatus.hasFatalError()) {
        result.merge(searchStatus);
        return result;
    }
    IFile[] filesToBeModified = getFilesToBeModified(units);
    result.merge(Checks.validateModifiesFiles(filesToBeModified, getValidationContext()));
    if (result.hasFatalError())
        return result;
    result.merge(ResourceChangeChecker.checkFilesToBeChanged(filesToBeModified, new SubProgressMonitor(pm, 1)));
    checkOverridden(result, new SubProgressMonitor(pm, 4));
    IProgressMonitor sub = new SubProgressMonitor(pm, 15);
    //$NON-NLS-1$
    sub.beginTask("", units.length * 3);
    for (int c = 0; c < units.length; c++) {
        ICompilationUnit unit = units[c];
        sub.subTask(Messages.format(RefactoringCoreMessages.InlineMethodRefactoring_processing, BasicElementLabels.getFileName(unit)));
        CallInliner inliner = null;
        try {
            boolean added = false;
            MultiTextEdit root = new MultiTextEdit();
            CompilationUnitChange change = (CompilationUnitChange) fChangeManager.get(unit);
            change.setEdit(root);
            BodyDeclaration[] bodies = fTargetProvider.getAffectedBodyDeclarations(unit, new SubProgressMonitor(pm, 1));
            if (bodies.length == 0)
                continue;
            inliner = new CallInliner(unit, (CompilationUnit) bodies[0].getRoot(), fSourceProvider);
            for (int b = 0; b < bodies.length; b++) {
                BodyDeclaration body = bodies[b];
                inliner.initialize(body);
                RefactoringStatus nestedInvocations = new RefactoringStatus();
                ASTNode[] invocations = removeNestedCalls(nestedInvocations, unit, fTargetProvider.getInvocations(body, new SubProgressMonitor(sub, 2)));
                for (int i = 0; i < invocations.length; i++) {
                    ASTNode invocation = invocations[i];
                    result.merge(inliner.initialize(invocation, fTargetProvider.getStatusSeverity()));
                    if (result.hasFatalError())
                        break;
                    if (result.getSeverity() < fTargetProvider.getStatusSeverity()) {
                        added = true;
                        TextEditGroup group = new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_inline);
                        change.addTextEditGroup(group);
                        result.merge(inliner.perform(group));
                    } else {
                        fDeleteSource = false;
                    }
                }
                // to generate the modifications.
                if (!nestedInvocations.isOK()) {
                    result.merge(nestedInvocations);
                    fDeleteSource = false;
                }
            }
            if (!added) {
                fChangeManager.remove(unit);
            } else {
                root.addChild(inliner.getModifications());
                ImportRewrite rewrite = inliner.getImportEdit();
                if (rewrite.hasRecordedChanges()) {
                    TextEdit edit = rewrite.rewriteImports(null);
                    if (edit instanceof MultiTextEdit ? ((MultiTextEdit) edit).getChildrenSize() > 0 : true) {
                        root.addChild(edit);
                        change.addTextEditGroup(new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_import, new TextEdit[] { edit }));
                    }
                }
            }
        } finally {
            if (inliner != null)
                inliner.dispose();
        }
        sub.worked(1);
        if (sub.isCanceled())
            throw new OperationCanceledException();
    }
    result.merge(searchStatus);
    sub.done();
    pm.done();
    return result;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IFile(org.eclipse.core.resources.IFile) ImportRewrite(org.eclipse.jdt.core.dom.rewrite.ImportRewrite) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ReferencesInBinaryContext(org.eclipse.jdt.internal.corext.refactoring.base.ReferencesInBinaryContext) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ASTNode(org.eclipse.jdt.core.dom.ASTNode) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration) TextEditGroup(org.eclipse.text.edits.TextEditGroup) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextChangeManager(org.eclipse.jdt.internal.corext.refactoring.util.TextChangeManager) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Example 3 with IProgressMonitor

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

the class RefactoringHistoryManager method removeIndexTree.

/**
	 * Removes the refactoring history index tree spanned by the specified file
	 * store.
	 *
	 * @param store
	 *            the file store spanning the history index tree
	 * @param monitor
	 *            the progress monitor to use
	 * @param task
	 *            the task label to use
	 * @throws CoreException
	 *             if an error occurs while removing the index tree
	 */
private static void removeIndexTree(final IFileStore store, final IProgressMonitor monitor, final String task) throws CoreException {
    try {
        monitor.beginTask(task, 16);
        final IFileInfo info = store.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
        if (info.isDirectory()) {
            if (info.getName().equalsIgnoreCase(RefactoringHistoryService.NAME_HISTORY_FOLDER))
                return;
            final IFileStore[] stores = store.childStores(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
            final IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL);
            try {
                subMonitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_updating_history, stores.length);
                for (int index = 0; index < stores.length; index++) {
                    final IFileInfo current = stores[index].fetchInfo(EFS.NONE, new SubProgressMonitor(subMonitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
                    if (current.isDirectory()) {
                        final char[] characters = stores[index].getName().toCharArray();
                        for (int offset = 0; offset < characters.length; offset++) {
                            if (Character.isDigit(characters[offset]))
                                return;
                            else
                                continue;
                        }
                    }
                }
            } finally {
                subMonitor.done();
            }
        }
        final IFileStore parent = store.getParent();
        store.delete(0, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
        removeIndexTree(parent, new SubProgressMonitor(monitor, 12, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL), task);
    } finally {
        monitor.done();
    }
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFileStore(org.eclipse.core.filesystem.IFileStore) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 4 with IProgressMonitor

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

the class ReplaceInvocationsRefactoring method checkFinalConditions.

@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
    //$NON-NLS-1$
    pm.beginTask("", 20);
    fChangeManager = new TextChangeManager();
    RefactoringStatus result = new RefactoringStatus();
    fSourceProvider = resolveSourceProvider(fMethodBinding, result);
    if (result.hasFatalError())
        return result;
    result.merge(fSourceProvider.checkActivation());
    if (result.hasFatalError())
        return result;
    fSourceProvider.initialize();
    fTargetProvider.initialize();
    pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_searching);
    RefactoringStatus searchStatus = new RefactoringStatus();
    String binaryRefsDescription = Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description, BasicElementLabels.getJavaElementName(fSourceProvider.getMethodName()));
    ReferencesInBinaryContext binaryRefs = new ReferencesInBinaryContext(binaryRefsDescription);
    ICompilationUnit[] units = fTargetProvider.getAffectedCompilationUnits(searchStatus, binaryRefs, new SubProgressMonitor(pm, 1));
    binaryRefs.addErrorIfNecessary(searchStatus);
    if (searchStatus.hasFatalError()) {
        result.merge(searchStatus);
        return result;
    }
    IFile[] filesToBeModified = getFilesToBeModified(units);
    result.merge(Checks.validateModifiesFiles(filesToBeModified, getValidationContext()));
    if (result.hasFatalError())
        return result;
    result.merge(ResourceChangeChecker.checkFilesToBeChanged(filesToBeModified, new SubProgressMonitor(pm, 1)));
    checkOverridden(result, new SubProgressMonitor(pm, 4));
    IProgressMonitor sub = new SubProgressMonitor(pm, 15);
    //$NON-NLS-1$
    sub.beginTask("", units.length * 3);
    for (int c = 0; c < units.length; c++) {
        ICompilationUnit unit = units[c];
        sub.subTask(Messages.format(RefactoringCoreMessages.InlineMethodRefactoring_processing, BasicElementLabels.getFileName(unit)));
        CallInliner inliner = null;
        try {
            boolean added = false;
            MultiTextEdit root = new MultiTextEdit();
            CompilationUnitChange change = (CompilationUnitChange) fChangeManager.get(unit);
            change.setEdit(root);
            BodyDeclaration[] bodies = fTargetProvider.getAffectedBodyDeclarations(unit, new SubProgressMonitor(pm, 1));
            if (bodies.length == 0)
                continue;
            inliner = new CallInliner(unit, (CompilationUnit) bodies[0].getRoot(), fSourceProvider);
            for (int b = 0; b < bodies.length; b++) {
                BodyDeclaration body = bodies[b];
                inliner.initialize(body);
                RefactoringStatus nestedInvocations = new RefactoringStatus();
                ASTNode[] invocations = removeNestedCalls(nestedInvocations, unit, fTargetProvider.getInvocations(body, new SubProgressMonitor(sub, 2)));
                for (int i = 0; i < invocations.length; i++) {
                    ASTNode invocation = invocations[i];
                    result.merge(inliner.initialize(invocation, fTargetProvider.getStatusSeverity()));
                    if (result.hasFatalError())
                        break;
                    if (result.getSeverity() < fTargetProvider.getStatusSeverity()) {
                        added = true;
                        TextEditGroup group = new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_inline);
                        change.addTextEditGroup(group);
                        result.merge(inliner.perform(group));
                    }
                }
                // do this after we have inlined the method calls. We still want
                // to generate the modifications.
                result.merge(nestedInvocations);
            }
            if (!added) {
                fChangeManager.remove(unit);
            } else {
                root.addChild(inliner.getModifications());
                ImportRewrite rewrite = inliner.getImportEdit();
                if (rewrite.hasRecordedChanges()) {
                    TextEdit edit = rewrite.rewriteImports(null);
                    if (edit instanceof MultiTextEdit ? ((MultiTextEdit) edit).getChildrenSize() > 0 : true) {
                        root.addChild(edit);
                        change.addTextEditGroup(new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_import, new TextEdit[] { edit }));
                    }
                }
            }
        } finally {
            if (inliner != null)
                inliner.dispose();
        }
        sub.worked(1);
        if (sub.isCanceled())
            throw new OperationCanceledException();
    }
    result.merge(searchStatus);
    sub.done();
    pm.done();
    return result;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IFile(org.eclipse.core.resources.IFile) ImportRewrite(org.eclipse.jdt.core.dom.rewrite.ImportRewrite) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ReferencesInBinaryContext(org.eclipse.jdt.internal.corext.refactoring.base.ReferencesInBinaryContext) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ASTNode(org.eclipse.jdt.core.dom.ASTNode) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration) TextEditGroup(org.eclipse.text.edits.TextEditGroup) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextChangeManager(org.eclipse.jdt.internal.corext.refactoring.util.TextChangeManager) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Example 5 with IProgressMonitor

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

the class JavaMoveProcessor method createChange.

@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
    Assert.isTrue(fMovePolicy.getJavaElementDestination() == null || fMovePolicy.getResourceDestination() == null);
    Assert.isTrue(fMovePolicy.getJavaElementDestination() != null || fMovePolicy.getResourceDestination() != null);
    try {
        final DynamicValidationStateChange result = new DynamicValidationStateChange(RefactoringCoreMessages.JavaMoveProcessor_change_name) {

            @Override
            public ChangeDescriptor getDescriptor() {
                return fMovePolicy.getDescriptor();
            }

            @Override
            public Change perform(IProgressMonitor pm2) throws CoreException {
                Change change = super.perform(pm2);
                Change[] changes = getChildren();
                for (int index = 0; index < changes.length; index++) {
                    if (!(changes[index] instanceof TextEditBasedChange))
                        return null;
                }
                return change;
            }
        };
        CreateTargetExecutionLog log = null;
        if (fCreateTargetQueries instanceof MonitoringCreateTargetQueries) {
            final MonitoringCreateTargetQueries queries = (MonitoringCreateTargetQueries) fCreateTargetQueries;
            final ICreateTargetQueries delegate = queries.getDelegate();
            if (delegate instanceof LoggedCreateTargetQueries)
                log = queries.getCreateTargetExecutionLog();
        }
        if (log != null) {
            final Object[] selected = log.getSelectedElements();
            for (int index = 0; index < selected.length; index++) {
                result.add(new LoggedCreateTargetChange(selected[index], fCreateTargetQueries));
            }
        }
        Change change = fMovePolicy.createChange(pm);
        if (change instanceof CompositeChange) {
            CompositeChange subComposite = (CompositeChange) change;
            result.merge(subComposite);
        } else {
            result.add(change);
        }
        return result;
    } finally {
        pm.done();
    }
}
Also used : CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) Change(org.eclipse.ltk.core.refactoring.Change) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)392 InvocationTargetException (java.lang.reflect.InvocationTargetException)152 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)144 CoreException (org.eclipse.core.runtime.CoreException)104 IStatus (org.eclipse.core.runtime.IStatus)85 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)74 ArrayList (java.util.ArrayList)73 Status (org.eclipse.core.runtime.Status)65 Job (org.eclipse.core.runtime.jobs.Job)57 IOException (java.io.IOException)54 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)53 ITask (com.cubrid.common.core.task.ITask)49 IFile (org.eclipse.core.resources.IFile)46 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)43 File (java.io.File)42 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)41 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)37 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)37 PersistenceException (org.talend.commons.exception.PersistenceException)36 IProject (org.eclipse.core.resources.IProject)33