當前位置: 首頁>>代碼示例>>Java>>正文


Java Position類代碼示例

本文整理匯總了Java中org.eclipse.jface.text.Position的典型用法代碼示例。如果您正苦於以下問題:Java Position類的具體用法?Java Position怎麽用?Java Position使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Position類屬於org.eclipse.jface.text包,在下文中一共展示了Position類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: calculatePositions

import org.eclipse.jface.text.Position; //導入依賴的package包/類
private void calculatePositions() {
	if (hasSnippetsModifications()) {
		final Map<ProjectionAnnotation, Position> annotations = getAllSnippetsAnnotations();

		Display.getDefault().asyncExec(new Runnable() {

			@Override
			public void run() {
				if (!annotations.isEmpty() && getProjectionAnnotationModel() == null) {
					enableProjection();
				}
				if (getProjectionAnnotationModel() != null) {
					Annotation[] oldAnno = oldAnnotations.keySet().toArray(new Annotation[0]);
					getProjectionAnnotationModel().modifyAnnotations(oldAnno, annotations, null);
					oldAnnotations.clear();
					oldAnnotations.putAll(annotations);
					if (annotations.isEmpty()) {
						disableProjection();
					}
				}
			}

		});
	}
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:26,代碼來源:SourceViewer.java

示例2: removeOldAnnotation

import org.eclipse.jface.text.Position; //導入依賴的package包/類
private void removeOldAnnotation(final int offset) {
  this.annotationModel.connect(this.document);

  final Iterator<Annotation> iter = this.annotationModel.getAnnotationIterator();
  Annotation beRemoved = null;
  while (iter.hasNext()) {
    beRemoved = iter.next();
    if (!beRemoved.getType().equals(this.MME_REASON_ANNOT_TYPE)) {
      continue;
    }
    final Position position = this.annotationModel.getPosition(beRemoved);

    if (position.getOffset() + position.getLength() == offset || position.includes(offset)) {
      this.annotationModel.removeAnnotation(beRemoved);
    }
  }
  this.annotationModel.disconnect(this.document);
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:19,代碼來源:ReasonReconcilingStrategy.java

示例3: addNewAnnotation

import org.eclipse.jface.text.Position; //導入依賴的package包/類
/**
 * We add new error annotation related to error which alloy parser is giving us.
 *
 * @param e the exception which is parse operation occurred
 */
private void addNewAnnotation(final Err e) {
  final int line = e.pos.y;
  int offset = 0;
  final int length = e.pos.x2 - e.pos.x + 1;
  final String message = e.getLocalizedMessage();
  try {
    offset = this.document.getLineOffset(line - 1) + e.pos.x - 1;
  } catch (final BadLocationException e1) {
    e1.printStackTrace();
  }

  final Annotation annotation = new Annotation(this.MME_PARSE_ANNOT_TYPE, true, message);
  this.annotationModel.connect(this.document);
  this.annotationModel.addAnnotation(annotation, new Position(offset, length));
  this.annotationModel.disconnect(this.document);
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:22,代碼來源:SyntacticReconcilingStrategy.java

示例4: updateFolding

import org.eclipse.jface.text.Position; //導入依賴的package包/類
private void updateFolding(EditorConfig editorConfig) {
	if (projectionAnnotationModel == null) {
		return;
	}
	List<Section> sections = editorConfig.getSections();
	CommentBlocks commentBlocks = editorConfig.getAdapter(CommentBlocks.class);
	List<CommentBlock> comments = commentBlocks != null ? commentBlocks.getCommentBlocks()
			: Collections.emptyList();
	Map<Annotation, Position> newAnnotations = new HashMap<>();
	// Collection section and comment spans;
	List<Span> spans = /*Stream.concat(sections.stream(), comments.stream())*/
			sections.stream()
			.map(a -> a.getAdapter(Span.class))
			.sorted((s1, s2) -> s1.getStart().getLine() - s2.getStart().getLine()).collect(Collectors.toList());
	Annotation[] annotations = new Annotation[spans.size()];
	for (int i = 0; i < spans.size(); i++) {
		Span span = spans.get(i);
		int startOffset = span.getStart().getOffset();
		int endOffset = span.getEnd().getOffset();
		ProjectionAnnotation annotation = new ProjectionAnnotation();
		newAnnotations.put(annotation, new Position(startOffset, endOffset - startOffset));
		annotations[i] = annotation;
	}
	projectionAnnotationModel.modifyAnnotations(oldAnnotations, newAnnotations, null);
	oldAnnotations = annotations;
}
 
開發者ID:angelozerr,項目名稱:ec4e,代碼行數:27,代碼來源:EditorConfigFoldingStrategy.java

示例5: getHoverInfo

import org.eclipse.jface.text.Position; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
@Override
public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) {
	IAnnotationModel model = sourceViewer.getAnnotationModel();
	Iterator iterator = model.getAnnotationIterator();
	while (iterator.hasNext()) {
		Annotation annotation = (Annotation) iterator.next();
		Position position = model.getPosition(annotation);
		try {
			int lineOfAnnotation = sourceViewer.getDocument().
					getLineOfOffset(position.getOffset());
			if (lineNumber == lineOfAnnotation) {
				return annotation.getText();
			}
		} catch (BadLocationException e) {
			// TODO: handle exception
		}
		
	}
	return null;
}
 
開發者ID:Imhotup,項目名稱:LibertyEiffel-Eclipse-Plugin,代碼行數:22,代碼來源:EiffelAnnotationHOver.java

示例6: updateCodefolding

import org.eclipse.jface.text.Position; //導入依賴的package包/類
/**
 * <p>
 * Checks whether the given positions are in the
 * <code>ProjectionAnnotationModel</code> or in the addition set. If not it tries
 * to add into <code>additions</code>. Deletes old ProjectionAnnotation with line
 * count less than 2.
 * </p>
 * 
 * @param positions a list of available foldable positions
 */
public void updateCodefolding(List<Position> positions) {
	IDocument document = sourceViewer.getDocument();
	if (document == null) {
		return;
	}
	oldAnnotations.clear();
	Iterator<?> annotationIterator = projectionAnnotationModel.getAnnotationIterator();
	while (annotationIterator.hasNext()) {
		oldAnnotations.add((ProjectionAnnotation) annotationIterator.next());
	}
	// Add new Position with a unique line offset
	for (Position position : positions) {
		if (!isInAdditions(position)) {
			addPosition(position);
		}
	}
	projectionAnnotationModel.modifyAnnotations(oldAnnotations.toArray(new Annotation[0]), additions, null);
	additions.clear();
}
 
開發者ID:DarwinSPL,項目名稱:DarwinSPL,代碼行數:30,代碼來源:DwprofileCodeFoldingManager.java

示例7: getPositions

import org.eclipse.jface.text.Position; //導入依賴的package包/類
/**
 * Returns the partitioner's positions.   Apparently, this is an array of TypedPosition objects
 * that partitions the document, ordered from start to end.  These TypedPosition objects mark
 * all the non-TLA+ portions of the document--that is, comments, strings, and PlusCal tokens.
 *
 * @return the partitioner's positions
 * @throws BadPositionCategoryException if getting the positions from the
 *         document fails
 */
protected final Position[] getPositions() throws BadPositionCategoryException {
    if (fCachedPositions == null) {
        fCachedPositions= fDocument.getPositions(fPositionCategory);
    } else if (CHECK_CACHE_CONSISTENCY) {
        Position[] positions= fDocument.getPositions(fPositionCategory);
        int len= Math.min(positions.length, fCachedPositions.length);
        for (int i= 0; i < len; i++) {
            if (!positions[i].equals(fCachedPositions[i]))
                System.err.println("FastPartitioner.getPositions(): cached position is not up to date: from document: " + toString(positions[i]) + " in cache: " + toString(fCachedPositions[i])); //$NON-NLS-1$ //$NON-NLS-2$
        }
        for (int i= len; i < positions.length; i++)
            System.err.println("FastPartitioner.getPositions(): new position in document: " + toString(positions[i])); //$NON-NLS-1$
        for (int i= len; i < fCachedPositions.length; i++)
            System.err.println("FastPartitioner.getPositions(): stale position in cache: " + toString(fCachedPositions[i])); //$NON-NLS-1$
    }
    return fCachedPositions;
}
 
開發者ID:tlaplus,項目名稱:tlaplus,代碼行數:27,代碼來源:TLAFastPartitioner.java

示例8: setBracketHighlighting

import org.eclipse.jface.text.Position; //導入依賴的package包/類
private void setBracketHighlighting(IDocument document) {
	StyleRange styleRange = null;
	Position[] positions = positionHelper.getPositions(document, de.darwinspl.preferences.resource.dwprofile.ui.DwprofilePositionCategory.BRACKET.toString());
	
	for (Position position : positions) {
		Position tmpPosition = convertToWidgetPosition(position);
		if (tmpPosition != null) {
			styleRange = getStyleRangeAtPosition(tmpPosition);
			styleRange.borderStyle = SWT.BORDER_SOLID;
			styleRange.borderColor = bracketColor;
			if (styleRange.foreground == null) {
				styleRange.foreground = black;
			}
			textWidget.setStyleRange(styleRange);
		}
	}
}
 
開發者ID:DarwinSPL,項目名稱:DarwinSPL,代碼行數:18,代碼來源:DwprofileHighlighting.java

示例9: getQuickFixes

import org.eclipse.jface.text.Position; //導入依賴的package包/類
private List<eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionQuickFix> getQuickFixes(ISourceViewer sourceViewer, int offset, int length) {
	List<eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionQuickFix> foundFixes = new ArrayList<eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionQuickFix>();
	IAnnotationModel model = annotationModelProvider.getAnnotationModel();
	
	if (model == null) {
		return foundFixes;
	}
	
	Iterator<?> iter = model.getAnnotationIterator();
	while (iter.hasNext()) {
		Annotation annotation = (Annotation) iter.next();
		Position position = model.getPosition(annotation);
		if (offset >= 0) {
			if (!position.overlapsWith(offset, length)) {
				continue;
			}
		}
		Collection<eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionQuickFix> quickFixes = getQuickFixes(annotation);
		if (quickFixes != null) {
			foundFixes.addAll(quickFixes);
		}
	}
	return foundFixes;
}
 
開發者ID:DarwinSPL,項目名稱:DarwinSPL,代碼行數:25,代碼來源:HyexpressionQuickAssistProcessor.java

示例10: removeHighlightingCategory

import org.eclipse.jface.text.Position; //導入依賴的package包/類
private void removeHighlightingCategory(IDocument document, String category) {
	Position[] positions = positionHelper.getPositions(document, category);
	if (category.equals(eu.hyvar.feature.expression.resource.hyexpression.ui.HyexpressionPositionCategory.BRACKET.toString())) {
		StyleRange styleRange;
		for (Position position : positions) {
			Position tmpPosition = convertToWidgetPosition(position);
			if (tmpPosition != null) {
				styleRange = getStyleRangeAtPosition(tmpPosition);
				styleRange.borderStyle = SWT.NONE;
				styleRange.borderColor = null;
				styleRange.background = null;
				textWidget.setStyleRange(styleRange);
			}
		}
	}
	positionHelper.removePositions(document, category);
}
 
開發者ID:DarwinSPL,項目名稱:DarwinSPL,代碼行數:18,代碼來源:HyexpressionHighlighting.java

示例11: saveCodeFolding

import org.eclipse.jface.text.Position; //導入依賴的package包/類
/**
 * Saves the code folding state into the given memento.
 */
public void saveCodeFolding(IMemento memento) {
	// The annotation model might be null if the editor opened an storage input
	// instead of a file input.
	if (projectionAnnotationModel == null) {
		return;
	}
	Iterator<?> annotationIt = projectionAnnotationModel.getAnnotationIterator();
	while (annotationIt.hasNext()) {
		ProjectionAnnotation annotation = (ProjectionAnnotation) annotationIt.next();
		IMemento annotationMemento = memento.createChild(ANNOTATION);
		Position position = projectionAnnotationModel.getPosition(annotation);
		annotationMemento.putBoolean(IS_COLLAPSED, annotation.isCollapsed());
		annotationMemento.putInteger(OFFSET, position.offset);
		annotationMemento.putInteger(LENGTH, position.length);
	}
}
 
開發者ID:DarwinSPL,項目名稱:DarwinSPL,代碼行數:20,代碼來源:HyvalidityformulaCodeFoldingManager.java

示例12: setBracketHighlighting

import org.eclipse.jface.text.Position; //導入依賴的package包/類
private void setBracketHighlighting(IDocument document) {
	StyleRange styleRange = null;
	Position[] positions = positionHelper.getPositions(document, eu.hyvar.context.contextValidity.resource.hyvalidityformula.ui.HyvalidityformulaPositionCategory.BRACKET.toString());
	
	for (Position position : positions) {
		Position tmpPosition = convertToWidgetPosition(position);
		if (tmpPosition != null) {
			styleRange = getStyleRangeAtPosition(tmpPosition);
			styleRange.borderStyle = SWT.BORDER_SOLID;
			styleRange.borderColor = bracketColor;
			if (styleRange.foreground == null) {
				styleRange.foreground = black;
			}
			textWidget.setStyleRange(styleRange);
		}
	}
}
 
開發者ID:DarwinSPL,項目名稱:DarwinSPL,代碼行數:18,代碼來源:HyvalidityformulaHighlighting.java

示例13: removeHighlightingCategory

import org.eclipse.jface.text.Position; //導入依賴的package包/類
private void removeHighlightingCategory(IDocument document, String category) {
	Position[] positions = positionHelper.getPositions(document, category);
	if (category.equals(eu.hyvar.context.contextValidity.resource.hyvalidityformula.ui.HyvalidityformulaPositionCategory.BRACKET.toString())) {
		StyleRange styleRange;
		for (Position position : positions) {
			Position tmpPosition = convertToWidgetPosition(position);
			if (tmpPosition != null) {
				styleRange = getStyleRangeAtPosition(tmpPosition);
				styleRange.borderStyle = SWT.NONE;
				styleRange.borderColor = null;
				styleRange.background = null;
				textWidget.setStyleRange(styleRange);
			}
		}
	}
	positionHelper.removePositions(document, category);
}
 
開發者ID:DarwinSPL,項目名稱:DarwinSPL,代碼行數:18,代碼來源:HyvalidityformulaHighlighting.java

示例14: getQuickFixes

import org.eclipse.jface.text.Position; //導入依賴的package包/類
private List<eu.hyvar.context.contextValidity.resource.hyvalidityformula.IHyvalidityformulaQuickFix> getQuickFixes(ISourceViewer sourceViewer, int offset, int length) {
	List<eu.hyvar.context.contextValidity.resource.hyvalidityformula.IHyvalidityformulaQuickFix> foundFixes = new ArrayList<eu.hyvar.context.contextValidity.resource.hyvalidityformula.IHyvalidityformulaQuickFix>();
	IAnnotationModel model = annotationModelProvider.getAnnotationModel();
	
	if (model == null) {
		return foundFixes;
	}
	
	Iterator<?> iter = model.getAnnotationIterator();
	while (iter.hasNext()) {
		Annotation annotation = (Annotation) iter.next();
		Position position = model.getPosition(annotation);
		if (offset >= 0) {
			if (!position.overlapsWith(offset, length)) {
				continue;
			}
		}
		Collection<eu.hyvar.context.contextValidity.resource.hyvalidityformula.IHyvalidityformulaQuickFix> quickFixes = getQuickFixes(annotation);
		if (quickFixes != null) {
			foundFixes.addAll(quickFixes);
		}
	}
	return foundFixes;
}
 
開發者ID:DarwinSPL,項目名稱:DarwinSPL,代碼行數:25,代碼來源:HyvalidityformulaQuickAssistProcessor.java

示例15: getMarkerPosition

import org.eclipse.jface.text.Position; //導入依賴的package包/類
/**
 * Returns the actual position of <i>marker</i> or null if the marker was
 * deleted. Code inspired by 
 * @param marker
 * @param sourceViewer
 * @return
 */
private static int[] getMarkerPosition(IMarker marker, ISourceViewer sourceViewer) {
    int[] p = new int[2];
    p[0] = marker.getAttribute(IMarker.CHAR_START, -1);
    p[1] = marker.getAttribute(IMarker.CHAR_END, -1);
 // look up the current range of the marker when the document has been edited
    IAnnotationModel model= sourceViewer.getAnnotationModel();
    if (model instanceof AbstractMarkerAnnotationModel) {

        AbstractMarkerAnnotationModel markerModel= (AbstractMarkerAnnotationModel) model;
        Position pos= markerModel.getMarkerPosition(marker);
        if (pos != null && !pos.isDeleted()) {
            // use position instead of marker values
            p[0] = pos.getOffset();
            p[1] = pos.getOffset() + pos.getLength();
        }

        if (pos != null && pos.isDeleted()) {
            // do nothing if position has been deleted
            return null;
        }
    }
    return p;
}
 
開發者ID:eclipse,項目名稱:texlipse,代碼行數:31,代碼來源:SpellChecker.java


注:本文中的org.eclipse.jface.text.Position類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。