/** * Find the index of the current class member. * * @param wc * @param classTree * @param offset * @return */ static int findClassMemberIndex(WorkingCopy wc, ClassTree classTree, int offset) { int index = 0; SourcePositions sp = wc.getTrees().getSourcePositions(); GuardedDocument gdoc = null; try { Document doc = wc.getDocument(); if (doc != null && doc instanceof GuardedDocument) { gdoc = (GuardedDocument) doc; } } catch (IOException ioe) { } Tree lastMember = null; for (Tree tree : classTree.getMembers()) { if (offset <= sp.getStartPosition(wc.getCompilationUnit(), tree)) { if (gdoc == null) { break; } int pos = (int) (lastMember != null ? sp.getEndPosition(wc.getCompilationUnit(), lastMember) : sp.getStartPosition(wc.getCompilationUnit(), classTree)); pos = gdoc.getGuardedBlockChain().adjustToBlockEnd(pos); if (pos <= sp.getStartPosition(wc.getCompilationUnit(), tree)) { break; } } index++; lastMember = tree; } return index; }