当前位置: 首页>>代码示例>>Java>>正文


Java ITextSelection.getOffset方法代码示例

本文整理汇总了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());
}
 
开发者ID:sebez,项目名称:vertigo-chroma-kspplugin,代码行数:26,代码来源:KspTextHover.java

示例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]);
}
 
开发者ID:sebez,项目名称:vertigo-chroma-kspplugin,代码行数:30,代码来源:BaseContentAssistProcessor.java

示例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;
}
 
开发者ID:sebez,项目名称:vertigo-chroma-kspplugin,代码行数:23,代码来源:KspStringContentAssistProcessor.java

示例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;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:30,代码来源:MarkerFactory.java

示例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);
				}
			}
		}
	}
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:23,代码来源:TweakedLinkedModeUI.java

示例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);
    }
}
 
开发者ID:eclipse,项目名称:texlipse,代码行数:21,代码来源:TexInsertMathSymbolAction.java

示例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);
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:23,代码来源:FluentMkEditor.java

示例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;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:23,代码来源:JsniParser.java

示例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;
}
 
开发者ID:ninneko,项目名称:velocity-edit,代码行数:27,代码来源:ToggleCommentAction.java

示例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;
	}

}
 
开发者ID:de-jcup,项目名称:eclipse-batch-editor,代码行数:38,代码来源:BatchBracketInsertionCompleter.java

示例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;
	}

}
 
开发者ID:de-jcup,项目名称:eclipse-bash-editor,代码行数:38,代码来源:BashBracketInsertionCompleter.java

示例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()]);
}
 
开发者ID:pgcodekeeper,项目名称:pgcodekeeper,代码行数:37,代码来源:SQLEditorTemplateAssistProcessor.java

示例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;
}
 
开发者ID:sebez,项目名称:vertigo-chroma-kspplugin,代码行数:39,代码来源:DocumentUtils.java

示例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
}
 
开发者ID:sebez,项目名称:vertigo-chroma-kspplugin,代码行数:36,代码来源:SqlTableHyperLinkDetector.java

示例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) };
}
 
开发者ID:sebez,项目名称:vertigo-chroma-kspplugin,代码行数:33,代码来源:FilePathHyperLinkDetector.java


注:本文中的org.eclipse.jface.text.ITextSelection.getOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。