@Override public int getColumnNumber() { return node.getBeginColumn(); }
@Override public int getBeginColumn() { if (beginColumn != -1) { return beginColumn; } else { if (children != null && children.length > 0) { return children[0].getBeginColumn(); } else { throw new RuntimeException("Unable to determine beginning line of Node."); } } }
private void tryToLog(String tag, NodeType type, Node node) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("pushOnStack " + tag + " " + type + ": line " + node.getBeginLine() + ", column " + node.getBeginColumn()); } }
private static int compareNodes(Node n1, Node n2) { int l1 = n1.getBeginLine(); int l2 = n2.getBeginLine(); if (l1 == l2) { return n1.getBeginColumn() - n2.getBeginColumn(); } return l1 - l2; }
@Override public int getBeginColumn() { if (this.beginColumn > 0) { return this.beginColumn; } Node parent = jjtGetParent(); if (parent != null) { return parent.getBeginColumn(); } throw new RuntimeException("Unable to determine beginning column of Node."); }
private void addDeclarations(SortedMap<Integer, Node> map, List<? extends Node> nodes) { for (Node node : nodes) { map.put((node.getBeginLine() << 16) + node.getBeginColumn(), node); } } }
private void checkIndentation(Object data, Node node, int indentation, String name) { if (node.getBeginColumn() != indentation) { addViolationWithMessage(data, node, name + " should begin at column " + indentation); } }
public String getToolTipText() { String tooltip = "Line: " + node.getBeginLine() + " Column: " + node.getBeginColumn(); tooltip += " " + label(); return tooltip; }
protected void tryToLog(String tag, DataFlowNode node) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest(tag + ": line" + node.getNode().getBeginLine() + ", column " + node.getNode().getBeginColumn() + " - " + node.toString()); } }
@Override public Object visit(ASTBulkCollectIntoClause node, Object data) { Node parent = node.jjtGetParent(); checkIndentation(data, node, parent.getBeginColumn() + indentation, "BULK COLLECT INTO"); checkEachChildOnNextLine(data, node, node.getBeginLine(), parent.getBeginColumn() + 7); return super.visit(node, data); }
@Override public Object visit(ASTFromClause node, Object data) { checkIndentation(data, node, node.jjtGetParent().getBeginColumn() + indentation, "FROM"); return super.visit(node, data); }
private void checkLineAndIndentation(Object data, Node node, int line, int indentation, String name) { if (node.getBeginLine() != line) { addViolationWithMessage(data, node, name + " should be on line " + line); } else if (node.getBeginColumn() != indentation) { addViolationWithMessage(data, node, name + " should begin at column " + indentation); } }
@Override public Object visit(ASTSelectList node, Object data) { Node parent = node.jjtGetParent(); checkEachChildOnNextLine(data, node, parent.getBeginLine(), parent.getBeginColumn() + 7); return super.visit(node, data); }
@Override public Object visit(ASTFormalParameters node, Object data) { int parameterIndentation = node.jjtGetParent().getBeginColumn() + indentation; checkEachChildOnNextLine(data, node, node.getBeginLine() + 1, parameterIndentation); // check the data type alignment List<ASTFormalParameter> parameters = node.findChildrenOfType(ASTFormalParameter.class); if (parameters.size() > 1) { ASTDatatype first = parameters.get(0).getFirstChildOfType(ASTDatatype.class); for (int i = 1; first != null && i < parameters.size(); i++) { ASTDatatype nextType = parameters.get(i).getFirstChildOfType(ASTDatatype.class); if (nextType != null) { checkIndentation(data, nextType, first.getBeginColumn(), "Type " + nextType.getImage()); } } } return super.visit(node, data); }
private boolean isCommentBefore(FormalComment n1, Node n2) { return n1.getEndLine() < n2.getBeginLine() || n1.getEndLine() == n2.getBeginLine() && n1.getEndColumn() < n2.getBeginColumn(); }
private static boolean isAfter(Node n1, Node n2) { return n1.getBeginLine() > n2.getBeginLine() || n1.getBeginLine() == n2.getBeginLine() && n1.getBeginColumn() >= n2.getEndColumn(); }
/** * Snapshots the absolute coordinates of the node in the code area * for the duration of the layering algorithm. */ // TODO I don't think there's any good reason for this laziness, // if anything, it may cause trouble if the layering algorithm uses // a snapshot taken too late, with outdated line and column coordinates // I originally wrote it like that because I didn't think enough about it, // and I don't have time to simplify it before 6.5.0 public PositionSnapshot snapshot() { int lastKnownStart = getAbsolutePosition(node.getBeginLine(), node.getBeginColumn() - 1); int lastKnownEnd = getAbsolutePosition(node.getEndLine(), node.getEndColumn()); return new PositionSnapshot(lastKnownStart, lastKnownEnd); }
private int checkEachChildOnNextLine(Object data, Node parent, int firstLine, int indentation) { int currentLine = firstLine; for (int i = 0; i < parent.jjtGetNumChildren(); i++) { Node child = parent.jjtGetChild(i); if (child.getBeginLine() != currentLine) { addViolationWithMessage(data, child, child.getImage() + " should be on line " + currentLine); } else if (i > 0 && child.getBeginColumn() != indentation) { addViolationWithMessage(data, child, child.getImage() + " should begin at column " + indentation); } // next entry needs to be on the next line currentLine++; } return currentLine; }
public void select(Node node) { String[] lines = getLines(); if (node.getBeginLine() >= 0) { setSelectionStart(getPosition(lines, node.getBeginLine(), node.getBeginColumn())); setSelectionEnd(getPosition(lines, node.getEndLine(), node.getEndColumn()) + 1); } requestFocus(); } }
@Override public Object visit(ASTSubqueryOperation node, Object data) { // get previous sibling int thisIndex = node.jjtGetChildIndex(); Node prevSibling = node.jjtGetParent().jjtGetChild(thisIndex - 1); checkIndentation(data, node, prevSibling.getBeginColumn(), node.getImage()); // it should also be on the next line if (node.getBeginLine() != prevSibling.getEndLine() + 1) { addViolationWithMessage(data, node, node.getImage() + " should be on line " + (prevSibling.getEndLine() + 1)); } return super.visit(node, data); }