Search in sources :

Example 6 with NullChange

use of org.eclipse.ltk.core.refactoring.NullChange in project che by eclipse.

the class UnimplementedCodeFix method createAddUnimplementedMethodsFix.

public static IProposableFix createAddUnimplementedMethodsFix(final CompilationUnit root, IProblemLocation problem) {
    ASTNode typeNode = getSelectedTypeNode(root, problem);
    if (typeNode == null)
        return null;
    if (isTypeBindingNull(typeNode))
        return null;
    AddUnimplementedMethodsOperation operation = new AddUnimplementedMethodsOperation(typeNode);
    if (operation.getMethodsToImplement().length > 0) {
        return new UnimplementedCodeFix(CorrectionMessages.UnimplementedMethodsCorrectionProposal_description, root, new CompilationUnitRewriteOperation[] { operation });
    } else {
        return new IProposableFix() {

            public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
                CompilationUnitChange change = new CompilationUnitChange(CorrectionMessages.UnimplementedMethodsCorrectionProposal_description, (ICompilationUnit) root.getJavaElement()) {

                    @Override
                    public Change perform(IProgressMonitor pm) throws CoreException {
                        //TODO
                        return new NullChange();
                    }
                };
                change.setEdit(new MultiTextEdit());
                return change;
            }

            public String getAdditionalProposalInfo() {
                return new String();
            }

            public String getDisplayString() {
                return CorrectionMessages.UnimplementedMethodsCorrectionProposal_description;
            }

            public IStatus getStatus() {
                return new Status(IStatus.ERROR, JavaPlugin.ID_PLUGIN, CorrectionMessages.UnimplementedCodeFix_DependenciesStatusMessage);
            }
        };
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NullChange(org.eclipse.ltk.core.refactoring.NullChange) ASTNode(org.eclipse.jdt.core.dom.ASTNode) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Example 7 with NullChange

use of org.eclipse.ltk.core.refactoring.NullChange in project che by eclipse.

the class DeleteSourceManipulationChange method doDelete.

/*
	 * @see DeleteChange#doDelete(IProgressMonitor)
	 */
@Override
protected Change doDelete(IProgressMonitor pm) throws CoreException {
    ISourceManipulation element = getSourceManipulation();
    // since the primary working copy still exists.
    if (element instanceof ICompilationUnit) {
        //$NON-NLS-1$
        pm.beginTask("", 2);
        ICompilationUnit unit = (ICompilationUnit) element;
        saveCUnitIfNeeded(unit, new SubProgressMonitor(pm, 1));
        IResource resource = unit.getResource();
        ResourceDescription resourceDescription = ResourceDescription.fromResource(resource);
        element.delete(false, new SubProgressMonitor(pm, 1));
        resourceDescription.recordStateFromHistory(resource, new SubProgressMonitor(pm, 1));
        return new UndoDeleteResourceChange(resourceDescription);
    } else if (element instanceof IPackageFragment) {
        ICompilationUnit[] units = ((IPackageFragment) element).getCompilationUnits();
        //$NON-NLS-1$
        pm.beginTask("", units.length + 1);
        for (int i = 0; i < units.length; i++) {
            // fix https://bugs.eclipse.org/bugs/show_bug.cgi?id=66835
            saveCUnitIfNeeded(units[i], new SubProgressMonitor(pm, 1));
        }
        element.delete(false, new SubProgressMonitor(pm, 1));
        // caveat: real undo implemented by UndoablePackageDeleteChange
        return new NullChange();
    } else {
        element.delete(false, pm);
        //should not happen
        return null;
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) NullChange(org.eclipse.ltk.core.refactoring.NullChange) ResourceDescription(org.eclipse.ui.ide.undo.ResourceDescription) ISourceManipulation(org.eclipse.jdt.core.ISourceManipulation) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IResource(org.eclipse.core.resources.IResource)

Aggregations

NullChange (org.eclipse.ltk.core.refactoring.NullChange)7 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)4 IResource (org.eclipse.core.resources.IResource)3 HashMap (java.util.HashMap)2 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)2 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)2 ResourceDescription (org.eclipse.ui.ide.undo.ResourceDescription)2 LinkedList (java.util.LinkedList)1 Entry (java.util.Map.Entry)1 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)1 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1