extract MethodReferenceResolver.canBeConstructed and use it in completion clion/146.1644 phpstorm/146.1645
authorpeter <peter@jetbrains.com>
Mon, 2 May 2016 09:00:00 +0000 (11:00 +0200)
committerpeter <peter@jetbrains.com>
Mon, 2 May 2016 09:00:42 +0000 (11:00 +0200)
java/java-impl/src/com/intellij/codeInsight/completion/FunctionalExpressionCompletionProvider.java
java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java

index b5301c510afe377e685e6452b6e2a2111f25d3f4..6400dfc9e12a4f8fefbe587b13711f07744f06c2 100644 (file)
@@ -30,6 +30,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager;
 import com.intellij.psi.codeStyle.JavaCodeStyleManager;
 import com.intellij.psi.impl.source.resolve.JavaResolveUtil;
 import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil;
+import com.intellij.psi.impl.source.tree.java.MethodReferenceResolver;
 import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.psi.util.PsiUtil;
 import com.intellij.psi.util.TypeConversionUtil;
@@ -151,7 +152,7 @@ public class FunctionalExpressionCompletionProvider extends CompletionProvider<C
             result.consume(createConstructorReferenceLookup(functionalInterfaceType, eachReturnType));
           }
         }
-        if (constructors.length == 0 && params.length == 0 && !psiClass.isInterface() && !psiClass.isEnum()) {
+        if (constructors.length == 0 && params.length == 0 && MethodReferenceResolver.canBeConstructed(psiClass)) {
           result.consume(createConstructorReferenceLookup(functionalInterfaceType, eachReturnType));
         }
       }
index 8d40e2914d9c61c2625e63a072623aa5398298a2..b993727a30edea4a25d5ab556af5f09c306ba62f 100644 (file)
@@ -54,9 +54,7 @@ public class MethodReferenceResolver implements ResolveCache.PolyVariantContextR
       final PsiElement element = reference.getReferenceNameElement();
       final boolean isConstructor = reference.isConstructor();
       if (element instanceof PsiIdentifier || isConstructor) {
-        if (isConstructor && (containingClass.isEnum() ||
-                              containingClass.hasModifierProperty(PsiModifier.ABSTRACT) ||
-                              containingClass instanceof PsiTypeParameter)) {
+        if (isConstructor && !canBeConstructed(containingClass)) {
           return JavaResolveResult.EMPTY_ARRAY;
         }
         final PsiType functionalInterfaceType = getInterfaceType(reference);
@@ -166,6 +164,10 @@ public class MethodReferenceResolver implements ResolveCache.PolyVariantContextR
     return JavaResolveResult.EMPTY_ARRAY;
   }
 
+  public static boolean canBeConstructed(@NotNull PsiClass psiClass) {
+    return !psiClass.isEnum() && !psiClass.hasModifierProperty(PsiModifier.ABSTRACT) && !(psiClass instanceof PsiTypeParameter);
+  }
+
   private static boolean isLocatedInStaticContext(PsiClass containingClass, PsiMethodReferenceExpression reference) {
     final PsiClass gContainingClass = containingClass.getContainingClass();
     if (gContainingClass == null || !containingClass.hasModifierProperty(PsiModifier.STATIC)) {