Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-ui-dev] Location in editor problems when source is folded

Title: Location in editor problems when source is folded

Hope this isn't to tediuos a question, here goes:

I have made a plugin that displays some information on top of a method int he editor when I get an event.

The following code works fine when nothing is folding in the editor, but if I fold a long list of import statements the location returned by this code is off by quite a bit, and in some cases I get an "Index out of bounds" from StyledText.getLocationAtOffset(int offset).

Snippet:
if (mElement instanceof IMethod) {
        IMethod method = (IMethod) mElement;
        Point methodP = new Point(0, 0);
        try {
                int offset = method.getSourceRange().getOffset();
                int methodOffset = method.getNameRange().getOffset();
                Point p = mSt.getLocationAtOffset(offset);
                methodP = mSt.getLocationAtOffset(methodOffset);
                methodP.x = p.x;
                methodP.y -= getTag().getBounds().height;
                getTag().setLocation(methodP);
        } catch (JavaModelException e) {
                log.error(ACView.getPrefix() + "Error setting position", e);
        }
}

Info:
mElement is of type IJavaElement
and I have checked for:
mElement.getElementType() == IJavaElement.METHOD

mSt is off type StyledText.

Im a bit unsure of how Im supposed to handle folding in the editor, or am I doing something totally wrong?

Any help is much appreciated on how I always retrieve the correct possition of the element.

/Per


Back to the top