本文整理汇总了Java中org.eclipse.jface.text.link.LinkedModeUI.getSelectedRegion方法的典型用法代码示例。如果您正苦于以下问题:Java LinkedModeUI.getSelectedRegion方法的具体用法?Java LinkedModeUI.getSelectedRegion怎么用?Java LinkedModeUI.getSelectedRegion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.link.LinkedModeUI
的用法示例。
在下文中一共展示了LinkedModeUI.getSelectedRegion方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import org.eclipse.jface.text.link.LinkedModeUI; //导入方法依赖的package包/类
@Override
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
apply(viewer.getDocument());
try {
LinkedModeModel model = new LinkedModeModel();
StringBuffer insert = new StringBuffer();
insert.append(macro.name);
insert.append("(");
int parameterOffset = position.offset + insert.length();
for (int k = 0; k < macro.parameters.length; k++) {
LinkedPositionGroup group = new LinkedPositionGroup();
if (k > 0)
// space between parameters
parameterOffset++;
group.addPosition(new LinkedPosition(viewer.getDocument(), parameterOffset, macro.parameters[k].length(),
LinkedPositionGroup.NO_STOP));
model.addGroup(group);
parameterOffset += macro.parameters[k].length();
}
model.forceInstall();
LinkedModeUI ui = new EditorLinkedModeUI(model, viewer);
ui.setExitPosition(viewer, parameterOffset + 1, 0, Integer.MAX_VALUE);
ui.setCyclingMode(LinkedModeUI.CYCLE_ALWAYS);
ui.enter();
fSelectedRegion = ui.getSelectedRegion();
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: apply
import org.eclipse.jface.text.link.LinkedModeUI; //导入方法依赖的package包/类
@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) {
try {
LinkedModeModel model= new LinkedModeModel();
for (int i= 0; i != fArgumentOffsets.length; i++) {
LinkedPositionGroup group= new LinkedPositionGroup();
group.addPosition(new LinkedPosition(document, baseOffset + fArgumentOffsets[i], fArgumentLengths[i], LinkedPositionGroup.NO_STOP));
model.addGroup(group);
}
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= ui.getSelectedRegion();
} catch (BadLocationException e) {
JavaPlugin.log(e);
openErrorDialog(e);
}
} else {
fSelectedRegion= new Region(baseOffset + replacement.length(), 0);
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:39,代码来源:FilledArgumentNamesMethodProposal.java
示例3: getLinkedPositions
import org.eclipse.jface.text.link.LinkedModeUI; //导入方法依赖的package包/类
/**
* Sets up linked positions and installs them on the viewer.
*
*/
protected void getLinkedPositions(ITextViewer viewer) {
final String replacement = getReplacementString();
final IDocument document = viewer.getDocument();
final int length = replacement.length();
boolean inAttribute = false, hasGroup = false;
int offset = 0;
char attType = 0;
int exitPosition = -1;
LinkedModeModel model = new LinkedModeModel();
try {
for (int i = 0; i < length; i++) {
final char c = replacement.charAt(i);
switch (c) {
case '=':
break;
case '\'':
case '\"':
if (!inAttribute) {
offset = i;
attType = c;
inAttribute = true;
} else {
// Found matching quotes establishing an attribute value
// region
if (attType == c && replacement.charAt(i - 1) != '\\') {
inAttribute = false; // Record position length
addPosition(model, document, getReplacementOffset()
+ offset + 1, i - offset - 1);
hasGroup = true;
}
}
break;
case '>':
if (!inAttribute && exitPosition == -1) {
exitPosition = getReplacementOffset() + i + 1;
}
break;
}
}
if (hasGroup) {
model.forceInstall();
final LinkedModeUI ui = new EditorLinkedModeUI(model, viewer);
ui.setExitPosition(viewer,
exitPosition < 0 ? getReplacementOffset()
+ getReplacementLength() + replacement.length()
- 1 : exitPosition, 0, Integer.MAX_VALUE);
ui.setCyclingMode(LinkedModeUI.CYCLE_WHEN_NO_PARENT);
ui.setDoContextInfo(true);
ui.enter();
fSelectedRegion = ui.getSelectedRegion();
}
} catch (BadLocationException e) {
Logger.logException(e);
}
}
示例4: apply
import org.eclipse.jface.text.link.LinkedModeUI; //导入方法依赖的package包/类
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();
LinkedPositionGroup group= new LinkedPositionGroup();
for (int i= 0; i < sameNodes.length; i++) {
ASTNode elem= sameNodes[i];
group.addPosition(new LinkedPosition(document, elem.getStartPosition(), elem.getLength(), i));
}
LinkedModeModel model= new LinkedModeModel();
model.addGroup(group);
model.forceInstall();
if (fContext instanceof AssistContext) {
IEditorPart editor= ((AssistContext)fContext).getEditor();
if (editor instanceof JavaEditor) {
model.addLinkingListener(new EditorHighlightingSynchronizer((JavaEditor) editor));
}
}
LinkedModeUI ui= new EditorLinkedModeUI(model, viewer);
ui.setExitPolicy(new DeleteBlockingExitPolicy(document));
ui.setExitPosition(viewer, offset, 0, LinkedPositionGroup.NO_STOP);
ui.enter();
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);
}
}