/** walks up the tree until reaching the CompilationUnit. */ private CompilationUnit getCompilationUnit(Node n) { Node unit = n; while (!(unit instanceof CompilationUnit) && unit != null) { unit = unit.getParentNode(); } return (CompilationUnit) unit; }
private void printOrphanCommentsBeforeThisChildNode(final Node node){ if (node instanceof Comment) return; Node parent = node.getParentNode(); if (parent==null) return; List<Node> everything = new LinkedList<Node>(); everything.addAll(parent.getChildrenNodes()); sortByBeginPosition(everything); int positionOfTheChild = -1; for (int i=0;i<everything.size();i++){ if (everything.get(i)==node) positionOfTheChild=i; } if (positionOfTheChild==-1) throw new RuntimeException("My index not found!!! "+node); int positionOfPreviousChild = -1; for (int i=positionOfTheChild-1;i>=0 && positionOfPreviousChild==-1;i--){ if (!(everything.get(i) instanceof Comment)) positionOfPreviousChild = i; } for (int i=positionOfPreviousChild+1;i<positionOfTheChild;i++){ Node nodeToPrint = everything.get(i); if (!(nodeToPrint instanceof Comment)) throw new RuntimeException("Expected comment, instead "+nodeToPrint.getClass()+". Position of previous child: "+positionOfPreviousChild+", position of child "+positionOfTheChild); nodeToPrint.accept(this,null); } }
@Override public final NodeData resolve(Node node, String mappedClass) { if (!(node instanceof FieldDeclaration)) { throw new IllegalArgumentException("this annotation belongs only on FieldDeclaration"); } final FieldDeclaration field = (FieldDeclaration) node; if (ResolverUtil.canFieldBeAnnotated(field)) { final TypeDeclaration dclr = (TypeDeclaration) node.getParentNode(); final String name = dclr.getName(); final String pckg = ((CompilationUnit) dclr.getParentNode()).getPackage().getName().toString(); final String fullyQualifiedClass = pckg + "." + name; final boolean mappedColumn = OjbUtil.isMappedColumn(mappedClass, ParserUtil.getFieldName(field), descriptorRepositories); if (mappedColumn) { return getAnnotationNodes(fullyQualifiedClass, ParserUtil.getFieldName(field), mappedClass); } } return null; }