mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-50677 Groovy 1.7: Smart Code Completion for anonymous interface implementation expression could be added
This commit is contained in:
+13
-4
@@ -27,6 +27,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -35,7 +36,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<LookupItem>> {
|
||||
public class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<LookupItem>> {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.ConstructorInsertHandler");
|
||||
public static final ConstructorInsertHandler SMART_INSTANCE = new ConstructorInsertHandler(true);
|
||||
public static final ConstructorInsertHandler BASIC_INSTANCE = new ConstructorInsertHandler(false);
|
||||
@@ -169,6 +170,7 @@ class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<L
|
||||
return hasParams;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Runnable generateAnonymousBody(final Editor editor, final PsiFile file) {
|
||||
final Project project = file.getProject();
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
@@ -180,13 +182,20 @@ class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<L
|
||||
PsiElement parent = element.getParent();
|
||||
if (!(parent instanceof PsiAnonymousClass)) return null;
|
||||
|
||||
try{
|
||||
return genAnonymousBodyFor((PsiAnonymousClass)parent, editor, file, project);
|
||||
}
|
||||
|
||||
public static Runnable genAnonymousBodyFor(PsiAnonymousClass parent,
|
||||
final Editor editor,
|
||||
final PsiFile file,
|
||||
final Project project) {
|
||||
try {
|
||||
CodeStyleManager.getInstance(project).reformat(parent);
|
||||
}
|
||||
catch(IncorrectOperationException e){
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
offset = parent.getTextRange().getEndOffset() - 1;
|
||||
int offset = parent.getTextRange().getEndOffset() - 1;
|
||||
editor.getCaretModel().moveToOffset(offset);
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
editor.getSelectionModel().removeSelection();
|
||||
|
||||
@@ -17,7 +17,7 @@ package com.intellij.codeInsight.generation;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.CreateFromUsageUtils;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.StdLanguages;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
@@ -109,7 +109,7 @@ public class GenerateMembersUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T extends GenerationInfo> List<T> insertMembersBeforeAnchor(PsiClass aClass, PsiElement anchor, @NotNull List<T> memberPrototypes) throws IncorrectOperationException {
|
||||
public static <T extends GenerationInfo> List<T> insertMembersBeforeAnchor(PsiClass aClass, @Nullable PsiElement anchor, @NotNull List<T> memberPrototypes) throws IncorrectOperationException {
|
||||
boolean before = true;
|
||||
for (T memberPrototype : memberPrototypes) {
|
||||
memberPrototype.insert(aClass, anchor, before);
|
||||
@@ -280,7 +280,7 @@ public class GenerateMembersUtil {
|
||||
if (paramName == null) paramName = "p" + i;
|
||||
|
||||
PsiParameter newParameter = factory.createParameter(paramName, substituted);
|
||||
if (parameter.getLanguage() == StdLanguages.JAVA) {
|
||||
if (parameter.getLanguage() == JavaLanguage.INSTANCE) {
|
||||
PsiModifierList modifierList = newParameter.getModifierList();
|
||||
modifierList = (PsiModifierList)modifierList.replace(parameter.getModifierList());
|
||||
processAnnotations(project, modifierList);
|
||||
|
||||
Reference in New Issue
Block a user