public void skipThrough(char[] in, int pos) throws IOException, BadLocationException { String origText = new String(in, offset, pos - offset); org.netbeans.api.java.source.ModificationResult.Difference diff = diffs.size() > 0 ? diffs.get(diffs.size() - 1) : null; if (diff != null && diff.getKind() == org.netbeans.api.java.source.ModificationResult.Difference.Kind.INSERT && diff.getStartPosition().getOffset() == offset) { diffs.remove(diffs.size() - 1); diffs.add(JavaSourceAccessor.getINSTANCE().createDifference(ModificationResult.Difference.Kind.CHANGE, diff.getStartPosition(), diff.getEndPosition(), origText, diff.getNewText(), diff.getDescription(), src)); } else { int off = converter != null ? converter.getOriginalPosition(offset) : offset; if (off >= 0) { diffs.add(JavaSourceAccessor.getINSTANCE().createDifference(ModificationResult.Difference.Kind.REMOVE, prp.createPosition(off, Bias.Forward), prp.createPosition(off + origText.length(), Bias.Backward), origText, null, userInfo.get(offset), src)); } } offset = pos; }
public void writeTo(String s) throws IOException, BadLocationException { ModificationResult.Difference diff = diffs.size() > 0 ? diffs.get(diffs.size() - 1) : null; if (diff != null && diff.getKind() == ModificationResult.Difference.Kind.REMOVE && diff.getEndPosition().getOffset() == offset) { diffs.remove(diffs.size() - 1); diffs.add(JavaSourceAccessor.getINSTANCE().createDifference(ModificationResult.Difference.Kind.CHANGE, diff.getStartPosition(), diff.getEndPosition(), diff.getOldText(), s, diff.getDescription(), src)); } else { int off = converter != null ? converter.getOriginalPosition(offset) : offset; if (off >= 0) { diffs.add(JavaSourceAccessor.getINSTANCE().createDifference(ModificationResult.Difference.Kind.INSERT, prp.createPosition(off, Bias.Forward), prp.createPosition(off, Bias.Backward), null, s, userInfo.get(offset), src)); } } }
public @NonNull PositionRef getEndPosition() { return (PositionRef)this.inst.getEndPosition(); }
/** * Factory method for DiffElement * @param diff diff instance corresponding to thid Element * @param fileObject fileObject corresponding to this Element * @param modification * @return ModificationResult corresponding to this change */ public static DiffElement create(Difference diff, FileObject fileObject, ModificationResult modification) { PositionRef start = diff.getStartPosition(); PositionRef end = diff.getEndPosition(); PositionBounds bounds = new PositionBounds(start, end); return new DiffElement(diff, bounds, fileObject, modification); } }