Java 类org.eclipse.jface.text.Position 实例源码

项目:Hydrograph    文件:SourceViewer.java   
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();
                    }
                }
            }

        });
    }
}
项目:Tarski    文件:ReasonReconcilingStrategy.java   
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);
}
项目:Tarski    文件:SyntacticReconcilingStrategy.java   
/**
 * 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);
}
项目:ec4e    文件:EditorConfigFoldingStrategy.java   
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;
}
项目:LibertyEiffel-Eclipse-Plugin    文件:EiffelAnnotationHOver.java   
@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;
}
项目:DarwinSPL    文件:DwprofileCodeFoldingManager.java   
/**
 * <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();
}
项目:tlaplus    文件:TLAFastPartitioner.java   
/**
 * 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;
}
项目:DarwinSPL    文件:DwprofileHighlighting.java   
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);
        }
    }
}
项目:DarwinSPL    文件:HyexpressionQuickAssistProcessor.java   
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;
}
项目:DarwinSPL    文件:HyexpressionHighlighting.java   
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);
}
项目:DarwinSPL    文件:HyexpressionCodeFoldingManager.java   
/**
 * <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();
}
项目:DarwinSPL    文件:HyvalidityformulaCodeFoldingManager.java   
/**
 * <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();
}
项目:DarwinSPL    文件:HyvalidityformulaCodeFoldingManager.java   
/**
 * 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);
    }
}
项目:DarwinSPL    文件:HyvalidityformulaHighlighting.java   
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);
        }
    }
}
项目:DarwinSPL    文件:HyvalidityformulaHighlighting.java   
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);
}
项目:DarwinSPL    文件:HyvalidityformulaQuickAssistProcessor.java   
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;
}
项目:texlipse    文件:SpellChecker.java   
/**
 * 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;
}
项目:DarwinSPL    文件:HydatavalueHighlighting.java   
private void setBracketHighlighting(IDocument document) {
    StyleRange styleRange = null;
    Position[] positions = positionHelper.getPositions(document, eu.hyvar.dataValues.resource.hydatavalue.ui.HydatavaluePositionCategory.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);
        }
    }
}
项目:DarwinSPL    文件:HydatavalueHighlighting.java   
private void removeHighlightingCategory(IDocument document, String category) {
    Position[] positions = positionHelper.getPositions(document, category);
    if (category.equals(eu.hyvar.dataValues.resource.hydatavalue.ui.HydatavaluePositionCategory.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);
}
项目:DarwinSPL    文件:HydatavalueCodeFoldingManager.java   
/**
 * <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();
}
项目:DarwinSPL    文件:HymappingHighlighting.java   
private void setBracketHighlighting(IDocument document) {
    StyleRange styleRange = null;
    Position[] positions = positionHelper.getPositions(document, eu.hyvar.feature.mapping.resource.hymapping.ui.HymappingPositionCategory.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);
        }
    }
}
项目:DarwinSPL    文件:HymappingHighlighting.java   
private void removeHighlightingCategory(IDocument document, String category) {
    Position[] positions = positionHelper.getPositions(document, category);
    if (category.equals(eu.hyvar.feature.mapping.resource.hymapping.ui.HymappingPositionCategory.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);
}
项目:DarwinSPL    文件:HymappingQuickAssistProcessor.java   
private List<eu.hyvar.feature.mapping.resource.hymapping.IHymappingQuickFix> getQuickFixes(ISourceViewer sourceViewer, int offset, int length) {
    List<eu.hyvar.feature.mapping.resource.hymapping.IHymappingQuickFix> foundFixes = new ArrayList<eu.hyvar.feature.mapping.resource.hymapping.IHymappingQuickFix>();
    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.mapping.resource.hymapping.IHymappingQuickFix> quickFixes = getQuickFixes(annotation);
        if (quickFixes != null) {
            foundFixes.addAll(quickFixes);
        }
    }
    return foundFixes;
}
项目:DarwinSPL    文件:HymappingCodeFoldingManager.java   
/**
 * <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();
}
项目:DarwinSPL    文件:HymappingCodeFoldingManager.java   
/**
 * 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);
    }
}
项目:DarwinSPL    文件:HyconstraintsCodeFoldingManager.java   
/**
 * 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);
    }
}
项目:DarwinSPL    文件:HyconstraintsQuickAssistProcessor.java   
private List<eu.hyvar.feature.constraint.resource.hyconstraints.IHyconstraintsQuickFix> getQuickFixes(ISourceViewer sourceViewer, int offset, int length) {
    List<eu.hyvar.feature.constraint.resource.hyconstraints.IHyconstraintsQuickFix> foundFixes = new ArrayList<eu.hyvar.feature.constraint.resource.hyconstraints.IHyconstraintsQuickFix>();
    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.constraint.resource.hyconstraints.IHyconstraintsQuickFix> quickFixes = getQuickFixes(annotation);
        if (quickFixes != null) {
            foundFixes.addAll(quickFixes);
        }
    }
    return foundFixes;
}
项目:DarwinSPL    文件:HyconstraintsHighlighting.java   
private void removeHighlightingCategory(IDocument document, String category) {
    Position[] positions = positionHelper.getPositions(document, category);
    if (category.equals(eu.hyvar.feature.constraint.resource.hyconstraints.ui.HyconstraintsPositionCategory.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);
}
项目:tlaplus    文件:TLAEditor.java   
/**
 * Update the annotation structure in the editor.
 * 
 * This is only currently used by comment
 * folding and should be removed because it
 * is incorrect.
 * 
 * @param positions
 * @deprecated
 */
