1 11 package org.eclipse.jdt.internal.corext.refactoring.surround; 12 13 import org.eclipse.jdt.core.ICompilationUnit; 14 import org.eclipse.jdt.core.JavaModelException; 15 import org.eclipse.jdt.core.dom.BodyDeclaration; 16 import org.eclipse.jdt.core.dom.CompilationUnit; 17 import org.eclipse.jdt.core.dom.ITypeBinding; 18 19 import org.eclipse.jdt.internal.corext.dom.ASTNodes; 20 import org.eclipse.jdt.internal.corext.dom.Selection; 21 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages; 22 23 public class SurroundWithTryCatchAnalyzer extends SurroundWithAnalyzer { 24 25 26 private ISurroundWithTryCatchQuery fQuery; 27 private ITypeBinding[] fExceptions; 28 29 public SurroundWithTryCatchAnalyzer(ICompilationUnit unit, Selection selection, ISurroundWithTryCatchQuery query) throws JavaModelException { 30 super(unit, selection); 31 fQuery= query; 32 } 33 34 public ITypeBinding[] getExceptions() { 35 return fExceptions; 36 } 37 38 public void endVisit(CompilationUnit node) { 39 BodyDeclaration enclosingNode= null; 40 if (!getStatus().hasFatalError() && hasSelectedNodes()) 41 enclosingNode= (BodyDeclaration)ASTNodes.getParent(getFirstSelectedNode(), BodyDeclaration.class); 42 43 super.endVisit(node); 44 if (enclosingNode != null && !getStatus().hasFatalError()) { 45 fExceptions= ExceptionAnalyzer.perform(enclosingNode, getSelection()); 46 if (fExceptions == null || fExceptions.length == 0) { 47 if (fQuery == null) { 48 invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_noUncaughtExceptions); 49 } else if (fQuery.catchRuntimeException()) { 50 fExceptions= new ITypeBinding[] {node.getAST().resolveWellKnownType("java.lang.RuntimeException")}; } 52 } 53 } 54 } 55 } 56 | Popular Tags |