|
Lines 2645-2650
Link Here
|
| 2645 |
typeBinding = type.resolveBinding(); |
2645 |
typeBinding = type.resolveBinding(); |
| 2646 |
assertFalse("A Functional interface", typeBinding.isFunctionalInterface()); |
2646 |
assertFalse("A Functional interface", typeBinding.isFunctionalInterface()); |
| 2647 |
} |
2647 |
} |
|
|
2648 |
/** |
| 2649 |
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=417017 |
| 2650 |
* |
| 2651 |
* @throws JavaModelException |
| 2652 |
*/ |
| 2653 |
public void test417017a() throws JavaModelException { |
| 2654 |
this.workingCopy = getWorkingCopy("/Converter18/src/test417017/X.java", |
| 2655 |
true/* resolve */); |
| 2656 |
String contents = "package test417017;" |
| 2657 |
+ "interface I {\n" |
| 2658 |
+ " int foo(int x);\n" |
| 2659 |
+ "}\n" |
| 2660 |
+ "public class X {\n" |
| 2661 |
+ " void fun(int a) {\n" |
| 2662 |
+" I i1 = x1-> x1;\n" |
| 2663 |
+" I i2 = xxx-> {\n" |
| 2664 |
+" i1.foo(a);\n" |
| 2665 |
+" return xxx;\n" |
| 2666 |
+" };\n" |
| 2667 |
+" }\n" |
| 2668 |
+"}\n"; |
| 2669 |
CompilationUnit cu = (CompilationUnit) buildAST(contents, this.workingCopy); |
| 2670 |
TypeDeclaration typedeclaration = (TypeDeclaration) getASTNode(cu, 1); |
| 2671 |
MethodDeclaration methodDeclaration = typedeclaration.getMethods()[0]; |
| 2672 |
VariableDeclarationFragment vdf= (VariableDeclarationFragment) ((VariableDeclarationStatement) methodDeclaration.getBody().statements().get(1)).fragments().get(0); |
| 2673 |
LambdaExpression lambda= (LambdaExpression) vdf.getInitializer(); |
| 2674 |
List parameters = lambda.parameters(); |
| 2675 |
assertTrue("Incorrect Number of parameters", parameters.size() == 1); |
| 2676 |
ITypeBinding[] parameterTypes= lambda.resolveMethodBinding().getParameterTypes(); |
| 2677 |
assertTrue("Incorrect Number of parameter type", parameterTypes.length == 1); |
| 2678 |
assertEquals("Incorrect parameter type", "int", parameterTypes[0].toString()); |
| 2679 |
} |
| 2680 |
/** |
| 2681 |
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=417017 |
| 2682 |
* |
| 2683 |
* @throws JavaModelException |
| 2684 |
*/ |
| 2685 |
public void test417017b() throws JavaModelException { |
| 2686 |
this.workingCopy = getWorkingCopy("/Converter18/src/test417017/X.java", |
| 2687 |
true/* resolve */); |
| 2688 |
String contents = "package test417017;" + |
| 2689 |
"interface I1 {\n" + |
| 2690 |
" int foo(int a);\n" + |
| 2691 |
"}\n" + |
| 2692 |
"\n" + |
| 2693 |
"interface I2 {\n" + |
| 2694 |
" public default int foo() {\n" + |
| 2695 |
" I1 i1 = (a) -> {\n" + |
| 2696 |
" return a;\n" + |
| 2697 |
" };\n" + |
| 2698 |
" //return 0;\n" + // Error on purpose |
| 2699 |
" }\n" + |
| 2700 |
"}\n" ; |
| 2701 |
CompilationUnit cu = (CompilationUnit) buildAST(contents, this.workingCopy, false); |
| 2702 |
TypeDeclaration typedeclaration = (TypeDeclaration) getASTNode(cu, 1); |
| 2703 |
MethodDeclaration methodDeclaration = typedeclaration.getMethods()[0]; |
| 2704 |
VariableDeclarationFragment vdf= (VariableDeclarationFragment) ((VariableDeclarationStatement) methodDeclaration.getBody().statements().get(0)).fragments().get(0); |
| 2705 |
LambdaExpression lambda= (LambdaExpression) vdf.getInitializer(); |
| 2706 |
List parameters = lambda.parameters(); |
| 2707 |
assertTrue("Incorrect Number of parameters", parameters.size() == 1); |
| 2708 |
ITypeBinding[] parameterTypes= lambda.resolveMethodBinding().getParameterTypes(); |
| 2709 |
assertTrue("Incorrect Number of parameter type", parameterTypes.length == 1); |
| 2710 |
assertEquals("Incorrect parameter type", "int", parameterTypes[0].toString()); |
| 2711 |
} |
| 2712 |
/** |
| 2713 |
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=417017 |
| 2714 |
* |
| 2715 |
* @throws JavaModelException |
| 2716 |
*/ |
| 2717 |
public void test417017c() throws JavaModelException { |
| 2718 |
this.workingCopy = getWorkingCopy("/Converter18/src/test417017/X.java", |
| 2719 |
true/* resolve */); |
| 2720 |
String contents = "package test417017;" + |
| 2721 |
"interface I1 {\n" + |
| 2722 |
" int foo(int a);\n" + |
| 2723 |
"}\n" + |
| 2724 |
"\n" + |
| 2725 |
"interface I2 {\n" + |
| 2726 |
" public default int foo() {\n" + |
| 2727 |
" I1 i1 = (float a) -> {\n" + |
| 2728 |
" return a;\n" + |
| 2729 |
" };\n" + |
| 2730 |
" //return 0;\n" + // Error on purpose |
| 2731 |
" }\n" + |
| 2732 |
"}\n" ; |
| 2733 |
CompilationUnit cu = (CompilationUnit) buildAST(contents, this.workingCopy, false); |
| 2734 |
TypeDeclaration typedeclaration = (TypeDeclaration) getASTNode(cu, 1); |
| 2735 |
MethodDeclaration methodDeclaration = typedeclaration.getMethods()[0]; |
| 2736 |
VariableDeclarationFragment vdf= (VariableDeclarationFragment) ((VariableDeclarationStatement) methodDeclaration.getBody().statements().get(0)).fragments().get(0); |
| 2737 |
LambdaExpression lambda= (LambdaExpression) vdf.getInitializer(); |
| 2738 |
List parameters = lambda.parameters(); |
| 2739 |
assertTrue("Incorrect Number of parameters", parameters.size() == 1); |
| 2740 |
ITypeBinding[] parameterTypes= lambda.resolveMethodBinding().getParameterTypes(); |
| 2741 |
assertTrue("Incorrect Number of parameter type", parameterTypes.length == 1); |
| 2742 |
assertEquals("Incorrect parameter type", "float", parameterTypes[0].toString()); |
| 2743 |
} |
| 2744 |
/** |
| 2745 |
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=417017 |
| 2746 |
* |
| 2747 |
* @throws JavaModelException |
| 2748 |
*/ |
| 2749 |
public void test417017d() throws JavaModelException { |
| 2750 |
this.workingCopy = getWorkingCopy("/Converter18/src/test399794/X.java", |
| 2751 |
true/* resolve */); |
| 2752 |
String contents = "package test399794;" + |
| 2753 |
"interface I {\n" + |
| 2754 |
" void foo(X x);\n" + |
| 2755 |
"}\n" + |
| 2756 |
"public class X {\n" + |
| 2757 |
" void foo(X x) {\n" + |
| 2758 |
" }\n" + |
| 2759 |
" I i = this::foo;\n" + |
| 2760 |
"}\n"; |
| 2761 |
|
| 2762 |
CompilationUnit cu = (CompilationUnit) buildAST(contents, this.workingCopy); |
| 2763 |
TypeDeclaration typeDeclaration = (TypeDeclaration) getASTNode(cu, 1); |
| 2764 |
FieldDeclaration field = typeDeclaration.getFields()[0]; |
| 2765 |
|
| 2766 |
VariableDeclarationFragment fragment = (VariableDeclarationFragment) field.fragments().get(0); |
| 2767 |
Expression expression = fragment.getInitializer(); |
| 2768 |
ExpressionMethodReference methodReference = (ExpressionMethodReference) expression; |
| 2769 |
IMethodBinding methodBinding = methodReference.resolveMethodBinding(); |
| 2770 |
assertNotNull(methodBinding); |
| 2771 |
ITypeBinding [] parameterTypes = methodBinding.getParameterTypes(); |
| 2772 |
assertTrue("Incorrect Number of parameter type", parameterTypes.length == 1); |
| 2773 |
assertEquals("Incorrect parameter type", "X", parameterTypes[0].getName()); |
| 2774 |
} |
| 2775 |
|
| 2776 |
/** |
| 2777 |
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=417017 |
| 2778 |
* |
| 2779 |
* @throws JavaModelException |
| 2780 |
*/ |
| 2781 |
public void test417017e() throws JavaModelException { |
| 2782 |
this.workingCopy = getWorkingCopy("/Converter18/src/test399794/X.java", |
| 2783 |
true/* resolve */); |
| 2784 |
String contents = "package test399794;" + |
| 2785 |
"interface I {\n" + |
| 2786 |
" int [] foo(int x);\n" + |
| 2787 |
"}\n" + |
| 2788 |
"public class X {\n" + |
| 2789 |
" I i = int []::new;\n" + |
| 2790 |
"}\n"; |
| 2791 |
|
| 2792 |
CompilationUnit cu = (CompilationUnit) buildAST(contents, this.workingCopy); |
| 2793 |
TypeDeclaration typeDeclaration = (TypeDeclaration) getASTNode(cu, 1); |
| 2794 |
FieldDeclaration field = typeDeclaration.getFields()[0]; |
| 2795 |
|
| 2796 |
VariableDeclarationFragment fragment = (VariableDeclarationFragment) field.fragments().get(0); |
| 2797 |
Expression expression = fragment.getInitializer(); |
| 2798 |
CreationReference creationReference = (CreationReference) expression; |
| 2799 |
IMethodBinding methodBinding = creationReference.resolveMethodBinding(); |
| 2800 |
assertNotNull(methodBinding); |
| 2801 |
assertEquals("Wrong name", "lambda$0", methodBinding.getName()); |
| 2802 |
ITypeBinding [] parameterTypes = methodBinding.getParameterTypes(); |
| 2803 |
assertTrue("Incorrect Number of parameter type", parameterTypes.length == 1); |
| 2804 |
assertEquals("Incorrect parameter type", "int", parameterTypes[0].getName()); |
| 2805 |
} |
| 2806 |
|
| 2807 |
/** |
| 2808 |
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=417017 |
| 2809 |
* |
| 2810 |
* @throws JavaModelException |
| 2811 |
*/ |
| 2812 |
public void test417017f() throws JavaModelException { |
| 2813 |
this.workingCopy = getWorkingCopy("/Converter18/src/test399794/X.java", |
| 2814 |
true/* resolve */); |
| 2815 |
String contents = "package test399794;" + |
| 2816 |
"interface I {\n" + |
| 2817 |
" void foo(X x);\n" + |
| 2818 |
"}\n" + |
| 2819 |
"public class X {\n" + |
| 2820 |
" private void foo(X x) {\n" + |
| 2821 |
" }\n" + |
| 2822 |
" class Y {\n" + |
| 2823 |
" I i = X.this::foo;\n" + |
| 2824 |
" }\n" + |
| 2825 |
"}\n"; |
| 2826 |
|
| 2827 |
CompilationUnit cu = (CompilationUnit) buildAST(contents, this.workingCopy); |
| 2828 |
TypeDeclaration typeDeclaration = (TypeDeclaration) getASTNode(cu, 1); |
| 2829 |
typeDeclaration = typeDeclaration.getTypes()[0]; |
| 2830 |
FieldDeclaration field = typeDeclaration.getFields()[0]; |
| 2831 |
|
| 2832 |
VariableDeclarationFragment fragment = (VariableDeclarationFragment) field.fragments().get(0); |
| 2833 |
Expression expression = fragment.getInitializer(); |
| 2834 |
ExpressionMethodReference reference = (ExpressionMethodReference) expression; |
| 2835 |
IMethodBinding methodBinding = reference.resolveMethodBinding(); |
| 2836 |
assertNotNull(methodBinding); |
| 2837 |
assertEquals("Wrong name", "foo", methodBinding.getName()); |
| 2838 |
ITypeBinding [] parameterTypes = methodBinding.getParameterTypes(); |
| 2839 |
assertTrue("Incorrect Number of parameter type", parameterTypes.length == 1); |
| 2840 |
assertEquals("Incorrect parameter type", "X", parameterTypes[0].getName()); |
| 2841 |
} |
| 2648 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=413942 |
2842 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=413942 |
| 2649 |
// also refer https://bugs.eclipse.org/bugs/show_bug.cgi?id=413569 |
2843 |
// also refer https://bugs.eclipse.org/bugs/show_bug.cgi?id=413569 |
| 2650 |
public void testBug413942() throws JavaModelException { |
2844 |
public void testBug413942() throws JavaModelException { |