Couple<ASTNode> (ASTNode one, ASTNode two) { if (one == two) return Couple.of(null, null); LinkedList<ASTNode> oneParents = new LinkedList<>(); while (one != null) { oneParents.add(one); one = one.getTreeParent(); } LinkedList<ASTNode> twoParents = new LinkedList<>(); while (two != null) { twoParents.add(two); two = two.getTreeParent(); } do { one = oneParents.pollLast(); two = twoParents.pollLast(); } while (one == two && one != null); return Couple.of(one, two); }