Search in sources :

Example 11 with NullProgressMonitor

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

the class RefactoringTest method performRefactoring.

protected final RefactoringStatus performRefactoring(Refactoring ref, boolean providesUndo) throws Exception {
    performDummySearch();
    IUndoManager undoManager = getUndoManager();
    if (DESCRIPTOR_TEST) {
        final CreateChangeOperation create = new CreateChangeOperation(new CheckConditionsOperation(ref, CheckConditionsOperation.ALL_CONDITIONS), RefactoringStatus.FATAL);
        create.run(new NullProgressMonitor());
        RefactoringStatus checkingStatus = create.getConditionCheckingStatus();
        if (!checkingStatus.isOK())
            return checkingStatus;
        Change change = create.getChange();
        ChangeDescriptor descriptor = change.getDescriptor();
        if (descriptor instanceof RefactoringChangeDescriptor) {
            RefactoringChangeDescriptor rcd = (RefactoringChangeDescriptor) descriptor;
            RefactoringDescriptor refactoringDescriptor = rcd.getRefactoringDescriptor();
            if (refactoringDescriptor instanceof JavaRefactoringDescriptor) {
                JavaRefactoringDescriptor jrd = (JavaRefactoringDescriptor) refactoringDescriptor;
                RefactoringStatus validation = jrd.validateDescriptor();
                if (!validation.isOK())
                    return validation;
                RefactoringStatus refactoringStatus = new RefactoringStatus();
                Class expected = jrd.getClass();
                RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(jrd.getID());
                jrd = (JavaRefactoringDescriptor) contribution.createDescriptor(jrd.getID(), jrd.getProject(), jrd.getDescription(), jrd.getComment(), contribution.retrieveArgumentMap(jrd), jrd.getFlags());
                assertEquals(expected, jrd.getClass());
                ref = jrd.createRefactoring(refactoringStatus);
                if (!refactoringStatus.isOK())
                    return refactoringStatus;
                TestRenameParticipantSingle.reset();
                TestCreateParticipantSingle.reset();
                TestMoveParticipantSingle.reset();
                TestDeleteParticipantSingle.reset();
            }
        }
    }
    final CreateChangeOperation create = new CreateChangeOperation(new CheckConditionsOperation(ref, CheckConditionsOperation.ALL_CONDITIONS), RefactoringStatus.FATAL);
    final PerformChangeOperation perform = new PerformChangeOperation(create);
    perform.setUndoManager(undoManager, ref.getName());
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    if (fIsPreDeltaTest) {
        IResourceChangeListener listener = new IResourceChangeListener() {

            public void resourceChanged(IResourceChangeEvent event) {
                if (create.getConditionCheckingStatus().isOK() && perform.changeExecuted()) {
                    TestModelProvider.assertTrue(event.getDelta());
                }
            }
        };
        try {
            TestModelProvider.clearDelta();
            workspace.checkpoint(false);
            workspace.addResourceChangeListener(listener);
            executePerformOperation(perform, workspace);
        } finally {
            workspace.removeResourceChangeListener(listener);
        }
    } else {
        executePerformOperation(perform, workspace);
    }
    RefactoringStatus status = create.getConditionCheckingStatus();
    if (!status.isOK())
        return status;
    assertTrue("Change wasn't executed", perform.changeExecuted());
    Change undo = perform.getUndoChange();
    if (providesUndo) {
        assertNotNull("Undo doesn't exist", undo);
        assertTrue("Undo manager is empty", undoManager.anythingToUndo());
    } else {
        assertNull("Undo manager contains undo but shouldn't", undo);
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IUndoManager(org.eclipse.ltk.core.refactoring.IUndoManager) RefactoringContribution(org.eclipse.ltk.core.refactoring.RefactoringContribution) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) Change(org.eclipse.ltk.core.refactoring.Change) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) ChangeDescriptor(org.eclipse.ltk.core.refactoring.ChangeDescriptor) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor) JavaRefactoringDescriptor(org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor) RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) CreateChangeOperation(org.eclipse.ltk.core.refactoring.CreateChangeOperation) PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IWorkspace(org.eclipse.core.resources.IWorkspace) CheckConditionsOperation(org.eclipse.ltk.core.refactoring.CheckConditionsOperation) JavaRefactoringDescriptor(org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor)

Example 12 with NullProgressMonitor

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

the class JavaDebuggerUtils method findTypeByFqn.

