/** * @param tryElement * @param negIdx 0 - last block, 1 - one before last block, ... * @return */ private int getEndOfLastTryBlock(CtTry tryElement, int negIdx) { //offset where we can start to search for catch int endOfLastBlock = tryElement.getBody().getPosition().getSourceEnd(); if (tryElement.getCatchers().size() > negIdx) { CtCatch prevCatcher = tryElement.getCatchers().get(tryElement.getCatchers().size() - 1 - negIdx); endOfLastBlock = prevCatcher.getPosition().getSourceEnd(); } return endOfLastBlock; }
SourcePosition buildPosition(CtCatch catcher) { int[] lineSeparatorPositions = jdtTreeBuilder.getContextBuilder().getCompilationUnitLineSeparatorPositions(); CtTry tryElement = catcher.getParent(CtTry.class); //offset after last bracket before catch int declarationStart = getEndOfLastTryBlock(tryElement, 1) + 1; DeclarationSourcePosition paramPos = (DeclarationSourcePosition) catcher.getParameter().getPosition(); int bodyStart = catcher.getBody().getPosition().getSourceStart(); int bodyEnd = catcher.getBody().getPosition().getSourceEnd(); return catcher.getFactory().Core().createBodyHolderSourcePosition( tryElement.getPosition().getCompilationUnit(), //on the place of name there is catch variable paramPos.getSourceStart(), paramPos.getSourceEnd(), //catch has no modifiers, They are in catch variable declarationStart, declarationStart - 1, declarationStart, bodyEnd, bodyStart, bodyEnd, lineSeparatorPositions); }
printer.writeSpace(); scan(m.getBody()); if (m.getBody().getPosition().isValidPosition()) { if (m.getBody().getPosition().getCompilationUnit() == sourceCompilationUnit) { if (m.getBody().getStatements().isEmpty() || !(m.getBody().getStatements().get(m.getBody().getStatements().size() - 1) instanceof CtReturn)) { getPrinterHelper().putLineNumberMapping(m.getBody().getPosition().getEndLine());
int newSourceStart = Math.min(oldPos.getSourceStart(), block.getPosition().getSourceStart()); if (newSourceStart != oldPos.getSourceStart()) { childStmt.setPosition(block.getFactory().Core().createSourcePosition(
write(" "); scan(m.getBody()); if (m.getBody().getPosition() != null) { if (m.getBody().getPosition().getCompilationUnit() == sourceCompilationUnit) { if (m.getBody().getStatements().isEmpty() || !(m.getBody().getStatements().get(m.getBody().getStatements().size() - 1) instanceof CtReturn)) { lineNumberMapping.put(line, m.getBody().getPosition().getEndLine());