Search in sources :

Example 1 with TextEditBasedChange

use of org.eclipse.ltk.core.refactoring.TextEditBasedChange 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)

Example 2 with TextEditBasedChange

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

the class TextEditChangePreviewViewer method setInput.

//	public void createControl(Composite parent) {
//		fViewer = new ComparePreviewer(parent);
//	}
//
//	public Control getControl() {
//		return fViewer;
//	}
public ChangePreview setInput(ChangePreviewViewerInput input) {
    try {
        Change change = input.getChange();
        if (input instanceof TextEditBasedChangeInput) {
            TextEditBasedChangeInput extended = (TextEditBasedChangeInput) input;
            if (extended.group != null && extended.surroundingLines >= 0) {
                TextEditBasedChangeGroup group = extended.group;
                TextEditBasedChange editChange = group.getTextEditChange();
                //					setInput(editChange, editChange.getCurrentContent(group.getRegion(), true, 2, new NullProgressMonitor()),
                //							 editChange.getPreviewContent(new TextEditBasedChangeGroup[]{group}, group.getRegion(), true, 2,
                //														  new NullProgressMonitor()),
                //							 editChange.getTextType());
                ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
                preview.setFileName(getFileName(editChange));
                preview.setOldContent(editChange.getCurrentContent(group.getRegion(), true, 2, new NullProgressMonitor()));
                preview.setNewContent(editChange.getPreviewContent(new TextEditBasedChangeGroup[] { group }, group.getRegion(), true, 2, new NullProgressMonitor()));
                return preview;
            } else if (extended.groups != null && extended.groups.length > 0 && extended.range != null) {
                TextEditBasedChange editChange = extended.groups[0].getTextEditChange();
                TextEditBasedChangeGroup[] groups = extended.groups;
                //					if (extended.groupCategory != null) {
                //
                //					}
                //					setInput(editChange, editChange.getCurrentContent(extended.range, true, 0, new NullProgressMonitor()),
                //							 editChange.getPreviewContent(groups, extended.range, true, 0, new NullProgressMonitor()),
                //							 editChange.getTextType());
                ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
                preview.setFileName(getFileName(editChange));
                preview.setOldContent(editChange.getCurrentContent(extended.range, true, 0, new NullProgressMonitor()));
                preview.setNewContent(editChange.getPreviewContent(groups, extended.range, true, 0, new NullProgressMonitor()));
                return preview;
            }
        } else if (change instanceof TextEditBasedChange) {
            TextEditBasedChange editChange = (TextEditBasedChange) change;
            //				setInput(editChange, editChange.getCurrentContent(new NullProgressMonitor()),
            //						 editChange.getPreviewContent(new NullProgressMonitor()), editChange.getTextType());
            ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
            preview.setFileName(getFileName(editChange));
            preview.setOldContent(editChange.getCurrentContent(new NullProgressMonitor()));
            preview.setNewContent(editChange.getPreviewContent(new NullProgressMonitor()));
            return preview;
        } else {
            //				fViewer.setInput(null);
            return null;
        }
    } catch (CoreException | AssertionFailedException e) {
        JavaPlugin.log(e);
        //			fViewer.setInput(null);
        return null;
    }
    //		}
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ChangePreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) Change(org.eclipse.ltk.core.refactoring.Change) AssertionFailedException(org.eclipse.core.runtime.AssertionFailedException) TextEditBasedChangeGroup(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup)

Example 3 with TextEditBasedChange

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

the class TextEditGroupNode method feedInput.

