private String getChildTextFromSource(GroovySourceAST child) { return sourceBuffer.getSnippet( new LineColumn(child.getLine(), child.getColumn()), new LineColumn(child.getLineLast(), child.getColumnLast())); }
private int getBoundType(AST node) { if (node == null) return -1; if (isType(TYPE_UPPER_BOUNDS, node)) return TYPE_UPPER_BOUNDS; if (isType(TYPE_LOWER_BOUNDS, node)) return TYPE_LOWER_BOUNDS; throw new ASTRuntimeException(node, "Unexpected node type: " + getTokenName(node) + " found when expecting type: " + getTokenName(TYPE_UPPER_BOUNDS) + " or type: " + getTokenName(TYPE_LOWER_BOUNDS)); }
public ASTParserException(String message, ASTRuntimeException e) { super(message, e, e.getLine(), e.getColumn(), getLineLast(e), getColumnLast(e)); this.ast = e.getAst(); }
private String getChildTextFromSource(GroovySourceAST child, String tokens) { String text = sourceBuffer.getSnippet( new LineColumn(child.getLine(), child.getColumn()), new LineColumn(child.getLine() + 1, 0)); StringTokenizer st = new StringTokenizer(text, tokens); return st.nextToken(); }
public void testSimpleUsage() throws Exception { SourceBuffer buffer = getSourceBuffer("println 'hello world'"); assertEquals("hello", buffer.getSnippet(new LineColumn(1, 10), new LineColumn(1, 15))); }
public /*final*/ Reduction parseCST(final SourceUnit sourceUnit, Reader reader) throws CompilationFailedException { final SourceBuffer sourceBuffer = new SourceBuffer(); transformCSTIntoAST(sourceUnit, reader, sourceBuffer); processAST(); return outputAST(sourceUnit, sourceBuffer); }
public void testEmptyBuffer() throws Exception { SourceBuffer buffer = getSourceBuffer(""); assertNull(buffer.getSnippet(new LineColumn(1, 1), new LineColumn(1, 1))); }
private AST attachLast(AST t, Object last) { if ((t instanceof GroovySourceAST) && (last instanceof SourceInfo)) { SourceInfo lastInfo = (SourceInfo) last; GroovySourceAST node = (GroovySourceAST)t; node.setColumnLast(lastInfo.getColumn()); node.setLineLast(lastInfo.getLine()); // This is a good point to call node.setSnippet(), // but it bulks up the AST too much for production code. } return t; }
protected void assertTypeNotNull(ClassNode type, AST rightNode) { if (type == null) { throw new ASTRuntimeException(rightNode, "No type available for: " + qualifiedName(rightNode)); } }
private String getText(GroovySourceAST node) { String returnValue = null; if (node != null) { returnValue = node.getText(); } return returnValue; }
private static void checkNoInvalidModifier(AST node, String nodeType, int modifiers, int modifier, String modifierText) { if ((modifiers & modifier) != 0) { throw new ASTRuntimeException(node, nodeType + " has an incorrect modifier '" + modifierText + "'."); } }
protected Statement statementListNoChild(AST node, AST alternativeConfigureNode) { BlockStatement block = siblingsToBlockStatement(node); // alternativeConfigureNode is used only to set the source position if (node != null) { configureAST(block, node); } else { configureAST(block, alternativeConfigureNode); } return block; }
public void testEquality() throws Exception { assertTrue(a.equals(a)); assertTrue(a.compareTo(a) == 0); }
protected void setUp() throws Exception { a = new GroovySourceAST(); a.setLine(3); a.setColumn(3); b = new GroovySourceAST(); b.setLine(4); b.setColumn(2); }
public void testGreaterThan() throws Exception { assertTrue(b.compareTo(a) > 0); } }
public void testUnixLineUsage() throws Exception { String endOfLine = "\n"; StringBuffer src = new StringBuffer(); src.append("println 'hello world'").append(endOfLine); src.append("println 'oh not, not that again'").append(endOfLine); SourceBuffer buffer = getSourceBuffer(src.toString()); assertEquals("hello", buffer.getSnippet(new LineColumn(1, 10), new LineColumn(1, 15))); assertEquals("world'" + endOfLine + "print", buffer.getSnippet(new LineColumn(1, 16), new LineColumn(2, 6))); assertEquals(endOfLine, buffer.getSnippet(new LineColumn(1, 22), new LineColumn(1, 23))); assertEquals(endOfLine, buffer.getSnippet(new LineColumn(2, 33), new LineColumn(2, 34))); }
private void isClosureListExpressionAllowedHere(AST node) { if (!forStatementBeingDef) { throw new ASTRuntimeException(node, "Expression list of the form (a; b; c) is not supported in this context."); } }
public void testLessThan() throws Exception { assertTrue(a.compareTo(b) < 0); }
public void testDOSLineUsage() throws Exception { String endOfLine = "\r\n"; StringBuffer src = new StringBuffer(); src.append("println 'hello world'").append(endOfLine); src.append("println 'oh not, not that again'").append(endOfLine); SourceBuffer buffer = getSourceBuffer(src.toString()); assertEquals("hello", buffer.getSnippet(new LineColumn(1, 10), new LineColumn(1, 15))); assertEquals("oh not", buffer.getSnippet(new LineColumn(2, 10), new LineColumn(2, 16))); assertEquals("world'" + endOfLine + "print", buffer.getSnippet(new LineColumn(1, 16), new LineColumn(2, 6))); assertEquals(endOfLine, buffer.getSnippet(new LineColumn(1, 22), new LineColumn(1, 24))); assertEquals(endOfLine, buffer.getSnippet(new LineColumn(2, 33), new LineColumn(2, 35))); }
public void testOutOfBounds() throws Exception { String endOfLine = "\n"; StringBuffer src = new StringBuffer(); src.append("println 'hello world'").append(endOfLine); src.append("println 'oh not, not that again'").append(endOfLine); SourceBuffer buffer = getSourceBuffer(src.toString()); assertEquals("println", buffer.getSnippet(new LineColumn(0, 0), new LineColumn(1, 8))); assertEquals("println", buffer.getSnippet(new LineColumn(-10, -1), new LineColumn(1, 8))); assertEquals(endOfLine, buffer.getSnippet(new LineColumn(2, 33), new LineColumn(2, 40))); assertEquals("", buffer.getSnippet(new LineColumn(3, 33), new LineColumn(6, 40))); }