org.eclipse.jface.text.Position Java Examples

The following examples show how to use org.eclipse.jface.text.Position. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContributionAnnotationManagerTest.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testInsertAnnotationWithLengthGreaterOne() {
  final int annotationLength = 3;

  manager.insertAnnotation(model, 5, annotationLength, ALICE_TEST_USER);

  final List<Position> annotationPositions = getAnnotationPositions(model);

  assertEquals(
      "Annotation was not split into multiple annotation of length 1",
      annotationLength,
      annotationPositions.size());
  assertTrue(annotationPositions.contains(new Position(5, 1)));
  assertTrue(annotationPositions.contains(new Position(6, 1)));
  assertTrue(annotationPositions.contains(new Position(7, 1)));
}
 
Example #2
Source File: IndentForTabHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Insert tab/spaces at selection offset and each subsequent line origin
 * 
 * @see com.mulgasoft.emacsplus.commands.EmacsPlusCmdHandler#transform(ITextEditor, IDocument, ITextSelection, ExecutionEvent)
 */
@Override
protected int transform(ITextEditor editor, IDocument document, ITextSelection currentSelection, ExecutionEvent event)
throws BadLocationException {
	// if we're here, either ^U or no relevant ^I
	ColumnSupport cs = new ColumnSupport(document,editor); 
	String tab = cs.getSpaces(0,cs.getTabWidth());
	int off = currentSelection.getOffset();
	Position coff = new Position(getCursorOffset(editor,currentSelection),0);
	try {
		document.addPosition(coff);
		int begin = document.getLineOfOffset(off);
		int end = document.getLineOfOffset(off+ currentSelection.getLength());
		if (begin != end) {
			while (++begin <= end) {
				document.replace(document.getLineOffset(begin), 0, tab);
			}
		}
		document.replace(off, 0, tab);
	} finally {
		document.removePosition(coff);
	} 
	return coff.offset;
}
 
Example #3
Source File: UnknownElementsIndexerTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void should_add_to_overriden_variables_a_variable_declared_and_already_in_the_process_scope() throws Exception {
    final BonitaScriptGroovyCompilationUnit groovyCompilationUnit = mock(BonitaScriptGroovyCompilationUnit.class, RETURNS_DEEP_STUBS);
    Map<String, ScriptVariable> context = new HashMap<String, ScriptVariable>();
    context.put("declaredVar", null);
    when(groovyCompilationUnit.getContext()).thenReturn(context);
    
    final List<Statement> statements = new ArrayList<Statement>();
    statements.add(new ExpressionStatement(
            new DeclarationExpression(new VariableExpression("declaredVar"), Token.NULL, new VariableExpression("something"))));
    statements.add(new ReturnStatement(new VariableExpression("declaredVar")));
    final VariableScope variableScope = new VariableScope();
    variableScope.putDeclaredVariable(new VariableExpression("declaredVar"));
    final BlockStatement blockStatement = new BlockStatement(statements, variableScope);

    when(groovyCompilationUnit.getModuleNode().getStatementBlock()).thenReturn(blockStatement);
    final UnknownElementsIndexer unknownElementsIndexer = new UnknownElementsIndexer(groovyCompilationUnit);

    unknownElementsIndexer.run(new NullProgressMonitor());

    assertThat(unknownElementsIndexer.getOverridenVariables()).containsExactly(entry("declaredVar", new Position(0)));
}
 
Example #4
Source File: EditorUtils.java    From typescript.java with MIT License 6 votes vote down vote up
public static Position getPosition(IFile file, TextSpan textSpan) throws BadLocationException {
	ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
	ITextFileBuffer buffer = bufferManager.getTextFileBuffer(file.getLocation(), LocationKind.IFILE);
	if (buffer != null) {
		return getPosition(buffer.getDocument(), textSpan);
	}
	IDocumentProvider provider = new TextFileDocumentProvider();
	try {
		provider.connect(file);
		IDocument document = provider.getDocument(file);
		if (document != null) {
			return getPosition(document, textSpan);
		}
	} catch (CoreException e) {
	} finally {
		provider.disconnect(file);
	}
	return null;
}
 
Example #5
Source File: TexOutlinePage.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Focuses the editor to the text of the selected item.
 * 
 * @param event the selection event
 */