public ChangePreview feedInput(IChangePreviewViewer viewer, List categories) throws CoreException {
    InternalTextEditChangeNode element = getTextEditChangeNode();
    if (element != null) {
        Change change = element.getChange();
        if (change instanceof TextEditBasedChange) {
            IRegion range = getTextRange(this);
            ChangePreviewViewerInput input = null;
            if (range != null) {
                input = TextEditChangePreviewViewer.createInput(change, new TextEditBasedChangeGroup[] { fChangeGroup }, range);
            } else {
                input = TextEditChangePreviewViewer.createInput(change, fChangeGroup, 2);
            }
            return viewer.setInput(input);
        }
    } else {
        return viewer.setInput(null);
    }
    return null;
}
Also used : TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) ChangePreviewViewerInput(org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) Change(org.eclipse.ltk.core.refactoring.Change) IRegion(org.eclipse.jface.text.IRegion) TextEditBasedChangeGroup(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup)

Example 4 with TextEditBasedChange

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

the class CompilationUnitChangeNode method createChildNodes.

@Override
protected ChildNode[] createChildNodes() {
    TextEditBasedChange change = getTextEditBasedChange();
    if (change instanceof MultiStateTextFileChange) {
        // no edit preview & edit disabling possible in the MultiStateTextFileChange (edits must be applied
        return new ChildNode[0];
    // in sequence)
    }
    ICompilationUnit cunit = (ICompilationUnit) change.getAdapter(ICompilationUnit.class);
    if (cunit != null) {
        List<ChildNode> children = new ArrayList<ChildNode>(5);
        Map<IJavaElement, JavaLanguageNode> map = new HashMap<IJavaElement, JavaLanguageNode>(20);
        TextEditBasedChangeGroup[] changes = getSortedChangeGroups(change);
        for (int i = 0; i < changes.length; i++) {
            TextEditBasedChangeGroup tec = changes[i];
            try {
                IJavaElement element = getModifiedJavaElement(tec, cunit);
                if (element.equals(cunit)) {
                    children.add(createTextEditGroupNode(this, tec));
                } else {
                    JavaLanguageNode pjce = getChangeElement(map, element, children, this);
                    pjce.addChild(createTextEditGroupNode(pjce, tec));
                }
            } catch (JavaModelException e) {
                children.add(createTextEditGroupNode(this, tec));
            }
        }
        return children.toArray(new ChildNode[children.size()]);
    } else {
        return EMPTY_CHILDREN;
    }
}
Also used : MultiStateTextFileChange(org.eclipse.ltk.core.refactoring.MultiStateTextFileChange) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaModelException(org.eclipse.jdt.core.JavaModelException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TextEditBasedChangeGroup(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange)

Example 5 with TextEditBasedChange

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

the class TextEditChangeNode method createChildNodes.

protected ChildNode[] createChildNodes() {
    TextEditBasedChange change = getTextEditBasedChange();
    if (change instanceof MultiStateTextFileChange) {
        // no edit preview & edit disabling possible in the MultiStateTextFileChange (edits must be applied in sequence)
        return new ChildNode[0];
    }
    TextEditBasedChangeGroup[] groups = getSortedChangeGroups(change);
    ChildNode[] result = new ChildNode[groups.length];
    for (int i = 0; i < groups.length; i++) {
        result[i] = new TextEditGroupNode(this, groups[i]);
    }
    return result;
}
Also used : MultiStateTextFileChange(org.eclipse.ltk.core.refactoring.MultiStateTextFileChange) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) TextEditGroupNode(org.eclipse.ltk.internal.ui.refactoring.TextEditGroupNode) TextEditBasedChangeGroup(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup)

Aggregations

TextEditBasedChange (org.eclipse.ltk.core.refactoring.TextEditBasedChange)5 TextEditBasedChangeGroup (org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup)4 Change (org.eclipse.ltk.core.refactoring.Change)3 MultiStateTextFileChange (org.eclipse.ltk.core.refactoring.MultiStateTextFileChange)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ChangePreview (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview)1 AssertionFailedException (org.eclipse.core.runtime.AssertionFailedException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 DynamicValidationStateChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange)1 IRegion (org.eclipse.jface.text.IRegion)1 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)1 TextEditGroupNode (org.eclipse.ltk.internal.ui.refactoring.TextEditGroupNode)1 ChangePreviewViewerInput (org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput)1