Search in sources :

Example 1 with IChange

use of org.eclipse.n4js.ui.changes.IChange in project n4js by eclipse.

the class ImportsRemovalChangesComputer2 method getImportDeletionChanges.

/**
 * Compute changes that will remove all imports.
 *
 * @param resource
 *            the resource to modify
 * @param document
 *            the document connected to the xtextResource, for textual changes.
 * @return list of changes to the document.
 */
public static List<IChange> getImportDeletionChanges(XtextResource resource, IXtextDocument document) throws BadLocationException {
    List<IChange> changes = new ArrayList<>();
    List<ScriptElement> elements = XtextResourceUtils.getScript(resource).getScriptElements();
    // elements.filter(ImportDeclaration).map[findActualNodeFor(it)].forEach[changes.add(document.removeNodeButKeepComments(it))]
    for (ScriptElement el : elements) {
        if (el instanceof ImportDeclaration) {
            INode nodeToRemove = NodeModelUtils.findActualNodeFor(el);
            changes.add(removeNodeButKeepComments(document, nodeToRemove));
        }
    }
    return changes;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ArrayList(java.util.ArrayList) ScriptElement(org.eclipse.n4js.n4JS.ScriptElement) ImportDeclaration(org.eclipse.n4js.n4JS.ImportDeclaration) IChange(org.eclipse.n4js.ui.changes.IChange)

Aggregations

ArrayList (java.util.ArrayList)1 ImportDeclaration (org.eclipse.n4js.n4JS.ImportDeclaration)1 ScriptElement (org.eclipse.n4js.n4JS.ScriptElement)1 IChange (org.eclipse.n4js.ui.changes.IChange)1 INode (org.eclipse.xtext.nodemodel.INode)1