Search in sources :

Example 1 with ChangedFile

use of org.erlide.wrangler.refactoring.backend.ChangedFile in project erlide_eclipse by erlang.

the class WranglerUtils method notifyErlide.

/**
 * Notifies Erlide about the changed files.
 *
 * @param changedFiles
 *            changed files
 */
public static void notifyErlide(final List<ChangedFile> changedFiles) {
    final IErlModel model = ErlangEngine.getInstance().getModel();
    for (final ChangedFile f : changedFiles) {
        IFile file;
        try {
            file = WranglerUtils.getFileFromPath(f.getNewPath());
            final IErlElement element = model.findElement(file);
            final IErlModule m = (IErlModule) element;
            m.resourceChanged(null);
            final IEditorPart editor = GlobalParameters.getEditor();
            if (editor instanceof ErlangEditor) {
                ((ErlangEditor) editor).resetAndCacheScannerAndParser();
            }
            model.notifyChange(m);
        } catch (final Exception e) {
            ErlLogger.error(e);
        }
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IFile(org.eclipse.core.resources.IFile) IErlModel(org.erlide.engine.model.root.IErlModel) IErlModule(org.erlide.engine.model.root.IErlModule) IEditorPart(org.eclipse.ui.IEditorPart) ChangedFile(org.erlide.wrangler.refactoring.backend.ChangedFile) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) BadLocationException(org.eclipse.jface.text.BadLocationException) IOException(java.io.IOException) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) ErlangEditor(org.erlide.ui.editors.erl.ErlangEditor)

Example 2 with ChangedFile

use of org.erlide.wrangler.refactoring.backend.ChangedFile in project erlide_eclipse by erlang.

the class RenameModuleRefactoring method createChange.

@Override
public Change createChange(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
    final CompositeChange c = (CompositeChange) super.createChange(pm);
    for (final ChangedFile f : changedFiles) {
        if (f.isNameChanged()) {
            final IPath p = f.getPath();
            final String s = f.getNewName();
            final RenameResourceChange rch = new RenameResourceChange(p, s);
            c.add(rch);
        }
    }
    return c;
}
Also used : IPath(org.eclipse.core.runtime.IPath) RenameResourceChange(org.eclipse.ltk.core.refactoring.resource.RenameResourceChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) ChangedFile(org.erlide.wrangler.refactoring.backend.ChangedFile)

Example 3 with ChangedFile

use of org.erlide.wrangler.refactoring.backend.ChangedFile in project erlide_eclipse by erlang.

the class WranglerRefactoring method createChange.

@Override
public Change createChange(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
    pm.beginTask("Creating changes", changedFiles.size() + 1);
    final CompositeChange change = new CompositeChange(getName());
    pm.internalWorked(1);
    try {
        Change c;
        for (final ChangedFile e : changedFiles) {
            c = e.createChanges();
            if (c != null) {
                change.add(c);
                pm.internalWorked(1);
            }
        }
    } catch (final IOException e) {
        final Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage());
        throw new CoreException(s);
    } finally {
        pm.done();
    }
    return change;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) CoreException(org.eclipse.core.runtime.CoreException) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Change(org.eclipse.ltk.core.refactoring.Change) IOException(java.io.IOException) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) ChangedFile(org.erlide.wrangler.refactoring.backend.ChangedFile)

Example 4 with ChangedFile

use of org.erlide.wrangler.refactoring.backend.ChangedFile in project erlide_eclipse by erlang.

the class AbstractRefactoringRpcMessage method parseFileList.

protected ArrayList<ChangedFile> parseFileList(final OtpErlangList fileList) {
    final ArrayList<ChangedFile> ret = new ArrayList<>();
    OtpErlangTuple e;
    OtpErlangString oldPath;
    OtpErlangString newPath;
    for (int i = 0; i < fileList.arity(); ++i) {
        e = (OtpErlangTuple) fileList.elementAt(i);
        oldPath = (OtpErlangString) e.elementAt(0);
        newPath = (OtpErlangString) e.elementAt(1);
        final String newContent = OtpErlang.asString(e.elementAt(2));
        ret.add(new ChangedFile(oldPath.stringValue(), newPath.stringValue(), newContent));
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) ChangedFile(org.erlide.wrangler.refactoring.backend.ChangedFile) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Aggregations

ChangedFile (org.erlide.wrangler.refactoring.backend.ChangedFile)4 IOException (java.io.IOException)2 CoreException (org.eclipse.core.runtime.CoreException)2 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)2 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)1 ArrayList (java.util.ArrayList)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 Change (org.eclipse.ltk.core.refactoring.Change)1 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)1 RenameResourceChange (org.eclipse.ltk.core.refactoring.resource.RenameResourceChange)1 IEditorPart (org.eclipse.ui.IEditorPart)1 PartInitException (org.eclipse.ui.PartInitException)1 IErlElement (org.erlide.engine.model.IErlElement)1 IErlModel (org.erlide.engine.model.root.IErlModel)1