duke@1: /* jjg@695: * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.javac.parser; duke@1: jjg@695: import java.nio.CharBuffer; duke@1: jjg@50: import com.sun.tools.javac.code.Source; jjg@695: import com.sun.tools.javac.util.Context; jjg@695: import com.sun.tools.javac.util.Log; jjg@695: import com.sun.tools.javac.util.Names; duke@1: duke@1: jjg@695: /** jjg@695: * A factory for creating scanners. duke@1: * jjg@581: *

This is NOT part of any supported API. jjg@695: * If you write code that depends on this, you do so at your own jjg@695: * risk. This code and its internal interfaces are subject to change jjg@695: * or deletion without notice. duke@1: */ jjg@695: public class ScannerFactory { jjg@695: /** The context key for the scanner factory. */ jjg@695: public static final Context.Key scannerFactoryKey = jjg@695: new Context.Key(); duke@1: jjg@695: /** Get the Factory instance for this context. */ jjg@695: public static ScannerFactory instance(Context context) { jjg@695: ScannerFactory instance = context.get(scannerFactoryKey); jjg@695: if (instance == null) jjg@695: instance = new ScannerFactory(context); jjg@695: return instance; jjg@695: } duke@1: jjg@695: final Log log; jjg@695: final Names names; jjg@695: final Source source; mcimadamore@1113: final Tokens tokens; duke@1: jjg@695: /** Create a new scanner factory. */ jjg@695: protected ScannerFactory(Context context) { jjg@695: context.put(scannerFactoryKey, this); jjg@695: this.log = Log.instance(context); jjg@695: this.names = Names.instance(context); jjg@695: this.source = Source.instance(context); mcimadamore@1113: this.tokens = Tokens.instance(context); jjg@695: } duke@1: jjg@695: public Scanner newScanner(CharSequence input, boolean keepDocComments) { jjg@695: if (input instanceof CharBuffer) { jjg@695: CharBuffer buf = (CharBuffer) input; jjg@695: if (keepDocComments) mcimadamore@1113: return new Scanner(this, new JavadocTokenizer(this, buf)); jjg@695: else jjg@695: return new Scanner(this, buf); jjg@695: } else { jjg@695: char[] array = input.toString().toCharArray(); jjg@695: return newScanner(array, array.length, keepDocComments); duke@1: } duke@1: } duke@1: jjg@695: public Scanner newScanner(char[] input, int inputLength, boolean keepDocComments) { jjg@695: if (keepDocComments) mcimadamore@1113: return new Scanner(this, new JavadocTokenizer(this, input, inputLength)); jjg@695: else jjg@695: return new Scanner(this, input, inputLength); duke@1: } duke@1: }