本文整理汇总了Java中org.eclipse.jface.text.ITextSelection.getLength方法的典型用法代码示例。如果您正苦于以下问题:Java ITextSelection.getLength方法的具体用法?Java ITextSelection.getLength怎么用?Java ITextSelection.getLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.ITextSelection
的用法示例。
在下文中一共展示了ITextSelection.getLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHoverRegion
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
IDocument document = textViewer.getDocument();
/* Vérifie qu'on est dans une String de KSP */
boolean isSqlString = DocumentUtils.isContentType(document, offset, KspRegionType.STRING);
if (!isSqlString) {
return null;
}
/* Extrait le mot courant. */
ITextSelection selection = new TextSelection(document, offset, 0);
ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, WordSelectionType.SNAKE_CASE);
if (currentWordSelection == null) {
return null;
}
String currentWord = currentWordSelection.getText();
if (currentWord == null) {
return null;
}
/* Renvoie la région du mot. */
return new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
}
示例2: buildProposals
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
/**
* Constuit les propositions d'aucomplétion.
*
* @param suggestions Suggestionsà proposer.
* @param currentWordSelection Mot courant à remplacer dans le document.
* @return Propositions d'autocomplétion.
*/
private ICompletionProposal[] buildProposals(List<CompletionCandidate> suggestions, ITextSelection currentWordSelection) {
/* Calcul l'offset et la longueur du mot à remplacer dans le document. */
int replacementLength = currentWordSelection.getLength();
int replacementOffset = currentWordSelection.getOffset();
/* Construit les propositions en parcourant les suggestions. */
List<ICompletionProposal> proposals = new ArrayList<>();
for (CompletionCandidate suggestion : suggestions) {
/* String qui remplacera le mot courant. */
String replacementString = suggestion.getDisplayString();
/* String affiché comme libellé de la proposition. */
String displayString = replacementString;
/* String affiché comme description de la proposition (dans la boîte jaune). */
String additionalProposalInfo = suggestion.getAdditionalProposalInfo();
CompletionProposal proposal = new CompletionProposal(replacementString, replacementOffset, replacementLength, replacementString.length(), null,
displayString, null, additionalProposalInfo);
proposals.add(proposal);
}
return proposals.toArray(new ICompletionProposal[0]);
}
示例3: getCandidates
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
@Override
protected List<CompletionCandidate> getCandidates(ITextSelection currentWordSelection) {
List<CompletionCandidate> list = new ArrayList<>();
/* Trouve la déclaration contenant le nom de paramètre. */
IFile file = UiUtils.getCurrentEditorFile();
FileRegion fileRegion = new FileRegion(file, currentWordSelection.getOffset(), currentWordSelection.getLength());
KspDeclaration declaration = KspManager.getInstance().findDeclarationAt(fileRegion);
if (declaration == null) {
return list;
}
/* Construit les candidats */
for (KspAttribute attribute : declaration.getAttributes()) {
handleAttribute(attribute, list);
}
/* Tri par libellé. */
list.sort((o1, o2) -> o1.getDisplayString().compareTo(o2.getDisplayString()));
return list;
}
示例4: findMarkersInSelection
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
/**
* @param resource
* @param selection
* @returns list of markers which are found by selection
*/
public static ArrayList<IMarker> findMarkersInSelection(final IResource resource,
final ITextSelection selection) {
final ArrayList<IMarker> markerListInArea = new ArrayList<>();
final ArrayList<IMarker> markerList = MarkerFactory.findMarkersAsArrayList(resource);
if (markerList.isEmpty()) {
return null;
}
final int textStart = selection.getOffset();
final int textEnd = textStart + selection.getLength();
for (final IMarker iMarker : markerList) {
final int markerStart = MarkUtilities.getStart(iMarker);
final int markerEnd = MarkUtilities.getEnd(iMarker);
if (textStart >= markerStart && textStart <= markerEnd
|| textEnd >= markerStart && textEnd <= markerEnd
|| markerStart >= textStart && markerStart <= textEnd
|| markerEnd >= textStart && markerEnd <= textEnd) {
markerListInArea.add(iMarker);
}
}
return markerListInArea;
}
示例5: reveal
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
/**
* Reveals the specified ranges in this text editor.
*
* @param offset the offset of the revealed range
* @param len the length of the revealed range
*/
protected void reveal(int offset, int len) {
if (viewer == null) return;
ISelection sel = getSelectionProvider().getSelection();
if (sel instanceof ITextSelection) {
ITextSelection tsel = (ITextSelection) sel;
if (tsel.getOffset() != 0 || tsel.getLength() != 0) markInNavigationHistory();
}
StyledText widget = viewer.getTextWidget();
widget.setRedraw(false);
setHighlightRange(offset, len, false);
viewer.revealRange(offset, len);
markInNavigationHistory();
widget.setRedraw(true);
}
示例6: selectionChanged
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection instanceof ITextSelection) {
ITextSelection textsel = (ITextSelection) selection;
if (event.getSelectionProvider() instanceof ITextViewer) {
IDocument doc = ((ITextViewer) event.getSelectionProvider()).getDocument();
if (doc != null) {
int offset = textsel.getOffset();
int length = textsel.getLength();
if (offset >= 0 && length >= 0) {
LinkedPosition find = new LinkedPosition(doc, offset, length, LinkedPositionGroup.NO_STOP);
LinkedPosition pos = fModel.findPosition(find);
if (pos == null && fExitPosition != null && fExitPosition.includes(find))
pos = fExitPosition;
if (pos != null)
switchPosition(pos, false, false);
}
}
}
}
}
示例7: getTextBlockFromSelection
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
/**
* Creates a region describing the text block (something that starts at
* the beginning of a line) completely containing the current selection.
*
* @param selection The selection to use
* @param document The document
* @return the region describing the text block comprising the given selection
*/
private IRegion getTextBlockFromSelection(ITextSelection selection, IDocument document)
{
try
{
IRegion line = document.getLineInformationOfOffset(selection.getOffset());
int length = selection.getLength() == 0 ? line.getLength() : selection.getLength()
+ (selection.getOffset() - line.getOffset());
return new Region(line.getOffset(), length);
} catch (BadLocationException x)
{
// should not happen
// TODO
}
return null;
}
示例8: execute
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
public Object execute(ExecutionEvent event) throws ExecutionException {
XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event);
if (xtextEditor != null) {
ITextSelection selection = (ITextSelection) xtextEditor.getSelectionProvider().getSelection();
IRegion region = new Region(selection.getOffset(), selection.getLength());
ISourceViewer internalSourceViewer = xtextEditor.getInternalSourceViewer();
IHyperlink[] hyperlinks = getDetector().detectHyperlinks(internalSourceViewer, region, false);
if (hyperlinks != null && hyperlinks.length > 0) {
IHyperlink hyperlink = hyperlinks[0];
hyperlink.open();
}
}
return null;
}
示例9: getEnclosingJsniRegion
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
public static ITypedRegion getEnclosingJsniRegion(ITextSelection selection,
IDocument document) {
try {
ITypedRegion region = TextUtilities.getPartition(document,
GWTPartitions.GWT_PARTITIONING, selection.getOffset(), false);
if (region.getType().equals(GWTPartitions.JSNI_METHOD)) {
int regionEnd = region.getOffset() + region.getLength();
int selectionEnd = selection.getOffset() + selection.getLength();
// JSNI region should entirely contain the selection
if (region.getOffset() <= selection.getOffset()
&& regionEnd >= selectionEnd) {
return region;
}
}
} catch (BadLocationException e) {
GWTPluginLog.logError(e);
}
return null;
}
示例10: getTextBlockFromSelection
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
/**
* Creates a region describing the text block (something that starts at the
* beginning of a line) completely containing the current selection.
*
* @param selection
* The selection to use
* @param document
* The document
* @return the region describing the text block comprising the given
* selection
*/
private IRegion getTextBlockFromSelection(ITextSelection selection, IDocument document)
{
try
{
IRegion line = document.getLineInformationOfOffset(selection.getOffset());
int length = selection.getLength() == 0 ? line.getLength() : selection.getLength() + (selection.getOffset() - line.getOffset());
return new Region(line.getOffset(), length);
}
catch (BadLocationException x)
{
// should not happen
// JavaPlugin.log(x);
}
return null;
}
示例11: computeCompletionProposals
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
int offset) {
ITextSelection selection = (ITextSelection) viewer
.getSelectionProvider().getSelection();
// adjust offset to end of normalized selection
if (selection.getOffset() == offset) {
offset = selection.getOffset() + selection.getLength();
}
String prefix = extractPrefix(viewer, offset);
Region region = new Region(offset - prefix.length(), prefix.length());
TemplateContext context = createContext(viewer, region);
if (context == null) {
return new ICompletionProposal[0];
}
context.setVariable("selection", selection.getText()); // name of the selection variables {line, word_selection //$NON-NLS-1$
Template[] templates = getTemplates(context.getContextType().getId());
List<ICompletionProposal> matches = new ArrayList<>();
for (Template template : templates) {
try {
context.getContextType().validate(template.getPattern());
} catch (TemplateException e) {
continue;
}
if (!prefix.equals("") && prefix.charAt(0) == '<') { //$NON-NLS-1$
prefix = prefix.substring(1);
}
if (!prefix.equals("") //$NON-NLS-1$
&& (template.getName().startsWith(prefix) && template
.matches(prefix, context.getContextType().getId()))) {
matches.add(createProposal(template, context, (IRegion) region,
getRelevance(template, prefix)));
}
}
return matches.toArray(new ICompletionProposal[matches.size()]);
}
示例12: isExactKspString
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
/**
* Indique si une sélection d'un document représente exactement une région de string (aux double quote près).
*
* @param document Document.
* @param selection Sélection de texte.
* @return <code>true</code> si c'est exactement une région de string.
*/
public static boolean isExactKspString(IDocument document, ITextSelection selection) {
IDocumentExtension3 extension = (IDocumentExtension3) document;
try {
/* Charge les régions du document couverte par la sélecion. */
ITypedRegion[] regions = extension.computePartitioning(KspRegionType.PARTITIONING, selection.getOffset(), selection.getLength(), false);
/* Vérifie qu'on a une seule région. */
if (regions.length != 1) {
return false;
}
/* Charge la région entière */
ITypedRegion region = extension.getPartition(KspRegionType.PARTITIONING, selection.getOffset(), false);
/* Vérifie que c'est une région de string KSP. */
if (!region.getType().equals(KspRegionType.STRING.getContentType())) {
return false;
}
/* Vérifie que la région couvre exactement la sélection */
int selectionWithQuoteOffset = selection.getOffset() - 1; // Prend en compte la double quote ouvrante.
int selectionWithQuoteLength = selection.getLength() + 2; // Prend en compte les deux double quote.
if (region.getOffset() == selectionWithQuoteOffset && region.getLength() == selectionWithQuoteLength) {
return true;
}
} catch (BadLocationException | BadPartitioningException e) {
ErrorUtils.handle(e);
}
return false;
}
示例13: detectHyperlinks
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
IDocument document = textViewer.getDocument();
/* Vérifie qu'on est dans une String de KSP */
boolean isSqlString = DocumentUtils.isContentType(document, region.getOffset(), KspRegionType.STRING);
if (!isSqlString) {
return null; // NOSONAR
}
/* Extrait le mot courant. */
ITextSelection selection = new TextSelection(document, region.getOffset(), region.getLength());
ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, WordSelectionType.SNAKE_CASE);
if (currentWordSelection == null) {
return null; // NOSONAR
}
String currentWord = currentWordSelection.getText();
if (currentWord == null) {
return null; // NOSONAR
}
/* Extrait un nom de DTO : Calcul le nom en PascalCase */
String javaName = StringUtils.toPascalCase(currentWord);
/* Cherche le fichier Java du DTO. */
DtoFile dtoFile = DtoManager.getInstance().findDtoFile(javaName);
/* Fichier Java trouvé : on ajoute un lien vers le fichier Java. */
if (dtoFile != null) {
IRegion targetRegion = new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
return new IHyperlink[] { new JavaImplementationHyperLink(targetRegion, dtoFile) };
}
return null; // NOSONAR
}
示例14: detectHyperlinks
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
IDocument document = textViewer.getDocument();
/* Extrait le mot courant. */
ITextSelection selection = new TextSelection(document, region.getOffset(), region.getLength());
ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, WordSelectionType.NOT_SPACE);
if (currentWordSelection == null) {
return null; // NOSONAR
}
String currentWord = currentWordSelection.getText();
if (currentWord == null) {
return null; // NOSONAR
}
/* Vérifie que c'est un chemin relatif valide. */
String absolutePath = getAbsolutePath(currentWord);
if (absolutePath == null) {
return null; // NOSONAR
}
/* Vérifie que le fichier existe. */
IFile file = (IFile) ResourcesPlugin.getWorkspace().getRoot().findMember(absolutePath);
if (file == null) {
return null; // NOSONAR
}
/* Renvoin un lien vers le fichier dont on a trouvé le chemin. */
IRegion targetRegion = new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
return new IHyperlink[] { new FileHyperLink(targetRegion, file) };
}
示例15: detectHyperlinks
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
IDocument document = textViewer.getDocument();
/* Extrait le mot courant. */
ITextSelection selection = new TextSelection(document, region.getOffset(), region.getLength());
ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, WordSelectionType.CONSTANT_CASE);
if (currentWordSelection == null) {
return null; // NOSONAR
}
String currentWord = currentWordSelection.getText();
if (currentWord == null) {
return null; // NOSONAR
}
IRegion targetRegion = new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
FileRegion fileRegion = new FileRegion(UiUtils.getCurrentEditorFile(), targetRegion.getOffset(), targetRegion.getLength());
/* Cherche un nom de DTO. */
IHyperlink[] hyperlinks = detectDtDefinitionName(currentWord, targetRegion, fileRegion);
if (hyperlinks != null) {
return hyperlinks;
}
/* Cherche un nom de Task. */
hyperlinks = detectTaskName(currentWord, targetRegion);
if (hyperlinks != null) {
return hyperlinks;
}
/* Cherche une déclaration KSP autre. */
return detectKspName(currentWord, targetRegion, fileRegion);
}