Search in sources :

Example 16 with CompositeChange

use of org.eclipse.ltk.core.refactoring.CompositeChange in project jbosstools-hibernate by jbosstools.

the class NewHibernateMappingPreviewPage method performCommit.

protected void performCommit() {
    final CompositeChange cc = (CompositeChange) getChange();
    if (cc == null) {
        return;
    }
    final ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
    Change[] changes = cc.getChildren();
    for (int i = 0; i < changes.length; i++) {
        Change change = changes[i];
        if (!(change instanceof TextFileChange)) {
            continue;
        }
        TextFileChange tfc = (TextFileChange) change;
        if (tfc.isEnabled() && tfc.getEdit() != null) {
            IPath path = new Path(tfc.getName());
            ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(path, LocationKind.IFILE);
            IDocument document = textFileBuffer.getDocument();
            try {
                tfc.getEdit().apply(document);
            } catch (MalformedTreeException e) {
                // $NON-NLS-1$
                HibernateConsolePlugin.getDefault().logErrorMessage("MalformedTreeException: ", e);
            } catch (BadLocationException e) {
                // $NON-NLS-1$
                HibernateConsolePlugin.getDefault().logErrorMessage("BadLocationException: ", e);
            }
            try {
                // commit changes to underlying file
                textFileBuffer.commit(null, true);
            } catch (CoreException e) {
                // $NON-NLS-1$
                HibernateConsolePlugin.getDefault().logErrorMessage("CoreException: ", e);
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Change(org.eclipse.ltk.core.refactoring.Change) CreateTextFileChange(org.eclipse.jdt.internal.corext.refactoring.nls.changes.CreateTextFileChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) CreateTextFileChange(org.eclipse.jdt.internal.corext.refactoring.nls.changes.CreateTextFileChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 17 with CompositeChange

use of org.eclipse.ltk.core.refactoring.CompositeChange in project titan.EclipsePlug-ins by eclipse.

the class InsertFieldRefactoring method createChange.

@Override
public Change createChange(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
    if (iselection == null) {
        return null;
    }
    final CompositeChange cchange = new CompositeChange("InsertFieldRefactoring");
    final Iterator<?> it = iselection.iterator();
    while (it.hasNext()) {
        final Object o = it.next();
        if (!(o instanceof IResource)) {
            continue;
        }
        final IResource res = (IResource) o;
        final ResourceVisitor vis = new ResourceVisitor();
        res.getProject().accept(vis);
        cchange.add(vis.getChange());
    }
    affectedObjects = cchange.getAffectedObjects();
    return cchange;
}
Also used : CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IResource(org.eclipse.core.resources.IResource)

Example 18 with CompositeChange

use of org.eclipse.ltk.core.refactoring.CompositeChange in project titan.EclipsePlug-ins by eclipse.

the class ContextLoggingRefactoring method createChange.

@Override
public Change createChange(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
    if (selection == null) {
        ErrorReporter.logError("ContextLoggingRefactoring: Selection is null! ");
        return null;
    }
    if (selection instanceof IStructuredSelection) {
        final CompositeChange cchange = new CompositeChange("ContextLoggingRefactoring");
        final IStructuredSelection ssel = (IStructuredSelection) selection;
        final Iterator<?> it = ssel.iterator();
        while (it.hasNext()) {
            final Object o = it.next();
            if (!(o instanceof IResource)) {
                continue;
            }
            final IResource res = (IResource) o;
            final ResourceVisitor vis = new ResourceVisitor();
            res.accept(vis);
            cchange.add(vis.getChange());
        }
        affectedObjects = cchange.getAffectedObjects();
        return cchange;
    } else if (selection instanceof TextSelection) {
        final ChangeCreator chCreator = new ChangeCreator(selectedFile, (TextSelection) selection, settings);
        chCreator.perform();
        final Change ch = chCreator.getChange();
        if (ch == null) {
            affectedObjects = new Object[] {};
            return new CompositeChange("EmptyLoggingRefactoring");
        } else {
            affectedObjects = ch.getAffectedObjects();
        }
        return ch;
    }
    return null;
}
Also used : ITextSelection(org.eclipse.jface.text.ITextSelection) TextSelection(org.eclipse.jface.text.TextSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Change(org.eclipse.ltk.core.refactoring.Change) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IResource(org.eclipse.core.resources.IResource)

Example 19 with CompositeChange

use of org.eclipse.ltk.core.refactoring.CompositeChange in project titan.EclipsePlug-ins by eclipse.

the class LazyficationRefactoring method createChange.

@Override
public Change createChange(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
    if (selection == null) {
        return null;
    }
    final CompositeChange cchange = new CompositeChange("LazyficationRefactoring");
    final Iterator<?> it = selection.iterator();
    while (it.hasNext()) {
        final Object o = it.next();
        if (!(o instanceof IResource)) {
            continue;
        }
        final IResource res = (IResource) o;
        final ResourceVisitor vis = new ResourceVisitor();
        res.accept(vis);
        cchange.add(vis.getChange());
    }
    affectedObjects = cchange.getAffectedObjects();
    return cchange;
}
Also used : CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IResource(org.eclipse.core.resources.IResource)

Example 20 with CompositeChange

use of org.eclipse.ltk.core.refactoring.CompositeChange in project titan.EclipsePlug-ins by eclipse.

the class MinimizeVisibilityRefactoring method createChange.

@Override
public Change createChange(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
    if (selection == null) {
        return null;
    }
    final CompositeChange cchange = new CompositeChange("MinimizeVisibilityRefactoring");
    final Iterator<?> it = selection.iterator();
    while (it.hasNext()) {
        final Object o = it.next();
        if (!(o instanceof IResource)) {
            continue;
        }
        final IResource res = (IResource) o;
        final ResourceVisitor vis = new ResourceVisitor();
        res.accept(vis);
        cchange.add(vis.getChange());
    }
    affectedObjects = cchange.getAffectedObjects();
    return cchange;
}
Also used : CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IResource(org.eclipse.core.resources.IResource)

Aggregations

CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)49 Change (org.eclipse.ltk.core.refactoring.Change)22 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)14 IFile (org.eclipse.core.resources.IFile)10 IResource (org.eclipse.core.resources.IResource)9 TextChange (org.eclipse.ltk.core.refactoring.TextChange)9 IResourceVisitor (org.eclipse.core.resources.IResourceVisitor)7 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)6 EditorDocumentChange (org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange)6 CoreException (org.eclipse.core.runtime.CoreException)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)4 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)4 TextEditBasedChange (org.eclipse.ltk.core.refactoring.TextEditBasedChange)4 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)3 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)3 TextEdit (org.eclipse.text.edits.TextEdit)3 IOException (java.io.IOException)2