intentions and document manipulation ...

!!to all intention gurus out there!!

im playing around with intentions and the IntentionAction.
what i want to implement as the simples possible intention
is create getter/setter from a field context if not getter setter is
available.
not too difficult: here is the code (field contains the accepted field).

public void invoke(Project project, Editor editor, PsiFile psiFile)
throws com.intellij.util.IncorrectOperationException {
PsiMethod m = PropertyUtil.generateGetterPrototype(field);
m = (PsiMethod) field.getParent().addAfter(m, field);

// editor.getSelectionModel().setSelection(m.getTextOffset(),
m.getTextOffset() + m.getTextLength());
}

what i want do in the commented line is to set the selection of the
editor to the newly created method so that i can move it with the
line-up-down mover.

now i have some questions ...
- why must return startInWriteAction return true (false throws an exception)
- why does the outcommented line select not the complete newly created
method but something really strange???
- wich operations are allowed in the invoke (my guess is that the change
of the selection comes a little bit before the document is updated)

thanks

cK

1 comment

// editor.getSelectionModel().setSelection(m.getTextOffset(),
m.getTextOffset() + m.getTextLength());
}

what i want do in the commented line is to set the selection of the
editor to the newly created method so that i can move it with the
line-up-down mover.

now i have some questions ...
- why must return startInWriteAction return true (false throws an
exception)

no answer ...

- why does the outcommented line select not the complete newly created
method but something really strange???

if the textrange is used rather than the getTextOffset-method then the
selection is correct???

- wich operations are allowed in the invoke (my guess is that the change
of the selection comes a little bit before the document is updated)

no answer

cK

0

Please sign in to leave a comment.