public void selectionChanged(SelectionChangedEvent event) {
    super.selectionChanged(event);
    
    ISelection selection = event.getSelection();
    if (selection.isEmpty()) {
        editor.resetHighlightRange();
    }
    
    else {
        OutlineNode node = (OutlineNode) ((IStructuredSelection) selection).getFirstElement();
        Position position = node.getPosition();
        if (position != null) {
            try {
                editor.setHighlightRange(position.getOffset(), position.getLength(), true);
                editor.getViewer().revealRange(position.getOffset(), position.getLength());
            } catch (IllegalArgumentException x) {
                editor.resetHighlightRange();
            }
        } else {
            editor.resetHighlightRange();
        }
    }        
}
 
Example #6
Source File: AnnotationWithQuickFixesHover.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected Object getHoverInfoInternal(ITextViewer textViewer, final int lineNumber, final int offset) {
	AnnotationInfo result = recentAnnotationInfo;
	if (result != null)
		return result;
	List<Annotation> annotations = getAnnotations(lineNumber, offset);
	for (Annotation annotation : sortBySeverity(annotations)) {
		Position position = getAnnotationModel().getPosition(annotation);
		if (annotation.getText() != null && position != null) {
			final QuickAssistInvocationContext invocationContext = new QuickAssistInvocationContext(sourceViewer, position.getOffset(), position.getLength(), true);
			CompletionProposalRunnable runnable = new CompletionProposalRunnable(invocationContext);
			// Note: the resolutions have to be retrieved from the UI thread, otherwise
			// workbench.getActiveWorkbenchWindow() will return null in LanguageSpecificURIEditorOpener and
			// cause an exception
			Display.getDefault().syncExec(runnable);
			if (invocationContext.isMarkedCancelled()) {
				return null;
			}
			result = new AnnotationInfo(annotation, position, sourceViewer, runnable.proposals);
			recentAnnotationInfo = result;
			return result;
		}
	}
	return null;
}
 
Example #7
Source File: ExternalBreakpointWatcher.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
protected void updateMarkerAnnotation(IMarker marker) {
	
	Iterator<Annotation> iter = annotationModel.getAnnotationIterator();
	
	for (Annotation ann : (Iterable<Annotation>) () -> iter) {
		if(ann instanceof MarkerAnnotation) {
			MarkerAnnotation markerAnnotation = (MarkerAnnotation) ann;
			if(markerAnnotation.getMarker().equals(marker)) {
				
				Position position = annotationModel.getPosition(markerAnnotation);
				
				// Trigger a model update.
				annotationModelExt.modifyAnnotationPosition(markerAnnotation, position);
				
				return;
			}
		}
	}
}
 
Example #8
Source File: JsonEditor.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean show(ShowInContext context) {
    ISelection selection = context.getSelection();

    if (selection instanceof IStructuredSelection) {
        Object selected = ((IStructuredSelection) selection).getFirstElement();

        if (selected instanceof AbstractNode) {
            Position position = ((AbstractNode) selected).getPosition(getSourceViewer().getDocument());
            selectAndReveal(position.getOffset(), position.getLength());
            return true;
        }
    }

    return false;
}
 
Example #9
Source File: TexOutlinePage.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #10
Source File: UpdateUnknownReferencesListener.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private Map<Annotation,Position> createWarningAnnotations(final String variable) {
    final FindReplaceDocumentAdapter finder = new FindReplaceDocumentAdapter(document);
    final String expression = document.get();
    final Map<Annotation,Position> annotations= new HashMap<Annotation,Position>();
    try {
        IRegion region = finder.find(0, variable, true, true, true, false);
        while (region != null) {
            final Position position = new Position(region.getOffset(), region.getLength());
            if (!isInAStringExpression(variable, region, expression)) {
                annotations.put(new Annotation(JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE, false, createDescription(variable)), position);
            }
            region = finder.find(position.getOffset() + position.getLength(), variable, true, true, true, false);

        }
    } catch (final BadLocationException e) {

    }
    return annotations ;
}
 
Example #11
Source File: TexOutlineDNDAdapter.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
    * 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;
}
 
