Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
596f839e
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看板
提交
596f839e
编写于
2月 28, 2011
作者:
J
jjg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7022741: warning counts are wrong after anno processing
Reviewed-by: mcimadamore
上级
4e95f373
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
346 addition
and
4 deletion
+346
-4
src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
...un/tools/javac/processing/JavacProcessingEnvironment.java
+2
-4
test/tools/javac/processing/TestWarnErrorCount.java
test/tools/javac/processing/TestWarnErrorCount.java
+340
-0
test/tools/javac/processing/warnings/gold_0.out
test/tools/javac/processing/warnings/gold_0.out
+1
-0
test/tools/javac/processing/warnings/gold_sv_warn_0_2.out
test/tools/javac/processing/warnings/gold_sv_warn_0_2.out
+1
-0
test/tools/javac/processing/warnings/gold_sv_warn_2_3.out
test/tools/javac/processing/warnings/gold_sv_warn_2_3.out
+1
-0
test/tools/javac/processing/warnings/gold_sv_warn_5_6.out
test/tools/javac/processing/warnings/gold_sv_warn_5_6.out
+1
-0
未找到文件。
src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
浏览文件 @
596f839e
...
...
@@ -807,8 +807,6 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
final
JavaCompiler
compiler
;
/** The log for the round. */
final
Log
log
;
/** The number of warnings in the previous round. */
final
int
priorWarnings
;
/** The ASTs to be compiled. */
List
<
JCCompilationUnit
>
roots
;
...
...
@@ -826,10 +824,10 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
private
Round
(
Context
context
,
int
number
,
int
priorWarnings
)
{
this
.
context
=
context
;
this
.
number
=
number
;
this
.
priorWarnings
=
priorWarnings
;
compiler
=
JavaCompiler
.
instance
(
context
);
log
=
Log
.
instance
(
context
);
log
.
nwarnings
+=
priorWarnings
;
log
.
deferDiagnostics
=
true
;
// the following is for the benefit of JavacProcessingEnvironment.getContext()
...
...
@@ -904,8 +902,8 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
JavaCompiler
finalCompiler
(
boolean
errorStatus
)
{
try
{
JavaCompiler
c
=
JavaCompiler
.
instance
(
nextContext
());
c
.
log
.
nwarnings
+=
compiler
.
log
.
nwarnings
;
if
(
errorStatus
)
{
c
.
log
.
nwarnings
+=
priorWarnings
+
compiler
.
log
.
nwarnings
;
c
.
log
.
nerrors
+=
compiler
.
log
.
nerrors
;
}
return
c
;
...
...
test/tools/javac/processing/TestWarnErrorCount.java
0 → 100644
浏览文件 @
596f839e
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7022337
* @summary repeated warnings about bootclasspath not set
* @library ../lib
* @build JavacTestingAbstractProcessor TestWarnErrorCount
* @run main TestWarnErrorCount
*/
import
java.io.*
;
import
java.util.*
;
import
javax.annotation.processing.*
;
import
javax.lang.model.element.*
;
import
javax.tools.*
;
@SupportedOptions
({
"errKind"
,
"msgrWarnKind"
,
"javaWarnKind"
})
public
class
TestWarnErrorCount
extends
JavacTestingAbstractProcessor
{
public
static
void
main
(
String
...
args
)
throws
Exception
{
new
TestWarnErrorCount
().
run
(
args
);
}
final
int
MAX_GEN
=
10
;
final
int
ERROR_ROUND
=
MAX_GEN
/
2
;
// when to generate error
/**
* Type of errors to generate in test case.
*/
enum
ErrorKind
{
/** No errors. */
NONE
,
/** Source code errors. */
JAVA
,
/** Errors reported to Messager. */
MESSAGER
,
/** Error as a result of using -Werror. */
WERROR
,
}
/**
* Frequency of warnings in test case.
*/
enum
WarnKind
{
/** No warnings. */
NONE
{
boolean
warn
(
int
round
)
{
return
false
;
}
int
count
(
int
start
,
int
end
)
{
return
0
;
}
},
/** Generate a warning if round count is a multiple of 2. */
EVERY_TWO
{
boolean
warn
(
int
round
)
{
return
(
round
%
2
)
==
0
;
}
int
count
(
int
start
,
int
end
)
{
return
(
end
/
2
)
-
((
start
-
1
)/
2
);
}
},
/** Generate a warning if round count is a multiple of 3. */
EVERY_THREE
{
boolean
warn
(
int
round
)
{
return
(
round
%
3
)
==
0
;
}
int
count
(
int
start
,
int
end
)
{
return
(
end
/
3
)
-
((
start
-
1
)/
3
);
}
},
/** Generate a warning every round. */
ALL
{
boolean
warn
(
int
round
)
{
return
true
;
}
int
count
(
int
start
,
int
end
)
{
return
(
end
-
start
+
1
);
}
};
/** whether to generate a warning in round 'round'. */
abstract
boolean
warn
(
int
round
);
/** number of warnings generated in a range of rounds, inclusive. */
abstract
int
count
(
int
start
,
int
end
);
}
/**
* Run test.
* @param args provide ability to specify particular test cases for debugging.
*/
void
run
(
String
...
args
)
throws
Exception
{
for
(
String
arg:
args
)
{
if
(
arg
.
matches
(
"[0-9]+"
))
{
if
(
testCases
==
null
)
testCases
=
new
HashSet
<
Integer
>();
testCases
.
add
(
Integer
.
valueOf
(
arg
));
}
else
if
(
arg
.
equals
(
"-stopOnError"
))
{
stopOnError
=
true
;
}
else
throw
new
IllegalArgumentException
(
arg
);
}
run
();
if
(
errors
>
0
)
throw
new
Exception
(
errors
+
" errors found"
);
}
/**
* Run test.
*/
void
run
()
throws
Exception
{
for
(
ErrorKind
ek:
ErrorKind
.
values
())
{
for
(
WarnKind
mwk:
WarnKind
.
values
())
{
for
(
WarnKind
jwk:
WarnKind
.
values
())
{
test
(
ek
,
mwk
,
jwk
);
if
(
stopOnError
&&
errors
>
0
)
throw
new
Exception
(
errors
+
" errors found"
);
}
}
}
}
boolean
stopOnError
;
Set
<
Integer
>
testCases
;
int
testNum
=
0
;
/**
* Run a test case.
* @param ek The type of errors to generate
* @param mwk The frequency of Messager warnings to generate
* @param jwk The frequency of Java warnings to generate
*/
void
test
(
ErrorKind
ek
,
WarnKind
mwk
,
WarnKind
jwk
)
{
testNum
++;
if
(
testCases
!=
null
&&
!
testCases
.
contains
(
testNum
))
return
;
System
.
err
.
println
(
"Test "
+
testNum
+
": ek:"
+
ek
+
" mwk:"
+
mwk
+
" jwk:"
+
jwk
);
File
testDir
=
new
File
(
"test"
+
testNum
);
testDir
.
mkdirs
();
String
myName
=
TestWarnErrorCount
.
class
.
getSimpleName
();
File
testSrc
=
new
File
(
System
.
getProperty
(
"test.src"
));
File
file
=
new
File
(
testSrc
,
myName
+
".java"
);
List
<
String
>
args
=
new
ArrayList
<
String
>();
args
.
addAll
(
Arrays
.
asList
(
"-XDrawDiagnostics"
,
"-d"
,
testDir
.
getPath
(),
"-processor"
,
myName
,
// "-XprintRounds",
"-Xlint"
,
"-AerrKind="
+
ek
,
"-AmsgrWarnKind="
+
mwk
,
"-AjavaWarnKind="
+
jwk
));
if
(
ek
==
ErrorKind
.
WERROR
)
args
.
add
(
"-Werror"
);
args
.
add
(
file
.
getPath
());
String
out
=
compile
(
args
.
toArray
(
new
String
[
args
.
size
()]));
int
errsFound
=
0
;
int
errsReported
=
0
;
int
warnsFound
=
0
;
int
warnsReported
=
0
;
// Scan the output looking for messages of interest.
for
(
String
line:
out
.
split
(
"[\r\n]+"
))
{
if
(
line
.
contains
(
"compiler.err."
))
{
errsFound
++;
}
else
if
(
line
.
contains
(
"compiler.warn."
))
{
warnsFound
++;
}
else
if
(
line
.
matches
(
"[0-9]+ error(?:s?)"
))
{
errsReported
=
Integer
.
valueOf
(
line
.
substring
(
0
,
line
.
indexOf
(
"error"
)).
trim
());
}
else
if
(
line
.
matches
(
"[0-9]+ warning(?:s?)"
))
{
warnsReported
=
Integer
.
valueOf
(
line
.
substring
(
0
,
line
.
indexOf
(
"warning"
)).
trim
());
}
}
// Compute the expected number of errors and warnings, based on
// the test case parameters.
// This is highly specific to the annotation processor below, and to
// the files it generates.
// Generally, the rules are:
// -- errors stop annotation processing, allowing for one extra "last round"
// -- messager warnings are immediate
// -- javac warnings are not shown before the final compilation
// (FIXME? -Werror does not stop processing for java warnings)
int
errsExpected
;
int
msgrWarnsExpected
;
int
javaWarnsExpected
;
switch
(
ek
)
{
case
NONE:
errsExpected
=
0
;
msgrWarnsExpected
=
mwk
.
count
(
1
,
1
+
MAX_GEN
+
1
);
javaWarnsExpected
=
jwk
.
count
(
2
,
1
+
MAX_GEN
);
break
;
case
MESSAGER:
errsExpected
=
1
;
msgrWarnsExpected
=
mwk
.
count
(
1
,
ERROR_ROUND
+
1
);
javaWarnsExpected
=
0
;
break
;
case
JAVA:
errsExpected
=
2
;
msgrWarnsExpected
=
mwk
.
count
(
1
,
ERROR_ROUND
+
1
);
javaWarnsExpected
=
0
;
break
;
case
WERROR:
errsExpected
=
(
mwk
!=
WarnKind
.
NONE
||
jwk
!=
WarnKind
.
NONE
)
?
1
:
0
;
switch
(
mwk
)
{
case
NONE:
msgrWarnsExpected
=
0
;
javaWarnsExpected
=
(
jwk
==
WarnKind
.
NONE
)
?
0
:
1
;
// this is surprising: javac only reports warning in first file
break
;
case
EVERY_TWO:
msgrWarnsExpected
=
mwk
.
count
(
1
,
2
+
1
);
javaWarnsExpected
=
0
;
break
;
case
EVERY_THREE:
msgrWarnsExpected
=
mwk
.
count
(
1
,
3
+
1
);
javaWarnsExpected
=
0
;
break
;
case
ALL:
msgrWarnsExpected
=
mwk
.
count
(
1
,
1
+
1
);
javaWarnsExpected
=
0
;
break
;
default
:
throw
new
IllegalStateException
();
}
break
;
default
:
throw
new
IllegalStateException
();
}
int
warnsExpected
=
msgrWarnsExpected
+
javaWarnsExpected
;
System
.
err
.
println
(
"mwk: "
+
msgrWarnsExpected
+
", jwk: "
+
javaWarnsExpected
+
", total: "
+
warnsExpected
);
boolean
ok
;
ok
=
checkEqual
(
"errors"
,
"reported"
,
errsFound
,
errsReported
);
ok
&=
checkEqual
(
"errors"
,
"expected"
,
errsFound
,
errsExpected
);
ok
&=
checkEqual
(
"warnings"
,
"reported"
,
warnsFound
,
warnsReported
);
ok
&=
checkEqual
(
"warnings"
,
"expected"
,
warnsFound
,
warnsExpected
);
if
(
ok
)
System
.
err
.
println
(
"OK"
);
System
.
err
.
println
();
}
String
compile
(
String
...
args
)
{
StringWriter
sw
=
new
StringWriter
();
PrintWriter
pw
=
new
PrintWriter
(
sw
);
int
rc
=
com
.
sun
.
tools
.
javac
.
Main
.
compile
(
args
,
pw
);
pw
.
close
();
String
out
=
sw
.
toString
();
if
(!
out
.
isEmpty
())
System
.
err
.
println
(
out
);
if
(
rc
!=
0
)
System
.
err
.
println
(
"compilation failed: rc="
+
rc
);
return
out
;
}
boolean
checkEqual
(
String
l1
,
String
l2
,
int
i1
,
int
i2
)
{
if
(
i1
!=
i2
)
error
(
"number of "
+
l1
+
" found, "
+
i1
+
", does not match number "
+
l2
+
", "
+
i2
);
return
(
i1
==
i2
);
}
void
error
(
String
msg
)
{
System
.
err
.
println
(
"Error: "
+
msg
);
errors
++;
}
int
errors
=
0
;
// ----- Annotation processor -----
int
round
=
0
;
@Override
public
boolean
process
(
Set
<?
extends
TypeElement
>
annotations
,
RoundEnvironment
roundEnv
)
{
round
++;
ErrorKind
ek
=
ErrorKind
.
valueOf
(
options
.
get
(
"errKind"
));
WarnKind
mwk
=
WarnKind
.
valueOf
(
options
.
get
(
"msgrWarnKind"
));
WarnKind
jwk
=
WarnKind
.
valueOf
(
options
.
get
(
"javaWarnKind"
));
messager
.
printMessage
(
Diagnostic
.
Kind
.
NOTE
,
"Round "
+
round
+
" "
+
roundEnv
.
getRootElements
()
+
", last round: "
+
roundEnv
.
processingOver
());
messager
.
printMessage
(
Diagnostic
.
Kind
.
NOTE
,
"ek: "
+
ek
+
", mwk: "
+
mwk
+
", jwk: "
+
jwk
);
if
(
round
<=
MAX_GEN
&&
!
roundEnv
.
processingOver
())
generate
(
"Gen"
+
round
,
(
ek
==
ErrorKind
.
JAVA
)
&&
(
round
==
ERROR_ROUND
),
jwk
.
warn
(
round
));
if
(
mwk
.
warn
(
round
))
messager
.
printMessage
(
Diagnostic
.
Kind
.
WARNING
,
"round "
+
round
);
if
((
ek
==
ErrorKind
.
MESSAGER
)
&&
(
round
==
ERROR_ROUND
))
messager
.
printMessage
(
Diagnostic
.
Kind
.
ERROR
,
"round "
+
round
);
return
true
;
}
void
generate
(
String
name
,
boolean
error
,
boolean
warn
)
{
try
{
JavaFileObject
fo
=
filer
.
createSourceFile
(
name
);
Writer
out
=
fo
.
openWriter
();
try
{
out
.
write
(
"class "
+
name
+
" {\n"
+
(
warn
?
" int i = (int) 0;\n"
:
""
)
+
(
error
?
" ERROR\n"
:
""
)
+
"}\n"
);
}
finally
{
out
.
close
();
}
}
catch
(
IOException
e
)
{
throw
new
Error
(
e
);
}
}
}
test/tools/javac/processing/warnings/gold_0.out
浏览文件 @
596f839e
- compiler.warn.proc.messager: No SourceVersion option given
1 warning
test/tools/javac/processing/warnings/gold_sv_warn_0_2.out
浏览文件 @
596f839e
- compiler.warn.proc.processor.incompatible.source.version: RELEASE_0, TestSourceVersionWarnings, 1.2
1 warning
test/tools/javac/processing/warnings/gold_sv_warn_2_3.out
浏览文件 @
596f839e
- compiler.warn.proc.processor.incompatible.source.version: RELEASE_2, TestSourceVersionWarnings, 1.3
1 warning
test/tools/javac/processing/warnings/gold_sv_warn_5_6.out
浏览文件 @
596f839e
- compiler.warn.proc.processor.incompatible.source.version: RELEASE_5, TestSourceVersionWarnings, 1.6
1 warning
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录