From a4d94edb4d65edf7a2003cf0958ebd7fae594a37 Mon Sep 17 00:00:00 2001 From: Eugene Vigdorchik Date: Mon, 14 Mar 2005 16:31:35 +0300 Subject: [PATCH] Well, hopefully fixed transforming code fragments' chameleons --- .../tempWithQuery/TempWithQueryHandler.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/source/com/intellij/refactoring/tempWithQuery/TempWithQueryHandler.java b/source/com/intellij/refactoring/tempWithQuery/TempWithQueryHandler.java index 3efdb45ebd4f..a1bca3fc7b7e 100644 --- a/source/com/intellij/refactoring/tempWithQuery/TempWithQueryHandler.java +++ b/source/com/intellij/refactoring/tempWithQuery/TempWithQueryHandler.java @@ -3,6 +3,7 @@ package com.intellij.refactoring.tempWithQuery; import com.intellij.codeInsight.TargetElementUtil; import com.intellij.codeInsight.highlighting.HighlightManager; import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.DataConstants; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.diagnostic.Logger; @@ -46,12 +47,14 @@ public class TempWithQueryHandler implements RefactoringActionHandler { return; } + invokeOnVariable(file, project, ((PsiLocalVariable)element), editor); + } + + private void invokeOnVariable(final PsiFile file, final Project project, final PsiLocalVariable local, final Editor editor) { if (!file.isWritable()) { if (!RefactoringMessageUtil.checkReadOnlyStatus(project, file)) return; } - final PsiLocalVariable local = (PsiLocalVariable) element; - String localName = local.getName(); final PsiExpression initializer = local.getInitializer(); if (initializer == null) { @@ -156,5 +159,14 @@ public class TempWithQueryHandler implements RefactoringActionHandler { } public void invoke(Project project, PsiElement[] elements, DataContext dataContext) { + if (elements != null && elements.length == 1 && elements[0] instanceof PsiLocalVariable) { + if (dataContext != null) { + final PsiFile file = (PsiFile)dataContext.getData(DataConstants.PSI_FILE); + final Editor editor = (Editor)dataContext.getData(DataConstants.EDITOR); + if (file != null && editor != null) { + invokeOnVariable(file, project, (PsiLocalVariable)elements[0], editor); + } + } + } } } \ No newline at end of file