MCPcopy Create free account
hub / github.com/antlr/codebuff / align

Method align

src/org/antlr/codebuff/Formatter.java:316–344  ·  view source on GitHub ↗
(int alignOrIndent, TerminalNode node)

Source from the content-addressed store, hash-verified

314 }
315
316 public void align(int alignOrIndent, TerminalNode node) {
317 int[] deltaChild = Trainer.triple(alignOrIndent);
318 int deltaFromAncestor = deltaChild[0];
319 int childIndex = deltaChild[1];
320 ParserRuleContext earliestLeftAncestor = earliestAncestorStartingWithToken(node);
321 ParserRuleContext ancestor = Trainer.getAncestor(earliestLeftAncestor, deltaFromAncestor);
322 Token start = null;
323 if ( ancestor==null ) {
324// System.err.println("Whoops. No ancestor at that delta");
325 }
326 else {
327 ParseTree child = ancestor.getChild(childIndex);
328 if (child instanceof ParserRuleContext) {
329 start = ((ParserRuleContext) child).getStart();
330 }
331 else if (child instanceof TerminalNode) {
332 start = ((TerminalNode) child).getSymbol();
333 }
334 else {
335 // uh oh.
336// System.err.println("Whoops. Tried to access invalid child");
337 }
338 }
339 if ( start!=null ) {
340 int indentCol = start.getCharPositionInLine();
341 charPosInLine = indentCol;
342 output.append(Tool.spaces(indentCol));
343 }
344 }
345
346 public int[] getFeatures(InputDocument doc, int tokenIndexInStream) {
347 Token prevToken = doc.tokens.getPreviousRealToken(tokenIndexInStream);

Callers 1

processTokenMethod · 0.95

Calls 7

tripleMethod · 0.95
getAncestorMethod · 0.95
spacesMethod · 0.95
getCharPositionInLineMethod · 0.80
getChildMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected