public PositionRef createPositionRef(int offset, Bias bias) { assert locked.get(); return editor.createPositionRef(offset, bias); } }
/** * @return PositionBounds representing the beginning of the file associated * with the <code>dataObject</code>. */ private PositionBounds getDefaultPositionBounds(){ PositionRef start = editorSupport.createPositionRef(0, Bias.Forward); PositionRef end = editorSupport.createPositionRef(0, Bias.Backward); return new PositionBounds(start, end); }
public static ModificationResult.Difference rename(int startOffset, int endOffset, CloneableEditorSupport ces, String oldName, String newName, String descr) { assert oldName != null; assert newName != null; PositionRef startPos = ces.createPositionRef(startOffset, Position.Bias.Forward); PositionRef endPos = ces.createPositionRef(endOffset, Position.Bias.Backward); ModificationResult.Difference diff = new ModificationResult.Difference(ModificationResult.Difference.Kind.CHANGE, startPos, endPos, oldName, newName, descr); return diff; }
private static PositionBounds createPositionBounds(DataObject dao, int start, int end) { CloneableEditorSupport ces = CsmUtilities.findCloneableEditorSupport(dao); if (ces != null) { PositionRef posBeg = ces.createPositionRef(start, Position.Bias.Forward); PositionRef posEnd = ces.createPositionRef(end, Position.Bias.Backward); return new PositionBounds(posBeg, posEnd); } return null; }
public static PositionBounds createPositionBounds(CsmOffsetable csmObj) { if (csmObj == null) { return null; } CloneableEditorSupport ces = findCloneableEditorSupport(csmObj.getContainingFile()); if (ces != null) { PositionRef beg = ces.createPositionRef(csmObj.getStartOffset(), Position.Bias.Forward); PositionRef end = ces.createPositionRef(csmObj.getEndOffset(), Position.Bias.Backward); return new PositionBounds(beg, end); } return null; }
/** *@return PositionBounds representing the position of the name of the entity that is being * refactored or PostionBounds representing the start of the file if the position * of the entity could not be resolved. */ public PositionBounds getPositionBounds(){ if (elementName != null){ try { BaseDocument doc = getDocument(); String text = doc.getText(0, doc.getLength()); int offset = text.indexOf(elementName); if (offset > -1){ PositionRef start = editorSupport.createPositionRef(offset, Bias.Forward); PositionRef end = editorSupport.createPositionRef(offset + elementName.length(), Bias.Backward); return new PositionBounds(start, end); } } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } return getDefaultPositionBounds(); }
public void run() { synchronized (editor.getLock()) { /* editor.getLock(): fixes deadlock - this lock is acquired later anyhow, so we are changing the order in which the locks are acquired */ try { // [MaM] remember doclen to compute new length // of the inserted string (the length changes // because insertString removes \r characters // from it) int docLen = doc.getLength(); int p1 = end.getOffset(); doc.insertString (p1, text, null); int p2 = p1 + doc.getLength() - docLen; end = editor.createPositionRef(p1, end.getPositionBias()); PositionRef posBegin = editor.createPositionRef(p1, Position.Bias.Forward); PositionRef posEnd = editor.createPositionRef(p2, Position.Bias.Backward); hold[1] = new PositionBounds(posBegin, posEnd); } catch (BadLocationException e) { hold[0] = e; } } } };
public static WhereUsedElement create(CloneableEditorSupport ces, FileObject fo, String name, String html, OffsetRange range, Icon icon) { int start = range.getStart(); int end = range.getEnd(); PositionRef ref1 = ces.createPositionRef(start, Bias.Forward); PositionRef ref2 = ces.createPositionRef(end, Bias.Forward); PositionBounds bounds = new PositionBounds(ref1, ref2); return new WhereUsedElement(bounds, html, fo, name, new OffsetRange(start, end), icon); } }
if (startOffset == -1) { bgn = editor.createPositionRef(0, Bias.Forward); end = editor.createPositionRef(0, Bias.Backward); } else { bgn = editor.createPositionRef(startOffset, Bias.Forward); end = editor.createPositionRef(endOffset, Bias.Backward);
public void run() { synchronized (editor.getLock()) { /* editor.getLock(): fixes deadlock - this lock is acquired later anyhow, so we are changing the order in which the locks are acquired */ try { // [MaM] remember doclen to compute new length // of the inserted string (the length changes // because insertString removes \r characters // from it) int docLen = doc.getLength(); int p1 = end.getOffset(); doc.insertString(p1, text, null); int p2 = (p1 + doc.getLength()) - docLen; end = editor.createPositionRef(p1, end.getPositionBias()); PositionRef posBegin = editor.createPositionRef(p1, Position.Bias.Forward); PositionRef posEnd = editor.createPositionRef(p2, Position.Bias.Backward); hold[1] = new PositionBounds(posBegin, posEnd); } catch (BadLocationException e) { hold[0] = e; } } } };
public void run() { synchronized (editor.getLock()) { /* editor.getLock(): fixes deadlock - this lock is acquired later anyhow, so we are changing the order in which the locks are acquired */ try { // [MaM] remember doclen to compute new length // of the inserted string (the length changes // because insertString removes \r characters // from it) int docLen = doc.getLength(); int p1 = end.getOffset(); doc.insertString (p1, text, null); int p2 = p1 + doc.getLength() - docLen; end = editor.createPositionRef(p1, end.getPositionBias()); PositionRef posBegin = editor.createPositionRef(p1, Position.Bias.Forward); PositionRef posEnd = editor.createPositionRef(p2, Position.Bias.Backward); hold[1] = new PositionBounds(posBegin, posEnd); } catch (BadLocationException e) { hold[0] = e; } } } };
private void refactorElements(ModificationResult modificationResult, RefactoringElementContext context, Collection<RefactoringElement> elementsToRename, String renameMsg) throws IOException, ParseException { Map<FileObject, List<Difference>> file2diffs = new HashMap<>(); for (RefactoringElement re : elementsToRename) { CloneableEditorSupport editor = GsfUtilities.findCloneableEditorSupport(re.getFile()); Difference diff = new Difference(Difference.Kind.CHANGE, editor.createPositionRef(re.getRange().getStart(), Bias.Forward), editor.createPositionRef(re.getRange().getEnd(), Bias.Backward), re.getName(), refactoring.getNewName(), renameMsg); List<Difference> diffs = file2diffs.get(re.getFile()); if (diffs == null) { diffs = new ArrayList<>(); file2diffs.put(re.getFile(), diffs); } diffs.add(diff); } for (Entry<FileObject, List<Difference>> entry : file2diffs.entrySet()) { modificationResult.addDifferences(entry.getKey(), entry.getValue()); } } }
ces = RetoucheUtils.findCloneableEditorSupport(workingCopy); PositionRef startPos = ces.createPositionRef(start, Bias.Forward); PositionRef endPos = ces.createPositionRef(end, Bias.Forward); String desc = getString("ChangeComment"); Difference diff = new Difference(Difference.Kind.CHANGE, startPos, endPos, oldName, newName, desc);
public static WhereUsedElement create(JsParseResult info, String name, String html, OffsetRange range, Icon icon) { int start = range.getStart(); int end = range.getEnd(); CloneableEditorSupport ces = RetoucheUtils.findCloneableEditorSupport(info); PositionRef ref1 = ces.createPositionRef(start, Bias.Forward); PositionRef ref2 = ces.createPositionRef(end, Bias.Forward); PositionBounds bounds = new PositionBounds(ref1, ref2); return new WhereUsedElement(bounds, html, info.getSnapshot().getSource().getFileObject(), name, new OffsetRange(start, end), icon); } }
PositionRef ref1 = ces.createPositionRef(start, Bias.Forward); PositionRef ref2 = ces.createPositionRef(end, Bias.Forward); PositionBounds bounds = new PositionBounds(ref1, ref2);
PositionRef ref1 = ces.createPositionRef(start, Bias.Forward); PositionRef ref2 = ces.createPositionRef(end, Bias.Forward); PositionBounds bounds = new PositionBounds(ref1, ref2);
begin = editor.createPositionRef(p1, begin.getPositionBias()); end = editor.createPositionRef(p1 + len, end.getPositionBias());
doc.remove(p1 + len, p2 - p1); if (begin.getOffset() != p1) begin = editor.createPositionRef(p1, begin.getPositionBias()); if (end.getOffset() - p1 != len) end = editor.createPositionRef(p1 + len, end.getPositionBias());
doc.remove(p1 + len, p2 - p1); if (begin.getOffset() != p1) begin = editor.createPositionRef(p1, begin.getPositionBias()); if (end.getOffset() - p1 != len) end = editor.createPositionRef(p1 + len, end.getPositionBias());
PositionRef startPos = ces.createPositionRef(start, Bias.Forward); PositionRef endPos = ces.createPositionRef(end, Bias.Forward); Difference diff = new Difference(Difference.Kind.CHANGE, startPos, endPos, "", "", desc); // NOI18N diffs.add(diff);