use of org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedModeModelImpl in project che by eclipse.
the class LinkedCorrectionProposal method performChange.
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.text.correction.ChangeCorrectionProposal#performChange(org.eclipse.jface.text.IDocument, org.eclipse.ui.IEditorPart)
*/
@Override
protected void performChange(/*IEditorPart part,*/
IDocument document) throws CoreException {
// try {
super.performChange(/*part,*/
document);
//
if (fLinkedProposalModel != null) {
if (fLinkedProposalModel.hasLinkedPositions()) {
// enter linked mode
// ITextViewer viewer= ((JavaEditor) part).getViewer();
// new LinkedProposalModelPresenter().enterLinkedMode(viewer, part, didOpenEditor(), fLinkedProposalModel);
boolean added = false;
LinkedModeModelImpl model = new LinkedModeModelImpl();
Iterator<LinkedProposalPositionGroup> iterator = fLinkedProposalModel.getPositionGroupIterator();
while (iterator.hasNext()) {
LinkedProposalPositionGroup curr = iterator.next();
LinkedPositionGroupImpl group = new LinkedPositionGroupImpl();
LinkedProposalPositionGroup.PositionInformation[] positions = curr.getPositions();
if (positions.length > 0) {
LinkedProposalPositionGroup.Proposal[] linkedModeProposals = curr.getProposals();
if (linkedModeProposals.length <= 1) {
for (int i = 0; i < positions.length; i++) {
LinkedProposalPositionGroup.PositionInformation pos = positions[i];
if (pos.getOffset() != -1) {
RegionImpl position = new RegionImpl();
position.setOffset(pos.getOffset());
position.setLength(pos.getLength());
// group.addPositions(
// new LinkedPosition(document, pos.getOffset(), pos.getLength(), pos.getSequenceRank()));
group.addPositions(position);
}
}
} else {
// LinkedPositionProposalImpl[] proposalImpls= new LinkedPositionProposalImpl[linkedModeProposals.length];
LinkedDataImpl data = new LinkedDataImpl();
for (int i = 0; i < linkedModeProposals.length; i++) {
// proposalImpls[i] = new LinkedPositionProposalImpl(linkedModeProposals[i], model);
data.addValues(linkedModeProposals[i].getDisplayString());
}
group.setData(data);
for (int i = 0; i < positions.length; i++) {
LinkedProposalPositionGroup.PositionInformation pos = positions[i];
if (pos.getOffset() != -1) {
// group.addPosition(
// new ProposalPosition(document, pos.getOffset(), pos.getLength(), pos.getSequenceRank(),
// proposalImpls));
RegionImpl position = new RegionImpl();
position.setOffset(pos.getOffset());
position.setLength(pos.getLength());
group.addPositions(position);
}
}
}
model.addGroups(group);
added = true;
}
}
if (added) {
LinkedProposalPositionGroup.PositionInformation endPosition = fLinkedProposalModel.getEndPosition();
if (endPosition != null && endPosition.getOffset() != -1) {
model.setEscapePosition(endPosition.getOffset() + endPosition.getLength());
}
this.linkedModel = model;
}
}
// else if (part instanceof ITextEditor) {
// LinkedProposalPositionGroup.PositionInformation endPosition= fLinkedProposalModel.getEndPosition();
// if (endPosition != null) {
// // select a result
// int pos= endPosition.getOffset() + endPosition.getLength();
// ((ITextEditor) part).selectAndReveal(pos, 0);
// }
// }
}
// } catch (BadLocationException e) {
// throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e));
// }
}
use of org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedModeModelImpl in project che by eclipse.
the class LinkedNamesAssistProposal method apply.
/* (non-Javadoc)
* @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer, char, int, int)
*/
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
try {
Point seletion = viewer.getSelectedRange();
// get full ast
CompilationUnit root = SharedASTProvider.getAST(fContext.getCompilationUnit(), SharedASTProvider.WAIT_YES, null);
ASTNode nameNode = NodeFinder.perform(root, fNode.getStartPosition(), fNode.getLength());
final int pos = fNode.getStartPosition();
ASTNode[] sameNodes;
if (nameNode instanceof SimpleName) {
sameNodes = LinkedNodeFinder.findByNode(root, (SimpleName) nameNode);
} else {
sameNodes = new ASTNode[] { nameNode };
}
// sort for iteration order, starting with the node @ offset
Arrays.sort(sameNodes, new Comparator<ASTNode>() {
public int compare(ASTNode o1, ASTNode o2) {
return rank(o1) - rank(o2);
}
/**
* Returns the absolute rank of an <code>ASTNode</code>. Nodes
* preceding <code>offset</code> are ranked last.
*
* @param node the node to compute the rank for
* @return the rank of the node with respect to the invocation offset
*/
private int rank(ASTNode node) {
int relativeRank = node.getStartPosition() + node.getLength() - pos;
if (relativeRank < 0)
return Integer.MAX_VALUE + relativeRank;
else
return relativeRank;
}
});
IDocument document = viewer.getDocument();
LinkedPositionGroupImpl group = new LinkedPositionGroupImpl();
for (int i = 0; i < sameNodes.length; i++) {
ASTNode elem = sameNodes[i];
RegionImpl region = new RegionImpl();
region.setOffset(elem.getStartPosition());
region.setLength(elem.getLength());
group.addPositions(region);
// group.addPosition(new LinkedPosition(document, elem.getStartPosition(), elem.getLength(), i));
}
LinkedModeModelImpl model = new LinkedModeModelImpl();
model.addGroups(group);
// model.forceInstall();
model.setEscapePosition(offset);
this.linkedModel = model;
if (fContext instanceof AssistContext) {
// IEditorPart editor = ((AssistContext)fContext).getEditor();
// if (editor instanceof JavaEditor) {
// model.addLinkingListener(new EditorHighlightingSynchronizer((JavaEditor)editor));
// }
}
if (fValueSuggestion != null) {
document.replace(nameNode.getStartPosition(), nameNode.getLength(), fValueSuggestion);
// IRegion selectedRegion = ui.getSelectedRegion();
// seletion = new Point(selectedRegion.getOffset(), fValueSuggestion.length());
}
// viewer.setSelectedRange(seletion.x, seletion.y); // by default full word is selected, restore original selection
} catch (BadLocationException e) {
JavaPlugin.log(e);
}
}
use of org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedModeModelImpl in project che by eclipse.
the class RenameLinkedModeRefactoringSession method getModel.
public LinkedModeModel getModel() {
CompilationUnit root = SharedASTProvider.getAST(compilationUnit, SharedASTProvider.WAIT_YES, null);
LinkedPositionGroupImpl group = new LinkedPositionGroupImpl();
ASTNode selectedNode = NodeFinder.perform(root, offset, 0);
if (!(selectedNode instanceof SimpleName)) {
return null;
}
SimpleName nameNode = (SimpleName) selectedNode;
fOriginalName = nameNode.getIdentifier();
final int pos = nameNode.getStartPosition();
ASTNode[] sameNodes = LinkedNodeFinder.findByNode(root, nameNode);
//TODO: copied from LinkedNamesAssistProposal#apply(..):
// sort for iteration order, starting with the node @ offset
Arrays.sort(sameNodes, new Comparator<ASTNode>() {
public int compare(ASTNode o1, ASTNode o2) {
return rank(o1) - rank(o2);
}
/**
* Returns the absolute rank of an <code>ASTNode</code>. Nodes
* preceding <code>pos</code> are ranked last.
*
* @param node the node to compute the rank for
* @return the rank of the node with respect to the invocation offset
*/
private int rank(ASTNode node) {
int relativeRank = node.getStartPosition() + node.getLength() - pos;
if (relativeRank < 0)
return Integer.MAX_VALUE + relativeRank;
else
return relativeRank;
}
});
for (int i = 0; i < sameNodes.length; i++) {
ASTNode elem = sameNodes[i];
RegionImpl position = new RegionImpl();
position.setOffset(elem.getStartPosition());
position.setLength(elem.getLength());
group.addPositions(position);
}
LinkedModeModelImpl model = new LinkedModeModelImpl();
model.addGroups(group);
return model;
}
use of org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedModeModelImpl in project che by eclipse.
the class FilledArgumentNamesMethodProposal method apply.
/*
* @see ICompletionProposalExtension#apply(IDocument, char)
*/
@Override
public void apply(IDocument document, char trigger, int offset) {
super.apply(document, trigger, offset);
int baseOffset = getReplacementOffset();
String replacement = getReplacementString();
if (fArgumentOffsets != null && getTextViewer() != null) {
LinkedModeModelImpl model = new LinkedModeModelImpl();
for (int i = 0; i != fArgumentOffsets.length; i++) {
LinkedPositionGroupImpl group = new LinkedPositionGroupImpl();
RegionImpl region = new RegionImpl();
region.setLength(fArgumentLengths[i]);
region.setOffset(baseOffset + fArgumentOffsets[i]);
group.addPositions(region);
model.addGroups(group);
}
model.setEscapePosition(baseOffset + replacement.length());
this.linkedModel = model;
// model.forceInstall();
// JavaEditor editor = getJavaEditor();
// if (editor != null) {
// model.addLinkingListener(new EditorHighlightingSynchronizer(editor));
// }
//
// LinkedModeUI ui = new EditorLinkedModeUI(model, getTextViewer());
// ui.setExitPosition(getTextViewer(), baseOffset + replacement.length(), 0, Integer.MAX_VALUE);
// ui.setExitPolicy(new ExitPolicy(')', document));
// ui.setDoContextInfo(true);
// ui.setCyclingMode(LinkedModeUI.CYCLE_WHEN_NO_PARENT);
// ui.enter();
fSelectedRegion = new Region(baseOffset + replacement.length(), 0);
} else {
fSelectedRegion = new Region(baseOffset + replacement.length(), 0);
}
}
use of org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedModeModelImpl in project che by eclipse.
the class LazyGenericTypeProposal method installLinkedMode.
private void installLinkedMode(final IDocument document, int[] offsets, int[] lengths, TypeArgumentProposal[] typeArgumentProposals, boolean withParentheses, final boolean onlyAppendArguments) {
int replacementOffset = getReplacementOffset();
String replacementString = getReplacementString();
try {
LinkedModeModelImpl model = new LinkedModeModelImpl();
for (int i = 0; i != offsets.length; i++) {
if (typeArgumentProposals[i].isAmbiguous()) {
LinkedPositionGroupImpl group = new LinkedPositionGroupImpl();
RegionImpl region = new RegionImpl();
region.setOffset(replacementOffset + offsets[i]);
region.setLength(lengths[i]);
group.addPositions(region);
model.addGroups(group);
}
}
if (withParentheses) {
LinkedPositionGroupImpl group = new LinkedPositionGroupImpl();
RegionImpl region = new RegionImpl();
region.setOffset(replacementOffset + getCursorPosition());
region.setLength(0);
group.addPositions(region);
model.addGroups(group);
}
model.setEscapePosition(replacementOffset + replacementString.length());
this.linkedModel = model;
if (!onlyAppendArguments && (document instanceof IDocumentExtension)) {
// see bug 301990
FormatterPrefs prefs = getFormatterPrefs();
final Position firstBracketPosition;
final Position secondBracketPosition;
int firstBracketOffset = replacementOffset + offsets[0] - 1;
if (prefs.afterOpeningBracket) {
firstBracketOffset--;
}
firstBracketPosition = new Position(firstBracketOffset, 1);
document.addPosition(firstBracketPosition);
int secondBracketOffset = replacementOffset + offsets[offsets.length - 1] + lengths[offsets.length - 1] + 1;
if (prefs.beforeClosingBracket) {
secondBracketOffset++;
}
secondBracketPosition = new Position(secondBracketOffset, 0);
document.addPosition(secondBracketPosition);
// model.addLinkingListener(new ILinkedModeListener() {
// public void left(LinkedModeModel environment, int flags) {
// try {
// if (getTextViewer().getSelectedRange().y > 1 || flags != ILinkedModeListener.EXTERNAL_MODIFICATION)
// return;
// ((IDocumentExtension) document).registerPostNotificationReplace(null, new IDocumentExtension.IReplace() {
// public void perform(IDocument d, IDocumentListener owner) {
// try {
// if ((firstBracketPosition.length == 0 || firstBracketPosition.isDeleted) && !secondBracketPosition.isDeleted) {
// d.replace(firstBracketPosition.offset, secondBracketPosition.offset - firstBracketPosition.offset, ""); //$NON-NLS-1$
// }
// } catch (BadLocationException e) {
// JavaPlugin.log(e);
// }
// }
// });
// } finally {
// document.removePosition(firstBracketPosition);
// document.removePosition(secondBracketPosition);
// }
// }
//
// public void suspend(LinkedModeModel environment) {
// }
//
// public void resume(LinkedModeModel environment, int flags) {
// }
// });
}
// LinkedModeUI ui= new EditorLinkedModeUI(model, getTextViewer());
// ui.setExitPolicy(new ExitPolicy(withParentheses ? ')' : '>', document));
// ui.setExitPosition(getTextViewer(), replacementOffset + replacementString.length(), 0, Integer.MAX_VALUE);
// ui.setDoContextInfo(true);
// ui.enter();
//ui.getSelectedRegion();
fSelectedRegion = new Region(replacementOffset + replacementString.length(), 0);
} catch (BadLocationException e) {
JavaPlugin.log(e);
openErrorDialog(e);
}
}
Aggregations