Example #12
Source File: ModulaSpellingHover.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private HoverInfoWithSpellingAnnotation getSpellingHover(ITextViewer textViewer, IRegion hoverRegion) {
    IAnnotationModel model= null;
    if (textViewer instanceof ISourceViewerExtension2) {
        model = ((ISourceViewerExtension2)textViewer).getVisualAnnotationModel();
    } else if (textViewer instanceof SourceViewer) {
        model= ((SourceViewer)textViewer).getAnnotationModel();
    }
    if (model != null) {
        @SuppressWarnings("rawtypes")
        Iterator e= model.getAnnotationIterator();
        while (e.hasNext()) {
            Annotation a= (Annotation) e.next();
            if (a instanceof SpellingAnnotation) {
                Position p= model.getPosition(a);
                if (p != null && p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
                    return new HoverInfoWithSpellingAnnotation((SpellingAnnotation)a, textViewer, p.getOffset());
                }
            }
        }
    }
    return null;
}
 
Example #13
Source File: CodeFoldingSetter.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @return an annotation that should be added (or null if that entry already has an annotation
 * added for it).
 */
private Tuple<ProjectionAnnotation, Position> getAnnotationToAdd(FoldingEntry node, int start, int end,
        ProjectionAnnotationModel model, List<Annotation> existing) throws BadLocationException {
    try {
        IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
        int offset = document.getLineOffset(start);
        int endOffset = offset;
        try {
            endOffset = document.getLineOffset(end);
        } catch (Exception e) {
            //sometimes when we are at the last line, the command above will not work very well
            IRegion lineInformation = document.getLineInformation(end);
            endOffset = lineInformation.getOffset() + lineInformation.getLength();
        }
        Position position = new Position(offset, endOffset - offset);

        return getAnnotationToAdd(position, node, model, existing);

    } catch (BadLocationException x) {
        //this could happen
    }
    return null;
}
 
Example #14
Source File: CompilationUnitDocumentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public Object get(Position position) {

			Entry entry;

			// behind anchor
			int length= fList.size();
			for (int i= fAnchor; i < length; i++) {
				entry= fList.get(i);
				if (entry.fPosition.equals(position)) {
					fAnchor= i;
					return entry.fValue;
				}
			}

			// before anchor
			for (int i= 0; i < fAnchor; i++) {
				entry= fList.get(i);
				if (entry.fPosition.equals(position)) {
					fAnchor= i;
					return entry.fValue;
				}
			}

			return null;
		}
 
Example #15
Source File: SemanticHighlightingPresenter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns index of the position in the positions, <code>-1</code> if not found.
 * @param positions the positions, must be ordered by offset but may overlap
 * @param position the position
 * @return the index
 */
private int indexOf(List<? extends Position> positions, Position position) {
	int index= computeIndexAtOffset(positions, position.getOffset());
	int size= positions.size();
	while (index < size) {
		if (positions.get(index) == position)
			return index;
		index++;
	}
	return -1;
}
 
Example #16
Source File: IndentFoldingStrategy.java    From typescript.java with MIT License 5 votes vote down vote up
private void addAnnotationForKeyword(List<Annotation> modifications, List<FoldingAnnotation> deletions,
		List<FoldingAnnotation> existing, Map<Annotation, Position> additions, int startLine,
		Integer lastLineForKeyword) throws BadLocationException {
	if (lastLineForKeyword != null) {
		updateAnnotation(modifications, deletions, existing, additions, startLine, lastLineForKeyword);
	}
}
 
Example #17
Source File: TLAAnnotationHover.java    From tlaplus with MIT License 5 votes vote down vote up
private String[] getMessagesForLine(final ISourceViewer viewer, final int line) {
	final IAnnotationModel model = viewer.getAnnotationModel();

	if (model == null) {
		return new String[0];
	}

	final Iterator<Annotation> it = model.getAnnotationIterator();
	final IDocument document = viewer.getDocument();
	final ArrayList<String> messages = new ArrayList<>();
	final HashMap<Position, Set<String>> placeMessagesMap = new HashMap<>();
	while (it.hasNext()) {
		final Annotation annotation = it.next();
		if (annotation instanceof MarkerAnnotation) {
			final MarkerAnnotation ma = (MarkerAnnotation) annotation;
			final Position p = model.getPosition(ma);
			if (compareRulerLine(p, document, line)) {
				final IMarker marker = ma.getMarker();
				final String message = marker.getAttribute(IMarker.MESSAGE, null);
				if ((message != null) && (message.trim().length() > 0)) {
					Set<String> priorMessages = placeMessagesMap.get(p);
					if (priorMessages == null) {
						priorMessages = new HashSet<>();
						placeMessagesMap.put(p, priorMessages);
					}
					
					if (!priorMessages.contains(message)) {
						messages.add(message);
						priorMessages.add(message);
					}
				}
			}
		}
	}
	return (String[]) messages.toArray(new String[messages.size()]);
}
 