public void updateFoldingStructure(List<Position> positions)
{
    if (annotationModel == null) {
        return;
    }

    Annotation[] annotations = new Annotation[positions.size()];

    // this will hold the new annotations along
    // with their corresponding positions
    Map<ProjectionAnnotation, Position> newAnnotations = new HashMap<ProjectionAnnotation, Position>();

    for (int i = 0; i < positions.size(); i++)
    {
        ProjectionAnnotation annotation = new ProjectionAnnotation();
        newAnnotations.put(annotation, positions.get(i));
        annotations[i] = annotation;
    }
    // If this method is called too early, then annotationModel
    // can be null. This should obviously be addressed.
    this.annotationModel.modifyAnnotations(oldAnnotations, newAnnotations, null);
    oldAnnotations = annotations;
}
项目:DarwinSPL    文件:HymanifestHighlighting.java   
private void removeHighlightingCategory(IDocument document, String category) {
    Position[] positions = positionHelper.getPositions(document, category);
    if (category.equals(eu.hyvar.mspl.manifest.resource.hymanifest.ui.HymanifestPositionCategory.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);
}
项目:DarwinSPL    文件:HymanifestCodeFoldingManager.java   
/**
 * <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();
}
项目:DarwinSPL    文件:HymanifestQuickAssistProcessor.java   
private List<eu.hyvar.mspl.manifest.resource.hymanifest.IHymanifestQuickFix> getQuickFixes(ISourceViewer sourceViewer, int offset, int length) {
    List<eu.hyvar.mspl.manifest.resource.hymanifest.IHymanifestQuickFix> foundFixes = new ArrayList<eu.hyvar.mspl.manifest.resource.hymanifest.IHymanifestQuickFix>();
    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.mspl.manifest.resource.hymanifest.IHymanifestQuickFix> quickFixes = getQuickFixes(annotation);
        if (quickFixes != null) {
            foundFixes.addAll(quickFixes);
        }
    }
    return foundFixes;
}
项目:fluentmark    文件:FluentMkEditor.java   
/**
 * Returns the annotation overlapping with the given range or <code>null</code>.
 *
 * @param offset the region offset
 * @param length the region length
 * @return the found annotation or <code>null</code>
 */
private Annotation getAnnotation(int offset, int length) {
    IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
    if (model == null) {
        return null;
    }

    Iterator<Annotation> e = new AnnotationIterator(model, true, false);
    while (e.hasNext()) {
        Annotation a = e.next();
        Position p = model.getPosition(a);
        if (p != null && p.overlapsWith(offset, length)) {
            return a;
        }
    }
    return null;
}
项目:fluentmark    文件:FoldingStructureProvider.java   
/**
 * Finds a match for <code>tuple</code> in a collection of annotations. The positions for the
 * <code>MkProjectionAnnotation</code> instances in <code>annotations</code> can be found in the
 * passed <code>positionMap</code> or in the model if <code>positionMap</code> is
 * <code>null</code>.
 * <p>
 * A tuple is said to match another if their annotations have the same category and their
 * position offsets are equal.
 * </p>
 * <p>
 * If a match is found, the annotation gets removed from <code>annotations</code>.
 * </p>
 * 
 * @param tuple the tuple for which we want to find a match
 * @param annotations collection of <code>MkProjectionAnnotation</code>
 * @param positionMap a <code>Map&lt;Annotation, Position&gt;</code> or <code>null</code>
 * @return a matching tuple or <code>null</code> for no match
 */
private Tuple findMatch(Tuple tuple, Collection<MkProjectionAnnotation> annotations,
        Map<MkProjectionAnnotation, Position> positionMap, FoldingStructureComputationContext ctx) {
    Iterator<MkProjectionAnnotation> it = annotations.iterator();
    while (it.hasNext()) {
        MkProjectionAnnotation annotation = it.next();
        if (tuple.annotation.getCategory() == annotation.getCategory()) {
            Position position = positionMap == null ? ctx.getModel().getPosition(annotation)
                    : positionMap.get(annotation);
            if (position == null) continue;

            if (tuple.position.getOffset() == position.getOffset()) {
                it.remove();
                return new Tuple(annotation, position);
            }
        }
    }

    return null;
}
项目:texlipse    文件:TexOutlinePage.java   
/**
 * Gets the text of the currently selected item. Use by copy paste
 * and drag'n'drop operations. 
 * 
 * @return text of the currently selected item or null if no item
 * is selected
 * 
 * TODO handle multiple selections
 */
public String getSelectedText() {
    IStructuredSelection selection = (IStructuredSelection)getTreeViewer().getSelection();
    if (selection == null) {
        return null;
    }

    OutlineNode node = (OutlineNode)selection.getFirstElement();
    Position pos = node.getPosition();

    String text;
    try {
        text = this.editor.getDocumentProvider().getDocument(this.editor.getEditorInput()).get(pos.getOffset(), pos.getLength());
    } catch (BadLocationException e) {
        return null;
    }
    return text;
}
项目:texlipse    文件:TexOutlinePage.java   
/**
 * Removes the text of the currently selected item From the 
 * document. Used by copy paste and drag'n'drop operations.
 * 
 * Trigger parsing after remove is done. 
 * 
 * TODO handle multiple selections
 */
public void removeSelectedText() {
    IStructuredSelection selection = (IStructuredSelection)getTreeViewer().getSelection();
    if (selection == null) {
        return;
    }

    OutlineNode node = (OutlineNode)selection.getFirstElement();
    Position pos = node.getPosition();

    try {
        this.editor.getDocumentProvider().getDocument(this.editor.getEditorInput()).replace(pos.getOffset(), pos.getLength(), "");
    } catch (BadLocationException e) {
        return;
    }

    this.editor.updateModelNow();
}
项目:texlipse    文件:TexOutlinePage.java   
/**
 * Pastes given text after the selected item. Used by the paste
 * action.
 * 
 * Triggers model update afterwards.
 * 
 * @param text the text to be pasted
 * @return true if pasting was succesful, otherwise false
 */
public boolean paste(String text) {
    // get selection
    IStructuredSelection selection = (IStructuredSelection)getTreeViewer().getSelection();
    if (selection == null) {
        return false;
    }
    OutlineNode node = (OutlineNode)selection.getFirstElement();
    Position pos = node.getPosition();

    // paste the text
    try {
        this.editor.getDocumentProvider().getDocument(this.editor.getEditorInput()).replace(pos.getOffset() + pos.getLength(), 0, text);
    } catch (BadLocationException e) {
        return false;
    }

    // trigger parsing
    this.editor.updateModelNow();
    return true;
}
项目:texlipse    文件:TexOutlineDNDAdapter.java   
/**
    * Set the text data into TextTransfer.
    * 
    * @see org.eclipse.swt.dnd.DragSourceListener#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
 */
   public void dragSetData(DragSourceEvent event) {

    // check that requested data type is supported
    if (!TextTransfer.getInstance().isSupportedType(event.dataType)) {
        return;
    }

       // get the source text
    int sourceOffset = this.dragSource.getPosition().getOffset();
    int sourceLength = this.dragSource.getPosition().getLength();

    Position sourcePosition = dragSource.getPosition();
    String sourceText = "";
    try {
        sourceText = getDocument().get(sourcePosition.getOffset(), sourcePosition.getLength());
    } catch (BadLocationException e) {
        TexlipsePlugin.log("Could not set drag data.", e);
        return;
    }

       // set the data
       event.data = sourceText;
}
项目:pgcodekeeper    文件:SQLEditor.java   
public void setLineBackground() {
    // TODO who deletes stale annotations after editor refresh?
    List<PgObjLocation> refs = getParser().getObjsForEditor(getEditorInput());
    IAnnotationModel model = getSourceViewer().getAnnotationModel();
    for (PgObjLocation loc : refs) {
        String annotationMsg = null;
        if (loc.getAction() == StatementActions.DROP && loc.getObjType() == DbObjType.TABLE){
            annotationMsg = "DROP TABLE statement"; //$NON-NLS-1$
        } else if (loc.getAction() == StatementActions.ALTER){
            String text = loc.getText();
            if (loc.getObjType() == DbObjType.TABLE) {
                if (DangerStatement.ALTER_COLUMN.getRegex().matcher(text).matches()) {
                    annotationMsg = "ALTER COLUMN ... TYPE statement"; //$NON-NLS-1$
                } else if (DangerStatement.DROP_COLUMN.getRegex().matcher(text).matches()) {
                    annotationMsg = "DROP COLUMN statement"; //$NON-NLS-1$
                }
            } else if (loc.getObjType() == DbObjType.SEQUENCE &&
                    DangerStatement.RESTART_WITH.getRegex().matcher(text).matches()) {
                annotationMsg = "ALTER SEQUENCE ... RESTART WITH statement"; //$NON-NLS-1$
            }
        }
        if (annotationMsg != null) {
            model.addAnnotation(new Annotation(MARKER.DANGER_ANNOTATION, false, annotationMsg),
                    new Position(loc.getOffset(), loc.getObjLength()));
        }
    }
}
项目:pgcodekeeper    文件:SQLMarkerUpdate.java   
@Override
public boolean updateMarker(IMarker marker, IDocument document, Position position) {
    try {
        int start = position.getOffset();
        int end = position.getOffset() + position.getLength();
        marker.setAttribute(IMarker.CHAR_START, start);
        marker.setAttribute(IMarker.CHAR_END, end);
    } catch (CoreException e) {
        Log.log(e);
    }
    return true;
}