protected void addExceptions(ITypeBinding[] exceptions, AST ast) { if(exceptions == null) return; for (int i= 0; i < exceptions.length;i++) { addException(exceptions[i], ast); } }
private void removeCaughtExceptions(ITypeBinding catchTypeBinding) { if (catchTypeBinding == null) return; for (Iterator<ITypeBinding> exceptions= new ArrayList<>(fCurrentExceptions).iterator(); exceptions.hasNext();) { ITypeBinding throwTypeBinding= exceptions.next(); if (catches(catchTypeBinding, throwTypeBinding)) fCurrentExceptions.remove(throwTypeBinding); } }
@Override public boolean visit(VariableDeclarationExpression node) { if (!isSelected(node)) return false; return super.visit(node); }
public boolean visit(TryStatement node) { fCurrentExceptions= new ArrayList(1); fTryStack.push(fCurrentExceptions); // visit try block node.getBody().accept(this); // Remove those exceptions that get catch by following catch blocks List catchClauses= node.catchClauses(); if (!catchClauses.isEmpty()) handleCatchArguments(catchClauses); List current= (List)fTryStack.pop(); fCurrentExceptions= (List)fTryStack.peek(); for (Iterator iter= current.iterator(); iter.hasNext();) { addException((ITypeBinding)iter.next()); } // visit catch and finally for (Iterator iter= catchClauses.iterator(); iter.hasNext(); ) { ((CatchClause)iter.next()).accept(this); } if (node.getFinally() != null) node.getFinally().accept(this); // return false. We have visited the body by ourselves. return false; }
private void handleCatchArguments(List<CatchClause> catchClauses) { for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext(); ) { Type type= iter.next().getException().getType(); if (type instanceof UnionType) { List<Type> types= ((UnionType) type).types(); for (Iterator<Type> iterator= types.iterator(); iterator.hasNext();) { removeCaughtExceptions(iterator.next().resolveBinding()); } } else { removeCaughtExceptions(type.resolveBinding()); } } }
@Override public boolean visit(VariableDeclarationExpression node) { if (node.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) { Type type= node.getType(); ITypeBinding resourceTypeBinding= type.resolveBinding(); if (resourceTypeBinding != null) { IMethodBinding methodBinding= Bindings.findMethodInHierarchy(resourceTypeBinding, "close", new ITypeBinding[0]); //$NON-NLS-1$ if (methodBinding != null) { addExceptions(methodBinding.getExceptionTypes(), node.getAST()); } } } return super.visit(node); }
@Override public boolean visit(TryStatement node) { fCurrentExceptions= new ArrayList<>(1); fTryStack.push(fCurrentExceptions); // visit try block node.getBody().accept(this); List<VariableDeclarationExpression> resources= node.resources(); for (Iterator<VariableDeclarationExpression> iterator= resources.iterator(); iterator.hasNext();) { iterator.next().accept(this); } // Remove those exceptions that get catch by following catch blocks List<CatchClause> catchClauses= node.catchClauses(); if (!catchClauses.isEmpty()) handleCatchArguments(catchClauses); List<ITypeBinding> current= fTryStack.pop(); fCurrentExceptions= fTryStack.peek(); for (Iterator<ITypeBinding> iter= current.iterator(); iter.hasNext();) { addException(iter.next(), node.getAST()); } // visit catch and finally for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext(); ) { iter.next().accept(this); } if (node.getFinally() != null) node.getFinally().accept(this); // return false. We have visited the body by ourselves. return false; }
private void handleCatchArguments(List<CatchClause> catchClauses) { for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext(); ) { Type type= iter.next().getException().getType(); if (type instanceof UnionType) { List<Type> types= ((UnionType) type).types(); for (Iterator<Type> iterator= types.iterator(); iterator.hasNext();) { removeCaughtExceptions(iterator.next().resolveBinding()); } } else { removeCaughtExceptions(type.resolveBinding()); } } }
@Override public boolean visit(VariableDeclarationExpression node) { if (node.getLocationInParent() == TryStatement.RESOURCES2_PROPERTY) { Type type= node.getType(); ITypeBinding resourceTypeBinding= type.resolveBinding(); if (resourceTypeBinding != null) { IMethodBinding methodBinding= Bindings.findMethodInHierarchy(resourceTypeBinding, "close", new ITypeBinding[0]); //$NON-NLS-1$ if (methodBinding != null) { addExceptions(methodBinding.getExceptionTypes(), node.getAST()); } } } return super.visit(node); }
@Override public boolean visit(TryStatement node) { fCurrentExceptions= new ArrayList<>(1); fTryStack.push(fCurrentExceptions); // visit try block node.getBody().accept(this); List<Expression> resources= node.resources(); for (Iterator<Expression> iterator= resources.iterator(); iterator.hasNext();) { iterator.next().accept(this); } // Remove those exceptions that get catch by following catch blocks List<CatchClause> catchClauses= node.catchClauses(); if (!catchClauses.isEmpty()) handleCatchArguments(catchClauses); List<ITypeBinding> current= fTryStack.pop(); fCurrentExceptions= fTryStack.peek(); for (Iterator<ITypeBinding> iter= current.iterator(); iter.hasNext();) { addException(iter.next(), node.getAST()); } // visit catch and finally for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext(); ) { iter.next().accept(this); } if (node.getFinally() != null) node.getFinally().accept(this); // return false. We have visited the body by ourselves. return false; }
protected void addExceptions(ITypeBinding[] exceptions) { if(exceptions == null) return; for (int i= 0; i < exceptions.length;i++) { addException(exceptions[i]); } }
private void removeCaughtExceptions(ITypeBinding catchTypeBinding) { if (catchTypeBinding == null) return; for (Iterator<ITypeBinding> exceptions= new ArrayList<>(fCurrentExceptions).iterator(); exceptions.hasNext();) { ITypeBinding throwTypeBinding= exceptions.next(); if (catches(catchTypeBinding, throwTypeBinding)) fCurrentExceptions.remove(throwTypeBinding); } }
@Override public boolean visit(VariableDeclarationExpression node) { if (!isSelected(node)) return false; return super.visit(node); }
protected void addExceptions(ITypeBinding[] exceptions, AST ast) { if(exceptions == null) return; for (int i= 0; i < exceptions.length;i++) { addException(exceptions[i], ast); } }
private void handleCatchArguments(List catchClauses) { for (Iterator iter= catchClauses.iterator(); iter.hasNext(); ) { CatchClause clause= (CatchClause)iter.next(); ITypeBinding catchTypeBinding= clause.getException().getType().resolveBinding(); if (catchTypeBinding == null) // No correct type resolve. continue; for (Iterator exceptions= new ArrayList(fCurrentExceptions).iterator(); exceptions.hasNext(); ) { ITypeBinding throwTypeBinding= (ITypeBinding)exceptions.next(); if (catches(catchTypeBinding, throwTypeBinding)) fCurrentExceptions.remove(throwTypeBinding); } } }