Example #18
Source File: IndentFoldingStrategy.java    From typescript.java with MIT License 5 votes vote down vote up
private void updateAnnotation(List<Annotation> modifications, List<FoldingAnnotation> deletions,
		List<FoldingAnnotation> existing, Map<Annotation, Position> additions, int line, int endLineNumber)
		throws BadLocationException {
	int startOffset = document.getLineOffset(line);
	int endOffset = document.getLineOffset(endLineNumber) + document.getLineLength(endLineNumber);
	Position newPos = new Position(startOffset, endOffset - startOffset);
	if (existing.size() > 0) {
		FoldingAnnotation existingAnnotation = existing.remove(existing.size() - 1);
		updateAnnotations(existingAnnotation, newPos, additions, modifications, deletions);
	} else {
		additions.put(new FoldingAnnotation(false), newPos);
	}
}
 
Example #19
Source File: GamlEditor.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public void applyTemplate(final Template t) {
	// TODO Create a specific context type (with GAML specific variables ??)
	final XtextTemplateContextType ct = new XtextTemplateContextType();
	final IDocument doc = getDocument();
	final ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection();
	final int offset = selection.getOffset();
	final int length = selection.getLength();
	final Position pos = new Position(offset, length);
	final DocumentTemplateContext dtc = new DocumentTemplateContext(ct, doc, pos);
	final IRegion r = new Region(offset, length);
	final TemplateProposal tp = new TemplateProposal(t, dtc, r, null);
	tp.apply(getInternalSourceViewer(), (char) 0, 0, offset);
}
 
Example #20
Source File: ExternalFileAnnotationModel.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private Position generatePosition(IProblem problem)
{
	int start = problem.getOffset();
	if (start < 0)
	{
		return new Position(0);
	}
	int length = problem.getLength();
	if (length < 0)
	{
		return null;
	}

	return new Position(start, length);
}
 
Example #21
Source File: TemplateEngine.java    From typescript.java with MIT License 5 votes vote down vote up
public void reset() {
	fProposals.clear();
	for (Iterator it = fPositions.entrySet().iterator(); it.hasNext();) {
		Entry entry = (Entry) it.next();
		IDocument doc = (IDocument) entry.getKey();
		Position position = (Position) entry.getValue();
		doc.removePosition(position);
	}
	fPositions.clear();
}
 
Example #22
Source File: TLAFastPartitioner.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * Returns the index of the first position which ends after the given offset.
 *
 * @param positions the positions in linear order
 * @param offset the offset
 * @return the index of the first position which ends after the offset
 */
private int getFirstIndexEndingAfterOffset(Position[] positions, int offset) {
    int i= -1, j= positions.length;
    while (j - i > 1) {
        int k= (i + j) >> 1;
        Position p= positions[k];
        if (p.getOffset() + p.getLength() > offset)
            j= k;
        else
            i= k;
    }
    return j;
}
 
Example #23
Source File: BibCodeFolder.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Fills the given annotation map with all the annotations from this document.
 * 
 * @param documentTree Document tree representing this document
 * @param map The annotation map to fill
 * @param fold Whether entries should be set as folded or not
 */
private void fillAnnotationMap(List documentTree, Map map, boolean fold) {
    for (ListIterator iter = documentTree.listIterator(); iter.hasNext();) {
        ReferenceEntry node = (ReferenceEntry) iter.next();
        
        Position pos = node.position;
        
        BibProjectionAnnotation tpa = new BibProjectionAnnotation(node, fold);
        map.put(tpa, pos);
    }
}
 
Example #24
Source File: DefaultFoldingStructureProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void updateFoldingRegions(boolean allowCollapse, ProjectionAnnotationModel model,
		Collection<FoldedPosition> foldedPositions, Annotation[] deletions) {
	Map<ProjectionAnnotation, Position> additionsMap = Maps.newHashMap();
	for (FoldedPosition foldedPosition: foldedPositions) {
		addProjectionAnnotation(allowCollapse, foldedPosition, additionsMap);
	}
	if (deletions.length != 0 || additionsMap.size() != 0) {
		model.modifyAnnotations(deletions, additionsMap, new Annotation[] {});
	}
}
 
