本文整理汇总了Java中org.eclipse.jface.text.IDocumentExtension3.getPartition方法的典型用法代码示例。如果您正苦于以下问题:Java IDocumentExtension3.getPartition方法的具体用法?Java IDocumentExtension3.getPartition怎么用?Java IDocumentExtension3.getPartition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.IDocumentExtension3
的用法示例。
在下文中一共展示了IDocumentExtension3.getPartition方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractPrefix
import org.eclipse.jface.text.IDocumentExtension3; //导入方法依赖的package包/类
@Override
protected String extractPrefix(ITextViewer viewer, int offset) {
try {
if (offset == 0) {
return "";
}
if (!(viewer.getDocument() instanceof IDocumentExtension3)) {
return super.extractPrefix(viewer, offset);
}
IDocumentExtension3 document3 = (IDocumentExtension3) viewer.getDocument();
ITypedRegion previousRegion = document3.getPartition(EditorConstants.BF_PARTITIONING, offset - 1, false);
if (EditorConstants.PARTITION_TYPE_TEMPLATE_PARAMETERS.equals(previousRegion.getType())) {
return viewer.getDocument().get(previousRegion.getOffset(), previousRegion.getLength());
}
}
catch (BadLocationException | BadPartitioningException ex) {
BfActivator.getDefault().logError("Prefix for Template could not be computed", ex);
}
return super.extractPrefix(viewer, offset);
}
示例2: getHoverRegion
import org.eclipse.jface.text.IDocumentExtension3; //导入方法依赖的package包/类
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
IRegion region = new Region(offset, 0);
try {
IDocument doc = textViewer.getDocument();
if (doc instanceof IDocumentExtension3) {
IDocumentExtension3 ext3 = (IDocumentExtension3) doc;
region = ext3.getPartition(EditorConstants.BF_PARTITIONING, offset, true);
}
else {
region = doc.getPartition(offset);
}
}
catch (BadPartitioningException | BadLocationException ex) {
BfActivator.getDefault().logError("Partitioning Problem", ex);
}
return region;
}
示例3: runInternal
import org.eclipse.jface.text.IDocumentExtension3; //导入方法依赖的package包/类
@Override
protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadLocationException, BadPartitioningException {
int selectionOffset= selection.getOffset();
int selectionEndOffset= selectionOffset + selection.getLength();
List<Edit> edits= new LinkedList<Edit>();
ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, selectionOffset, false);
handleFirstPartition(partition, edits, factory, selectionOffset);
while (partition.getOffset() + partition.getLength() < selectionEndOffset) {
partition= handleInteriorPartition(partition, edits, factory, docExtension);
}
handleLastPartition(partition, edits, factory, selectionEndOffset);
executeEdits(edits);
}
示例4: isExactKspString
import org.eclipse.jface.text.IDocumentExtension3; //导入方法依赖的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;
}
示例5: isUnclosedPair
import org.eclipse.jface.text.IDocumentExtension3; //导入方法依赖的package包/类
private boolean isUnclosedPair(char c, IDocument document, int offset) throws BadLocationException
{
// TODO Refactor and combine this copy-pasted code from PeerCharacterCloser
int beginning = 0;
// Don't check from very beginning of the document! Be smarter/quicker and check from beginning of
// partition if we can
if (document instanceof IDocumentExtension3)
{
try
{
IDocumentExtension3 ext = (IDocumentExtension3) document;
ITypedRegion region = ext.getPartition(IDocumentExtension3.DEFAULT_PARTITIONING, offset, false);
beginning = region.getOffset();
}
catch (BadPartitioningException e)
{
// ignore
}
}
// Now check leading source and see if we're an unclosed pair.
String previous = document.get(beginning, offset - beginning);
boolean open = false;
int index = -1;
while ((index = previous.indexOf(c, index + 1)) != -1)
{
open = !open;
}
return open;
}
示例6: runInternal
import org.eclipse.jface.text.IDocumentExtension3; //导入方法依赖的package包/类
@Override
protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadPartitioningException, BadLocationException {
List<Edit> edits= new LinkedList<Edit>();
int tokenLength= getCommentStart().length();
int offset= selection.getOffset();
int endOffset= offset + selection.getLength();
ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, offset, false);
int partOffset= partition.getOffset();
int partEndOffset= partOffset + partition.getLength();
while (partEndOffset < endOffset) {
if (partition.getType() == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) {
edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
}
partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, partEndOffset, false);
partOffset= partition.getOffset();
partEndOffset= partOffset + partition.getLength();
}
if (partition.getType() == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) {
edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
}
executeEdits(edits);
}
示例7: getHoverInfo2
import org.eclipse.jface.text.IDocumentExtension3; //导入方法依赖的package包/类
@Override
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
IAnnotationModel model = sourceViewer.getAnnotationModel();
@SuppressWarnings("unchecked")
Iterator<Annotation> i = model.getAnnotationIterator();
Annotation provideText = null;
AnnotationPreferenceLookup preferenceLookup = EditorsUI.getAnnotationPreferenceLookup();
int annotationLayer = -1;
while (i.hasNext()) {
Annotation ann = i.next();
Position p = model.getPosition(ann);
if (p == null || !p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
continue;
}
if (UNCHANGED_QUICKDIFF_ANNOTATION.equals(ann.getType())) {
continue; //Ignore unchanged line notification
}
if (provideText == null) {
provideText = ann;
}
AnnotationPreference preference = preferenceLookup.getAnnotationPreference(ann);
if (preference != null && preference.getPresentationLayer() > annotationLayer) {
provideText = ann;
annotationLayer = preference.getPresentationLayer();
}
}
String text = null;
if (provideText != null) {
if (this.hoverContributions.containsKey(provideText.getType())) {
text = this.hoverContributions.get(provideText.getType()).getHoverText(provideText, textViewer, hoverRegion);
}
else {
text = "<b>" + provideText.getText() + "</b>";
}
}
try {
if (text == null) {
IDocument document = textViewer.getDocument();
if (document instanceof IDocumentExtension3) {
IDocumentExtension3 ext3 = (IDocumentExtension3) document;
ITypedRegion partition = ext3.getPartition(EditorConstants.BF_PARTITIONING, hoverRegion.getOffset(), false);
if (EditorConstants.PARTITION_TYPE_BRAINFUCK_CODE.equals(partition.getType())) {
text = "Offset: [<b>" + hoverRegion.getOffset() + "</b>]";
}
}
}
}
catch (BadLocationException | BadPartitioningException ex) {
BfActivator.getDefault().logError("hoverRegion partitioning could not be evaluated", ex);
}
return text;
}
示例8: getPartition
import org.eclipse.jface.text.IDocumentExtension3; //导入方法依赖的package包/类
protected ITypedRegion getPartition(IDocumentExtension3 ext, String defaultPartitioning, int offset, boolean b)
throws BadLocationException, BadPartitioningException
{
return ext.getPartition(defaultPartitioning, offset, b);
}
示例9: handleInteriorPartition
import org.eclipse.jface.text.IDocumentExtension3; //导入方法依赖的package包/类
/**
* Handles partition boundaries within the selection. The end of the current
* partition and the start of the next partition are examined for whether
* they contain comment tokens that interfere with the created comment.
* <p>
* Comment tokens are removed from interior multi-line comments. Javadoc
* comments are left as is; instead, multi-line comment tokens are inserted
* before and after Javadoc partitions to ensure that the entire selected
* area is commented.
* </p>
* <p>
* The next partition is returned.
* </p>
*
* @param partition the current partition
* @param edits the list of edits to add to
* @param factory the edit factory
* @param docExtension the document to get the partitions from
* @return the next partition after the current
* @throws BadLocationException if accessing the document fails - this can
* only happen if the document gets modified concurrently
* @throws BadPartitioningException if the document does not have a Java
* partitioning
*/
private ITypedRegion handleInteriorPartition(ITypedRegion partition, List<Edit> edits, Edit.EditFactory factory, IDocumentExtension3 docExtension) throws BadPartitioningException, BadLocationException {
// end of previous partition
String partType= partition.getType();
int partEndOffset= partition.getOffset() + partition.getLength();
int tokenLength= getCommentStart().length();
boolean wasJavadoc= false; // true if the previous partition is javadoc
if (partType == IJavaPartitions.JAVA_DOC) {
wasJavadoc= true;
} else if (partType == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) {
// already in a comment - remove ending mark
edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
}
// advance to next partition
partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, partEndOffset, false);
partType= partition.getType();
// start of next partition
if (wasJavadoc) {
// if previous was javadoc, and the current one is not a comment,
// then add a block comment start
if (partType == IDocument.DEFAULT_CONTENT_TYPE
|| isSpecialPartition(partType)) {
edits.add(factory.createEdit(partition.getOffset(), 0, getCommentStart()));
}
} else { // !wasJavadoc
if (partType == IJavaPartitions.JAVA_DOC) {
// if next is javadoc, end block comment before
edits.add(factory.createEdit(partition.getOffset(), 0, getCommentEnd()));
} else if (partType == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) {
// already in a comment - remove startToken
edits.add(factory.createEdit(partition.getOffset(), getCommentStart().length(), "")); //$NON-NLS-1$
}
}
return partition;
}