DiagnosticCollector.java revision 2837:1e3266d870d6
10SN/A/* 211303Samlu * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. 30SN/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 40SN/A * 50SN/A * This code is free software; you can redistribute it and/or modify it 60SN/A * under the terms of the GNU General Public License version 2 only, as 72362SN/A * published by the Free Software Foundation. Oracle designates this 80SN/A * particular file as subject to the "Classpath" exception as provided 92362SN/A * by Oracle in the LICENSE file that accompanied this code. 100SN/A * 110SN/A * This code is distributed in the hope that it will be useful, but WITHOUT 120SN/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 130SN/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 140SN/A * version 2 for more details (a copy is included in the LICENSE file that 150SN/A * accompanied this code). 160SN/A * 170SN/A * You should have received a copy of the GNU General Public License version 180SN/A * 2 along with this work; if not, write to the Free Software Foundation, 190SN/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 200SN/A * 212362SN/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 222362SN/A * or visit www.oracle.com if you need additional information or have any 232362SN/A * questions. 240SN/A */ 250SN/A 260SN/Apackage javax.tools; 270SN/A 280SN/Aimport java.util.ArrayList; 290SN/Aimport java.util.Collections; 300SN/Aimport java.util.List; 310SN/Aimport java.util.Objects; 320SN/A 330SN/A/** 340SN/A * Provides an easy way to collect diagnostics in a list. 350SN/A * 360SN/A * @param <S> the type of source objects used by diagnostics received 370SN/A * by this object 380SN/A * 390SN/A * @author Peter von der Ahé 400SN/A * @since 1.6 4111064Sprappo */ 42893SN/Apublic final class DiagnosticCollector<S> implements DiagnosticListener<S> { 430SN/A private List<Diagnostic<? extends S>> diagnostics = 440SN/A Collections.synchronizedList(new ArrayList<Diagnostic<? extends S>>()); 450SN/A 460SN/A public void report(Diagnostic<? extends S> diagnostic) { 470SN/A Objects.requireNonNull(diagnostic); 480SN/A diagnostics.add(diagnostic); 490SN/A } 500SN/A 510SN/A /** 5211064Sprappo * Returns a list view of diagnostics collected by this object. 5311064Sprappo * 540SN/A * @return a list view of diagnostics 550SN/A */ 560SN/A public List<Diagnostic<? extends S>> getDiagnostics() { 570SN/A return Collections.unmodifiableList(diagnostics); 580SN/A } 590SN/A} 600SN/A