Skip to content

Commit

Permalink
Bug 428856: [1.8][extract method] Extracted method adds an additional…
Browse files Browse the repository at this point in the history
… throws clause which result in compiler error
  • Loading branch information
noopur2507 authored and mkeller committed Apr 30, 2014
1 parent b1b64fc commit 5ef5a0e
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package defaultMethods_in;

import java.io.IOException;

@FunctionalInterface
interface FI {
int foo(int i) throws IOException;

default FI method1(FI i1) {
/*[*/return FI::fun;/*]*/
}

static int fun(int i) throws IOException {
return i++;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package defaultMethods_in;

import java.io.IOException;

@FunctionalInterface
interface FI {
int foo(int i) throws IOException;

default FI method1(FI i1) {
return extracted();
}

default FI extracted() {
/*[*/return FI::fun;/*]*/
}

static int fun(int i) throws IOException {
return i++;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package lambdaExpression18_in;

import java.io.IOException;

@FunctionalInterface
interface FI {
int foo(int i) throws IOException;

default FI method(FI i1) throws InterruptedException {
/*[*/if (i1 == null)
throw new InterruptedException();
return x -> {
throw new IOException();
};/*]*/
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package lambdaExpression18_in;

import java.io.IOException;

@FunctionalInterface
interface FI {
int foo(int i) throws IOException;

default FI method(FI i1) throws InterruptedException {
return extracted(i1);
}

default FI extracted(FI i1) throws InterruptedException {
/*[*/if (i1 == null)
throw new InterruptedException();
return x -> {
throw new IOException();
};/*]*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public void test5() throws Exception {
defaultMethodsTest(0, Modifier.PUBLIC);
}

public void test6() throws Exception {
defaultMethodsTest(0, Modifier.PUBLIC);
}

//====================================================================================
// Testing Static Methods
//====================================================================================
Expand Down Expand Up @@ -222,7 +226,7 @@ public void test320() throws Exception {
public void test321() throws Exception {
performTest(fgTestSetup.getLambdaExpressionPackage(), "A", INVALID_SELECTION, null);
}

public void test322() throws Exception {
performTest(fgTestSetup.getLambdaExpressionPackage(), "A", INVALID_SELECTION, null);
}
Expand All @@ -238,4 +242,8 @@ public void test324() throws Exception {
public void test325() throws Exception {
lambdaExpressionTest(0, Modifier.PRIVATE);
}

public void test326() throws Exception {
lambdaExpressionTest(0, Modifier.PUBLIC);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.jdt.core.dom.ConstructorInvocation;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.LambdaExpression;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
Expand Down Expand Up @@ -84,6 +85,15 @@ public static ITypeBinding[] perform(BodyDeclaration enclosingNode, Selection se
Collections.sort(exceptions, new ExceptionComparator());
return exceptions.toArray(new ITypeBinding[exceptions.size()]);
}

@Override
public boolean visit(LambdaExpression node) {
/*
* FIXME: Remove this method. It's just a workaround for bug 433426.
* ExceptionAnalyzer forces clients to on the wrong enclosing node (BodyDeclaration instead of LambdaExpression's body).
*/
return true;
}

@Override
public boolean visit(ThrowStatement node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.jdt.core.dom.EnumDeclaration;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.LambdaExpression;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.dom.ThrowStatement;
import org.eclipse.jdt.core.dom.TryStatement;
Expand Down Expand Up @@ -84,6 +85,12 @@ public boolean visit(AnonymousClassDeclaration node) {
return false;
}

@Override
public boolean visit(LambdaExpression node) {
// Don't dive into a lambda type.
return false;
}

@Override
public boolean visit(TryStatement node) {
fCurrentExceptions= new ArrayList<ITypeBinding>(1);
Expand Down

0 comments on commit 5ef5a0e

Please sign in to comment.