Example #25
Source File: ModulaOccurrencesMarker.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private Map<Annotation, Position> createOccurrencesAnnotations(IModulaSymbol symToMark, Collection<TextPosition> symPositions) {
    final Map<Annotation, Position> map = new HashMap<Annotation, Position>();
    if (symPositions != null && symToMark != null) {
        for (TextPosition pos : symPositions) {
            String msg = String.format(Messages.OccurrencesMarker_OccurrenceOf, symToMark.getName());
            Annotation annotation = new Annotation(OCCURENCE_ANNOTATION_ID, false, msg);
            //TODO: write occurrences when need:
            //String.format(Messages.OccurrencesMarker_WriteOccurrencesMarker, symToMark.getName());
            //Annotation annotation = new Annotation(WRITE_ANNOTATION_ID, false, msg);
            Position position = new Position(pos.getOffset(), symToMark.getName().length());
            map.put(annotation, position);
        }
    }
    return map;
}
 
Example #26
Source File: AnnotationWithQuickFixesHover.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Region getHoverRegionInternal(final int lineNumber, final int offset) {
	recentAnnotationInfo = null;
	List<Annotation> annotations = getAnnotations(lineNumber, offset);
	for (Annotation annotation : sortBySeverity(annotations)) {
		Position position = sourceViewer.getAnnotationModel().getPosition(annotation);
		if (position != null) {
			final int start = position.getOffset();
			return new Region(start, position.getLength());	
		}
	}
	return null;
}
 
Example #27
Source File: JavaTemplatesPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get context
 * 
 * @param document the document
 * @param template the template
 * @param offset the offset
 * @param length the length
 * @return the context
 */
private DocumentTemplateContext getContext(IDocument document, Template template, final int offset, int length) {
	DocumentTemplateContext context;
	if (template.getContextTypeId().equals(JavaDocContextType.ID)) {
		context= new JavaDocContext(getContextTypeRegistry().getContextType(template.getContextTypeId()), document, new Position(offset, length), (ICompilationUnit) EditorUtility
				.getEditorInputJavaElement(fJavaEditor, true));
	} else {
		context= new JavaContext(getContextTypeRegistry().getContextType(template.getContextTypeId()), document, new Position(offset, length), (ICompilationUnit) EditorUtility.getEditorInputJavaElement(
				fJavaEditor, true));
	}
	return context;
}
 
Example #28
Source File: DocumentPartitioner.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the index of the first position which ends after the given offset.
 * 
 * @param positions
 *            the positions in linear order
 * @param offset
 *            the offset
 * @return the index of the first position which ends after the offset
 */
private int getFirstIndexEndingAfterOffset(Position[] positions, int offset) {
	int i = -1, j = positions.length;
	while (j - i > 1) {
		int k = (i + j) >> 1;
		Position p = positions[k];
		if (p.getOffset() + p.getLength() > offset)
			j = k;
		else
			i = k;
	}
	return j;
}
 
Example #29
Source File: CommonReconcilingStrategy.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected void calculatePositions(boolean initialReconcile, IProgressMonitor monitor, IParseRootNode ast)
{
	if (monitor != null && monitor.isCanceled())
	{
		return;
	}

	// Folding...

	try
	{
		Map<ProjectionAnnotation, Position> positions = folder.emitFoldingRegions(initialReconcile, monitor, ast);
		synchronized (fPositionsLock)
		{
			fPositions = positions;
		}
	}
	catch (BadLocationException e)
	{
		IdeLog.logError(CommonEditorPlugin.getDefault(), e);
	}
	// If we had all positions we shouldn't probably listen to cancel, but we may have exited emitFoldingRegions
	// early because of cancel...
	if (monitor != null && monitor.isCanceled() || !shouldUpdatePositions(folder))
	{
		return;
	}

	updatePositions();
}
 
Example #30
Source File: JavaDebugElementCodeMining.java    From jdt-codemining with Eclipse Public License 1.0 5 votes vote down vote up
private static Position getPosition(ASTNode node, IDocument document) {
	int offset = node.getStartPosition();
	try {
		IRegion region = document.getLineInformationOfOffset(offset);
		return new Position(region.getOffset() + region.getLength(), 1);
	} catch (BadLocationException e) {
		return new Position(offset, 1);
	}
}