Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
95b4f357
D
dragonwell8_langtools
项目概览
openanolis
/
dragonwell8_langtools
通知
0
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_langtools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
95b4f357
编写于
9月 09, 2008
作者:
J
jjg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6724118: change JavaCompiler to not use Scanner directly
6736119: refactor Parser and Parser.Factory Reviewed-by: mcimadamore
上级
f94871f0
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
2945 addition
and
2844 deletion
+2945
-2844
src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java
src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java
+9
-9
src/share/classes/com/sun/tools/javac/main/JavaCompiler.java
src/share/classes/com/sun/tools/javac/main/JavaCompiler.java
+4
-12
src/share/classes/com/sun/tools/javac/parser/EndPosParser.java
...hare/classes/com/sun/tools/javac/parser/EndPosParser.java
+5
-5
src/share/classes/com/sun/tools/javac/parser/JavacParser.java
...share/classes/com/sun/tools/javac/parser/JavacParser.java
+2819
-0
src/share/classes/com/sun/tools/javac/parser/Parser.java
src/share/classes/com/sun/tools/javac/parser/Parser.java
+24
-2814
src/share/classes/com/sun/tools/javac/parser/ParserFactory.java
...are/classes/com/sun/tools/javac/parser/ParserFactory.java
+79
-0
test/tools/javac/6304921/TestLog.java
test/tools/javac/6304921/TestLog.java
+5
-4
未找到文件。
src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java
浏览文件 @
95b4f357
...
...
@@ -27,6 +27,7 @@ package com.sun.tools.javac.api;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.CharBuffer
;
import
java.util.*
;
import
java.util.concurrent.atomic.AtomicBoolean
;
...
...
@@ -45,7 +46,7 @@ import com.sun.tools.javac.file.JavacFileManager;
import
com.sun.tools.javac.main.*
;
import
com.sun.tools.javac.model.*
;
import
com.sun.tools.javac.parser.Parser
;
import
com.sun.tools.javac.parser.
Scanner
;
import
com.sun.tools.javac.parser.
ParserFactory
;
import
com.sun.tools.javac.tree.*
;
import
com.sun.tools.javac.tree.JCTree.*
;
import
com.sun.tools.javac.util.*
;
...
...
@@ -93,6 +94,9 @@ public class JavacTaskImpl extends JavacTask {
args
.
getClass
();
context
.
getClass
();
fileObjects
.
getClass
();
// force the use of the scanner that captures Javadoc comments
com
.
sun
.
tools
.
javac
.
parser
.
DocCommentScanner
.
Factory
.
preRegister
(
context
);
}
JavacTaskImpl
(
JavacTool
tool
,
...
...
@@ -166,8 +170,6 @@ public class JavacTaskImpl extends JavacTask {
if
(!
filenames
.
isEmpty
())
throw
new
IllegalArgumentException
(
"Malformed arguments "
+
filenames
.
toString
(
" "
));
compiler
=
JavaCompiler
.
instance
(
context
);
// force the use of the scanner that captures Javadoc comments
com
.
sun
.
tools
.
javac
.
parser
.
DocCommentScanner
.
Factory
.
preRegister
(
context
);
compiler
.
keepComments
=
true
;
compiler
.
genEndPos
=
true
;
// NOTE: this value will be updated after annotation processing
...
...
@@ -519,14 +521,12 @@ public class JavacTaskImpl extends JavacTask {
throw
new
IllegalArgumentException
();
compiler
=
JavaCompiler
.
instance
(
context
);
JavaFileObject
prev
=
compiler
.
log
.
useSource
(
null
);
Scanner
.
Factory
scannerFactory
=
Scanner
.
Factory
.
instance
(
context
);
Parser
.
Factory
parserFactory
=
Parser
.
Factory
.
instance
(
context
);
ParserFactory
parserFactory
=
ParserFactory
.
instance
(
context
);
Attr
attr
=
Attr
.
instance
(
context
);
try
{
Scanner
scanner
=
scannerFactory
.
newScanner
((
expr
+
"\u0000"
).
toCharArray
(),
expr
.
length
());
Parser
parser
=
parserFactory
.
newParser
(
scanner
,
false
,
false
);
JCTree
tree
=
parser
.
type
();
CharBuffer
buf
=
CharBuffer
.
wrap
((
expr
+
"\u0000"
).
toCharArray
(),
0
,
expr
.
length
());
Parser
parser
=
parserFactory
.
newParser
(
buf
,
false
,
false
,
false
);
JCTree
tree
=
parser
.
parseType
();
return
attr
.
attribType
(
tree
,
(
Symbol
.
TypeSymbol
)
scope
);
}
finally
{
compiler
.
log
.
useSource
(
prev
);
...
...
src/share/classes/com/sun/tools/javac/main/JavaCompiler.java
浏览文件 @
95b4f357
...
...
@@ -276,7 +276,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
/** Factory for parsers.
*/
protected
Parser
.
Factory
parserFactory
;
protected
ParserFactory
parserFactory
;
/** Optional listener for progress events
*/
...
...
@@ -320,7 +320,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
todo
=
Todo
.
instance
(
context
);
fileManager
=
context
.
get
(
JavaFileManager
.
class
);
parserFactory
=
Parser
.
Factory
.
instance
(
context
);
parserFactory
=
ParserFactory
.
instance
(
context
);
try
{
// catch completion problems with predefineds
...
...
@@ -510,10 +510,6 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
return
parseErrors
;
}
protected
Scanner
.
Factory
getScannerFactory
()
{
return
Scanner
.
Factory
.
instance
(
context
);
}
/** Try to open input stream with given name.
* Report an error if this fails.
* @param filename The file name of the input stream to be opened.
...
...
@@ -545,13 +541,9 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
taskListener
.
started
(
e
);
}
int
initialErrorCount
=
log
.
nerrors
;
Scanner
scanner
=
getScannerFactory
().
newScanner
(
content
);
Parser
parser
=
parserFactory
.
newParser
(
scanner
,
keepComments
(),
genEndPos
);
tree
=
parser
.
compilationUnit
();
Parser
parser
=
parserFactory
.
newParser
(
content
,
keepComments
(),
genEndPos
,
lineDebugInfo
);
tree
=
parser
.
parseCompilationUnit
();
parseErrors
|=
(
log
.
nerrors
>
initialErrorCount
);
if
(
lineDebugInfo
)
{
tree
.
lineMap
=
scanner
.
getLineMap
();
}
if
(
verbose
)
{
printVerbose
(
"parsing.done"
,
Long
.
toString
(
elapsed
(
msec
)));
}
...
...
src/share/classes/com/sun/tools/javac/parser/EndPosParser.java
浏览文件 @
95b4f357
...
...
@@ -41,10 +41,10 @@ import static com.sun.tools.javac.tree.JCTree.*;
* This code and its internal interfaces are subject to change or
* deletion without notice.</b></p>
*/
public
class
EndPosParser
extends
Parser
{
public
class
EndPosParser
extends
Javac
Parser
{
public
EndPosParser
(
Factory
fac
,
Lexer
S
,
boolean
keepDocComments
)
{
super
(
fac
,
S
,
keepDocComments
);
public
EndPosParser
(
ParserFactory
fac
,
Lexer
S
,
boolean
keepDocComments
,
boolean
keepLineMap
)
{
super
(
fac
,
S
,
keepDocComments
,
keepLineMap
);
this
.
S
=
S
;
endPositions
=
new
HashMap
<
JCTree
,
Integer
>();
}
...
...
@@ -79,8 +79,8 @@ public class EndPosParser extends Parser {
}
@Override
public
JCCompilationUnit
c
ompilationUnit
()
{
JCCompilationUnit
t
=
super
.
c
ompilationUnit
();
public
JCCompilationUnit
parseC
ompilationUnit
()
{
JCCompilationUnit
t
=
super
.
parseC
ompilationUnit
();
t
.
endPositions
=
endPositions
;
return
t
;
}
...
...
src/share/classes/com/sun/tools/javac/parser/JavacParser.java
0 → 100644
浏览文件 @
95b4f357
此差异已折叠。
点击以展开。
src/share/classes/com/sun/tools/javac/parser/Parser.java
浏览文件 @
95b4f357
此差异已折叠。
点击以展开。
src/share/classes/com/sun/tools/javac/parser/ParserFactory.java
0 → 100644
浏览文件 @
95b4f357
/*
* Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package
com.sun.tools.javac.parser
;
import
com.sun.tools.javac.code.Source
;
import
com.sun.tools.javac.tree.TreeMaker
;
import
com.sun.tools.javac.util.Context
;
import
com.sun.tools.javac.util.Log
;
import
com.sun.tools.javac.util.Name
;
import
com.sun.tools.javac.util.Options
;
/**
* A factory for creating parsers.
*/
public
class
ParserFactory
{
/** The context key for the parser factory. */
protected
static
final
Context
.
Key
<
ParserFactory
>
parserFactoryKey
=
new
Context
.
Key
<
ParserFactory
>();
public
static
ParserFactory
instance
(
Context
context
)
{
ParserFactory
instance
=
context
.
get
(
parserFactoryKey
);
if
(
instance
==
null
)
{
instance
=
new
ParserFactory
(
context
);
}
return
instance
;
}
final
TreeMaker
F
;
final
Log
log
;
final
Keywords
keywords
;
final
Source
source
;
final
Name
.
Table
names
;
final
Options
options
;
final
Scanner
.
Factory
scannerFactory
;
protected
ParserFactory
(
Context
context
)
{
super
();
context
.
put
(
parserFactoryKey
,
this
);
this
.
F
=
TreeMaker
.
instance
(
context
);
this
.
log
=
Log
.
instance
(
context
);
this
.
names
=
Name
.
Table
.
instance
(
context
);
this
.
keywords
=
Keywords
.
instance
(
context
);
this
.
source
=
Source
.
instance
(
context
);
this
.
options
=
Options
.
instance
(
context
);
this
.
scannerFactory
=
Scanner
.
Factory
.
instance
(
context
);
}
public
Parser
newParser
(
CharSequence
input
,
boolean
keepDocComments
,
boolean
keepEndPos
,
boolean
keepLineMap
)
{
Lexer
lexer
=
scannerFactory
.
newScanner
(
input
);
if
(
keepEndPos
)
{
return
new
EndPosParser
(
this
,
lexer
,
keepDocComments
,
keepLineMap
);
}
else
{
return
new
JavacParser
(
this
,
lexer
,
keepDocComments
,
keepLineMap
);
}
}
}
test/tools/javac/6304921/TestLog.java
浏览文件 @
95b4f357
...
...
@@ -34,6 +34,7 @@ import javax.tools.JavaFileObject;
import
javax.tools.SimpleJavaFileObject
;
import
com.sun.tools.javac.file.JavacFileManager
;
import
com.sun.tools.javac.parser.Parser
;
import
com.sun.tools.javac.parser.ParserFactory
;
import
com.sun.tools.javac.parser.Scanner
;
import
com.sun.tools.javac.tree.JCTree
;
import
com.sun.tools.javac.tree.TreeScanner
;
...
...
@@ -60,7 +61,7 @@ public class TestLog
JavacFileManager
.
preRegister
(
context
);
Scanner
.
Factory
sfac
=
Scanner
.
Factory
.
instance
(
context
);
Parser
.
Factory
pfac
=
Parser
.
Factory
.
instance
(
context
);
Parser
Factory
pfac
=
Parser
Factory
.
instance
(
context
);
final
String
text
=
"public class Foo {\n"
...
...
@@ -74,9 +75,9 @@ public class TestLog
JavaFileObject
fo
=
new
StringJavaFileObject
(
"Foo"
,
text
);
log
.
useSource
(
fo
);
Scanner
s
=
sfac
.
newScanner
(
fo
.
getCharContent
(
true
)
);
Parser
parser
=
pfac
.
newParser
(
s
,
false
,
genEndPos
);
JCTree
.
JCCompilationUnit
tree
=
parser
.
c
ompilationUnit
();
CharSequence
cs
=
fo
.
getCharContent
(
true
);
Parser
parser
=
pfac
.
newParser
(
cs
,
false
,
genEndPos
,
false
);
JCTree
.
JCCompilationUnit
tree
=
parser
.
parseC
ompilationUnit
();
log
.
setEndPosTable
(
fo
,
tree
.
endPositions
);
TreeScanner
ts
=
new
LogTester
(
log
,
tree
.
endPositions
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录