public void test_visitCatchClause() { ElementHolder holder = new ElementHolder(); ElementBuilder builder = new ElementBuilder(holder); String exceptionParameterName = "e"; String stackParameterName = "s"; CatchClause clause = catchClause(exceptionParameterName, stackParameterName); clause.accept(builder); VariableElement[] variables = holder.getVariables(); assertLength(2, variables); VariableElement exceptionVariable = variables[0]; assertNotNull(exceptionVariable); assertEquals(exceptionParameterName, exceptionVariable.getName()); assertFalse(exceptionVariable.isSynthetic()); assertFalse(exceptionVariable.isConst()); assertFalse(exceptionVariable.isFinal()); assertNull(exceptionVariable.getInitializer()); VariableElement stackVariable = variables[1]; assertNotNull(stackVariable); assertEquals(stackParameterName, stackVariable.getName()); assertFalse(stackVariable.isSynthetic()); assertFalse(stackVariable.isConst()); assertFalse(stackVariable.isFinal()); assertNull(stackVariable.getInitializer()); }
@Override public Void visitCatchClause(CatchClause node) { SimpleIdentifier exceptionParameter = node.getExceptionParameter(); if (exceptionParameter != null) { VariableElementImpl exception = new VariableElementImpl(exceptionParameter); currentHolder.addVariable(exception); SimpleIdentifier stackTraceParameter = node.getStackTraceParameter(); if (stackTraceParameter != null) { VariableElementImpl stackTrace = new VariableElementImpl(stackTraceParameter); currentHolder.addVariable(stackTrace); } } node.visitChildren(this); return null; }
@Override public Void visitCatchClause(CatchClause node) { SimpleIdentifier exceptionParameter = node.getExceptionParameter(); if (exceptionParameter != null) { LocalVariableElementImpl exception = new LocalVariableElementImpl(exceptionParameter); currentHolder.addLocalVariable(exception); exceptionParameter.setStaticElement(exception); SimpleIdentifier stackTraceParameter = node.getStackTraceParameter(); if (stackTraceParameter != null) { LocalVariableElementImpl stackTrace = new LocalVariableElementImpl(stackTraceParameter); currentHolder.addLocalVariable(stackTrace); stackTraceParameter.setStaticElement(stackTrace); } } return super.visitCatchClause(node); }
@Override public Void visitCatchClause(CatchClause node) { visit("on ", node.getExceptionType()); if (node.getCatchKeyword() != null) { if (node.getExceptionType() != null) { writer.print(' '); } writer.print("catch ("); visit(node.getExceptionParameter()); visit(", ", node.getStackTraceParameter()); writer.print(") "); } else { writer.print(" "); } visit(node.getBody()); return null; }
@Override public R visitCatchClause(CatchClause node) { node.visitChildren(this); return null; }