Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 417017 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java (+194 lines)
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 {
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java (-2 / +6 lines)
Lines 38-44 Link Here
38
	
38
	
39
	TypeBinding expectedType;
39
	TypeBinding expectedType;
40
	public MethodBinding descriptor;
40
	public MethodBinding descriptor;
41
	public MethodBinding binding;
41
	public MethodBinding binding;                 // Code generation binding. May include synthetics. See getMethodBinding()
42
	protected MethodBinding actualMethodBinding;  // void of synthetics.
42
	boolean ignoreFurtherInvestigation;
43
	boolean ignoreFurtherInvestigation;
43
	protected ExpressionContext expressionContext = VANILLA_CONTEXT;
44
	protected ExpressionContext expressionContext = VANILLA_CONTEXT;
44
	protected SimpleLookupTable resultExpressions;
45
	protected SimpleLookupTable resultExpressions;
Lines 51-57 Link Here
51
	public FunctionalExpression(CompilationResult compilationResult) {
52
	public FunctionalExpression(CompilationResult compilationResult) {
52
		this.compilationResult = compilationResult;
53
		this.compilationResult = compilationResult;
53
	}
54
	}
54
55
	// Return the actual (non-code generation) method binding that is void of synthetics.
56
	public MethodBinding getMethodBinding() {
57
		return null;
58
	}
55
	public void setExpectedType(TypeBinding expectedType) {
59
	public void setExpectedType(TypeBinding expectedType) {
56
		this.expectedType = this.ellipsisArgument ? ((ArrayBinding) expectedType).elementsType() : expectedType;
60
		this.expectedType = this.ellipsisArgument ? ((ArrayBinding) expectedType).elementsType() : expectedType;
57
	}
61
	}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java (+12 lines)
Lines 49-54 Link Here
49
import org.eclipse.jdt.internal.compiler.lookup.Scope;
49
import org.eclipse.jdt.internal.compiler.lookup.Scope;
50
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
50
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
51
import org.eclipse.jdt.internal.compiler.lookup.SyntheticArgumentBinding;
51
import org.eclipse.jdt.internal.compiler.lookup.SyntheticArgumentBinding;
52
import org.eclipse.jdt.internal.compiler.lookup.SyntheticMethodBinding;
52
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
53
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
53
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
54
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
54
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
55
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
Lines 783-788 Link Here
783
				return this.outerLocalVariables[i];
784
				return this.outerLocalVariables[i];
784
		return null;
785
		return null;
785
	}
786
	}
787
788
	// Return the actual method binding devoid of synthetics. 
789
	public MethodBinding getMethodBinding() {
790
		if (this.actualMethodBinding == null) {
791
			this.actualMethodBinding = new MethodBinding(this.binding.modifiers, this.binding.selector, this.binding.returnType, 
792
					this.binding instanceof SyntheticMethodBinding ? this.descriptor.parameters : this.binding.parameters,  // retain any faults in parameter list.
793
							this.binding.thrownExceptions, this.binding.declaringClass);
794
			this.actualMethodBinding.tagBits = this.binding.tagBits;
795
		}
796
		return this.actualMethodBinding;
797
	}
786
}
798
}
787
class IncongruentLambdaException extends RuntimeException {
799
class IncongruentLambdaException extends RuntimeException {
788
	private static final long serialVersionUID = 4145723509219836114L;
800
	private static final long serialVersionUID = 4145723509219836114L;
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java (+7 lines)
Lines 81-86 Link Here
81
	}
81
	}
82
 
82
 
83
	public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
83
	public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
84
		this.actualMethodBinding = this.binding; // grab before synthetics come into play.
84
		SourceTypeBinding sourceType = currentScope.enclosingSourceType();
85
		SourceTypeBinding sourceType = currentScope.enclosingSourceType();
