One thing though, I keep wanting to change the type from the type of the declaration, not the variable. e.g.: Arr<cursor>ayList list = new ArrayList();
Can you enable it there too?
Bas, I've tried that, but for some mysterious reason,
final CaretModel caretModel = editor.getCaretModel(); return file.findElementAt(caretModel.getOffset());
returns me a PsiComment(C_STYLE_COMMENT), when positioning the caret at the type in the declaration of a field. Even more strange:
final PsiFile file = psiManager.findFile(descriptor.getFile()); final boolean writable = file.isWritable();
They only reasonable guess I could made is... probably that was another 'editor'?
>> One thing though, I keep wanting to change the type from the type of >> the declaration, not the variable. >> >> e.g.: >> >> ArrayList list = new ArrayList();
>>
>> Can you enable it there too?
>>]]>
Bas, I've tried that, but for some mysterious reason,
final CaretModel caretModel = editor.getCaretModel(); return file.findElementAt(caretModel.getOffset()); returns me a PsiComment(C_STYLE_COMMENT), when positioning the caret at the type in the declaration of a field. Even more strange:
final PsiFile file = psiManager.findFile(descriptor.getFile()); final boolean writable = file.isWritable(); writable is false???
Don't use OpenFileDescriptor for anything rather opening files in editor. Use DataConstants.PSI_FILE instead. As the matter of fact the OpenFileDescriptor returned in your case refers to ArrayList.java file.
Max, there is only one file open. I use following code:
dataContext) {
> final Project project =
> (Project)dataContext.getData(DataConstants.PROJECT);
> final PsiManager manager = PsiManager.getInstance(project);
> final PsiElement element = getElementAtCaret(editor, dataContext,
> manager);
> // this element is a PsiComment(C_STYLE_COMMENT)
> ...
> }
> private PsiElement getElementAtCaret(Editor editor, DataContext
> dataContext,
> PsiManager psiManager) {
> final OpenFileDescriptor descriptor =
> (OpenFileDescriptor)dataContext.getData(DataConstants.OPEN_FILE_DESCRI
> PTOR);
> final PsiFile file = psiManager.findFile(descriptor.getFile());
> final CaretModel caretModel = editor.getCaretModel();
> return file.findElementAt(caretModel.getOffset());
> }]]>
Don't use OpenFileDescriptor for anything rather opening files in editor. Use DataConstants.PSI_FILE instead. As the matter of fact the OpenFileDescriptor returned in your case refers to ArrayList.java file.
Do you mean something like this?
final PsiFile file = (PsiFile)dataContext.getData(DataConstants.PSI_FILE);
Sorry. It only appears in the build to be released. You can try "psi.File" string until it is released.
>> Don't use OpenFileDescriptor for anything rather opening files in >> editor. Use DataConstants.PSI_FILE instead. >> As the matter of fact the OpenFileDescriptor returned in your case >> refers to ArrayList.java file.
Do you mean something like this?
final PsiFile file = (PsiFile)dataContext.getData(DataConstants.PSI_FILE);
final Project project = (Project)dataContext.getData(DataConstants.PROJECT); final Document document = editor.getDocument(); final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
Bas, I've tried that, but for some mysterious reason,
final CaretModel caretModel = editor.getCaretModel();
return file.findElementAt(caretModel.getOffset());
returns me a PsiComment(C_STYLE_COMMENT), when positioning the caret at the
type in the declaration of a field. Even more strange:
final PsiFile file = psiManager.findFile(descriptor.getFile());
final boolean writable = file.isWritable();
writable is false???
Tom
They only reasonable guess I could made is... probably that was another 'editor'?
>> One thing though, I keep wanting to change the type from the type of
>> the declaration, not the variable.
>>
>> e.g.:
>>
>> ArrayList list = new ArrayList(); >> >> Can you enable it there too? >>]]>
Max, there is only one file open. I use following code:
Maybe the code is wrong?
Tom
Don't use OpenFileDescriptor for anything rather opening files in editor.
Use DataConstants.PSI_FILE instead.
As the matter of fact the OpenFileDescriptor returned in your case refers
to ArrayList.java file.
Do you mean something like this?
final PsiFile file = (PsiFile)dataContext.getData(DataConstants.PSI_FILE);
There is no constant PSI_FILE available :(
Tom
Sorry. It only appears in the build to be released. You can try "psi.File"
string until it is released.
>> Don't use OpenFileDescriptor for anything rather opening files in
>> editor. Use DataConstants.PSI_FILE instead.
>> As the matter of fact the OpenFileDescriptor returned in your case
>> refers to ArrayList.java file.
Thanks. I've found another way, too:
final Project project = (Project)dataContext.getData(DataConstants.PROJECT);
final Document document = editor.getDocument();
final PsiFile file =
PsiDocumentManager.getInstance(project).getPsiFile(document);
Tom