本文整理匯總了Java中org.eclipse.jface.text.ITextSelection.getOffset方法的典型用法代碼示例。如果您正苦於以下問題:Java ITextSelection.getOffset方法的具體用法?Java ITextSelection.getOffset怎麽用?Java ITextSelection.getOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jface.text.ITextSelection
的用法示例。
在下文中一共展示了ITextSelection.getOffset方法的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: 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);
}
}
}
}
}
示例6: run
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
public void run() {
if (editor == null)
return;
ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
TexCompletionProposal prop = new TexCompletionProposal(entry, selection.getOffset() + 1, 0,
editor.getViewer());
try {
// insert a backslash first
doc.replace(selection.getOffset(), 0, "\\");
prop.apply(doc);
int newOffset = selection.getOffset() + entry.key.length() + 1;
if (entry.arguments > 0) {
newOffset += 1;
}
editor.getSelectionProvider().setSelection(new TextSelection(newOffset, 0));
} catch (BadLocationException e) {
TexlipsePlugin.log("Error while trying to insert command", e);
}
}
示例7: 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);
}
示例8: 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;
}
示例9: 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;
}
示例10: keyReleased
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
@Override
public void keyReleased(KeyEvent e) {
InsertClosingBracketsSupport insertClosingBracketsSupport = getInsertionSupport(e);
if (insertClosingBracketsSupport == null) {
return;
}
/*
* do not use last caret start - because the listener ordering could be
* different
*/
ISelectionProvider selectionProvider = this.batchEditor.getSelectionProvider();
if (selectionProvider == null) {
return;
}
ISelection selection = selectionProvider.getSelection();
if (!(selection instanceof ITextSelection)) {
return;
}
boolean enabled = getPreferences().getBooleanPreference(P_EDITOR_AUTO_CREATE_END_BRACKETSY);
if (!enabled) {
return;
}
ITextSelection textSelection = (ITextSelection) selection;
int offset = textSelection.getOffset();
try {
IDocument document = this.batchEditor.getDocument();
if (document == null) {
return;
}
insertClosingBracketsSupport.insertClosingBrackets(document, selectionProvider, offset);
} catch (BadLocationException e1) {
/* ignore */
return;
}
}
示例11: keyReleased
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
@Override
public void keyReleased(KeyEvent e) {
InsertClosingBracketsSupport insertClosingBracketsSupport = getInsertionSupport(e);
if (insertClosingBracketsSupport == null) {
return;
}
/*
* do not use last caret start - because the listener ordering could be
* different
*/
ISelectionProvider selectionProvider = this.bashEditor.getSelectionProvider();
if (selectionProvider == null) {
return;
}
ISelection selection = selectionProvider.getSelection();
if (!(selection instanceof ITextSelection)) {
return;
}
boolean enabled = getPreferences().getBooleanPreference(P_EDITOR_AUTO_CREATE_END_BRACKETSY);
if (!enabled) {
return;
}
ITextSelection textSelection = (ITextSelection) selection;
int offset = textSelection.getOffset();
try {
IDocument document = this.bashEditor.getDocument();
if (document == null) {
return;
}
insertClosingBracketsSupport.insertClosingBrackets(document, selectionProvider, offset);
} catch (BadLocationException e1) {
/* ignore */
return;
}
}
示例12: 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()]);
}
示例13: 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;
}
示例14: 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
}
示例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.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) };
}