src/share/classes/com/sun/tools/javac/api/BasicJavacTask.java

Sun, 17 Feb 2013 16:44:55 -0500

author
dholmes
date
Sun, 17 Feb 2013 16:44:55 -0500
changeset 1571
af8417e590f4
parent 1455
75ab654b5cd5
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Merge

jjg@1210 1 /*
jjg@1210 2 * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
jjg@1210 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@1210 4 *
jjg@1210 5 * This code is free software; you can redistribute it and/or modify it
jjg@1210 6 * under the terms of the GNU General Public License version 2 only, as
jjg@1210 7 * published by the Free Software Foundation. Oracle designates this
jjg@1210 8 * particular file as subject to the "Classpath" exception as provided
jjg@1210 9 * by Oracle in the LICENSE file that accompanied this code.
jjg@1210 10 *
jjg@1210 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@1210 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@1210 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@1210 14 * version 2 for more details (a copy is included in the LICENSE file that
jjg@1210 15 * accompanied this code).
jjg@1210 16 *
jjg@1210 17 * You should have received a copy of the GNU General Public License version
jjg@1210 18 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@1210 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@1210 20 *
jjg@1210 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jjg@1210 22 * or visit www.oracle.com if you need additional information or have any
jjg@1210 23 * questions.
jjg@1210 24 */
jjg@1210 25
jjg@1210 26 package com.sun.tools.javac.api;
jjg@1210 27
jjg@1210 28 import java.io.IOException;
jjg@1357 29 import java.util.Collection;
jjg@1210 30 import java.util.Locale;
jjg@1210 31
jjg@1210 32 import javax.annotation.processing.Processor;
jjg@1210 33 import javax.lang.model.element.Element;
jjg@1210 34 import javax.lang.model.type.TypeMirror;
jjg@1210 35 import javax.lang.model.util.Elements;
jjg@1210 36 import javax.lang.model.util.Types;
jjg@1210 37 import javax.tools.JavaFileObject;
jjg@1210 38
jjg@1210 39 import com.sun.source.tree.CompilationUnitTree;
jjg@1210 40 import com.sun.source.tree.Tree;
jjg@1210 41 import com.sun.source.util.JavacTask;
jjg@1210 42 import com.sun.source.util.TaskListener;
jjg@1210 43 import com.sun.tools.javac.model.JavacElements;
jjg@1210 44 import com.sun.tools.javac.model.JavacTypes;
jjg@1210 45 import com.sun.tools.javac.tree.JCTree;
jjg@1210 46 import com.sun.tools.javac.util.Context;
jjg@1210 47
jjg@1210 48 /**
jjg@1210 49 * Provides basic functionality for implementations of JavacTask.
jjg@1210 50 *
jjg@1210 51 * <p><b>This is NOT part of any supported API.
jjg@1210 52 * If you write code that depends on this, you do so at your own
jjg@1210 53 * risk. This code and its internal interfaces are subject to change
jjg@1210 54 * or deletion without notice.</b></p>
jjg@1210 55 */
jjg@1210 56 public class BasicJavacTask extends JavacTask {
jjg@1210 57 protected Context context;
jjg@1210 58 private TaskListener taskListener;
jjg@1210 59
jjg@1455 60 public static JavacTask instance(Context context) {
jjg@1455 61 JavacTask instance = context.get(JavacTask.class);
jjg@1455 62 if (instance == null)
jjg@1455 63 instance = new BasicJavacTask(context, true);
jjg@1455 64 return instance;
jjg@1455 65 }
jjg@1455 66
jjg@1210 67 public BasicJavacTask(Context c, boolean register) {
jjg@1210 68 context = c;
jjg@1210 69 if (register)
jjg@1210 70 context.put(JavacTask.class, this);
jjg@1210 71 }
jjg@1210 72
jjg@1210 73 @Override
jjg@1210 74 public Iterable<? extends CompilationUnitTree> parse() throws IOException {
jjg@1210 75 throw new IllegalStateException();
jjg@1210 76 }
jjg@1210 77
jjg@1210 78 @Override
jjg@1210 79 public Iterable<? extends Element> analyze() throws IOException {
jjg@1210 80 throw new IllegalStateException();
jjg@1210 81 }
jjg@1210 82
jjg@1210 83 @Override
jjg@1210 84 public Iterable<? extends JavaFileObject> generate() throws IOException {
jjg@1210 85 throw new IllegalStateException();
jjg@1210 86 }
jjg@1210 87
jjg@1210 88 @Override
jjg@1210 89 public void setTaskListener(TaskListener tl) {
jjg@1210 90 MultiTaskListener mtl = MultiTaskListener.instance(context);
jjg@1210 91 if (taskListener != null)
jjg@1210 92 mtl.remove(taskListener);
jjg@1210 93 if (tl != null)
jjg@1210 94 mtl.add(tl);
jjg@1210 95 taskListener = tl;
jjg@1210 96 }
jjg@1210 97
jjg@1210 98 @Override
jjg@1210 99 public void addTaskListener(TaskListener taskListener) {
jjg@1210 100 MultiTaskListener mtl = MultiTaskListener.instance(context);
jjg@1210 101 mtl.add(taskListener);
jjg@1210 102 }
jjg@1210 103
jjg@1210 104 @Override
jjg@1210 105 public void removeTaskListener(TaskListener taskListener) {
jjg@1210 106 MultiTaskListener mtl = MultiTaskListener.instance(context);
jjg@1210 107 mtl.remove(taskListener);
jjg@1210 108 }
jjg@1210 109
jjg@1210 110 public Collection<TaskListener> getTaskListeners() {
jjg@1210 111 MultiTaskListener mtl = MultiTaskListener.instance(context);
jjg@1210 112 return mtl.getTaskListeners();
jjg@1210 113 }
jjg@1210 114
jjg@1210 115 @Override
jjg@1210 116 public TypeMirror getTypeMirror(Iterable<? extends Tree> path) {
jjg@1210 117 // TODO: Should complete attribution if necessary
jjg@1210 118 Tree last = null;
jjg@1210 119 for (Tree node : path)
jjg@1210 120 last = node;
jjg@1210 121 return ((JCTree)last).type;
jjg@1210 122 }
jjg@1210 123
jjg@1210 124 @Override
jjg@1210 125 public Elements getElements() {
jjg@1210 126 return JavacElements.instance(context);
jjg@1210 127 }
jjg@1210 128
jjg@1210 129 @Override
jjg@1210 130 public Types getTypes() {
jjg@1210 131 return JavacTypes.instance(context);
jjg@1210 132 }
jjg@1210 133
jjg@1210 134 public void setProcessors(Iterable<? extends Processor> processors) {
jjg@1210 135 throw new IllegalStateException();
jjg@1210 136 }
jjg@1210 137
jjg@1210 138 public void setLocale(Locale locale) {
jjg@1210 139 throw new IllegalStateException();
jjg@1210 140 }
jjg@1210 141
jjg@1210 142 public Boolean call() {
jjg@1210 143 throw new IllegalStateException();
jjg@1210 144 }
jjg@1210 145
jjg@1334 146 /**
jjg@1334 147 * For internal use only. This method will be
jjg@1334 148 * removed without warning.
jjg@1334 149 */
jjg@1416 150 public Context getContext() {
jjg@1416 151 return context;
jjg@1416 152 }
jjg@1416 153
jjg@1416 154 /**
jjg@1416 155 * For internal use only. This method will be
jjg@1416 156 * removed without warning.
jjg@1416 157 */
jjg@1334 158 public void updateContext(Context newContext) {
jjg@1334 159 context = newContext;
jjg@1334 160 }
jjg@1210 161 }

mercurial