2 * Copyright 2000-2015 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.codeInsight.daemon.lambda;
18 import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
19 import com.intellij.openapi.application.ApplicationManager;
20 import com.intellij.openapi.projectRoots.Sdk;
21 import com.intellij.psi.*;
22 import com.intellij.psi.util.PsiTreeUtil;
23 import com.intellij.testFramework.IdeaTestUtil;
24 import org.jetbrains.annotations.NonNls;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.Collections;
29 import java.util.List;
31 public class Java8ExpressionsCheckTest extends LightDaemonAnalyzerTestCase {
32 @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/lambda/expressions";
34 public void testSecondConflictResolutionOnSameMethodCall() throws Exception {
35 doTestAllMethodCallExpressions();
38 public void testNestedLambdaAdditionalConstraints() throws Exception {
39 doTestAllMethodCallExpressions();
42 public void testAvoidClassRefCachingDuringInference() throws Exception {
43 doTestAllMethodCallExpressions();
46 public void testInfinitiveParameterBoundsCheck() throws Exception {
47 doTestAllMethodCallExpressions();
50 public void testCachedUnresolvedMethods() throws Exception {
51 doTestCachedUnresolved();
54 public void testCacheUnresolvedMethods2() throws Exception {
55 doTestCachedUnresolved();
58 public void testCacheUnresolvedMethods3() throws Exception {
59 doTestCachedUnresolved();
62 private void doTestCachedUnresolved() {
63 configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
64 PsiMethodCallExpression callExpression =
65 PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiMethodCallExpression.class);
67 assertNotNull(callExpression);
68 assertNotNull(callExpression.getType());
70 final Collection<PsiCallExpression> methodCallExpressions = PsiTreeUtil.findChildrenOfType(getFile(), PsiCallExpression.class);
71 for (PsiCallExpression expression : methodCallExpressions) {
72 assertNotNull("Failed inference for: " + expression.getText(), expression.getType());
76 public void testIDEA140035() throws Exception {
77 doTestAllMethodCallExpressions();
78 final Collection<PsiParameter> parameterLists = PsiTreeUtil.findChildrenOfType(getFile(), PsiParameter.class);
79 for (PsiParameter parameter : parameterLists) {
80 if (parameter.getTypeElement() != null) continue;
81 getPsiManager().dropResolveCaches();
82 final PsiType type = parameter.getType();
83 assertFalse("Failed inference for: " + parameter.getParent().getText(), type instanceof PsiLambdaParameterType);
87 public void testAdditionalConstraintsBasedOnLambdaResolution() throws Exception {
88 doTestAllMethodCallExpressions();
91 private void doTestAllMethodCallExpressions() {
92 configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
93 final Collection<PsiCallExpression> methodCallExpressions = PsiTreeUtil.findChildrenOfType(getFile(), PsiCallExpression.class);
94 for (PsiCallExpression expression : methodCallExpressions) {
95 getPsiManager().dropResolveCaches();
96 assertNotNull("Failed inference for: " + expression.getText(), expression.getType());
99 final Collection<PsiReferenceParameterList> parameterLists = PsiTreeUtil.findChildrenOfType(getFile(), PsiReferenceParameterList.class);
100 for (PsiReferenceParameterList list : parameterLists) {
101 getPsiManager().dropResolveCaches();
102 final PsiType[] arguments = list.getTypeArguments();
103 assertNotNull("Failed inference for: " + list.getParent().getText(), arguments);
108 protected Sdk getProjectJDK() {
109 return IdeaTestUtil.getMockJdk18();