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

Mon, 14 Nov 2011 15:11:10 -0800

author
ksrini
date
Mon, 14 Nov 2011 15:11:10 -0800
changeset 1138
7375d4979bd3
parent 1113
d346ab55031b
child 1409
33abf479f202
permissions
-rw-r--r--

7106166: (javac) re-factor EndPos parser
Reviewed-by: jjg

jjg@111 1 /*
ksrini@1138 2 * Copyright (c) 1999, 2011, 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;
mcimadamore@1113 58 final Tokens tokens;
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);
mcimadamore@1113 70 this.tokens = Tokens.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);
ksrini@1138 78 return new JavacParser(this, lexer, keepDocComments, keepLineMap, keepEndPos);
jjg@111 79 }
jjg@111 80 }

mercurial