1 | /* |
2 | * Copyright 2005-2006 Sun Microsystems, Inc. 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. Sun designates this |
8 | * particular file as subject to the "Classpath" exception as provided |
9 | * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
23 | * have any questions. |
24 | */ |
25 | |
26 | package com.sun.source.util; |
27 | |
28 | import com.sun.source.tree.CompilationUnitTree; |
29 | import javax.lang.model.element.TypeElement; |
30 | import javax.tools.JavaFileObject; |
31 | |
32 | /** |
33 | * Provides details about work that has been done by the Sun Java Compiler, javac. |
34 | * |
35 | * @author Jonathan Gibbons |
36 | * @since 1.6 |
37 | */ |
38 | public final class TaskEvent |
39 | { |
40 | /** |
41 | * Kind of task event. |
42 | * @since 1.6 |
43 | */ |
44 | public enum Kind { |
45 | /** |
46 | * For events related to the parsing of a file. |
47 | */ |
48 | PARSE, |
49 | /** |
50 | * For events relating to elements being entered. |
51 | **/ |
52 | ENTER, |
53 | /** |
54 | * For events relating to elements being analyzed for errors. |
55 | **/ |
56 | ANALYZE, |
57 | /** |
58 | * For events relating to class files being generated. |
59 | **/ |
60 | GENERATE, |
61 | /** |
62 | * For events relating to overall annotaion processing. |
63 | **/ |
64 | ANNOTATION_PROCESSING, |
65 | /** |
66 | * For events relating to an individual annotation processing round. |
67 | **/ |
68 | ANNOTATION_PROCESSING_ROUND |
69 | }; |
70 | |
71 | public TaskEvent(Kind kind) { |
72 | this(kind, null, null, null); |
73 | } |
74 | |
75 | public TaskEvent(Kind kind, JavaFileObject sourceFile) { |
76 | this(kind, sourceFile, null, null); |
77 | } |
78 | |
79 | public TaskEvent(Kind kind, CompilationUnitTree unit) { |
80 | this(kind, unit.getSourceFile(), unit, null); |
81 | } |
82 | |
83 | public TaskEvent(Kind kind, CompilationUnitTree unit, TypeElement clazz) { |
84 | this(kind, unit.getSourceFile(), unit, clazz); |
85 | } |
86 | |
87 | private TaskEvent(Kind kind, JavaFileObject file, CompilationUnitTree unit, TypeElement clazz) { |
88 | this.kind = kind; |
89 | this.file = file; |
90 | this.unit = unit; |
91 | this.clazz = clazz; |
92 | } |
93 | |
94 | public Kind getKind() { |
95 | return kind; |
96 | } |
97 | |
98 | public JavaFileObject getSourceFile() { |
99 | return file; |
100 | } |
101 | |
102 | public CompilationUnitTree getCompilationUnit() { |
103 | return unit; |
104 | } |
105 | |
106 | public TypeElement getTypeElement() { |
107 | return clazz; |
108 | } |
109 | |
110 | public String toString() { |
111 | return "TaskEvent[" |
112 | + kind + "," |
113 | + file + "," |
114 | // the compilation unit is identified by the file |
115 | + clazz + "]"; |
116 | } |
117 | |
118 | private Kind kind; |
119 | private JavaFileObject file; |
120 | private CompilationUnitTree unit; |
121 | private TypeElement clazz; |
122 | } |