author | briangoetz |
Wed, 18 Dec 2013 16:05:18 -0500 | |
changeset 22163 | 3651128c74eb |
parent 10815 | a719aa5f1631 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
2 |
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.parser; |
|
27 |
||
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
28 |
import java.nio.CharBuffer; |
10 | 29 |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
10
diff
changeset
|
30 |
import com.sun.tools.javac.code.Source; |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
31 |
import com.sun.tools.javac.util.Context; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
32 |
import com.sun.tools.javac.util.Log; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
33 |
import com.sun.tools.javac.util.Names; |
10 | 34 |
|
35 |
||
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
36 |
/** |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
37 |
* A factory for creating scanners. |
10 | 38 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
39 |
* <p><b>This is NOT part of any supported API. |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
40 |
* If you write code that depends on this, you do so at your own |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
41 |
* risk. This code and its internal interfaces are subject to change |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
42 |
* or deletion without notice.</b> |
10 | 43 |
*/ |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
44 |
public class ScannerFactory { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
45 |
/** The context key for the scanner factory. */ |
22163 | 46 |
public static final Context.Key<ScannerFactory> scannerFactoryKey = new Context.Key<>(); |
10 | 47 |
|
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
48 |
/** Get the Factory instance for this context. */ |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
49 |
public static ScannerFactory instance(Context context) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
50 |
ScannerFactory instance = context.get(scannerFactoryKey); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
51 |
if (instance == null) |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
52 |
instance = new ScannerFactory(context); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
53 |
return instance; |
10 | 54 |
} |
55 |
||
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
56 |
final Log log; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
57 |
final Names names; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
58 |
final Source source; |
10815 | 59 |
final Tokens tokens; |
10 | 60 |
|
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
61 |
/** Create a new scanner factory. */ |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
62 |
protected ScannerFactory(Context context) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
63 |
context.put(scannerFactoryKey, this); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
64 |
this.log = Log.instance(context); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
65 |
this.names = Names.instance(context); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
66 |
this.source = Source.instance(context); |
10815 | 67 |
this.tokens = Tokens.instance(context); |
3895 | 68 |
} |
69 |
||
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
70 |
public Scanner newScanner(CharSequence input, boolean keepDocComments) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
71 |
if (input instanceof CharBuffer) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
72 |
CharBuffer buf = (CharBuffer) input; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
73 |
if (keepDocComments) |
10815 | 74 |
return new Scanner(this, new JavadocTokenizer(this, buf)); |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
75 |
else |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
76 |
return new Scanner(this, buf); |
10 | 77 |
} else { |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
78 |
char[] array = input.toString().toCharArray(); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
79 |
return newScanner(array, array.length, keepDocComments); |
10 | 80 |
} |
81 |
} |
|
82 |
||
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
83 |
public Scanner newScanner(char[] input, int inputLength, boolean keepDocComments) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
84 |
if (keepDocComments) |
10815 | 85 |
return new Scanner(this, new JavadocTokenizer(this, input, inputLength)); |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
86 |
else |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6592
diff
changeset
|
87 |
return new Scanner(this, input, inputLength); |
10 | 88 |
} |
89 |
} |