85
		if (this.receiverType.isArrayType()) {
86
		if (this.receiverType.isArrayType()) {
86
			if (isConstructorReference()) {
87
			if (isConstructorReference()) {
Lines 637-640 Link Here
637
		tSam = t.getSingleAbstractMethod(this.enclosingScope);
638
		tSam = t.getSingleAbstractMethod(this.enclosingScope);
638
		return resultExpression.tIsMoreSpecific(tSam.returnType, sSam.returnType);
639
		return resultExpression.tIsMoreSpecific(tSam.returnType, sSam.returnType);
639
	}
640
	}
641
642
	public org.eclipse.jdt.internal.compiler.lookup.MethodBinding getMethodBinding() {
643
		if (this.actualMethodBinding == null)  // array new/clone, no real binding.
644
			this.actualMethodBinding = this.binding;
645
		return this.actualMethodBinding;
646
	}
640
}
647
}
(-)a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java (-4 / +4 lines)
Lines 883-889 Link Here
883
		Object oldNode = this.newAstToOldAst.get(lambda);
883
		Object oldNode = this.newAstToOldAst.get(lambda);
884
		if (oldNode instanceof org.eclipse.jdt.internal.compiler.ast.LambdaExpression) {
884
		if (oldNode instanceof org.eclipse.jdt.internal.compiler.ast.LambdaExpression) {
885
			org.eclipse.jdt.internal.compiler.ast.LambdaExpression lambdaExpression = (org.eclipse.jdt.internal.compiler.ast.LambdaExpression) oldNode;
885
			org.eclipse.jdt.internal.compiler.ast.LambdaExpression lambdaExpression = (org.eclipse.jdt.internal.compiler.ast.LambdaExpression) oldNode;
886
			IMethodBinding methodBinding = getMethodBinding(lambdaExpression.binding);
886
			IMethodBinding methodBinding = getMethodBinding(lambdaExpression.getMethodBinding());
887
			if (methodBinding == null) {
887
			if (methodBinding == null) {
888
				return null;
888
				return null;
889
			}
889
			}
Lines 934-940 Link Here
934
		Object oldNode = this.newAstToOldAst.get(methodReference);
934
		Object oldNode = this.newAstToOldAst.get(methodReference);
935
		if (oldNode instanceof org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) {
935
		if (oldNode instanceof org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) {
936
			org.eclipse.jdt.internal.compiler.ast.ReferenceExpression referenceExpression = (org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) oldNode;
936
			org.eclipse.jdt.internal.compiler.ast.ReferenceExpression referenceExpression = (org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) oldNode;
937
			IMethodBinding methodBinding = getMethodBinding(referenceExpression.binding);
937
			IMethodBinding methodBinding = getMethodBinding(referenceExpression.getMethodBinding());
938
			if (methodBinding == null) {
938
			if (methodBinding == null) {
939
				return null;
939
				return null;
940
			}
940
			}
Lines 1166-1172 Link Here
1166
			return method.getReturnType();
1166
			return method.getReturnType();
1167
		} else if (node instanceof org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) {
1167
		} else if (node instanceof org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) {
1168
			org.eclipse.jdt.internal.compiler.ast.ReferenceExpression referenceExpression = (org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) node;
1168
			org.eclipse.jdt.internal.compiler.ast.ReferenceExpression referenceExpression = (org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) node;
1169
			IMethodBinding method = getMethodBinding(referenceExpression.binding);
1169
			IMethodBinding method = getMethodBinding(referenceExpression.getMethodBinding());
1170
			if (method == null) return null;
1170
			if (method == null) return null;
1171
			return method.getReturnType();
1171
			return method.getReturnType();
1172
		}
1172
		}
Lines 1431-1437 Link Here
1431
			return getMethodBinding(memberValuePair.binding);
1431
			return getMethodBinding(memberValuePair.binding);
1432
		} else if (node instanceof org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) {
1432
		} else if (node instanceof org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) {
1433
			org.eclipse.jdt.internal.compiler.ast.ReferenceExpression referenceExpression = (org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) node;
1433
			org.eclipse.jdt.internal.compiler.ast.ReferenceExpression referenceExpression = (org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) node;
1434
			return getMethodBinding(referenceExpression.binding);
1434
			return getMethodBinding(referenceExpression.getMethodBinding());
1435
		}
1435
		}
1436
		return null;
1436
		return null;
1437
	}
1437
	}

Return to bug 417017