src/share/classes/com/sun/tools/javac/parser/ParserFactory.java

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

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

Merge

jjg@111 1 /*
jjg@1409 2 * Copyright (c) 1999, 2012, 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@1409 28 import java.util.Locale;
jjg@1409 29
jjg@111 30 import com.sun.tools.javac.code.Source;
jjg@1409 31 import com.sun.tools.javac.tree.DocTreeMaker;
jjg@111 32 import com.sun.tools.javac.tree.TreeMaker;
jjg@111 33 import com.sun.tools.javac.util.Context;
jjg@111 34 import com.sun.tools.javac.util.Log;
jjg@113 35 import com.sun.tools.javac.util.Names;
jjg@111 36 import com.sun.tools.javac.util.Options;
jjg@111 37
jjg@111 38 /**
jjg@111 39 * A factory for creating parsers.
jjg@333 40 *
jjg@581 41 * <p><b>This is NOT part of any supported API.
jjg@333 42 * If you write code that depends on this, you do so at your own risk.
jjg@333 43 * This code and its internal interfaces are subject to change or
jjg@333 44 * deletion without notice.</b>
jjg@111 45 */
jjg@111 46 public class ParserFactory {
jjg@111 47
jjg@111 48 /** The context key for the parser factory. */
jjg@111 49 protected static final Context.Key<ParserFactory> parserFactoryKey = new Context.Key<ParserFactory>();
jjg@111 50
jjg@111 51 public static ParserFactory instance(Context context) {
jjg@111 52 ParserFactory instance = context.get(parserFactoryKey);
jjg@111 53 if (instance == null) {
jjg@111 54 instance = new ParserFactory(context);
jjg@111 55 }
jjg@111 56 return instance;
jjg@111 57 }
jjg@111 58
jjg@111 59 final TreeMaker F;
jjg@1409 60 final DocTreeMaker docTreeMaker;
jjg@111 61 final Log log;
mcimadamore@1113 62 final Tokens tokens;
jjg@111 63 final Source source;
jjg@113 64 final Names names;
jjg@111 65 final Options options;
jjg@695 66 final ScannerFactory scannerFactory;
jjg@1409 67 final Locale locale;
jjg@111 68
jjg@111 69 protected ParserFactory(Context context) {
jjg@111 70 super();
jjg@111 71 context.put(parserFactoryKey, this);
jjg@111 72 this.F = TreeMaker.instance(context);
jjg@1409 73 this.docTreeMaker = DocTreeMaker.instance(context);
jjg@111 74 this.log = Log.instance(context);
jjg@113 75 this.names = Names.instance(context);
mcimadamore@1113 76 this.tokens = Tokens.instance(context);
jjg@111 77 this.source = Source.instance(context);
jjg@111 78 this.options = Options.instance(context);
jjg@695 79 this.scannerFactory = ScannerFactory.instance(context);
jjg@1409 80 this.locale = context.get(Locale.class);
jjg@111 81 }
jjg@111 82
jjg@1409 83 public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap) {
jjg@695 84 Lexer lexer = scannerFactory.newScanner(input, keepDocComments);
ksrini@1138 85 return new JavacParser(this, lexer, keepDocComments, keepLineMap, keepEndPos);
jjg@111 86 }
jjg@111 87 }

mercurial