1 /*
2  * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package com.sun.source.util;
27 
28 import javax.lang.model.element.TypeElement;
29 import javax.tools.JavaFileObject;
30 
31 import com.sun.source.tree.CompilationUnitTree;
32 
33 /**
34  * Provides details about work that has been done by the JDK Java Compiler, javac.
35  *
36  * @author Jonathan Gibbons
37  * @since 1.6
38  */
39 @jdk.Exported
40 public final class TaskEvent
41 {
42     /**
43      * Kind of task event.
44      * @since 1.6
45      */
46     @jdk.Exported
47     public enum Kind {
48         /**
49          * For events related to the parsing of a file.
50          */
51         PARSE,
52         /**
53          * For events relating to elements being entered.
54          **/
55         ENTER,
56         /**
57          * For events relating to elements being analyzed for errors.
58          **/
59         ANALYZE,
60         /**
61          * For events relating to class files being generated.
62          **/
63         GENERATE,
64         /**
65          * For events relating to overall annotation processing.
66          **/
67         ANNOTATION_PROCESSING,
68         /**
69          * For events relating to an individual annotation processing round.
70          **/
71         ANNOTATION_PROCESSING_ROUND
72     };
73 
TaskEvent(Kind kind)74     public TaskEvent(Kind kind) {
75         this(kind, null, null, null);
76     }
77 
TaskEvent(Kind kind, JavaFileObject sourceFile)78     public TaskEvent(Kind kind, JavaFileObject sourceFile) {
79         this(kind, sourceFile, null, null);
80     }
81 
TaskEvent(Kind kind, CompilationUnitTree unit)82     public TaskEvent(Kind kind, CompilationUnitTree unit) {
83         this(kind, unit.getSourceFile(), unit, null);
84     }
85 
TaskEvent(Kind kind, CompilationUnitTree unit, TypeElement clazz)86     public TaskEvent(Kind kind, CompilationUnitTree unit, TypeElement clazz) {
87         this(kind, unit.getSourceFile(), unit, clazz);
88     }
89 
TaskEvent(Kind kind, JavaFileObject file, CompilationUnitTree unit, TypeElement clazz)90     private TaskEvent(Kind kind, JavaFileObject file, CompilationUnitTree unit, TypeElement clazz) {
91         this.kind = kind;
92         this.file = file;
93         this.unit = unit;
94         this.clazz = clazz;
95     }
96 
getKind()97     public Kind getKind() {
98         return kind;
99     }
100 
getSourceFile()101     public JavaFileObject getSourceFile() {
102         return file;
103     }
104 
getCompilationUnit()105     public CompilationUnitTree getCompilationUnit() {
106         return unit;
107     }
108 
getTypeElement()109     public TypeElement getTypeElement() {
110         return clazz;
111     }
112 
toString()113     public String toString() {
114         return "TaskEvent["
115             + kind + ","
116             + file + ","
117             // the compilation unit is identified by the file
118             + clazz + "]";
119     }
120 
121     private Kind kind;
122     private JavaFileObject file;
123     private CompilationUnitTree unit;
124     private TypeElement clazz;
125 }
126