import org.jastadd.plugin.compiler.ast.IFoldingNode; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.BadLocationException; aspect Folding { /* * The IFoldingNode interface need to be implemented by ASTNode * for the AST to provide support for folding */ ASTNode implements IFoldingNode; /* * The default behavior for foldingPositions(..) is to collect * all folding information from descendants and to put the * information in a list which is returned. * Uses information provided by the IJastAddNode interface. */ syn ArrayList ASTNode.foldingPositions(IDocument document) { ArrayList list = new ArrayList(); if (hasFolding()) { try { int lineStart = ASTNode.getLine(getStart()); int lineEnd = ASTNode.getLine(getEnd()); int nbrOfLines = document.getNumberOfLines(); int startOffset = document.getLineOffset(lineStart > 1 ? lineStart - 1 : 0); int endOffset = document.getLineOffset(lineEnd < nbrOfLines ? lineEnd : lineEnd - 1); int foldLength = endOffset - startOffset; if ((lineEnd - lineStart) > 0) { list.add(new Position(startOffset, foldLength)); } } catch (BadLocationException e) { e.printStackTrace(); } } for (int i = 0; i < getNumChild(); i++) { list.addAll(getChild(i).foldingPositions(document)); } return list; } /* * Default behavior is no folding */ syn boolean ASTNode.hasFolding() = false; }