private static <S extends AstNode<S>> boolean addIntern(ArrayList<S> list, int index, S element) { if (element == null) { return false; } else { switch (element.getNodeType()) { case AstNode.NT_NODE_LIST: return addAllIntern(list, index, element); case AstNode.NT_TEXT: return addTextIntern(list, index, (AstStringNode<S>) element); default: list.add(index, element); return true; } } }
@SuppressWarnings("unchecked") private static <S extends AstNode<S>> S setTextIntern( ArrayList<S> list, int index, AstStringNode<S> text) { if (text.getContent().isEmpty()) { return list.remove(index); } else { if (index > 0 && !text.hasAttributes()) { S prev = list.get(index - 1); if (prev.getNodeType() == AstNode.NT_TEXT && !prev.hasAttributes()) { try { list.set(index - 1, (S) mergeTextNodes((AstStringNode<S>) prev, text)); return list.remove(index); } catch (CloneNotSupportedException e) { // Just set, don't merge } } } return list.set(index, (S) text); } }