author | jjg |
Fri, 15 Jan 2016 15:40:24 -0800 | |
changeset 35346 | c0614a805fad |
permissions | -rw-r--r-- |
35346
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
1 |
/* |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
2 |
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
4 |
* |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
10 |
* |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
15 |
* accompanied this code). |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
16 |
* |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
20 |
* |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
23 |
* questions. |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
24 |
*/ |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
25 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
26 |
package com.sun.tools.javac.parser; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
27 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
28 |
import com.sun.tools.javac.parser.Tokens.TokenKind; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
29 |
import com.sun.tools.javac.tree.JCTree; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
30 |
import com.sun.tools.javac.util.List; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
31 |
import com.sun.tools.javac.util.ListBuffer; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
32 |
import com.sun.tools.javac.util.Log; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
33 |
import com.sun.tools.javac.util.Name; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
34 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
35 |
/** |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
36 |
* A utility class to parse a string in a doc comment containing a |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
37 |
* reference to an API element, such as a type, field or method. |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
38 |
* |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
39 |
* <p><b>This is NOT part of any supported API. |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
40 |
* If you write code that depends on this, you do so at your own risk. |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
41 |
* This code and its internal interfaces are subject to change or |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
42 |
* deletion without notice.</b> |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
43 |
*/ |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
44 |
public class ReferenceParser { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
45 |
/** |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
46 |
* An object to contain the result of parsing a reference to an API element. |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
47 |
* Any, but not all, of the member fields may be null. |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
48 |
*/ |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
49 |
static public class Reference { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
50 |
/** The type, if any, in the signature. */ |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
51 |
public final JCTree qualExpr; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
52 |
/** The member name, if any, in the signature. */ |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
53 |
public final Name member; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
54 |
/** The parameter types, if any, in the signature. */ |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
55 |
public final List<JCTree> paramTypes; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
56 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
57 |
Reference(JCTree qualExpr, Name member, List<JCTree> paramTypes) { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
58 |
this.qualExpr = qualExpr; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
59 |
this.member = member; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
60 |
this.paramTypes = paramTypes; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
61 |
} |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
62 |
} |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
63 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
64 |
/** |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
65 |
* An exception that indicates an error occurred while parsing a signature. |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
66 |
*/ |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
67 |
static public class ParseException extends Exception { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
68 |
private static final long serialVersionUID = 0; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
69 |
ParseException(String message) { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
70 |
super(message); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
71 |
} |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
72 |
} |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
73 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
74 |
private final ParserFactory fac; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
75 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
76 |
/** |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
77 |
* Create a parser object to parse reference signatures. |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
78 |
* @param fac a factory for parsing Java source code. |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
79 |
*/ |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
80 |
public ReferenceParser(ParserFactory fac) { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
81 |
this.fac = fac; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
82 |
} |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
83 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
84 |
/** |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
85 |
* Parse a reference to an API element as may be found in doc comment. |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
86 |
* @param sig the signature to be parsed |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
87 |
* @return a {@code Reference} object containing the result of parsing the signature |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
88 |
* @throws ParseException if there is an error while parsing the signature |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
89 |
*/ |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
90 |
public Reference parse(String sig) throws ParseException { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
91 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
92 |
// Break sig apart into qualifiedExpr member paramTypes. |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
93 |
JCTree qualExpr; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
94 |
Name member; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
95 |
List<JCTree> paramTypes; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
96 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
97 |
Log.DeferredDiagnosticHandler deferredDiagnosticHandler |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
98 |
= new Log.DeferredDiagnosticHandler(fac.log); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
99 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
100 |
try { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
101 |
int hash = sig.indexOf("#"); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
102 |
int lparen = sig.indexOf("(", hash + 1); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
103 |
if (hash == -1) { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
104 |
if (lparen == -1) { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
105 |
qualExpr = parseType(sig); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
106 |
member = null; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
107 |
} else { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
108 |
qualExpr = null; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
109 |
member = parseMember(sig.substring(0, lparen)); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
110 |
} |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
111 |
} else { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
112 |
qualExpr = (hash == 0) ? null : parseType(sig.substring(0, hash)); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
113 |
if (lparen == -1) |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
114 |
member = parseMember(sig.substring(hash + 1)); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
115 |
else |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
116 |
member = parseMember(sig.substring(hash + 1, lparen)); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
117 |
} |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
118 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
119 |
if (lparen < 0) { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
120 |
paramTypes = null; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
121 |
} else { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
122 |
int rparen = sig.indexOf(")", lparen); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
123 |
if (rparen != sig.length() - 1) |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
124 |
throw new ParseException("dc.ref.bad.parens"); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
125 |
paramTypes = parseParams(sig.substring(lparen + 1, rparen)); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
126 |
} |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
127 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
128 |
if (!deferredDiagnosticHandler.getDiagnostics().isEmpty()) |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
129 |
throw new ParseException("dc.ref.syntax.error"); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
130 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
131 |
} finally { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
132 |
fac.log.popDiagnosticHandler(deferredDiagnosticHandler); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
133 |
} |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
134 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
135 |
return new Reference(qualExpr, member, paramTypes); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
136 |
} |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
137 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
138 |
private JCTree parseType(String s) throws ParseException { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
139 |
JavacParser p = fac.newParser(s, false, false, false); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
140 |
JCTree tree = p.parseType(); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
141 |
if (p.token().kind != TokenKind.EOF) |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
142 |
throw new ParseException("dc.ref.unexpected.input"); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
143 |
return tree; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
144 |
} |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
145 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
146 |
private Name parseMember(String s) throws ParseException { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
147 |
JavacParser p = fac.newParser(s, false, false, false); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
148 |
Name name = p.ident(); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
149 |
if (p.token().kind != TokenKind.EOF) |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
150 |
throw new ParseException("dc.ref.unexpected.input"); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
151 |
return name; |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
152 |
} |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
153 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
154 |
private List<JCTree> parseParams(String s) throws ParseException { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
155 |
if (s.trim().isEmpty()) |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
156 |
return List.nil(); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
157 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
158 |
JavacParser p = fac.newParser(s.replace("...", "[]"), false, false, false); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
159 |
ListBuffer<JCTree> paramTypes = new ListBuffer<>(); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
160 |
paramTypes.add(p.parseType()); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
161 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
162 |
if (p.token().kind == TokenKind.IDENTIFIER) |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
163 |
p.nextToken(); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
164 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
165 |
while (p.token().kind == TokenKind.COMMA) { |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
166 |
p.nextToken(); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
167 |
paramTypes.add(p.parseType()); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
168 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
169 |
if (p.token().kind == TokenKind.IDENTIFIER) |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
170 |
p.nextToken(); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
171 |
} |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
172 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
173 |
if (p.token().kind != TokenKind.EOF) |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
174 |
throw new ParseException("dc.ref.unexpected.input"); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
175 |
|
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
176 |
return paramTypes.toList(); |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
177 |
} |
c0614a805fad
8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents:
diff
changeset
|
178 |
} |