src/jdk.compiler/share/classes/com/sun/source/util/JavacTask.java
author jlahoda
Mon, 01 Apr 2019 14:46:17 +0200
branchjlahoda-tree-builder
changeset 57298 72d5f7163f12
parent 47216 71c04702a3d5
child 54514 b0651dcc8d98
permissions -rw-r--r--
Adding ability to supply code as text instead of Trees on some places.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
     2
 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.source.util;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    29
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    30
import javax.annotation.processing.ProcessingEnvironment;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import javax.lang.model.element.Element;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import javax.lang.model.type.TypeMirror;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import javax.lang.model.util.Elements;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import javax.lang.model.util.Types;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import javax.tools.JavaCompiler.CompilationTask;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    38
import com.sun.source.tree.CompilationUnitTree;
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    39
import com.sun.source.tree.Tree;
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    40
import com.sun.tools.javac.api.BasicJavacTask;
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    41
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    42
import com.sun.tools.javac.util.Context;
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    43
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
/**
5848
c5a4ce47e780 6960407: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    45
 * Provides access to functionality specific to the JDK Java Compiler, javac.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * @author Peter von der Ahé
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * @author Jonathan Gibbons
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * @since 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
public abstract class JavacTask implements CompilationTask {
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    54
     * Returns the {@code JavacTask} for a {@code ProcessingEnvironment}.
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    55
     * If the compiler is being invoked using a
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    56
     * {@link javax.tools.JavaCompiler.CompilationTask CompilationTask},
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    57
     * then that task will be returned.
16559
e927a4e65b0c 8010315: doclint errors in javac public API
jjg
parents: 16303
diff changeset
    58
     * @param processingEnvironment the processing environment
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    59
     * @return the {@code JavacTask} for a {@code ProcessingEnvironment}
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    60
     * @since 1.8
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    61
     */
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    62
    public static JavacTask instance(ProcessingEnvironment processingEnvironment) {
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    63
        if (!processingEnvironment.getClass().getName().equals(
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    64
                "com.sun.tools.javac.processing.JavacProcessingEnvironment"))
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    65
            throw new IllegalArgumentException();
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    66
        Context c = ((JavacProcessingEnvironment) processingEnvironment).getContext();
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    67
        JavacTask t = c.get(JavacTask.class);
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    68
        return (t != null) ? t : new BasicJavacTask(c, true);
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    69
    }
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    70
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    71
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    72
     * Parses the specified files returning a list of abstract syntax trees.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     * @return a list of abstract syntax trees
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     * @throws IOException if an unhandled I/O error occurred in the compiler.
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    76
     * @throws IllegalStateException if the operation cannot be performed at this time.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    public abstract Iterable<? extends CompilationUnitTree> parse()
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    82
     * Completes all analysis.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
     * @return a list of elements that were analyzed
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     * @throws IOException if an unhandled I/O error occurred in the compiler.
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    86
     * @throws IllegalStateException if the operation cannot be performed at this time.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    public abstract Iterable<? extends Element> analyze() throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    91
     * Generates code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     * @return a list of files that were generated
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     * @throws IOException if an unhandled I/O error occurred in the compiler.
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
    95
     * @throws IllegalStateException if the operation cannot be performed at this time.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    public abstract Iterable<? extends JavaFileObject> generate() throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
   100
     * Sets a specified listener to receive notification of events
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   101
     * describing the progress of this compilation task.
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   102
     *
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   103
     * If another listener is receiving notifications as a result of a prior
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   104
     * call of this method, then that listener will no longer receive notifications.
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   105
     *
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   106
     * Informally, this method is equivalent to calling {@code removeTaskListener} for
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   107
     * any listener that has been previously set, followed by {@code addTaskListener}
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   108
     * for the new listener.
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   109
     *
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
   110
     * @param taskListener the task listener
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   111
     * @throws IllegalStateException if the specified listener has already been added.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    public abstract void setTaskListener(TaskListener taskListener);
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
   116
     * Adds a specified listener so that it receives notification of events
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   117
     * describing the progress of this compilation task.
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   118
     *
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   119
     * This method may be called at any time before or during the compilation.
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   120
     *
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
   121
     * @param taskListener the task listener
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   122
     * @throws IllegalStateException if the specified listener has already been added.
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   123
     * @since 1.8
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   124
     */
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   125
    public abstract void addTaskListener(TaskListener taskListener);
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   126
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   127
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
   128
     * Removes the specified listener so that it no longer receives
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
   129
     * notification of events describing the progress of this
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
   130
     * compilation task.
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   131
     *
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   132
     * This method may be called at any time before or during the compilation.
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   133
     *
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
   134
     * @param taskListener the task listener
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   135
     * @since 1.8
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   136
     */
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   137
    public abstract void removeTaskListener(TaskListener taskListener);
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   138
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   139
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
   140
     * Returns a type mirror of the tree node determined by the specified path.
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   141
     * This method has been superceded by methods on
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   142
     * {@link com.sun.source.util.Trees Trees}.
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   143
     *
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
   144
     * @param path the path
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
   145
     * @return the type mirror
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 5848
diff changeset
   146
     * @see com.sun.source.util.Trees#getTypeMirror
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    public abstract TypeMirror getTypeMirror(Iterable<? extends Tree> path);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents: 12016
diff changeset
   149
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
   151
     * Returns a utility object for dealing with program elements.
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   152
     *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   153
     * @return a utility object for dealing with program elements
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    public abstract Elements getElements();
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
   158
     * Returns a utility object for dealing with type mirrors.
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   159
     *
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
   160
     * @return the utility object for dealing with type mirrors
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    public abstract Types getTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
}