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

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.javac.api;
aoqi@0 27
aoqi@0 28 import java.io.File;
aoqi@0 29 import java.io.IOException;
aoqi@0 30 import java.nio.CharBuffer;
aoqi@0 31 import java.util.*;
aoqi@0 32 import java.util.concurrent.atomic.AtomicBoolean;
aoqi@0 33
aoqi@0 34 import javax.annotation.processing.Processor;
aoqi@0 35 import javax.lang.model.element.Element;
aoqi@0 36 import javax.lang.model.element.TypeElement;
aoqi@0 37 import javax.lang.model.type.TypeMirror;
aoqi@0 38 import javax.tools.*;
aoqi@0 39
aoqi@0 40 import com.sun.source.tree.*;
aoqi@0 41 import com.sun.source.util.*;
aoqi@0 42 import com.sun.tools.javac.code.*;
aoqi@0 43 import com.sun.tools.javac.code.Symbol.*;
aoqi@0 44 import com.sun.tools.javac.comp.*;
aoqi@0 45 import com.sun.tools.javac.file.JavacFileManager;
aoqi@0 46 import com.sun.tools.javac.main.*;
aoqi@0 47 import com.sun.tools.javac.main.JavaCompiler;
aoqi@0 48 import com.sun.tools.javac.model.*;
aoqi@0 49 import com.sun.tools.javac.parser.Parser;
aoqi@0 50 import com.sun.tools.javac.parser.ParserFactory;
aoqi@0 51 import com.sun.tools.javac.tree.*;
aoqi@0 52 import com.sun.tools.javac.tree.JCTree.*;
aoqi@0 53 import com.sun.tools.javac.util.*;
aoqi@0 54 import com.sun.tools.javac.util.List;
aoqi@0 55
aoqi@0 56 /**
aoqi@0 57 * Provides access to functionality specific to the JDK Java Compiler, javac.
aoqi@0 58 *
aoqi@0 59 * <p><b>This is NOT part of any supported API.
aoqi@0 60 * If you write code that depends on this, you do so at your own
aoqi@0 61 * risk. This code and its internal interfaces are subject to change
aoqi@0 62 * or deletion without notice.</b></p>
aoqi@0 63 *
aoqi@0 64 * @author Peter von der Ah&eacute;
aoqi@0 65 * @author Jonathan Gibbons
aoqi@0 66 */
aoqi@0 67 public class JavacTaskImpl extends BasicJavacTask {
aoqi@0 68 private Main compilerMain;
aoqi@0 69 private JavaCompiler compiler;
aoqi@0 70 private Locale locale;
aoqi@0 71 private String[] args;
aoqi@0 72 private String[] classNames;
aoqi@0 73 private List<JavaFileObject> fileObjects;
aoqi@0 74 private Map<JavaFileObject, JCCompilationUnit> notYetEntered;
aoqi@0 75 private ListBuffer<Env<AttrContext>> genList;
aoqi@0 76 private final AtomicBoolean used = new AtomicBoolean();
aoqi@0 77 private Iterable<? extends Processor> processors;
aoqi@0 78
aoqi@0 79 private Main.Result result = null;
aoqi@0 80
aoqi@0 81 JavacTaskImpl(Main compilerMain,
aoqi@0 82 String[] args,
aoqi@0 83 String[] classNames,
aoqi@0 84 Context context,
aoqi@0 85 List<JavaFileObject> fileObjects) {
aoqi@0 86 super(null, false);
aoqi@0 87 this.compilerMain = compilerMain;
aoqi@0 88 this.args = args;
aoqi@0 89 this.classNames = classNames;
aoqi@0 90 this.context = context;
aoqi@0 91 this.fileObjects = fileObjects;
aoqi@0 92 setLocale(Locale.getDefault());
aoqi@0 93 // null checks
aoqi@0 94 compilerMain.getClass();
aoqi@0 95 args.getClass();
aoqi@0 96 fileObjects.getClass();
aoqi@0 97 }
aoqi@0 98
aoqi@0 99 JavacTaskImpl(Main compilerMain,
aoqi@0 100 Iterable<String> args,
aoqi@0 101 Context context,
aoqi@0 102 Iterable<String> classes,
aoqi@0 103 Iterable<? extends JavaFileObject> fileObjects) {
aoqi@0 104 this(compilerMain, toArray(args), toArray(classes), context, toList(fileObjects));
aoqi@0 105 }
aoqi@0 106
aoqi@0 107 static private String[] toArray(Iterable<String> iter) {
aoqi@0 108 ListBuffer<String> result = new ListBuffer<String>();
aoqi@0 109 if (iter != null)
aoqi@0 110 for (String s : iter)
aoqi@0 111 result.append(s);
aoqi@0 112 return result.toArray(new String[result.length()]);
aoqi@0 113 }
aoqi@0 114
aoqi@0 115 static private List<JavaFileObject> toList(Iterable<? extends JavaFileObject> fileObjects) {
aoqi@0 116 if (fileObjects == null)
aoqi@0 117 return List.nil();
aoqi@0 118 ListBuffer<JavaFileObject> result = new ListBuffer<JavaFileObject>();
aoqi@0 119 for (JavaFileObject fo : fileObjects)
aoqi@0 120 result.append(fo);
aoqi@0 121 return result.toList();
aoqi@0 122 }
aoqi@0 123
aoqi@0 124 public Main.Result doCall() {
aoqi@0 125 if (!used.getAndSet(true)) {
aoqi@0 126 initContext();
aoqi@0 127 notYetEntered = new HashMap<JavaFileObject, JCCompilationUnit>();
aoqi@0 128 compilerMain.setAPIMode(true);
aoqi@0 129 result = compilerMain.compile(args, classNames, context, fileObjects, processors);
aoqi@0 130 cleanup();
aoqi@0 131 return result;
aoqi@0 132 } else {
aoqi@0 133 throw new IllegalStateException("multiple calls to method 'call'");
aoqi@0 134 }
aoqi@0 135 }
aoqi@0 136
aoqi@0 137 public Boolean call() {
aoqi@0 138 return doCall().isOK();
aoqi@0 139 }
aoqi@0 140
aoqi@0 141 public void setProcessors(Iterable<? extends Processor> processors) {
aoqi@0 142 processors.getClass(); // null check
aoqi@0 143 // not mt-safe
aoqi@0 144 if (used.get())
aoqi@0 145 throw new IllegalStateException();
aoqi@0 146 this.processors = processors;
aoqi@0 147 }
aoqi@0 148
aoqi@0 149 public void setLocale(Locale locale) {
aoqi@0 150 if (used.get())
aoqi@0 151 throw new IllegalStateException();
aoqi@0 152 this.locale = locale;
aoqi@0 153 }
aoqi@0 154
aoqi@0 155 private void prepareCompiler() throws IOException {
aoqi@0 156 if (used.getAndSet(true)) {
aoqi@0 157 if (compiler == null)
aoqi@0 158 throw new IllegalStateException();
aoqi@0 159 } else {
aoqi@0 160 initContext();
aoqi@0 161 compilerMain.log = Log.instance(context);
aoqi@0 162 compilerMain.setOptions(Options.instance(context));
aoqi@0 163 compilerMain.filenames = new LinkedHashSet<File>();
aoqi@0 164 Collection<File> filenames = compilerMain.processArgs(CommandLine.parse(args), classNames);
aoqi@0 165 if (filenames != null && !filenames.isEmpty())
aoqi@0 166 throw new IllegalArgumentException("Malformed arguments " + toString(filenames, " "));
aoqi@0 167 compiler = JavaCompiler.instance(context);
aoqi@0 168 compiler.keepComments = true;
aoqi@0 169 compiler.genEndPos = true;
aoqi@0 170 // NOTE: this value will be updated after annotation processing
aoqi@0 171 compiler.initProcessAnnotations(processors);
aoqi@0 172 notYetEntered = new HashMap<JavaFileObject, JCCompilationUnit>();
aoqi@0 173 for (JavaFileObject file: fileObjects)
aoqi@0 174 notYetEntered.put(file, null);
aoqi@0 175 genList = new ListBuffer<Env<AttrContext>>();
aoqi@0 176 // endContext will be called when all classes have been generated
aoqi@0 177 // TODO: should handle the case after each phase if errors have occurred
aoqi@0 178 args = null;
aoqi@0 179 classNames = null;
aoqi@0 180 }
aoqi@0 181 }
aoqi@0 182
aoqi@0 183 <T> String toString(Iterable<T> items, String sep) {
aoqi@0 184 String currSep = "";
aoqi@0 185 StringBuilder sb = new StringBuilder();
aoqi@0 186 for (T item: items) {
aoqi@0 187 sb.append(currSep);
aoqi@0 188 sb.append(item.toString());
aoqi@0 189 currSep = sep;
aoqi@0 190 }
aoqi@0 191 return sb.toString();
aoqi@0 192 }
aoqi@0 193
aoqi@0 194 private void initContext() {
aoqi@0 195 context.put(JavacTask.class, this);
aoqi@0 196 //initialize compiler's default locale
aoqi@0 197 context.put(Locale.class, locale);
aoqi@0 198 }
aoqi@0 199
aoqi@0 200 void cleanup() {
aoqi@0 201 if (compiler != null)
aoqi@0 202 compiler.close();
aoqi@0 203 compiler = null;
aoqi@0 204 compilerMain = null;
aoqi@0 205 args = null;
aoqi@0 206 classNames = null;
aoqi@0 207 context = null;
aoqi@0 208 fileObjects = null;
aoqi@0 209 notYetEntered = null;
aoqi@0 210 }
aoqi@0 211
aoqi@0 212 /**
aoqi@0 213 * Construct a JavaFileObject from the given file.
aoqi@0 214 *
aoqi@0 215 * <p><b>TODO: this method is useless here</b></p>
aoqi@0 216 *
aoqi@0 217 * @param file a file
aoqi@0 218 * @return a JavaFileObject from the standard file manager.
aoqi@0 219 */
aoqi@0 220 public JavaFileObject asJavaFileObject(File file) {
aoqi@0 221 JavacFileManager fm = (JavacFileManager)context.get(JavaFileManager.class);
aoqi@0 222 return fm.getRegularFile(file);
aoqi@0 223 }
aoqi@0 224
aoqi@0 225 /**
aoqi@0 226 * Parse the specified files returning a list of abstract syntax trees.
aoqi@0 227 *
aoqi@0 228 * @throws java.io.IOException TODO
aoqi@0 229 * @return a list of abstract syntax trees
aoqi@0 230 */
aoqi@0 231 public Iterable<? extends CompilationUnitTree> parse() throws IOException {
aoqi@0 232 try {
aoqi@0 233 prepareCompiler();
aoqi@0 234 List<JCCompilationUnit> units = compiler.parseFiles(fileObjects);
aoqi@0 235 for (JCCompilationUnit unit: units) {
aoqi@0 236 JavaFileObject file = unit.getSourceFile();
aoqi@0 237 if (notYetEntered.containsKey(file))
aoqi@0 238 notYetEntered.put(file, unit);
aoqi@0 239 }
aoqi@0 240 return units;
aoqi@0 241 }
aoqi@0 242 finally {
aoqi@0 243 parsed = true;
aoqi@0 244 if (compiler != null && compiler.log != null)
aoqi@0 245 compiler.log.flush();
aoqi@0 246 }
aoqi@0 247 }
aoqi@0 248
aoqi@0 249 private boolean parsed = false;
aoqi@0 250
aoqi@0 251 /**
aoqi@0 252 * Translate all the abstract syntax trees to elements.
aoqi@0 253 *
aoqi@0 254 * @throws IOException TODO
aoqi@0 255 * @return a list of elements corresponding to the top level
aoqi@0 256 * classes in the abstract syntax trees
aoqi@0 257 */
aoqi@0 258 public Iterable<? extends TypeElement> enter() throws IOException {
aoqi@0 259 return enter(null);
aoqi@0 260 }
aoqi@0 261
aoqi@0 262 /**
aoqi@0 263 * Translate the given abstract syntax trees to elements.
aoqi@0 264 *
aoqi@0 265 * @param trees a list of abstract syntax trees.
aoqi@0 266 * @throws java.io.IOException TODO
aoqi@0 267 * @return a list of elements corresponding to the top level
aoqi@0 268 * classes in the abstract syntax trees
aoqi@0 269 */
aoqi@0 270 public Iterable<? extends TypeElement> enter(Iterable<? extends CompilationUnitTree> trees)
aoqi@0 271 throws IOException
aoqi@0 272 {
aoqi@0 273 if (trees == null && notYetEntered != null && notYetEntered.isEmpty())
aoqi@0 274 return List.nil();
aoqi@0 275
aoqi@0 276 prepareCompiler();
aoqi@0 277
aoqi@0 278 ListBuffer<JCCompilationUnit> roots = null;
aoqi@0 279
aoqi@0 280 if (trees == null) {
aoqi@0 281 // If there are still files which were specified to be compiled
aoqi@0 282 // (i.e. in fileObjects) but which have not yet been entered,
aoqi@0 283 // then we make sure they have been parsed and add them to the
aoqi@0 284 // list to be entered.
aoqi@0 285 if (notYetEntered.size() > 0) {
aoqi@0 286 if (!parsed)
aoqi@0 287 parse(); // TODO would be nice to specify files needed to be parsed
aoqi@0 288 for (JavaFileObject file: fileObjects) {
aoqi@0 289 JCCompilationUnit unit = notYetEntered.remove(file);
aoqi@0 290 if (unit != null) {
aoqi@0 291 if (roots == null)
aoqi@0 292 roots = new ListBuffer<JCCompilationUnit>();
aoqi@0 293 roots.append(unit);
aoqi@0 294 }
aoqi@0 295 }
aoqi@0 296 notYetEntered.clear();
aoqi@0 297 }
aoqi@0 298 }
aoqi@0 299 else {
aoqi@0 300 for (CompilationUnitTree cu : trees) {
aoqi@0 301 if (cu instanceof JCCompilationUnit) {
aoqi@0 302 if (roots == null)
aoqi@0 303 roots = new ListBuffer<JCCompilationUnit>();
aoqi@0 304 roots.append((JCCompilationUnit)cu);
aoqi@0 305 notYetEntered.remove(cu.getSourceFile());
aoqi@0 306 }
aoqi@0 307 else
aoqi@0 308 throw new IllegalArgumentException(cu.toString());
aoqi@0 309 }
aoqi@0 310 }
aoqi@0 311
aoqi@0 312 if (roots == null)
aoqi@0 313 return List.nil();
aoqi@0 314
aoqi@0 315 try {
aoqi@0 316 List<JCCompilationUnit> units = compiler.enterTrees(roots.toList());
aoqi@0 317
aoqi@0 318 if (notYetEntered.isEmpty())
aoqi@0 319 compiler = compiler.processAnnotations(units);
aoqi@0 320
aoqi@0 321 ListBuffer<TypeElement> elements = new ListBuffer<TypeElement>();
aoqi@0 322 for (JCCompilationUnit unit : units) {
aoqi@0 323 for (JCTree node : unit.defs) {
aoqi@0 324 if (node.hasTag(JCTree.Tag.CLASSDEF)) {
aoqi@0 325 JCClassDecl cdef = (JCClassDecl) node;
aoqi@0 326 if (cdef.sym != null) // maybe null if errors in anno processing
aoqi@0 327 elements.append(cdef.sym);
aoqi@0 328 }
aoqi@0 329 }
aoqi@0 330 }
aoqi@0 331 return elements.toList();
aoqi@0 332 }
aoqi@0 333 finally {
aoqi@0 334 compiler.log.flush();
aoqi@0 335 }
aoqi@0 336 }
aoqi@0 337
aoqi@0 338 /**
aoqi@0 339 * Complete all analysis.
aoqi@0 340 * @throws IOException TODO
aoqi@0 341 */
aoqi@0 342 @Override
aoqi@0 343 public Iterable<? extends Element> analyze() throws IOException {
aoqi@0 344 return analyze(null);
aoqi@0 345 }
aoqi@0 346
aoqi@0 347 /**
aoqi@0 348 * Complete all analysis on the given classes.
aoqi@0 349 * This can be used to ensure that all compile time errors are reported.
aoqi@0 350 * The classes must have previously been returned from {@link #enter}.
aoqi@0 351 * If null is specified, all outstanding classes will be analyzed.
aoqi@0 352 *
aoqi@0 353 * @param classes a list of class elements
aoqi@0 354 */
aoqi@0 355 // This implementation requires that we open up privileges on JavaCompiler.
aoqi@0 356 // An alternative implementation would be to move this code to JavaCompiler and
aoqi@0 357 // wrap it here
aoqi@0 358 public Iterable<? extends Element> analyze(Iterable<? extends TypeElement> classes) throws IOException {
aoqi@0 359 enter(null); // ensure all classes have been entered
aoqi@0 360
aoqi@0 361 final ListBuffer<Element> results = new ListBuffer<Element>();
aoqi@0 362 try {
aoqi@0 363 if (classes == null) {
aoqi@0 364 handleFlowResults(compiler.flow(compiler.attribute(compiler.todo)), results);
aoqi@0 365 } else {
aoqi@0 366 Filter f = new Filter() {
aoqi@0 367 public void process(Env<AttrContext> env) {
aoqi@0 368 handleFlowResults(compiler.flow(compiler.attribute(env)), results);
aoqi@0 369 }
aoqi@0 370 };
aoqi@0 371 f.run(compiler.todo, classes);
aoqi@0 372 }
aoqi@0 373 } finally {
aoqi@0 374 compiler.log.flush();
aoqi@0 375 }
aoqi@0 376 return results;
aoqi@0 377 }
aoqi@0 378 // where
aoqi@0 379 private void handleFlowResults(Queue<Env<AttrContext>> queue, ListBuffer<Element> elems) {
aoqi@0 380 for (Env<AttrContext> env: queue) {
aoqi@0 381 switch (env.tree.getTag()) {
aoqi@0 382 case CLASSDEF:
aoqi@0 383 JCClassDecl cdef = (JCClassDecl) env.tree;
aoqi@0 384 if (cdef.sym != null)
aoqi@0 385 elems.append(cdef.sym);
aoqi@0 386 break;
aoqi@0 387 case TOPLEVEL:
aoqi@0 388 JCCompilationUnit unit = (JCCompilationUnit) env.tree;
aoqi@0 389 if (unit.packge != null)
aoqi@0 390 elems.append(unit.packge);
aoqi@0 391 break;
aoqi@0 392 }
aoqi@0 393 }
aoqi@0 394 genList.addAll(queue);
aoqi@0 395 }
aoqi@0 396
aoqi@0 397
aoqi@0 398 /**
aoqi@0 399 * Generate code.
aoqi@0 400 * @throws IOException TODO
aoqi@0 401 */
aoqi@0 402 @Override
aoqi@0 403 public Iterable<? extends JavaFileObject> generate() throws IOException {
aoqi@0 404 return generate(null);
aoqi@0 405 }
aoqi@0 406
aoqi@0 407 /**
aoqi@0 408 * Generate code corresponding to the given classes.
aoqi@0 409 * The classes must have previously been returned from {@link #enter}.
aoqi@0 410 * If there are classes outstanding to be analyzed, that will be done before
aoqi@0 411 * any classes are generated.
aoqi@0 412 * If null is specified, code will be generated for all outstanding classes.
aoqi@0 413 *
aoqi@0 414 * @param classes a list of class elements
aoqi@0 415 */
aoqi@0 416 public Iterable<? extends JavaFileObject> generate(Iterable<? extends TypeElement> classes) throws IOException {
aoqi@0 417 final ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>();
aoqi@0 418 try {
aoqi@0 419 analyze(null); // ensure all classes have been parsed, entered, and analyzed
aoqi@0 420
aoqi@0 421 if (classes == null) {
aoqi@0 422 compiler.generate(compiler.desugar(genList), results);
aoqi@0 423 genList.clear();
aoqi@0 424 }
aoqi@0 425 else {
aoqi@0 426 Filter f = new Filter() {
aoqi@0 427 public void process(Env<AttrContext> env) {
aoqi@0 428 compiler.generate(compiler.desugar(ListBuffer.of(env)), results);
aoqi@0 429 }
aoqi@0 430 };
aoqi@0 431 f.run(genList, classes);
aoqi@0 432 }
aoqi@0 433 if (genList.isEmpty()) {
aoqi@0 434 compiler.reportDeferredDiagnostics();
aoqi@0 435 cleanup();
aoqi@0 436 }
aoqi@0 437 }
aoqi@0 438 finally {
aoqi@0 439 if (compiler != null)
aoqi@0 440 compiler.log.flush();
aoqi@0 441 }
aoqi@0 442 return results;
aoqi@0 443 }
aoqi@0 444
aoqi@0 445 public TypeMirror getTypeMirror(Iterable<? extends Tree> path) {
aoqi@0 446 // TODO: Should complete attribution if necessary
aoqi@0 447 Tree last = null;
aoqi@0 448 for (Tree node : path)
aoqi@0 449 last = node;
aoqi@0 450 return ((JCTree)last).type;
aoqi@0 451 }
aoqi@0 452
aoqi@0 453 public JavacElements getElements() {
aoqi@0 454 if (context == null)
aoqi@0 455 throw new IllegalStateException();
aoqi@0 456 return JavacElements.instance(context);
aoqi@0 457 }
aoqi@0 458
aoqi@0 459 public JavacTypes getTypes() {
aoqi@0 460 if (context == null)
aoqi@0 461 throw new IllegalStateException();
aoqi@0 462 return JavacTypes.instance(context);
aoqi@0 463 }
aoqi@0 464
aoqi@0 465 public Iterable<? extends Tree> pathFor(CompilationUnitTree unit, Tree node) {
aoqi@0 466 return TreeInfo.pathFor((JCTree) node, (JCTree.JCCompilationUnit) unit).reverse();
aoqi@0 467 }
aoqi@0 468
aoqi@0 469 abstract class Filter {
aoqi@0 470 void run(Queue<Env<AttrContext>> list, Iterable<? extends TypeElement> classes) {
aoqi@0 471 Set<TypeElement> set = new HashSet<TypeElement>();
aoqi@0 472 for (TypeElement item: classes)
aoqi@0 473 set.add(item);
aoqi@0 474
aoqi@0 475 ListBuffer<Env<AttrContext>> defer = new ListBuffer<>();
aoqi@0 476 while (list.peek() != null) {
aoqi@0 477 Env<AttrContext> env = list.remove();
aoqi@0 478 ClassSymbol csym = env.enclClass.sym;
aoqi@0 479 if (csym != null && set.contains(csym.outermostClass()))
aoqi@0 480 process(env);
aoqi@0 481 else
aoqi@0 482 defer = defer.append(env);
aoqi@0 483 }
aoqi@0 484
aoqi@0 485 list.addAll(defer);
aoqi@0 486 }
aoqi@0 487
aoqi@0 488 abstract void process(Env<AttrContext> env);
aoqi@0 489 }
aoqi@0 490
aoqi@0 491 /**
aoqi@0 492 * For internal use only. This method will be
aoqi@0 493 * removed without warning.
aoqi@0 494 */
aoqi@0 495 public Type parseType(String expr, TypeElement scope) {
aoqi@0 496 if (expr == null || expr.equals(""))
aoqi@0 497 throw new IllegalArgumentException();
aoqi@0 498 compiler = JavaCompiler.instance(context);
aoqi@0 499 JavaFileObject prev = compiler.log.useSource(null);
aoqi@0 500 ParserFactory parserFactory = ParserFactory.instance(context);
aoqi@0 501 Attr attr = Attr.instance(context);
aoqi@0 502 try {
aoqi@0 503 CharBuffer buf = CharBuffer.wrap((expr+"\u0000").toCharArray(), 0, expr.length());
aoqi@0 504 Parser parser = parserFactory.newParser(buf, false, false, false);
aoqi@0 505 JCTree tree = parser.parseType();
aoqi@0 506 return attr.attribType(tree, (Symbol.TypeSymbol)scope);
aoqi@0 507 } finally {
aoqi@0 508 compiler.log.useSource(prev);
aoqi@0 509 }
aoqi@0 510 }
aoqi@0 511
aoqi@0 512 }

mercurial