mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-10 15:09:52 +07:00
IDEA-73264 GenerationInfo manages caret position for the generated member
This commit is contained in:
+2
-2
@@ -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);
|
||||
|
||||
+1
-1
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user