001    /*
002     * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
003     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004     *
005     * This code is free software; you can redistribute it and/or modify it
006     * under the terms of the GNU General Public License version 2 only, as
007     * published by the Free Software Foundation.  Sun designates this
008     * particular file as subject to the "Classpath" exception as provided
009     * by Sun in the LICENSE file that accompanied this code.
010     *
011     * This code is distributed in the hope that it will be useful, but WITHOUT
012     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014     * version 2 for more details (a copy is included in the LICENSE file that
015     * accompanied this code).
016     *
017     * You should have received a copy of the GNU General Public License version
018     * 2 along with this work; if not, write to the Free Software Foundation,
019     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020     *
021     * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022     * CA 95054 USA or visit www.sun.com if you need additional information or
023     * have any questions.
024     */
025    
026    package com.sun.source.util;
027    
028    import com.sun.source.tree.CompilationUnitTree;
029    import javax.lang.model.element.TypeElement;
030    import javax.tools.JavaFileObject;
031    
032    /**
033     * Provides details about work that has been done by the Sun Java Compiler, javac.
034     *
035     * @author Jonathan Gibbons
036     * @since 1.6
037     */
038    public final class TaskEvent
039    {
040        /**
041         * Kind of task event.
042         * @since 1.6
043         */
044        public enum Kind {
045            /**
046             * For events related to the parsing of a file.
047             */
048            PARSE,
049            /**
050             * For events relating to elements being entered.
051             **/
052            ENTER,
053            /**
054             * For events relating to elements being analyzed for errors.
055             **/
056            ANALYZE,
057            /**
058             * For events relating to class files being generated.
059             **/
060            GENERATE,
061            /**
062             * For events relating to overall annotaion processing.
063             **/
064            ANNOTATION_PROCESSING,
065            /**
066             * For events relating to an individual annotation processing round.
067             **/
068            ANNOTATION_PROCESSING_ROUND
069        };
070    
071        public TaskEvent(Kind kind) {
072            this(kind, null, null, null);
073        }
074    
075        public TaskEvent(Kind kind, JavaFileObject sourceFile) {
076            this(kind, sourceFile, null, null);
077        }
078    
079        public TaskEvent(Kind kind, CompilationUnitTree unit) {
080            this(kind, unit.getSourceFile(), unit, null);
081        }
082    
083        public TaskEvent(Kind kind, CompilationUnitTree unit, TypeElement clazz) {
084            this(kind, unit.getSourceFile(), unit, clazz);
085        }
086    
087        private TaskEvent(Kind kind, JavaFileObject file, CompilationUnitTree unit, TypeElement clazz) {
088            this.kind = kind;
089            this.file = file;
090            this.unit = unit;
091            this.clazz = clazz;
092        }
093    
094        public Kind getKind() {
095            return kind;
096        }
097    
098        public JavaFileObject getSourceFile() {
099            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    }