addExceptionTypeLinkProposals(proposal, uncaughtExceptions[i], proposal.getExceptionTypeGroupId(i));
addExceptionTypeLinkProposals(proposal, uncaughtExceptions[i], proposal.getExceptionTypeGroupId(i + nExistingExceptions));
	public static void addUncaughtExceptionProposals(IInvocationContext context, IProblemLocation problem, Collection proposals) throws CoreException {		ICompilationUnit cu= context.getCompilationUnit();		CompilationUnit astRoot= context.getASTRoot();		ASTNode selectedNode= problem.getCoveringNode(astRoot);		if (selectedNode == null) {			return;		}		while (selectedNode != null && !(selectedNode instanceof Statement)) {			selectedNode= selectedNode.getParent();		}		if (selectedNode == null) {			return;		}		int offset= selectedNode.getStartPosition();		int length= selectedNode.getLength();		int selectionEnd= context.getSelectionOffset() + context.getSelectionLength();		if (selectionEnd > offset + length) {			// extend the selection if more than one statement is selected (bug 72149)			length= selectionEnd - offset;		}		SurroundWithTryCatchRefactoring refactoring= SurroundWithTryCatchRefactoring.create(cu, offset, length, null);		if (refactoring == null)			return;		refactoring.setLeaveDirty(true);		if (refactoring.checkActivationBasics(astRoot).isOK()) {			String label= CorrectionMessages.LocalCorrectionsSubProcessor_surroundwith_description;			Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION);			CUCorrectionProposal proposal= new CUCorrectionProposal(label, cu, (CompilationUnitChange) refactoring.createChange(null), 4, image);			proposals.add(proposal);		}		BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode);		if (decl == null) {			return;		}		ITypeBinding[] uncaughtExceptions= ExceptionAnalyzer.perform(decl, Selection.createFromStartLength(offset, length));		if (uncaughtExceptions.length == 0) {			return;		}		TryStatement surroundingTry= ASTResolving.findParentTryStatement(selectedNode);		if (surroundingTry != null && ASTNodes.isParent(selectedNode, surroundingTry.getBody())) {			ASTRewrite rewrite= ASTRewrite.create(surroundingTry.getAST());			ImportRewrite imports= new ImportRewrite(cu);			String label= CorrectionMessages.LocalCorrectionsSubProcessor_addadditionalcatch_description;			Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION);			LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, 5, image);			proposal.setImportRewrite(imports);			AST ast= astRoot.getAST();			ListRewrite clausesRewrite= rewrite.getListRewrite(surroundingTry, TryStatement.CATCH_CLAUSES_PROPERTY);			for (int i= 0; i < uncaughtExceptions.length; i++) {				ITypeBinding excBinding= uncaughtExceptions[i];				String varName= StubUtility.getExceptionVariableName(cu.getJavaProject());				SingleVariableDeclaration var= ast.newSingleVariableDeclaration();				var.setName(ast.newSimpleName(varName));				var.setType(imports.addImport(excBinding, ast));				CatchClause newClause= ast.newCatchClause();				newClause.setException(var);				String catchBody = StubUtility.getCatchBodyContent(cu, excBinding.getName(), varName, String.valueOf('\n'));				if (catchBody != null) {					ASTNode node= rewrite.createStringPlaceholder(catchBody, ASTNode.RETURN_STATEMENT);					newClause.getBody().statements().add(node);				}				clausesRewrite.insertLast(newClause, null);				String typeKey= "type" + i; //$NON-NLS-1$				String nameKey= "name" + i; //$NON-NLS-1$				proposal.addLinkedPosition(rewrite.track(var.getType()), false, typeKey);				proposal.addLinkedPosition(rewrite.track(var.getName()), false, nameKey);				addExceptionTypeLinkProposals(proposal, excBinding, typeKey);			}			proposals.add(proposal);		}		if (decl instanceof MethodDeclaration) {			MethodDeclaration methodDecl= (MethodDeclaration) decl;			IMethodBinding binding= methodDecl.resolveBinding();			if (binding != null) {				ITypeBinding[] methodExceptions= binding.getExceptionTypes();				ArrayList unhandledExceptions= new ArrayList(uncaughtExceptions.length);				for (int i= 0; i < uncaughtExceptions.length; i++) {					ITypeBinding curr= uncaughtExceptions[i];					if (!canRemoveException(curr, methodExceptions)) {						unhandledExceptions.add(curr);					}				}				uncaughtExceptions= (ITypeBinding[]) unhandledExceptions.toArray(new ITypeBinding[unhandledExceptions.size()]);				List exceptions= methodDecl.thrownExceptions();				int nExistingExceptions= exceptions.size();				ChangeDescription[] desc= new ChangeDescription[nExistingExceptions + uncaughtExceptions.length];				for (int i= 0; i < exceptions.size(); i++) {					Name elem= (Name) exceptions.get(i);					if (canRemoveException(elem.resolveTypeBinding(), uncaughtExceptions)) {						desc[i]= new RemoveDescription();					}				}				for (int i = 0; i < uncaughtExceptions.length; i++) {					desc[i + nExistingExceptions]= new InsertDescription(uncaughtExceptions[i], ""); //$NON-NLS-1$				}				String label= CorrectionMessages.LocalCorrectionsSubProcessor_addthrows_description;				Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION);				ChangeMethodSignatureProposal proposal= new ChangeMethodSignatureProposal(label, cu, astRoot, binding, null, desc, 6, image);				for (int i= 0; i < uncaughtExceptions.length; i++) {					addExceptionTypeLinkProposals(proposal, uncaughtExceptions[i], proposal.getExceptionTypeGroupId(i));				}				proposal.setCommandId(ADD_EXCEPTION_TO_THROWS_ID);				proposals.add(proposal);			}		}	}