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

Tue, 09 Oct 2012 19:10:00 -0700

author
jjg
date
Tue, 09 Oct 2012 19:10:00 -0700
changeset 1357
c75be5bc5283
parent 1334
8987971bcb45
child 1416
c0f0c41cafa0
permissions
-rw-r--r--

8000663: clean up langtools imports
Reviewed-by: darcy

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@1210 60 public BasicJavacTask(Context c, boolean register) {
jjg@1210 61 context = c;
jjg@1210 62 if (register)
jjg@1210 63 context.put(JavacTask.class, this);
jjg@1210 64 }
jjg@1210 65
jjg@1210 66 @Override
jjg@1210 67 public Iterable<? extends CompilationUnitTree> parse() throws IOException {
jjg@1210 68 throw new IllegalStateException();
jjg@1210 69 }
jjg@1210 70
jjg@1210 71 @Override
jjg@1210 72 public Iterable<? extends Element> analyze() throws IOException {
jjg@1210 73 throw new IllegalStateException();
jjg@1210 74 }
jjg@1210 75
jjg@1210 76 @Override
jjg@1210 77 public Iterable<? extends JavaFileObject> generate() throws IOException {
jjg@1210 78 throw new IllegalStateException();
jjg@1210 79 }
jjg@1210 80
jjg@1210 81 @Override
jjg@1210 82 public void setTaskListener(TaskListener tl) {
jjg@1210 83 MultiTaskListener mtl = MultiTaskListener.instance(context);
jjg@1210 84 if (taskListener != null)
jjg@1210 85 mtl.remove(taskListener);
jjg@1210 86 if (tl != null)
jjg@1210 87 mtl.add(tl);
jjg@1210 88 taskListener = tl;
jjg@1210 89 }
jjg@1210 90
jjg@1210 91 @Override
jjg@1210 92 public void addTaskListener(TaskListener taskListener) {
jjg@1210 93 MultiTaskListener mtl = MultiTaskListener.instance(context);
jjg@1210 94 mtl.add(taskListener);
jjg@1210 95 }
jjg@1210 96
jjg@1210 97 @Override
jjg@1210 98 public void removeTaskListener(TaskListener taskListener) {
jjg@1210 99 MultiTaskListener mtl = MultiTaskListener.instance(context);
jjg@1210 100 mtl.remove(taskListener);
jjg@1210 101 }
jjg@1210 102
jjg@1210 103 public Collection<TaskListener> getTaskListeners() {
jjg@1210 104 MultiTaskListener mtl = MultiTaskListener.instance(context);
jjg@1210 105 return mtl.getTaskListeners();
jjg@1210 106 }
jjg@1210 107
jjg@1210 108 @Override
jjg@1210 109 public TypeMirror getTypeMirror(Iterable<? extends Tree> path) {
jjg@1210 110 // TODO: Should complete attribution if necessary
jjg@1210 111 Tree last = null;
jjg@1210 112 for (Tree node : path)
jjg@1210 113 last = node;
jjg@1210 114 return ((JCTree)last).type;
jjg@1210 115 }
jjg@1210 116
jjg@1210 117 @Override
jjg@1210 118 public Elements getElements() {
jjg@1210 119 return JavacElements.instance(context);
jjg@1210 120 }
jjg@1210 121
jjg@1210 122 @Override
jjg@1210 123 public Types getTypes() {
jjg@1210 124 return JavacTypes.instance(context);
jjg@1210 125 }
jjg@1210 126
jjg@1210 127 public void setProcessors(Iterable<? extends Processor> processors) {
jjg@1210 128 throw new IllegalStateException();
jjg@1210 129 }
jjg@1210 130
jjg@1210 131 public void setLocale(Locale locale) {
jjg@1210 132 throw new IllegalStateException();
jjg@1210 133 }
jjg@1210 134
jjg@1210 135 public Boolean call() {
jjg@1210 136 throw new IllegalStateException();
jjg@1210 137 }
jjg@1210 138
jjg@1334 139 /**
jjg@1334 140 * For internal use only. This method will be
jjg@1334 141 * removed without warning.
jjg@1334 142 */
jjg@1334 143 public void updateContext(Context newContext) {
jjg@1334 144 context = newContext;
jjg@1334 145 }
jjg@1210 146 }

mercurial