Example usage for org.eclipse.jdt.core.dom TextElement getStartPosition

List of usage examples for org.eclipse.jdt.core.dom TextElement getStartPosition

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom TextElement getStartPosition.

Prototype

public final int getStartPosition() 

Source Link

Document

Returns the character index into the original source file indicating where the source fragment corresponding to this node begins.

Usage

From source file:com.google.gwt.eclipse.core.refactoring.regionupdater.TextElementRegionUpdater.java

License:Open Source License

@Override
protected ReplaceEdit createUpdatedEditForEquivalentNode(TextElement equivalentNode)
        throws RefactoringException {
    // Adjust the offset based on the difference between start positions of
    // equivalent nodes
    int newOffset = getOriginalEdit().getOffset() + equivalentNode.getStartPosition()
            - getOriginalNode().getStartPosition();

    return new ReplaceEdit(newOffset, getOriginalEdit().getLength(), getOriginalEdit().getText());
}

From source file:org.eclipse.mylyn.internal.bugs.java.BugzillaHyperLinkDetector.java

License:Open Source License

@SuppressWarnings("unchecked")
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region,
        boolean canShowMultipleHyperlinks) {

    ITextEditor textEditor = getEditor();
    if (region == null || textEditor == null || canShowMultipleHyperlinks
            || !(textEditor instanceof JavaEditor))
        return null;

    IEditorSite site = textEditor.getEditorSite();
    if (site == null)
        return null;

    IJavaElement javaElement;//from   w  ww.jav  a 2 s .c  om
    Object adapter = textEditor.getEditorInput().getAdapter(IJavaElement.class);
    if (adapter instanceof IJavaElement) {
        javaElement = (IJavaElement) adapter;
    } else {
        return null;
    }

    if (javaElement == null)
        return null;

    CompilationUnit ast = JavaPlugin.getDefault().getASTProvider().getAST(javaElement, ASTProvider.WAIT_NO,
            null);
    if (ast == null)
        return null;

    ASTNode node = NodeFinder.perform(ast, region.getOffset(), 1);

    if (node == null || !(node instanceof TextElement || node instanceof Block))
        return null;

    String comment = null;
    int commentStart = -1;

    if (node instanceof TextElement) {
        TextElement element = (TextElement) node;
        comment = element.getText();
        commentStart = element.getStartPosition();
    } else if (node instanceof Block) {
        Comment c = findComment(ast.getCommentList(), region.getOffset(), 1);
        if (c != null) {
            try {
                IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
                String commentString = document.get(c.getStartPosition(), c.getLength());
                comment = getStringFromComment(c, region.getOffset(), commentString);
                commentStart = getLocationFromComment(c, comment, commentString) + c.getStartPosition();
            } catch (BadLocationException e) {
                MylarStatusHandler.log(e, "Failed to get text for comment");
            }
        }
    }

    if (comment == null)
        return null;

    int startOffset = region.getOffset();
    int endOffset = startOffset + region.getLength();

    return BugzillaHyperlinkUtil.findBugHyperlinks(repository.getUrl(), startOffset, endOffset, comment,
            commentStart);
}