From 477a5341c1ca8f3037a921dd1c05addc74e5a5a3 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Fri, 17 Jan 2014 21:14:24 +0100 Subject: Close the outputstream if it is a file after printing the AST --- src/core/lombok/eclipse/handlers/HandlePrintAST.java | 17 +++++++++++++---- src/core/lombok/javac/handlers/HandlePrintAST.java | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) (limited to 'src/core') diff --git a/src/core/lombok/eclipse/handlers/HandlePrintAST.java b/src/core/lombok/eclipse/handlers/HandlePrintAST.java index da6fa2a2..65cda98a 100644 --- a/src/core/lombok/eclipse/handlers/HandlePrintAST.java +++ b/src/core/lombok/eclipse/handlers/HandlePrintAST.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2012 The Project Lombok Authors. + * Copyright (C) 2009-2014 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -52,7 +52,16 @@ public class HandlePrintAST extends EclipseAnnotationHandler { } catch (FileNotFoundException e) { Lombok.sneakyThrow(e); } - - annotationNode.up().traverse(new EclipseASTVisitor.Printer(annotation.getInstance().printContent(), stream, annotation.getInstance().printPositions())); + try { + annotationNode.up().traverse(new EclipseASTVisitor.Printer(annotation.getInstance().printContent(), stream, annotation.getInstance().printPositions())); + } finally { + if (stream != System.out) { + try { + stream.close(); + } catch (Exception e) { + Lombok.sneakyThrow(e); + } + } + } } -} +} \ No newline at end of file diff --git a/src/core/lombok/javac/handlers/HandlePrintAST.java b/src/core/lombok/javac/handlers/HandlePrintAST.java index 7b6d942c..2c229f2b 100644 --- a/src/core/lombok/javac/handlers/HandlePrintAST.java +++ b/src/core/lombok/javac/handlers/HandlePrintAST.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2011 The Project Lombok Authors. + * Copyright (C) 2009-2014 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -52,6 +52,16 @@ public class HandlePrintAST extends JavacAnnotationHandler { Lombok.sneakyThrow(e); } - annotationNode.up().traverse(new JavacASTVisitor.Printer(annotation.getInstance().printContent(), stream)); + try { + annotationNode.up().traverse(new JavacASTVisitor.Printer(annotation.getInstance().printContent(), stream)); + } finally { + if (stream != System.out) { + try { + stream.close(); + } catch (Exception e) { + Lombok.sneakyThrow(e); + } + } + } } } -- cgit