Merge remote-tracking branch 'origin/master'

This commit is contained in:
Yann Cébron
2014-05-26 08:27:40 +02:00
7 changed files with 70 additions and 12 deletions
@@ -1234,11 +1234,19 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
}
if (!myHolder.hasErrorResults()) {
final PsiType functionalInterfaceType = expression.getFunctionalInterfaceType();
if (functionalInterfaceType != null && LambdaUtil.dependsOnTypeParams(functionalInterfaceType, functionalInterfaceType, expression)) {
HighlightInfo result1 =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip("Cyclic inference").create();
myHolder.add(result1); //todo[ann] append not inferred type params info
} else {
if (functionalInterfaceType != null) {
final boolean notFunctional = !LambdaUtil.isFunctionalType(functionalInterfaceType);
if (notFunctional) {
myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression)
.descriptionAndTooltip(functionalInterfaceType.getPresentableText() + " is not a functional interface").create());
}
else if (LambdaUtil.dependsOnTypeParams(functionalInterfaceType, functionalInterfaceType, expression)) {
HighlightInfo result1 =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip("Cyclic inference").create();
myHolder.add(result1); //todo[ann] append not inferred type params info
}
}
if (!myHolder.hasErrorResults()) {
final PsiElement referenceNameElement = expression.getReferenceNameElement();
if (referenceNameElement instanceof PsiKeyword) {
if (!PsiMethodReferenceUtil.isValidQualifier(expression)) {
@@ -38,5 +38,5 @@ class Test2 {
void foo(Integer i) {}
<error descr="Incompatible types. Found: '<method reference>', required: 'java.lang.Object'">Object o = Test2::foo;</error>
Object o = <error descr="Object is not a functional interface">Test2::foo</error>;
}
@@ -0,0 +1,8 @@
class Java8 {
public void test() {
}
private int m() {
return <error descr="int is not a functional interface">Java8::test</error>;
}
}
@@ -102,6 +102,9 @@ public class MethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testQualifiersInStaticContext() throws Exception {
doTest();
}
public void testInvalidFunctionalTypeInReturnStmt() throws Exception {
doTest();
}
private void doTest() {
doTest(false);
@@ -649,7 +649,7 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
}
});
ApplicationManager.getApplication().invokeLater(new Runnable() {
Runnable runnable = new Runnable() {
@Override
public void run() {
if (!FileModificationService.getInstance().preparePsiElementsForWrite(results.keySet())) return;
@@ -673,7 +673,12 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
}
}, commandName, null);
}
});
};
if (ApplicationManager.getApplication().isUnitTestMode()) {
runnable.run();
} else {
ApplicationManager.getApplication().invokeLater(runnable);
}
}
});
@@ -15,10 +15,7 @@
*/
package com.siyeh.ig.assignment;
import com.intellij.psi.PsiAssignmentExpression;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiExpressionListStatement;
import com.intellij.psi.PsiExpressionStatement;
import com.intellij.psi.*;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
@@ -57,6 +54,7 @@ public class NestedAssignmentInspection extends BaseInspection {
}
final PsiElement grandparent = parent.getParent();
if (parent instanceof PsiExpressionStatement ||
parent instanceof PsiLambdaExpression ||
grandparent instanceof PsiExpressionListStatement) {
return;
}
@@ -0,0 +1,36 @@
/*
* Copyright 2000-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.siyeh.ig.assignment;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.siyeh.ig.LightInspectionTestCase;
public class NestedAssignmentInspectionTest extends LightInspectionTestCase {
public void testLambda() throws Exception {
doTest("class Test {" +
" {" +
" int[] array = new int[1];" +
" Runnable r = () -> array[0] = 0;" +
" }" +
"}");
}
@Override
protected InspectionProfileEntry getInspection() {
return new NestedAssignmentInspection();
}
}