Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quickfix for unreachable catch #481

Merged
merged 1 commit into from
Dec 7, 2017

Conversation

yaohaizh
Copy link
Contributor

@yaohaizh yaohaizh commented Dec 6, 2017

Signed-off-by: Yaohai Zheng yaozheng@microsoft.com

@fbricon @gorkem

}

Statement statement = ASTResolving.findParentStatement(node);
if (statement != catchClause.getParent() && statement != catchClause.getBody()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't you use equals(...) instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fbricon it is comparing 2 AST nodes. They should point to the same object instance in this case.

return false;
}

if (resultingCollections == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move that block at the beginning of the method, no need to compute anything if a simple check fails

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

}

private static boolean isNotYetThrown(ITypeBinding binding, List<Type> thrownExceptions) {
for (int i = 0; i < thrownExceptions.size(); i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use enhanced for loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@Test
public void testUnneededCatchBlock() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringBuilder

public void testUnneededCatchBlockInInitializer() throws Exception {

IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringBuilder

public void testUnneededCatchBlockSingle() throws Exception {

IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringBuilder

public void testUnneededCatchBlockWithFinally() throws Exception {

IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringBuilder

@fbricon
Copy link
Contributor

fbricon commented Dec 6, 2017

test this please

Hey wake up Jenkins!

Signed-off-by: Yaohai Zheng <yaozheng@microsoft.com>
@fbricon fbricon merged commit 94ecb6d into eclipse-jdtls:master Dec 7, 2017
@fbricon
Copy link
Contributor

fbricon commented Dec 7, 2017

Thanks for the new quick fixes @yaohaizh !

@fbricon fbricon added this to the Mid December 2017 milestone Dec 15, 2017
@fbricon fbricon changed the title Add quickfix for unreachable ctach Add quickfix for unreachable catch Dec 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants