use of org.eclipse.n4js.n4JS.ScriptElement 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;
}
use of org.eclipse.n4js.n4JS.ScriptElement in project n4js by eclipse.
the class ScriptFactory method buildComplexNode.
static ComplexNode buildComplexNode(ReentrantASTIterator astpp, Script script) {
ComplexNode cNode = new ComplexNode(astpp.container(), script);
Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), script);
List<Node> scriptNodes = new LinkedList<>();
EList<ScriptElement> scriptElems = script.getScriptElements();
for (int n = 0; n < scriptElems.size(); n++) {
ScriptElement scriptElem = getScriptElementAt(script, n);
if (isControlFlowStatement(scriptElem)) {
Node blockNode = DelegatingNodeFactory.create(astpp, "stmt_" + n, script, (Statement) scriptElem);
scriptNodes.add(blockNode);
}
}
Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), script);
cNode.addNode(entryNode);
for (Node scriptNode : scriptNodes) cNode.addNode(scriptNode);
cNode.addNode(exitNode);
List<Node> nodes = new LinkedList<>();
nodes.add(entryNode);
nodes.addAll(scriptNodes);
nodes.add(exitNode);
cNode.connectInternalSucc(nodes);
cNode.setEntryNode(entryNode);
cNode.setExitNode(exitNode);
exitNode.addCatchToken(new CatchToken(ControlFlowType.CatchesAll));
return cNode;
}
use of org.eclipse.n4js.n4JS.ScriptElement in project n4js by eclipse.
the class ScriptFactory method getScriptElementAt.
private static ScriptElement getScriptElementAt(Script script, int i) {
EList<ScriptElement> scriptElems = script.getScriptElements();
ScriptElement scriptElement = scriptElems.get(i);
if (scriptElement instanceof ExportDeclaration) {
ExportableElement expElem = ((ExportDeclaration) scriptElement).getExportedElement();
if (expElem instanceof ExportedVariableStatement) {
scriptElement = (ExportedVariableStatement) expElem;
}
}
return scriptElement;
}
use of org.eclipse.n4js.n4JS.ScriptElement in project n4js by eclipse.
the class ImportRewriter method findInsertionOffset.
private int findInsertionOffset() {
int result = 0;
List<ScriptElement> scriptElements = script.getScriptElements();
for (int i = 0, size = scriptElements.size(); i < size; i++) {
ScriptElement element = scriptElements.get(i);
if (element instanceof ImportDeclaration) {
// Instead of getting the total offset for the first non-import-declaration, we try to get the
// total end offset for the most recent import declaration which is followed by any other script element
// this is required for the linebreak handling for automatic semicolon insertion.
final ICompositeNode importNode = NodeModelUtils.findActualNodeFor(element);
if (null != importNode) {
result = importNode.getTotalOffset() + getLengthWithoutAutomaticSemicolon(importNode);
}
} else {
// Otherwise, we assume there is no import declarations yet, we can put it to the top of the document.
return result;
}
}
return result;
}
use of org.eclipse.n4js.n4JS.ScriptElement in project n4js by eclipse.
the class BuiltInTypeScopeTest method testParsing.
@SuppressWarnings("javadoc")
@Test
public void testParsing() throws Exception {
String content = "var name: any = 'global'";
Script result = parseHelper.parse(content);
Assert.assertNotNull(result);
Assert.assertEquals(1, result.getScriptElements().size());
ScriptElement elem = result.getScriptElements().get(0);
Assert.assertTrue(elem instanceof VariableStatement);
VariableStatement stmt = (VariableStatement) elem;
VariableDeclaration varDecl = stmt.getVarDecl().get(0);
ParameterizedTypeRef typeRef = (ParameterizedTypeRef) varDecl.getDeclaredTypeRef();
Assert.assertFalse("Proxy URI: " + ((InternalEObject) typeRef.getDeclaredType()).eProxyURI(), typeRef.getDeclaredType().eIsProxy());
}
Aggregations