private String getJavaDocCommentsBeforeNode(GroovySourceAST t) { String result = ""; LineColumn thisLineCol = new LineColumn(t.getLine(), t.getColumn()); String text = sourceBuffer.getSnippet(lastLineCol, thisLineCol); if (text != null) { Matcher m = PREV_JAVADOC_COMMENT_PATTERN.matcher(text); if (m.find()) { result = m.group(1); } } if (isMajorType(t)) { lastLineCol = thisLineCol; } return result; }
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 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))); }
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))); }
private String getChildTextFromSource(GroovySourceAST child) { return sourceBuffer.getSnippet( new LineColumn(child.getLine(), child.getColumn()), new LineColumn(child.getLineLast(), child.getColumnLast())); }
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 visitDefault(GroovySourceAST t,int visit) { if (visit == OPENING_VISIT ) { System.out.println("[" + tokenNames[t.getType()] + "]"); int line = t.getLine(); int column = t.getColumn(); int lineLast = t.getLineLast(); int columnLast = t.getColumnLast(); System.out.println("" + line + " / " + column + " - " + lineLast + " / " + columnLast); if (line > 0 && column > 0 && lineLast > 0 && columnLast > 0) { System.out.println("" + sourceBuffer.getSnippet(new LineColumn(line, column), new LineColumn(lineLast, columnLast))); } else { System.out.println("ZERO"); } } else if (visit == CLOSING_VISIT) { System.out.println(); } } }
public void testEmptyBuffer() throws Exception { SourceBuffer buffer = getSourceBuffer(""); assertNull(buffer.getSnippet(new LineColumn(1, 1), new LineColumn(1, 1))); }
public void testSimpleUsage() throws Exception { SourceBuffer buffer = getSourceBuffer("println 'hello world'"); assertEquals("hello", buffer.getSnippet(new LineColumn(1, 10), new LineColumn(1, 15))); }
private String getName(GroovySourceAST t) { String name = tokenNames[t.getType()] + " <" + t.getType() + ">"; if (!(escape(tokenNames[t.getType()]).equals(escape(t.getText())))) { name = name + " : " + t.getText(); } switch (t.getType()) { case GroovyTokenTypes.METHOD_DEF : case GroovyTokenTypes.VARIABLE_DEF : GroovySourceAST identNode = t.childOfType(GroovyTokenTypes.IDENT); if (identNode != null) { name = name + " : " + identNode.getText() + ""; } } name = escape(name); if (sourceBuffer != null) { name += "
"; name += t.getLine() + "," + t.getColumn() + " - " + t.getLineLast() + "," + t.getColumnLast(); name += "
"; name += escape(sourceBuffer.getSnippet(new LineColumn(t.getLine(), t.getColumn()), new LineColumn(t.getLineLast(), t.getColumnLast()))); } return name; }
private String getJavaDocCommentsBeforeNode(GroovySourceAST t) { String returnValue = ""; String text = sourceBuffer.getSnippet(new LineColumn(1,1), new LineColumn(t.getLine(), t.getColumn())); if (text != null) { int openBlockIndex = text.lastIndexOf("{"); int closingBlockIndex = text.lastIndexOf("}"); int lastBlockIndex = Math.max(openBlockIndex, closingBlockIndex); if (lastBlockIndex > 0) { text = text.substring(lastBlockIndex); } Matcher m = previousJavaDocCommentPattern.matcher(text); if (m.find()) { returnValue = m.group(1); } } return returnValue; }
private String getJavaDocCommentsBeforeNode(GroovySourceAST t) { String result = ""; LineColumn thisLineCol = new LineColumn(t.getLine(), t.getColumn()); String text = sourceBuffer.getSnippet(lastLineCol, thisLineCol); if (text != null) { Matcher m = PREV_JAVADOC_COMMENT_PATTERN.matcher(text); if (m.find()) { result = m.group(1); } } if (isMajorType(t)) { lastLineCol = thisLineCol; } return result; }
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(); }
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(); }
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(); }
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(); }
private String getChildTextFromSource(GroovySourceAST child) { return sourceBuffer.getSnippet( new LineColumn(child.getLine(), child.getColumn()), new LineColumn(child.getLineLast(), child.getColumnLast())); }
private String getChildTextFromSource(GroovySourceAST child) { return sourceBuffer.getSnippet( new LineColumn(child.getLine(), child.getColumn()), new LineColumn(child.getLineLast(), child.getColumnLast())); }
private String getChildTextFromSource(GroovySourceAST child) { return sourceBuffer.getSnippet( new LineColumn(child.getLine(), child.getColumn()), new LineColumn(child.getLineLast(), child.getColumnLast())); }
private String getChildTextFromSource(GroovySourceAST child) { return sourceBuffer.getSnippet( new LineColumn(child.getLine(), child.getColumn()), new LineColumn(child.getLineLast(), child.getColumnLast())); }