Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
a7252396
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看板
提交
a7252396
编写于
12月 13, 2011
作者:
J
jjg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7120736: refactor javac option handling
Reviewed-by: mcimadamore
上级
70f64bb9
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
158 addition
and
201 deletion
+158
-201
src/share/classes/com/sun/tools/javac/api/JavacTool.java
src/share/classes/com/sun/tools/javac/api/JavacTool.java
+33
-76
src/share/classes/com/sun/tools/javac/code/Source.java
src/share/classes/com/sun/tools/javac/code/Source.java
+1
-1
src/share/classes/com/sun/tools/javac/comp/Check.java
src/share/classes/com/sun/tools/javac/comp/Check.java
+2
-3
src/share/classes/com/sun/tools/javac/comp/Enter.java
src/share/classes/com/sun/tools/javac/comp/Enter.java
+1
-1
src/share/classes/com/sun/tools/javac/comp/Lower.java
src/share/classes/com/sun/tools/javac/comp/Lower.java
+1
-1
src/share/classes/com/sun/tools/javac/file/Locations.java
src/share/classes/com/sun/tools/javac/file/Locations.java
+31
-31
src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
+1
-1
src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
+1
-1
src/share/classes/com/sun/tools/javac/jvm/Gen.java
src/share/classes/com/sun/tools/javac/jvm/Gen.java
+1
-1
src/share/classes/com/sun/tools/javac/jvm/Target.java
src/share/classes/com/sun/tools/javac/jvm/Target.java
+1
-1
src/share/classes/com/sun/tools/javac/main/JavaCompiler.java
src/share/classes/com/sun/tools/javac/main/JavaCompiler.java
+3
-3
src/share/classes/com/sun/tools/javac/main/Main.java
src/share/classes/com/sun/tools/javac/main/Main.java
+31
-45
src/share/classes/com/sun/tools/javac/nio/JavacPathFileManager.java
...classes/com/sun/tools/javac/nio/JavacPathFileManager.java
+1
-1
src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
...un/tools/javac/processing/JavacProcessingEnvironment.java
+1
-1
src/share/classes/com/sun/tools/javac/util/BaseFileManager.java
...are/classes/com/sun/tools/javac/util/BaseFileManager.java
+28
-12
src/share/classes/com/sun/tools/javac/util/Log.java
src/share/classes/com/sun/tools/javac/util/Log.java
+5
-7
src/share/classes/com/sun/tools/javac/util/Options.java
src/share/classes/com/sun/tools/javac/util/Options.java
+14
-14
test/tools/javac/diags/examples/UnsupportedEncoding.java
test/tools/javac/diags/examples/UnsupportedEncoding.java
+2
-1
未找到文件。
src/share/classes/com/sun/tools/javac/api/JavacTool.java
浏览文件 @
a7252396
...
...
@@ -25,18 +25,15 @@
package
com.sun.tools.javac.api
;
import
java.io.File
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStreamWriter
;
import
java.io.PrintWriter
;
import
java.io.Writer
;
import
java.nio.charset.Charset
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.EnumSet
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Set
;
import
javax.lang.model.SourceVersion
;
...
...
@@ -44,17 +41,15 @@ import javax.tools.*;
import
com.sun.source.util.JavacTask
;
import
com.sun.tools.javac.file.JavacFileManager
;
import
com.sun.tools.javac.main.JavacOption.OptionKind
;
import
com.sun.tools.javac.main.JavacOption
;
import
com.sun.tools.javac.main.Main
;
import
com.sun.tools.javac.main.RecognizedOptions.GrumpyHelper
;
import
com.sun.tools.javac.main.RecognizedOptions
;
import
com.sun.tools.javac.main.Option
;
import
com.sun.tools.javac.main.OptionHelper
;
import
com.sun.tools.javac.main.OptionHelper.GrumpyHelper
;
import
com.sun.tools.javac.util.ClientCodeException
;
import
com.sun.tools.javac.util.Context
;
import
com.sun.tools.javac.util.Log
;
import
com.sun.tools.javac.util.Log.PrefixKind
;
import
com.sun.tools.javac.util.Options
;
import
com.sun.tools.javac.util.Pair
;
/**
* TODO: describe com.sun.tools.javac.api.Tool
...
...
@@ -67,23 +62,10 @@ import com.sun.tools.javac.util.Pair;
* @author Peter von der Ah\u00e9
*/
public
final
class
JavacTool
implements
JavaCompiler
{
private
final
List
<
Pair
<
String
,
String
>>
options
=
new
ArrayList
<
Pair
<
String
,
String
>>();
private
final
Context
dummyContext
=
new
Context
();
private
final
PrintWriter
silent
=
new
PrintWriter
(
new
OutputStream
(){
public
void
write
(
int
b
)
{}
});
private
final
Main
sharedCompiler
=
new
Main
(
"javac"
,
silent
);
{
sharedCompiler
.
setOptions
(
Options
.
instance
(
dummyContext
));
}
/**
* Constructor used by service provider mechanism. The
correct
way to
* obtain an instance of this class is
using create or the service provider
* mechanism.
* Constructor used by service provider mechanism. The
recommended
way to
* obtain an instance of this class is
by using {@link #create} or the
*
service provider
mechanism.
* @see javax.tools.JavaCompilerTool
* @see javax.tools.ToolProvider
* @see #create
...
...
@@ -99,49 +81,6 @@ public final class JavacTool implements JavaCompiler {
return
new
JavacTool
();
}
private
String
argsToString
(
Object
...
args
)
{
String
newArgs
=
null
;
if
(
args
.
length
>
0
)
{
StringBuilder
sb
=
new
StringBuilder
();
String
separator
=
""
;
for
(
Object
arg
:
args
)
{
sb
.
append
(
separator
).
append
(
arg
.
toString
());
separator
=
File
.
pathSeparator
;
}
newArgs
=
sb
.
toString
();
}
return
newArgs
;
}
private
void
setOption1
(
String
name
,
OptionKind
kind
,
Object
...
args
)
{
String
arg
=
argsToString
(
args
);
JavacOption
option
=
sharedCompiler
.
getOption
(
name
);
if
(
option
==
null
||
!
match
(
kind
,
option
.
getKind
()))
throw
new
IllegalArgumentException
(
name
);
if
((
args
.
length
!=
0
)
!=
option
.
hasArg
())
throw
new
IllegalArgumentException
(
name
);
if
(
option
.
hasArg
())
{
if
(
option
.
process
(
null
,
name
,
arg
))
// FIXME
throw
new
IllegalArgumentException
(
name
);
}
else
{
if
(
option
.
process
(
null
,
name
))
// FIXME
throw
new
IllegalArgumentException
(
name
);
}
options
.
add
(
new
Pair
<
String
,
String
>(
name
,
arg
));
}
public
void
setOption
(
String
name
,
Object
...
args
)
{
setOption1
(
name
,
OptionKind
.
NORMAL
,
args
);
}
public
void
setExtendedOption
(
String
name
,
Object
...
args
)
{
setOption1
(
name
,
OptionKind
.
EXTENDED
,
args
);
}
private
static
boolean
match
(
OptionKind
clientKind
,
OptionKind
optionKind
)
{
return
(
clientKind
==
(
optionKind
==
OptionKind
.
HIDDEN
?
OptionKind
.
EXTENDED
:
optionKind
));
}
public
JavacFileManager
getStandardFileManager
(
DiagnosticListener
<?
super
JavaFileObject
>
diagnosticListener
,
Locale
locale
,
...
...
@@ -209,7 +148,9 @@ public final class JavacTool implements JavaCompiler {
if
(
fileManager
==
null
)
fileManager
=
getStandardFileManager
(
diagnosticListener
,
null
,
null
);
fileManager
=
ccw
.
wrap
(
fileManager
);
context
.
put
(
JavaFileManager
.
class
,
fileManager
);
processOptions
(
context
,
fileManager
,
options
);
Main
compiler
=
new
Main
(
"javacTask"
,
context
.
get
(
Log
.
outKey
));
return
new
JavacTaskImpl
(
compiler
,
options
,
context
,
classes
,
compilationUnits
);
...
...
@@ -225,11 +166,28 @@ public final class JavacTool implements JavaCompiler {
if
(
options
==
null
)
return
;
Options
optionTable
=
Options
.
instance
(
context
);
final
Options
optionTable
=
Options
.
instance
(
context
);
Log
log
=
Log
.
instance
(
context
);
JavacOption
[]
recognizedOptions
=
RecognizedOptions
.
getJavacToolOptions
(
new
GrumpyHelper
(
log
));
Option
[]
recognizedOptions
=
Option
.
getJavacToolOptions
().
toArray
(
new
Option
[
0
]);
OptionHelper
optionHelper
=
new
GrumpyHelper
(
log
)
{
@Override
public
String
get
(
Option
option
)
{
return
optionTable
.
get
(
option
.
getText
());
}
@Override
public
void
put
(
String
name
,
String
value
)
{
optionTable
.
put
(
name
,
value
);
}
@Override
public
void
remove
(
String
name
)
{
optionTable
.
remove
(
name
);
}
};
Iterator
<
String
>
flags
=
options
.
iterator
();
while
(
flags
.
hasNext
())
{
String
flag
=
flags
.
next
();
...
...
@@ -247,19 +205,19 @@ public final class JavacTool implements JavaCompiler {
}
}
Javac
Option
option
=
recognizedOptions
[
j
];
Option
option
=
recognizedOptions
[
j
];
if
(
option
.
hasArg
())
{
if
(!
flags
.
hasNext
())
{
String
msg
=
log
.
localize
(
PrefixKind
.
JAVAC
,
"err.req.arg"
,
flag
);
throw
new
IllegalArgumentException
(
msg
);
}
String
operand
=
flags
.
next
();
if
(
option
.
process
(
option
Table
,
flag
,
operand
))
if
(
option
.
process
(
option
Helper
,
flag
,
operand
))
// should not happen as the GrumpyHelper will throw exceptions
// in case of errors
throw
new
IllegalArgumentException
(
flag
+
" "
+
operand
);
}
else
{
if
(
option
.
process
(
option
Table
,
flag
))
if
(
option
.
process
(
option
Helper
,
flag
))
// should not happen as the GrumpyHelper will throw exceptions
// in case of errors
throw
new
IllegalArgumentException
(
flag
);
...
...
@@ -283,9 +241,8 @@ public final class JavacTool implements JavaCompiler {
}
public
int
isSupportedOption
(
String
option
)
{
JavacOption
[]
recognizedOptions
=
RecognizedOptions
.
getJavacToolOptions
(
new
GrumpyHelper
(
null
));
for
(
JavacOption
o
:
recognizedOptions
)
{
Set
<
Option
>
recognizedOptions
=
Option
.
getJavacToolOptions
();
for
(
Option
o
:
recognizedOptions
)
{
if
(
o
.
matches
(
option
))
return
o
.
hasArg
()
?
1
:
0
;
}
...
...
src/share/classes/com/sun/tools/javac/code/Source.java
浏览文件 @
a7252396
...
...
@@ -32,7 +32,7 @@ import static javax.lang.model.SourceVersion.*;
import
com.sun.tools.javac.util.*
;
import
com.sun.tools.javac.jvm.Target
;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
Name
.*;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
.*;
/** The source language version accepted.
*
...
...
src/share/classes/com/sun/tools/javac/comp/Check.java
浏览文件 @
a7252396
...
...
@@ -48,7 +48,6 @@ import static com.sun.tools.javac.code.Kinds.*;
import
static
com
.
sun
.
tools
.
javac
.
code
.
TypeTags
.*;
import
static
com
.
sun
.
tools
.
javac
.
code
.
TypeTags
.
WILDCARD
;
import
static
com
.
sun
.
tools
.
javac
.
main
.
OptionName
.*;
import
static
com
.
sun
.
tools
.
javac
.
tree
.
JCTree
.
Tag
.*;
/** Type checking helper class for the attribution phase.
...
...
@@ -110,7 +109,7 @@ public class Check {
allowAnnotations
=
source
.
allowAnnotations
();
allowCovariantReturns
=
source
.
allowCovariantReturns
();
allowSimplifiedVarargs
=
source
.
allowSimplifiedVarargs
();
complexInference
=
options
.
isSet
(
COMPLEXINFERENCE
);
complexInference
=
options
.
isSet
(
"complexinference"
);
skipAnnotations
=
options
.
isSet
(
"skipAnnotations"
);
warnOnSyntheticConflicts
=
options
.
isSet
(
"warnOnSyntheticConflicts"
);
suppressAbortOnBadClassFile
=
options
.
isSet
(
"suppressAbortOnBadClassFile"
);
...
...
@@ -2482,7 +2481,7 @@ public class Check {
warnDeprecated
(
pos
,
s
);
}
});
}
;
}
}
void
checkSunAPI
(
final
DiagnosticPosition
pos
,
final
Symbol
s
)
{
...
...
src/share/classes/com/sun/tools/javac/comp/Enter.java
浏览文件 @
a7252396
...
...
@@ -34,7 +34,7 @@ import com.sun.tools.javac.code.Scope.*;
import
com.sun.tools.javac.code.Symbol.*
;
import
com.sun.tools.javac.code.Type.*
;
import
com.sun.tools.javac.jvm.*
;
import
com.sun.tools.javac.main.
RecognizedOptions
.PkgInfo
;
import
com.sun.tools.javac.main.
Option
.PkgInfo
;
import
com.sun.tools.javac.tree.*
;
import
com.sun.tools.javac.tree.JCTree.*
;
import
com.sun.tools.javac.util.*
;
...
...
src/share/classes/com/sun/tools/javac/comp/Lower.java
浏览文件 @
a7252396
...
...
@@ -29,7 +29,7 @@ import java.util.*;
import
com.sun.tools.javac.code.*
;
import
com.sun.tools.javac.jvm.*
;
import
com.sun.tools.javac.main.
RecognizedOptions
.PkgInfo
;
import
com.sun.tools.javac.main.
Option
.PkgInfo
;
import
com.sun.tools.javac.tree.*
;
import
com.sun.tools.javac.util.*
;
import
com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition
;
...
...
src/share/classes/com/sun/tools/javac/file/Locations.java
浏览文件 @
a7252396
...
...
@@ -47,14 +47,14 @@ import javax.tools.JavaFileManager.Location;
import
javax.tools.StandardLocation
;
import
com.sun.tools.javac.code.Lint
;
import
com.sun.tools.javac.main.Option
Name
;
import
com.sun.tools.javac.main.Option
;
import
com.sun.tools.javac.util.ListBuffer
;
import
com.sun.tools.javac.util.Log
;
import
com.sun.tools.javac.util.Options
;
import
javax.tools.JavaFileManager
;
import
static
javax
.
tools
.
StandardLocation
.*;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
Name
.*;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
.*;
/** This class converts command line arguments, environment variables
* and system properties (in File.pathSeparator-separated String form)
...
...
@@ -318,23 +318,23 @@ public class Locations {
*/
protected
abstract
class
LocationHandler
{
final
Location
location
;
final
Set
<
Option
Name
>
options
;
final
Set
<
Option
>
options
;
/**
* Create a handler. The location and options provide a way to map
* from a location or an option to the corresponding handler.
* @see #initHandlers
*/
protected
LocationHandler
(
Location
location
,
Option
Name
...
options
)
{
protected
LocationHandler
(
Location
location
,
Option
...
options
)
{
this
.
location
=
location
;
this
.
options
=
options
.
length
==
0
?
EnumSet
.
noneOf
(
Option
Name
.
class
):
EnumSet
.
noneOf
(
Option
.
class
):
EnumSet
.
copyOf
(
Arrays
.
asList
(
options
));
}
// TODO: TEMPORARY, while Options still used for command line options
void
update
(
Options
optionTable
)
{
for
(
Option
Name
o:
options
)
{
for
(
Option
o:
options
)
{
String
v
=
optionTable
.
get
(
o
);
if
(
v
!=
null
)
{
handleOption
(
o
,
v
);
...
...
@@ -343,7 +343,7 @@ public class Locations {
}
/** @see JavaFileManager#handleOption. */
abstract
boolean
handleOption
(
Option
Name
option
,
String
value
);
abstract
boolean
handleOption
(
Option
option
,
String
value
);
/** @see JavaFileManager#getLocation. */
abstract
Collection
<
File
>
getLocation
();
/** @see JavaFileManager#setLocation. */
...
...
@@ -359,12 +359,12 @@ public class Locations {
private
class
OutputLocationHandler
extends
LocationHandler
{
private
File
outputDir
;
OutputLocationHandler
(
Location
location
,
Option
Name
...
options
)
{
OutputLocationHandler
(
Location
location
,
Option
...
options
)
{
super
(
location
,
options
);
}
@Override
boolean
handleOption
(
Option
Name
option
,
String
value
)
{
boolean
handleOption
(
Option
option
,
String
value
)
{
if
(!
options
.
contains
(
option
))
return
false
;
...
...
@@ -410,12 +410,12 @@ public class Locations {
private
class
SimpleLocationHandler
extends
LocationHandler
{
protected
Collection
<
File
>
searchPath
;
SimpleLocationHandler
(
Location
location
,
Option
Name
...
options
)
{
SimpleLocationHandler
(
Location
location
,
Option
...
options
)
{
super
(
location
,
options
);
}
@Override
boolean
handleOption
(
Option
Name
option
,
String
value
)
{
boolean
handleOption
(
Option
option
,
String
value
)
{
if
(!
options
.
contains
(
option
))
return
false
;
searchPath
=
value
==
null
?
null
:
...
...
@@ -452,7 +452,7 @@ public class Locations {
private
class
ClassPathLocationHandler
extends
SimpleLocationHandler
{
ClassPathLocationHandler
()
{
super
(
StandardLocation
.
CLASS_PATH
,
Option
Name
.
CLASSPATH
,
OptionName
.
CP
);
Option
.
CLASSPATH
,
Option
.
CP
);
}
@Override
...
...
@@ -500,7 +500,7 @@ public class Locations {
*/
private
class
BootClassPathLocationHandler
extends
LocationHandler
{
private
Collection
<
File
>
searchPath
;
final
Map
<
Option
Name
,
String
>
optionValues
=
new
EnumMap
<
OptionName
,
String
>(
OptionName
.
class
);
final
Map
<
Option
,
String
>
optionValues
=
new
EnumMap
<
Option
,
String
>(
Option
.
class
);
/**
* rt.jar as found on the default bootclasspath.
...
...
@@ -515,11 +515,11 @@ public class Locations {
BootClassPathLocationHandler
()
{
super
(
StandardLocation
.
PLATFORM_CLASS_PATH
,
Option
Name
.
BOOTCLASSPATH
,
OptionName
.
XBOOTCLASSPATH
,
Option
Name
.
XBOOTCLASSPATH_PREPEND
,
Option
Name
.
XBOOTCLASSPATH_APPEND
,
Option
Name
.
ENDORSEDDIRS
,
OptionName
.
DJAVA_ENDORSED_DIRS
,
Option
Name
.
EXTDIRS
,
OptionName
.
DJAVA_EXT_DIRS
);
Option
.
BOOTCLASSPATH
,
Option
.
XBOOTCLASSPATH
,
Option
.
XBOOTCLASSPATH_PREPEND
,
Option
.
XBOOTCLASSPATH_APPEND
,
Option
.
ENDORSEDDIRS
,
Option
.
DJAVA_ENDORSED_DIRS
,
Option
.
EXTDIRS
,
Option
.
DJAVA_EXT_DIRS
);
}
boolean
isDefault
()
{
...
...
@@ -533,7 +533,7 @@ public class Locations {
}
@Override
boolean
handleOption
(
Option
Name
option
,
String
value
)
{
boolean
handleOption
(
Option
option
,
String
value
)
{
if
(!
options
.
contains
(
option
))
return
false
;
...
...
@@ -549,14 +549,14 @@ public class Locations {
// where
// TODO: would be better if option aliasing was handled at a higher
// level
private
Option
Name
canonicalize
(
OptionName
option
)
{
private
Option
canonicalize
(
Option
option
)
{
switch
(
option
)
{
case
XBOOTCLASSPATH:
return
Option
Name
.
BOOTCLASSPATH
;
return
Option
.
BOOTCLASSPATH
;
case
DJAVA_ENDORSED_DIRS:
return
Option
Name
.
ENDORSEDDIRS
;
return
Option
.
ENDORSEDDIRS
;
case
DJAVA_EXT_DIRS:
return
Option
Name
.
EXTDIRS
;
return
Option
.
EXTDIRS
;
default
:
return
option
;
}
...
...
@@ -636,29 +636,29 @@ public class Locations {
}
Map
<
Location
,
LocationHandler
>
handlersForLocation
;
Map
<
Option
Name
,
LocationHandler
>
handlersForOption
;
Map
<
Option
,
LocationHandler
>
handlersForOption
;
void
initHandlers
()
{
handlersForLocation
=
new
HashMap
<
Location
,
LocationHandler
>();
handlersForOption
=
new
EnumMap
<
Option
Name
,
LocationHandler
>(
OptionName
.
class
);
handlersForOption
=
new
EnumMap
<
Option
,
LocationHandler
>(
Option
.
class
);
LocationHandler
[]
handlers
=
{
new
BootClassPathLocationHandler
(),
new
ClassPathLocationHandler
(),
new
SimpleLocationHandler
(
StandardLocation
.
SOURCE_PATH
,
Option
Name
.
SOURCEPATH
),
new
SimpleLocationHandler
(
StandardLocation
.
ANNOTATION_PROCESSOR_PATH
,
Option
Name
.
PROCESSORPATH
),
new
OutputLocationHandler
((
StandardLocation
.
CLASS_OUTPUT
),
Option
Name
.
D
),
new
OutputLocationHandler
((
StandardLocation
.
SOURCE_OUTPUT
),
Option
Name
.
S
)
new
SimpleLocationHandler
(
StandardLocation
.
SOURCE_PATH
,
Option
.
SOURCEPATH
),
new
SimpleLocationHandler
(
StandardLocation
.
ANNOTATION_PROCESSOR_PATH
,
Option
.
PROCESSORPATH
),
new
OutputLocationHandler
((
StandardLocation
.
CLASS_OUTPUT
),
Option
.
D
),
new
OutputLocationHandler
((
StandardLocation
.
SOURCE_OUTPUT
),
Option
.
S
)
};
for
(
LocationHandler
h:
handlers
)
{
handlersForLocation
.
put
(
h
.
location
,
h
);
for
(
Option
Name
o:
h
.
options
)
for
(
Option
o:
h
.
options
)
handlersForOption
.
put
(
o
,
h
);
}
}
boolean
handleOption
(
Option
Name
option
,
String
value
)
{
boolean
handleOption
(
Option
option
,
String
value
)
{
LocationHandler
h
=
handlersForOption
.
get
(
option
);
return
(
h
==
null
?
false
:
h
.
handleOption
(
option
,
value
));
}
...
...
src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
浏览文件 @
a7252396
...
...
@@ -59,7 +59,7 @@ import static com.sun.tools.javac.code.TypeTags.*;
import
static
com
.
sun
.
tools
.
javac
.
jvm
.
ClassFile
.*;
import
static
com
.
sun
.
tools
.
javac
.
jvm
.
ClassFile
.
Version
.*;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
Name
.*;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
.*;
/** This class provides operations to read a classfile into an internal
* representation. The internal representation is anchored in a
...
...
src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
浏览文件 @
a7252396
...
...
@@ -45,7 +45,7 @@ import static com.sun.tools.javac.code.Flags.*;
import
static
com
.
sun
.
tools
.
javac
.
code
.
Kinds
.*;
import
static
com
.
sun
.
tools
.
javac
.
code
.
TypeTags
.*;
import
static
com
.
sun
.
tools
.
javac
.
jvm
.
UninitializedType
.*;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
Name
.*;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
.*;
import
static
javax
.
tools
.
StandardLocation
.
CLASS_OUTPUT
;
...
...
src/share/classes/com/sun/tools/javac/jvm/Gen.java
浏览文件 @
a7252396
...
...
@@ -45,7 +45,7 @@ import static com.sun.tools.javac.code.Kinds.*;
import
static
com
.
sun
.
tools
.
javac
.
code
.
TypeTags
.*;
import
static
com
.
sun
.
tools
.
javac
.
jvm
.
ByteCodes
.*;
import
static
com
.
sun
.
tools
.
javac
.
jvm
.
CRTFlags
.*;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
Name
.*;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
.*;
import
static
com
.
sun
.
tools
.
javac
.
tree
.
JCTree
.
Tag
.*;
import
static
com
.
sun
.
tools
.
javac
.
tree
.
JCTree
.
Tag
.
BLOCK
;
...
...
src/share/classes/com/sun/tools/javac/jvm/Target.java
浏览文件 @
a7252396
...
...
@@ -31,7 +31,7 @@ import com.sun.tools.javac.code.Flags;
import
com.sun.tools.javac.code.Symbol
;
import
com.sun.tools.javac.util.*
;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
Name
.*;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
.*;
/** The classfile version target.
*
...
...
src/share/classes/com/sun/tools/javac/main/JavaCompiler.java
浏览文件 @
a7252396
...
...
@@ -62,7 +62,7 @@ import com.sun.tools.javac.util.*;
import
com.sun.tools.javac.util.Log.WriterKind
;
import
static
javax
.
tools
.
StandardLocation
.
CLASS_OUTPUT
;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
Name
.*;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
.*;
import
static
com
.
sun
.
tools
.
javac
.
util
.
JCDiagnostic
.
DiagnosticFlag
.*;
import
static
com
.
sun
.
tools
.
javac
.
util
.
ListBuffer
.
lb
;
...
...
@@ -817,8 +817,8 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
// forcibly set the equivalent of -Xlint:-options, so that no further
// warnings about command line options are generated from this point on
options
.
put
(
XLINT_CUSTOM
+
"-"
+
LintCategory
.
OPTIONS
.
option
,
"true"
);
options
.
remove
(
XLINT_CUSTOM
+
LintCategory
.
OPTIONS
.
option
);
options
.
put
(
XLINT_CUSTOM
.
text
+
"-"
+
LintCategory
.
OPTIONS
.
option
,
"true"
);
options
.
remove
(
XLINT_CUSTOM
.
text
+
LintCategory
.
OPTIONS
.
option
);
start_msec
=
now
();
...
...
src/share/classes/com/sun/tools/javac/main/Main.java
浏览文件 @
a7252396
...
...
@@ -42,14 +42,12 @@ import com.sun.tools.javac.code.Source;
import
com.sun.tools.javac.file.CacheFSInfo
;
import
com.sun.tools.javac.file.JavacFileManager
;
import
com.sun.tools.javac.jvm.Target
;
import
com.sun.tools.javac.main.JavacOption.Option
;
import
com.sun.tools.javac.main.RecognizedOptions.OptionHelper
;
import
com.sun.tools.javac.util.*
;
import
com.sun.tools.javac.util.Log.WriterKind
;
import
com.sun.tools.javac.util.Log.PrefixKind
;
import
com.sun.tools.javac.processing.AnnotationProcessingError
;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
Name
.*;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
.*;
/** This class provides a commandline interface to the GJC compiler.
*
...
...
@@ -99,42 +97,51 @@ public class Main {
public
final
int
exitCode
;
}
private
Option
[]
recognizedOptions
=
RecognizedOptions
.
getJavaCompilerOptions
(
new
OptionHelper
()
{
private
Option
[]
recognizedOptions
=
Option
.
getJavaCompilerOptions
().
toArray
(
new
Option
[
0
]);
public
void
setOut
(
PrintWriter
out
)
{
Main
.
this
.
out
=
out
;
Main
.
this
.
log
.
setWriters
(
out
);
private
OptionHelper
optionHelper
=
new
OptionHelper
()
{
@Override
public
String
get
(
Option
option
)
{
return
options
.
get
(
option
);
}
public
void
error
(
String
key
,
Object
...
args
)
{
Main
.
this
.
error
(
key
,
args
);
@Override
public
void
put
(
String
name
,
String
value
)
{
options
.
put
(
name
,
value
);
}
public
void
printVersion
()
{
log
.
printLines
(
PrefixKind
.
JAVAC
,
"version"
,
ownName
,
JavaCompiler
.
version
());
@Override
public
void
remove
(
String
name
)
{
options
.
remove
(
name
);
}
public
void
printFullVersion
()
{
log
.
printLines
(
PrefixKind
.
JAVAC
,
"fullVersion"
,
ownName
,
JavaCompiler
.
fullVersion
());
@Override
public
Log
getLog
()
{
return
log
;
}
public
void
printHelp
()
{
help
();
@Override
public
String
getOwnName
()
{
return
ownName
;
}
public
void
printXhelp
()
{
xhelp
();
@Override
public
void
error
(
String
key
,
Object
...
args
)
{
Main
.
this
.
error
(
key
,
args
);
}
@Override
public
void
addFile
(
File
f
)
{
filenames
.
add
(
f
);
}
@Override
public
void
addClassName
(
String
s
)
{
classnames
.
append
(
s
);
}
}
)
;
};
/**
* Construct a compiler instance.
...
...
@@ -161,26 +168,6 @@ public class Main {
*/
public
ListBuffer
<
String
>
classnames
=
null
;
// XXX sb protected
/** Print a string that explains usage.
*/
void
help
()
{
log
.
printLines
(
PrefixKind
.
JAVAC
,
"msg.usage.header"
,
ownName
);
for
(
int
i
=
0
;
i
<
recognizedOptions
.
length
;
i
++)
{
recognizedOptions
[
i
].
help
(
log
);
}
log
.
printNewline
();
}
/** Print a string that explains usage for X options.
*/
void
xhelp
()
{
for
(
int
i
=
0
;
i
<
recognizedOptions
.
length
;
i
++)
{
recognizedOptions
[
i
].
xhelp
(
log
);
}
log
.
printNewline
();
log
.
printLines
(
PrefixKind
.
JAVAC
,
"msg.usage.nonstandard.footer"
);
}
/** Report a usage error.
*/
void
error
(
String
key
,
Object
...
args
)
{
...
...
@@ -253,10 +240,10 @@ public class Main {
}
String
operand
=
flags
[
ac
];
ac
++;
if
(
option
.
process
(
option
s
,
flag
,
operand
))
if
(
option
.
process
(
option
Helper
,
flag
,
operand
))
return
null
;
}
else
{
if
(
option
.
process
(
option
s
,
flag
))
if
(
option
.
process
(
option
Helper
,
flag
))
return
null
;
}
}
...
...
@@ -317,8 +304,8 @@ public class Main {
return
filenames
;
}
// where
private
boolean
checkDirectory
(
Option
Name
optName
)
{
String
value
=
options
.
get
(
opt
Name
);
private
boolean
checkDirectory
(
Option
option
)
{
String
value
=
options
.
get
(
opt
ion
);
if
(
value
==
null
)
return
true
;
File
file
=
new
File
(
value
);
...
...
@@ -375,7 +362,7 @@ public class Main {
*/
try
{
if
(
args
.
length
==
0
&&
fileObjects
.
isEmpty
())
{
help
(
);
Option
.
HELP
.
process
(
optionHelper
,
"-help"
);
return
Result
.
CMDERR
;
}
...
...
@@ -407,8 +394,7 @@ public class Main {
boolean
forceStdOut
=
options
.
isSet
(
"stdout"
);
if
(
forceStdOut
)
{
log
.
flush
();
out
=
new
PrintWriter
(
System
.
out
,
true
);
log
.
setWriters
(
out
);
log
.
setWriters
(
new
PrintWriter
(
System
.
out
,
true
));
}
// allow System property in following line as a Mustang legacy
...
...
src/share/classes/com/sun/tools/javac/nio/JavacPathFileManager.java
浏览文件 @
a7252396
...
...
@@ -63,7 +63,7 @@ import com.sun.tools.javac.util.Context;
import
com.sun.tools.javac.util.List
;
import
com.sun.tools.javac.util.ListBuffer
;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
Name
.*;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
.*;
// NOTE the imports carefully for this compilation unit.
...
...
src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
浏览文件 @
a7252396
...
...
@@ -82,7 +82,7 @@ import com.sun.tools.javac.util.Options;
import
static
javax
.
tools
.
StandardLocation
.*;
import
static
com
.
sun
.
tools
.
javac
.
util
.
JCDiagnostic
.
DiagnosticFlag
.*;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
Name
.*;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
.*;
import
static
com
.
sun
.
tools
.
javac
.
code
.
Lint
.
LintCategory
.
PROCESSING
;
/**
...
...
src/share/classes/com/sun/tools/javac/util/BaseFileManager.java
浏览文件 @
a7252396
...
...
@@ -46,6 +46,7 @@ import java.util.Collection;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Set
;
import
javax.tools.JavaFileObject
;
import
javax.tools.JavaFileObject.Kind
;
...
...
@@ -53,9 +54,9 @@ import com.sun.tools.javac.code.Lint;
import
com.sun.tools.javac.code.Source
;
import
com.sun.tools.javac.file.FSInfo
;
import
com.sun.tools.javac.file.Locations
;
import
com.sun.tools.javac.main.
Javac
Option
;
import
com.sun.tools.javac.main.Option
Name
;
import
com.sun.tools.javac.main.
RecognizedOptions
;
import
com.sun.tools.javac.main.Option
;
import
com.sun.tools.javac.main.Option
Helper
;
import
com.sun.tools.javac.main.
OptionHelper.GrumpyHelper
;
import
com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition
;
/**
...
...
@@ -101,7 +102,7 @@ public abstract class BaseFileManager {
protected
Locations
locations
;
protected
Source
getSource
()
{
String
sourceName
=
options
.
get
(
Option
Name
.
SOURCE
);
String
sourceName
=
options
.
get
(
Option
.
SOURCE
);
Source
source
=
null
;
if
(
sourceName
!=
null
)
source
=
Source
.
lookup
(
sourceName
);
...
...
@@ -145,15 +146,31 @@ public abstract class BaseFileManager {
// <editor-fold defaultstate="collapsed" desc="Option handling">
public
boolean
handleOption
(
String
current
,
Iterator
<
String
>
remaining
)
{
for
(
JavacOption
o:
javacFileManagerOptions
)
{
OptionHelper
helper
=
new
GrumpyHelper
(
log
)
{
@Override
public
String
get
(
Option
option
)
{
return
options
.
get
(
option
.
getText
());
}
@Override
public
void
put
(
String
name
,
String
value
)
{
options
.
put
(
name
,
value
);
}
@Override
public
void
remove
(
String
name
)
{
options
.
remove
(
name
);
}
};
for
(
Option
o:
javacFileManagerOptions
)
{
if
(
o
.
matches
(
current
))
{
if
(
o
.
hasArg
())
{
if
(
remaining
.
hasNext
())
{
if
(!
o
.
process
(
options
,
current
,
remaining
.
next
()))
if
(!
o
.
process
(
helper
,
current
,
remaining
.
next
()))
return
true
;
}
}
else
{
if
(!
o
.
process
(
options
,
current
))
if
(!
o
.
process
(
helper
,
current
))
return
true
;
}
// operand missing, or process returned false
...
...
@@ -164,12 +181,11 @@ public abstract class BaseFileManager {
return
false
;
}
// where
private
static
JavacOption
[]
javacFileManagerOptions
=
RecognizedOptions
.
getJavacFileManagerOptions
(
new
RecognizedOptions
.
GrumpyHelper
(
Log
.
instance
(
new
Context
())));
private
static
Set
<
Option
>
javacFileManagerOptions
=
Option
.
getJavacFileManagerOptions
();
public
int
isSupportedOption
(
String
option
)
{
for
(
Javac
Option
o
:
javacFileManagerOptions
)
{
for
(
Option
o
:
javacFileManagerOptions
)
{
if
(
o
.
matches
(
option
))
return
o
.
hasArg
()
?
1
:
0
;
}
...
...
@@ -191,7 +207,7 @@ public abstract class BaseFileManager {
}
public
String
getEncodingName
()
{
String
encName
=
options
.
get
(
Option
Name
.
ENCODING
);
String
encName
=
options
.
get
(
Option
.
ENCODING
);
if
(
encName
==
null
)
return
getDefaultEncodingName
();
else
...
...
src/share/classes/com/sun/tools/javac/util/Log.java
浏览文件 @
a7252396
...
...
@@ -25,25 +25,23 @@
package
com.sun.tools.javac.util
;
import
com.sun.tools.javac.main.Main
;
import
java.io.*
;
import
java.util.Arrays
;
import
java.util.EnumSet
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Queue
;
import
java.util.Set
;
import
javax.tools.DiagnosticListener
;
import
javax.tools.JavaFileObject
;
import
com.sun.tools.javac.api.DiagnosticFormatter
;
import
com.sun.tools.javac.main.OptionName
;
import
com.sun.tools.javac.main.Main
;
import
com.sun.tools.javac.main.Option
;
import
com.sun.tools.javac.parser.EndPosTable
;
import
com.sun.tools.javac.tree.JCTree
;
import
com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition
;
import
com.sun.tools.javac.util.JCDiagnostic.DiagnosticType
;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
Name
.*;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
.*;
/** A class for error logs. Reports errors and warnings, and
* keeps track of error numbers and positions.
...
...
@@ -179,8 +177,8 @@ public class Log extends AbstractLog {
expectDiagKeys
=
new
HashSet
<
String
>(
Arrays
.
asList
(
ek
.
split
(
", *"
)));
}
private
int
getIntOption
(
Options
options
,
Option
Name
optionName
,
int
defaultValue
)
{
String
s
=
options
.
get
(
option
Name
);
private
int
getIntOption
(
Options
options
,
Option
option
,
int
defaultValue
)
{
String
s
=
options
.
get
(
option
);
try
{
if
(
s
!=
null
)
{
int
n
=
Integer
.
parseInt
(
s
);
...
...
src/share/classes/com/sun/tools/javac/util/Options.java
浏览文件 @
a7252396
...
...
@@ -26,8 +26,8 @@
package
com.sun.tools.javac.util
;
import
java.util.*
;
import
com.sun.tools.javac.main.Option
Name
;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
Name
.*;
import
com.sun.tools.javac.main.Option
;
import
static
com
.
sun
.
tools
.
javac
.
main
.
Option
.*;
/** A table of all command-line options.
* If an option has an argument, the option name is mapped to the argument.
...
...
@@ -71,8 +71,8 @@ public class Options {
/**
* Get the value for an option.
*/
public
String
get
(
Option
Name
name
)
{
return
values
.
get
(
name
.
optionName
);
public
String
get
(
Option
option
)
{
return
values
.
get
(
option
.
text
);
}
/**
...
...
@@ -101,15 +101,15 @@ public class Options {
/**
* Check if the value for an option has been set.
*/
public
boolean
isSet
(
Option
Name
name
)
{
return
(
values
.
get
(
name
.
optionName
)
!=
null
);
public
boolean
isSet
(
Option
option
)
{
return
(
values
.
get
(
option
.
text
)
!=
null
);
}
/**
* Check if the value for a choice option has been set to a specific value.
*/
public
boolean
isSet
(
Option
Name
name
,
String
value
)
{
return
(
values
.
get
(
name
.
optionName
+
value
)
!=
null
);
public
boolean
isSet
(
Option
option
,
String
value
)
{
return
(
values
.
get
(
option
.
text
+
value
)
!=
null
);
}
/**
...
...
@@ -122,23 +122,23 @@ public class Options {
/**
* Check if the value for an option has not been set.
*/
public
boolean
isUnset
(
Option
Name
name
)
{
return
(
values
.
get
(
name
.
optionName
)
==
null
);
public
boolean
isUnset
(
Option
option
)
{
return
(
values
.
get
(
option
.
text
)
==
null
);
}
/**
* Check if the value for a choice option has not been set to a specific value.
*/
public
boolean
isUnset
(
Option
Name
name
,
String
value
)
{
return
(
values
.
get
(
name
.
optionName
+
value
)
==
null
);
public
boolean
isUnset
(
Option
option
,
String
value
)
{
return
(
values
.
get
(
option
.
text
+
value
)
==
null
);
}
public
void
put
(
String
name
,
String
value
)
{
values
.
put
(
name
,
value
);
}
public
void
put
(
Option
Name
name
,
String
value
)
{
values
.
put
(
name
.
optionName
,
value
);
public
void
put
(
Option
option
,
String
value
)
{
values
.
put
(
option
.
text
,
value
);
}
public
void
putAll
(
Options
options
)
{
...
...
test/tools/javac/diags/examples/UnsupportedEncoding.java
浏览文件 @
a7252396
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010,
2011,
Oracle and/or its affiliates. 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
...
...
@@ -23,5 +23,6 @@
// key: compiler.err.unsupported.encoding
// options: -encoding UNSUPPORTED -doe
// run: simple
class
UnsupportedEncoding
{
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录