Wed, 21 Sep 2011 21:56:53 -0700
7092965: javac should not close processorClassLoader before end of compilation
Reviewed-by: darcy
jjg@111 | 1 | /* |
jjg@695 | 2 | * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
jjg@111 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@111 | 4 | * |
jjg@111 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@111 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
jjg@111 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
jjg@111 | 10 | * |
jjg@111 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@111 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@111 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@111 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@111 | 15 | * accompanied this code). |
jjg@111 | 16 | * |
jjg@111 | 17 | * You should have received a copy of the GNU General Public License version |
jjg@111 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@111 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@111 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
jjg@111 | 24 | */ |
jjg@111 | 25 | |
jjg@111 | 26 | package com.sun.tools.javac.parser; |
jjg@111 | 27 | |
jjg@111 | 28 | import com.sun.tools.javac.code.Source; |
jjg@111 | 29 | import com.sun.tools.javac.tree.TreeMaker; |
jjg@111 | 30 | import com.sun.tools.javac.util.Context; |
jjg@111 | 31 | import com.sun.tools.javac.util.Log; |
jjg@113 | 32 | import com.sun.tools.javac.util.Names; |
jjg@111 | 33 | import com.sun.tools.javac.util.Options; |
jjg@111 | 34 | |
jjg@111 | 35 | /** |
jjg@111 | 36 | * A factory for creating parsers. |
jjg@333 | 37 | * |
jjg@581 | 38 | * <p><b>This is NOT part of any supported API. |
jjg@333 | 39 | * If you write code that depends on this, you do so at your own risk. |
jjg@333 | 40 | * This code and its internal interfaces are subject to change or |
jjg@333 | 41 | * deletion without notice.</b> |
jjg@111 | 42 | */ |
jjg@111 | 43 | public class ParserFactory { |
jjg@111 | 44 | |
jjg@111 | 45 | /** The context key for the parser factory. */ |
jjg@111 | 46 | protected static final Context.Key<ParserFactory> parserFactoryKey = new Context.Key<ParserFactory>(); |
jjg@111 | 47 | |
jjg@111 | 48 | public static ParserFactory instance(Context context) { |
jjg@111 | 49 | ParserFactory instance = context.get(parserFactoryKey); |
jjg@111 | 50 | if (instance == null) { |
jjg@111 | 51 | instance = new ParserFactory(context); |
jjg@111 | 52 | } |
jjg@111 | 53 | return instance; |
jjg@111 | 54 | } |
jjg@111 | 55 | |
jjg@111 | 56 | final TreeMaker F; |
jjg@111 | 57 | final Log log; |
jjg@111 | 58 | final Keywords keywords; |
jjg@111 | 59 | final Source source; |
jjg@113 | 60 | final Names names; |
jjg@111 | 61 | final Options options; |
jjg@695 | 62 | final ScannerFactory scannerFactory; |
jjg@111 | 63 | |
jjg@111 | 64 | protected ParserFactory(Context context) { |
jjg@111 | 65 | super(); |
jjg@111 | 66 | context.put(parserFactoryKey, this); |
jjg@111 | 67 | this.F = TreeMaker.instance(context); |
jjg@111 | 68 | this.log = Log.instance(context); |
jjg@113 | 69 | this.names = Names.instance(context); |
jjg@111 | 70 | this.keywords = Keywords.instance(context); |
jjg@111 | 71 | this.source = Source.instance(context); |
jjg@111 | 72 | this.options = Options.instance(context); |
jjg@695 | 73 | this.scannerFactory = ScannerFactory.instance(context); |
jjg@111 | 74 | } |
jjg@111 | 75 | |
jjg@111 | 76 | public Parser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap) { |
jjg@695 | 77 | Lexer lexer = scannerFactory.newScanner(input, keepDocComments); |
jjg@111 | 78 | if (keepEndPos) { |
jjg@111 | 79 | return new EndPosParser(this, lexer, keepDocComments, keepLineMap); |
jjg@111 | 80 | } else { |
jjg@111 | 81 | return new JavacParser(this, lexer, keepDocComments, keepLineMap); |
jjg@111 | 82 | } |
jjg@111 | 83 | } |
jjg@111 | 84 | } |