]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 IBM Corporation and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * IBM Corporation - initial API and implementation | |
10 | *******************************************************************************/ | |
11 | package org.eclipse.jdt.internal.corext.refactoring.code; | |
12 | ||
13 | import java.util.List; | |
14 | ||
15 | import org.eclipse.jdt.core.dom.ASTNode; | |
16 | import org.eclipse.jdt.core.dom.ClassInstanceCreation; | |
17 | import org.eclipse.jdt.core.dom.IMethodBinding; | |
18 | import org.eclipse.jdt.core.dom.ITypeBinding; | |
19 | import org.eclipse.jdt.core.dom.MethodInvocation; | |
20 | import org.eclipse.jdt.core.dom.SuperMethodInvocation; | |
21 | import org.eclipse.jdt.core.dom.ThrowStatement; | |
22 | ||
23 | import org.eclipse.jdt.internal.corext.refactoring.util.AbstractExceptionAnalyzer; | |
24 | ||
25 | /* package */ class ExceptionAnalyzer extends AbstractExceptionAnalyzer { | |
26 | ||
27 | public static ITypeBinding[] perform(ASTNode[] statements) { | |
28 | ExceptionAnalyzer analyzer= new ExceptionAnalyzer(); | |
29 | for (int i= 0; i < statements.length; i++) { | |
30 | statements[i].accept(analyzer); | |
31 | } | |
32 | List<ITypeBinding> exceptions= analyzer.getCurrentExceptions(); | |
33 | return exceptions.toArray(new ITypeBinding[exceptions.size()]); | |
34 | } | |
35 | ||
36 | @Override | |
37 | public boolean visit(ThrowStatement node) { | |
38 | ITypeBinding exception= node.getExpression().resolveTypeBinding(); | |
39 | if (exception == null) // Safety net for null bindings when compiling fails. | |
40 | return true; | |
41 | ||
42 | addException(exception); | |
43 | return true; | |
44 | } | |
45 | ||
46 | @Override | |
47 | public boolean visit(MethodInvocation node) { | |
48 | return handleExceptions((IMethodBinding)node.getName().resolveBinding()); | |
49 | } | |
50 | ||
51 | @Override | |
52 | public boolean visit(SuperMethodInvocation node) { | |
53 | return handleExceptions((IMethodBinding)node.getName().resolveBinding()); | |
54 | } | |
55 | ||
56 | @Override | |
57 | public boolean visit(ClassInstanceCreation node) { | |
58 | return handleExceptions(node.resolveConstructorBinding()); | |
59 | } | |
60 | ||
61 | private boolean handleExceptions(IMethodBinding binding) { | |
62 | if (binding == null) | |
63 | return true; | |
64 | addExceptions(binding.getExceptionTypes()); | |
65 | return true; | |
66 | } | |
67 | } |