private List<IType> findTypeByFqn(char[][] packages, char[][] names, IJavaSearchScope scope) throws JavaModelException {
    List<IType> result = new ArrayList<>();
    SearchEngine searchEngine = new SearchEngine();
    searchEngine.searchAllTypeNames(packages, names, scope, new TypeNameMatchRequestor() {

        @Override
        public void acceptTypeNameMatch(TypeNameMatch typeNameMatch) {
            result.add(typeNameMatch.getType());
        }
    }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor());
    return result;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) TypeNameMatch(org.eclipse.jdt.core.search.TypeNameMatch) ArrayList(java.util.ArrayList) TypeNameMatchRequestor(org.eclipse.jdt.core.search.TypeNameMatchRequestor) IType(org.eclipse.jdt.core.IType)

Example 13 with NullProgressMonitor

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

the class CreateCopyOfCompilationUnitChange method getCopiedFileSource.

private static String getCopiedFileSource(IProgressMonitor monitor, ICompilationUnit unit, String newTypeName) throws CoreException {
    ICompilationUnit copy = unit.getPrimary().getWorkingCopy(null);
    try {
        TextChangeManager manager = createChangeManager(monitor, copy, newTypeName);
        String result = manager.get(copy).getPreviewContent(new NullProgressMonitor());
        return result;
    } finally {
        copy.discardWorkingCopy();
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TextChangeManager(org.eclipse.jdt.internal.corext.refactoring.util.TextChangeManager)

Example 14 with NullProgressMonitor

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

the class ChangeSignatureProcessor method checkCompilationofDeclaringCu.

private RefactoringStatus checkCompilationofDeclaringCu() throws CoreException {
    ICompilationUnit cu = getCu();
    TextChange change = fChangeManager.get(cu);
    String newCuSource = change.getPreviewContent(new NullProgressMonitor());
    CompilationUnit newCUNode = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(newCuSource, cu, true, false, null);
    IProblem[] problems = RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, fBaseCuRewrite.getRoot());
    RefactoringStatus result = new RefactoringStatus();
    for (int i = 0; i < problems.length; i++) {
        IProblem problem = problems[i];
        if (shouldReport(problem, newCUNode))
            result.addEntry(new RefactoringStatusEntry((problem.isError() ? RefactoringStatus.ERROR : RefactoringStatus.WARNING), problem.getMessage(), new JavaStringStatusContext(newCuSource, SourceRangeFactory.create(problem))));
    }
    return result;
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RefactoringASTParser(org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser) RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) TextChange(org.eclipse.ltk.core.refactoring.TextChange) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) JavaStringStatusContext(org.eclipse.jdt.internal.corext.refactoring.base.JavaStringStatusContext) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Example 15 with NullProgressMonitor

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

the class MultiStateTextFileChange method getCurrentDocument.

/**
	 * Returns a document representing the current state of the buffer,
	 * prior to the application of the change.
	 * <p>
	 * The returned document should not be modified.
	 * </p>
	 *
	 * @param monitor
	 *            the progress monitor to use, or <code>null</code>
	 * @return the current document, or the empty document
	 * @throws CoreException
	 *             if no document could be acquired
	 */
public final IDocument getCurrentDocument(IProgressMonitor monitor) throws CoreException {
    if (monitor == null)
        monitor = new NullProgressMonitor();
    IDocument result = null;
    //$NON-NLS-1$
    monitor.beginTask("", 2);
    try {
        result = acquireDocument(new SubProgressMonitor(monitor, 1));
    } finally {
        if (result != null)
            releaseDocument(result, new SubProgressMonitor(monitor, 1));
    }
    monitor.done();
    if (result == null)
        result = new Document();
    return result;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1626 CoreException (org.eclipse.core.runtime.CoreException)430 Test (org.junit.Test)353 IFile (org.eclipse.core.resources.IFile)316 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)276 IProject (org.eclipse.core.resources.IProject)261 File (java.io.File)213 IPath (org.eclipse.core.runtime.IPath)184 IOException (java.io.IOException)162 Path (org.eclipse.core.runtime.Path)141 ArrayList (java.util.ArrayList)125 IStatus (org.eclipse.core.runtime.IStatus)116 IFolder (org.eclipse.core.resources.IFolder)90 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)70 List (java.util.List)63 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)63 InvocationTargetException (java.lang.reflect.InvocationTargetException)61 IProjectDescription (org.eclipse.core.resources.IProjectDescription)58 Status (org.eclipse.core.runtime.Status)57 IResource (org.eclipse.core.resources.IResource)56