mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 15:27:45 +07:00
lambda: check interface functional
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
abstract class Foo { public abstract void run(); }
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
interface Foo {
|
||||
int m();
|
||||
Object clone();
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
interface Foo { <T> T execute(Action<T> a); }
|
||||
interface Action<A>{}
|
||||
// Functional
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
interface Bar { boolean equals(Object obj); }
|
||||
|
||||
interface Foo extends Bar { int compare(String o1, String o2); }
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
interface Foo<T> {
|
||||
boolean equals(Object obj);
|
||||
int compare(T o1, T o2);
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
interface Foo { boolean equals(Object obj); }
|
||||
+1
@@ -0,0 +1 @@
|
||||
interface Foo { void run(); }
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
interface X { int m(Iterable<String> arg); }
|
||||
interface Y { int m(Iterable<Integer> arg); }
|
||||
interface Foo extends X, Y {}
|
||||
// Not functional: No method has a subsignature of all abstract methods
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
interface X { int m(Iterable<String> arg, Class c); }
|
||||
interface Y { int m(Iterable arg, Class<?> c); }
|
||||
interface Foo extends X, Y {}
|
||||
// Not functional: No method has a subsignature of all abstract methods
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import java.util.*;
|
||||
interface X { int m(Iterable<String> arg); }
|
||||
interface Y { int m(Iterable<String> arg); }
|
||||
interface Foo extends X, Y {}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
interface Action<A>{}
|
||||
interface X { <T> T execute(Action<T> a); }
|
||||
interface Y { <S> S execute(Action<S> a); }
|
||||
interface Foo extends X, Y {}
|
||||
// Functional: signatures are "the same"
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
interface Foo1<T, N extends Number> {
|
||||
void m(T arg);
|
||||
void m(N arg);
|
||||
}
|
||||
interface Foo extends Foo1<Integer, Integer> {}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import java.util.*;
|
||||
interface X { Iterable m(Iterable<String> arg); }
|
||||
interface Y { Iterable<String> m(Iterable arg); }
|
||||
interface Foo extends X, Y {}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.intellij.codeInsight.daemon;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.impl.source.tree.java.FunctionalInterfaceUtil;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class FunctionalInterfaceTest extends LightDaemonAnalyzerTestCase {
|
||||
@NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/lambda/functionalInterface";
|
||||
|
||||
private void doTestFunctionalInterface(@Nullable String expectedErrorMessage) throws Exception {
|
||||
String filePath = BASE_PATH + "/" + getTestName(false) + ".java";
|
||||
configureByFile(filePath);
|
||||
final PsiClass psiClass = getJavaFacade().findClass("Foo", GlobalSearchScope.projectScope(getProject()));
|
||||
assertNotNull("Class Foo not found", psiClass);
|
||||
|
||||
final String errorMessage = FunctionalInterfaceUtil.checkInterfaceFunctional(psiClass);
|
||||
assertEquals(expectedErrorMessage, errorMessage);
|
||||
}
|
||||
|
||||
public void testSimple() throws Exception {
|
||||
doTestFunctionalInterface(null);
|
||||
}
|
||||
|
||||
public void testNoMethods() throws Exception {
|
||||
doTestFunctionalInterface("No target method found");
|
||||
}
|
||||
|
||||
public void testMultipleMethods() throws Exception {
|
||||
doTestFunctionalInterface(null);
|
||||
}
|
||||
|
||||
public void testMultipleMethodsInOne() throws Exception {
|
||||
doTestFunctionalInterface(null);
|
||||
}
|
||||
|
||||
public void testClone() throws Exception {
|
||||
doTestFunctionalInterface("Multiple non-overriding abstract methods found");
|
||||
}
|
||||
|
||||
public void testTwoMethodsSameSignature() throws Exception {
|
||||
doTestFunctionalInterface(null);
|
||||
}
|
||||
|
||||
public void testTwoMethodsSubSignature() throws Exception {
|
||||
doTestFunctionalInterface(null);
|
||||
}
|
||||
|
||||
public void testTwoMethodsNoSubSignature() throws Exception {
|
||||
doTestFunctionalInterface("Multiple non-overriding abstract methods found");
|
||||
}
|
||||
|
||||
public void testTwoMethodsNoSubSignature1() throws Exception {
|
||||
doTestFunctionalInterface("Multiple non-overriding abstract methods found");
|
||||
}
|
||||
|
||||
public void testTwoMethodsSameSubstSignature() throws Exception {
|
||||
doTestFunctionalInterface(null);
|
||||
}
|
||||
|
||||
public void testMethodWithTypeParam() throws Exception {
|
||||
doTestFunctionalInterface(null);
|
||||
}
|
||||
|
||||
public void testTwoMethodsSameSignatureTypeParams() throws Exception {
|
||||
doTestFunctionalInterface(null);
|
||||
}
|
||||
|
||||
public void testAbstractClass() throws Exception {
|
||||
doTestFunctionalInterface("Target type of a lambda conversion must be an interface");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user