cleanup closure completer

This commit is contained in:
Max Medvedev
2013-09-30 14:27:59 +04:00
parent 21dbd3514f
commit 03e1eed9de
3 changed files with 9 additions and 17 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,15 +47,13 @@ import java.util.List;
* @author Max Medvedev
*/
public abstract class ClosureCompleter {
private static ExtensionPointName<ClosureCompleter> EP_NAME = ExtensionPointName.create("org.intellij.groovy.closureCompleter");
private static final ExtensionPointName<ClosureCompleter> EP_NAME = ExtensionPointName.create("org.intellij.groovy.closureCompleter");
@Nullable
protected abstract List<ClosureParameterInfo> getParameterInfos(InsertionContext context,
PsiMethod method,
PsiSubstitutor substitutor,
Document document,
int offset,
PsiElement parent);
PsiElement place);
public static boolean runClosureCompletion(InsertionContext context,
PsiMethod method,
@@ -64,7 +62,7 @@ public abstract class ClosureCompleter {
int offset,
PsiElement parent) {
for (ClosureCompleter completer : EP_NAME.getExtensions()) {
final List<ClosureParameterInfo> parameterInfos = completer.getParameterInfos(context, method, substitutor, document, offset, parent);
final List<ClosureParameterInfo> parameterInfos = completer.getParameterInfos(context, method, substitutor, parent);
if (parameterInfos != null) {
runClosureTemplate(context, document, offset, substitutor, method, parameterInfos);
return true;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.jetbrains.plugins.groovy.lang.completion;
import com.intellij.codeInsight.completion.InsertionContext;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.util.InheritanceUtil;
@@ -42,9 +41,7 @@ public class EachWithIndexClosureCompleter extends ClosureCompleter {
protected List<ClosureParameterInfo> getParameterInfos(InsertionContext context,
PsiMethod method,
PsiSubstitutor substitutor,
Document document,
int offset,
PsiElement parent) {
PsiElement place) {
final String name = method.getName();
if (!"eachWithIndex".equals(name)) return null;
@@ -63,7 +60,7 @@ public class EachWithIndexClosureCompleter extends ClosureCompleter {
final PsiType type = parameters[0].getType();
final PsiType collection = substitutor.substitute(type);
final PsiType iterable = getIteratedType(parent, collection);
final PsiType iterable = getIteratedType(place, collection);
if (iterable != null) {
return Arrays.asList(
new ClosureParameterInfo(iterable.getCanonicalText(), "entry"),
@@ -76,7 +73,7 @@ public class EachWithIndexClosureCompleter extends ClosureCompleter {
final Project project = context.getProject();
final PsiClass entry = JavaPsiFacade.getInstance(project).findClass(CommonClassNames.JAVA_UTIL_MAP_ENTRY, parent.getResolveScope());
final PsiClass entry = JavaPsiFacade.getInstance(project).findClass(CommonClassNames.JAVA_UTIL_MAP_ENTRY, place.getResolveScope());
if (entry == null) return null;
final PsiClassType entryType = JavaPsiFacade.getElementFactory(project).createType(entry, typeParams);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.jetbrains.plugins.groovy.lang.completion;
import com.intellij.codeInsight.completion.InsertionContext;
import com.intellij.openapi.editor.Document;
import com.intellij.psi.*;
import com.intellij.psi.scope.BaseScopeProcessor;
import org.jetbrains.annotations.NotNull;
@@ -42,8 +41,6 @@ public class GdslClosureCompleter extends ClosureCompleter {
protected List<ClosureParameterInfo> getParameterInfos(InsertionContext context,
PsiMethod method,
PsiSubstitutor substitutor,
Document document,
int offset,
PsiElement place) {
final ArrayList<ClosureDescriptor> descriptors = new ArrayList<ClosureDescriptor>();
GrReferenceExpression ref = (GrReferenceExpression)place;