Path: blob/master/src/jdk.compiler/share/classes/com/sun/source/util/TaskEvent.java
41175 views
/*1* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.source.util;2627import javax.lang.model.element.TypeElement;28import javax.tools.JavaFileObject;2930import com.sun.source.tree.CompilationUnitTree;3132/**33* Provides details about work that has been done by the JDK Java Compiler, javac.34*35* @author Jonathan Gibbons36* @since 1.637*/38public final class TaskEvent39{40/**41* Kind of task event.42* @since 1.643*/44public enum Kind {45/**46* For events related to the parsing of a file.47*/48PARSE,49/**50* For events relating to elements being entered.51**/52ENTER,53/**54* For events relating to elements being analyzed for errors.55**/56ANALYZE,57/**58* For events relating to class files being generated.59**/60GENERATE,61/**62* For events relating to overall annotation processing.63**/64ANNOTATION_PROCESSING,65/**66* For events relating to an individual annotation processing round.67**/68ANNOTATION_PROCESSING_ROUND,69/**70* Sent before parsing first source file, and after writing the last output file.71* This event is not sent when using {@link JavacTask#parse()},72* {@link JavacTask#analyze()} or {@link JavacTask#generate()}.73*74* @since 975*/76COMPILATION,77}7879/**80* Creates a task event for a given kind.81* The source file, compilation unit and type element82* are all set to {@code null}.83* @param kind the kind of the event84*/85public TaskEvent(Kind kind) {86this(kind, null, null, null);87}8889/**90* Creates a task event for a given kind and source file.91* The compilation unit and type element are both set to {@code null}.92* @param kind the kind of the event93* @param sourceFile the source file94*/95public TaskEvent(Kind kind, JavaFileObject sourceFile) {96this(kind, sourceFile, null, null);97}9899/**100* Creates a task event for a given kind and compilation unit.101* The source file is set from the compilation unit,102* and the type element is set to {@code null}.103* @param kind the kind of the event104* @param unit the compilation unit105*/106public TaskEvent(Kind kind, CompilationUnitTree unit) {107this(kind, unit.getSourceFile(), unit, null);108}109110/**111* Creates a task event for a given kind, compilation unit112* and type element.113* The source file is set from the compilation unit.114* @param kind the kind of the event115* @param unit the compilation unit116* @param clazz the type element117*/118public TaskEvent(Kind kind, CompilationUnitTree unit, TypeElement clazz) {119this(kind, unit.getSourceFile(), unit, clazz);120}121122private TaskEvent(Kind kind, JavaFileObject file, CompilationUnitTree unit, TypeElement clazz) {123this.kind = kind;124this.file = file;125this.unit = unit;126this.clazz = clazz;127}128129/**130* Returns the kind for this event.131* @return the kind132*/133public Kind getKind() {134return kind;135}136137/**138* Returns the source file for this event.139* May be {@code null}.140* @return the source file141*/142public JavaFileObject getSourceFile() {143return file;144}145146/**147* Returns the compilation unit for this event.148* May be {@code null}.149* @return the compilation unit150*/151public CompilationUnitTree getCompilationUnit() {152return unit;153}154155/**156* Returns the type element for this event.157* May be {@code null}.158* @return the type element159*/160public TypeElement getTypeElement() {161return clazz;162}163164@Override165public String toString() {166return "TaskEvent["167+ kind + ","168+ file + ","169// the compilation unit is identified by the file170+ clazz + "]";171}172173private Kind kind;174private JavaFileObject file;175private CompilationUnitTree unit;176private TypeElement clazz;177}178179180