IDEA-73264 GenerationInfo manages caret position for the generated member

This commit is contained in:
Maxim.Medvedev
2012-02-10 13:02:22 +04:00
parent db484241dc
commit 826bd5cabb
11 changed files with 95 additions and 19 deletions
@@ -205,7 +205,7 @@ class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<L
List<PsiMethod> methods = OverrideImplementUtil.overrideOrImplementMethodCandidates(aClass, candidatesToImplement, false);
List<PsiGenerationInfo<PsiMethod>> prototypes = OverrideImplementUtil.convert2GenerationInfos(methods);
List<PsiGenerationInfo<PsiMethod>> resultMembers = GenerateMembersUtil.insertMembersBeforeAnchor(aClass, null, prototypes);
GenerateMembersUtil.positionCaret(editor, resultMembers.get(0).getPsiMember(), true);
resultMembers.get(0).positionCaret(editor, true);
}
catch(IncorrectOperationException ioe){
LOG.error(ioe);
@@ -260,7 +260,7 @@ class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<L
}
List<PsiGenerationInfo<PsiMethod>> resultMembers = GenerateMembersUtil.insertMembersAtOffset(aClass.getContainingFile(), offset, prototypes);
GenerateMembersUtil.positionCaret(editor, resultMembers.get(0).getPsiMember(), true);
resultMembers.get(0).positionCaret(editor, true);
}
catch(IncorrectOperationException e){
LOG.error(e);
@@ -134,7 +134,7 @@ public abstract class GenerateMembersHandlerBase implements CodeInsightActionHan
runTemplates(project, editor, templates, 0);
}
else if (!newMembers.isEmpty()){
GenerateMembersUtil.positionCaret(editor, newMembers.get(0).getPsiMember(), false);
newMembers.get(0).positionCaret(editor, false);
}
}
@@ -119,6 +119,9 @@ public class GenerateMembersUtil {
return memberPrototypes;
}
/**
* @see GenerationInfo#positionCaret(com.intellij.openapi.editor.Editor, boolean)
*/
public static void positionCaret(@NotNull Editor editor, @NotNull PsiElement firstMember, boolean toEditMethodBody) {
LOG.assertTrue(firstMember.isValid());
@@ -15,6 +15,7 @@
*/
package com.intellij.codeInsight.generation;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
@@ -58,4 +59,8 @@ public abstract class GenerationInfoBase implements GenerationInfo {
}
return element;
}
public void positionCaret(Editor editor, boolean toEditMethodBody) {
GenerateMembersUtil.positionCaret(editor, getPsiMember(), toEditMethodBody);
}
}
@@ -670,7 +670,7 @@ public class OverrideImplementUtil {
}
if (!resultMembers.isEmpty()) {
GenerateMembersUtil.positionCaret(editor, resultMembers.get(0).getPsiMember(), true);
resultMembers.get(0).positionCaret(editor, true);
}
}
catch(IncorrectOperationException e){
@@ -724,10 +724,11 @@ public class OverrideImplementUtil {
Editor editor = fileEditorManager.openTextEditor(new OpenFileDescriptor(psiFile.getProject(), psiFile.getVirtualFile()), false);
if (editor == null) return;
GenerateMembersUtil.positionCaret(editor, results.get(0).getPsiMember(), true);
results.get(0).positionCaret(editor, true);
editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
}
@Nullable
public static PsiClass getContextClass(Project project, Editor editor, PsiFile file, boolean allowInterface) {
PsiDocumentManager.getInstance(project).commitAllDocuments();
@@ -740,8 +741,7 @@ public class OverrideImplementUtil {
final PsiClass aClass = (PsiClass)element;
if (aClass instanceof JspClass) return null;
return aClass == null ||
!allowInterface && aClass.isInterface() ? null : aClass;
return aClass == null || !allowInterface && aClass.isInterface() ? null : aClass;
}
private static PsiSubstitutor getContextSubstitutor(PsiClass aClass) {