Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
29ab714c
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看板
提交
29ab714c
编写于
1月 25, 2011
作者:
D
darcy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7013420: Project Coin: remove general expression support from try-with-resources statement
Reviewed-by: mcimadamore, jjg
上级
e871a245
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
116 addition
and
123 deletion
+116
-123
src/share/classes/com/sun/tools/javac/parser/JavacParser.java
...share/classes/com/sun/tools/javac/parser/JavacParser.java
+10
-16
src/share/classes/com/sun/tools/javac/resources/compiler.properties
...classes/com/sun/tools/javac/resources/compiler.properties
+2
-0
test/tools/javac/TryWithResources/BadTwrSyntax.out
test/tools/javac/TryWithResources/BadTwrSyntax.out
+1
-1
test/tools/javac/TryWithResources/DuplicateResource.java
test/tools/javac/TryWithResources/DuplicateResource.java
+5
-5
test/tools/javac/TryWithResources/ExplicitFinal.java
test/tools/javac/TryWithResources/ExplicitFinal.java
+56
-0
test/tools/javac/TryWithResources/ImplicitFinal.java
test/tools/javac/TryWithResources/ImplicitFinal.java
+17
-4
test/tools/javac/TryWithResources/ImplicitFinal.out
test/tools/javac/TryWithResources/ImplicitFinal.out
+4
-1
test/tools/javac/TryWithResources/TwrFlow.java
test/tools/javac/TryWithResources/TwrFlow.java
+4
-14
test/tools/javac/TryWithResources/TwrFlow.out
test/tools/javac/TryWithResources/TwrFlow.out
+1
-3
test/tools/javac/TryWithResources/TwrIntersection02.java
test/tools/javac/TryWithResources/TwrIntersection02.java
+0
-37
test/tools/javac/TryWithResources/TwrIntersection02.out
test/tools/javac/TryWithResources/TwrIntersection02.out
+0
-3
test/tools/javac/TryWithResources/TwrMultiCatch.java
test/tools/javac/TryWithResources/TwrMultiCatch.java
+6
-6
test/tools/javac/TryWithResources/TwrOnNonResource.java
test/tools/javac/TryWithResources/TwrOnNonResource.java
+1
-13
test/tools/javac/TryWithResources/TwrOnNonResource.out
test/tools/javac/TryWithResources/TwrOnNonResource.out
+1
-4
test/tools/javac/diags/examples/TryResourceTrailingSemi.java
test/tools/javac/diags/examples/TryResourceTrailingSemi.java
+8
-16
未找到文件。
src/share/classes/com/sun/tools/javac/parser/JavacParser.java
浏览文件 @
29ab714c
...
...
@@ -142,7 +142,7 @@ public class JavacParser implements Parser {
*/
boolean
allowAnnotations
;
/** Switch: should we recognize
automatic resource management
?
/** Switch: should we recognize
try-with-resources
?
*/
boolean
allowTWR
;
...
...
@@ -2184,29 +2184,23 @@ public class JavacParser implements Parser {
while
(
S
.
token
()
==
SEMI
)
{
// All but last of multiple declarators subsume a semicolon
storeEnd
(
defs
.
elems
.
last
(),
S
.
endPos
());
int
semiColonPos
=
S
.
pos
();
S
.
nextToken
();
if
(
S
.
token
()
==
RPAREN
)
{
// Illegal trailing semicolon
// after last resource
error
(
semiColonPos
,
"try.resource.trailing.semi"
);
break
;
}
defs
.
append
(
resource
());
}
return
defs
.
toList
();
}
/** Resource =
* VariableModifiers Type VariableDeclaratorId = Expression
* | Expression
/** Resource = VariableModifiersOpt Type VariableDeclaratorId = Expression
*/
JCTree
resource
()
{
int
pos
=
S
.
pos
();
if
(
S
.
token
()
==
FINAL
||
S
.
token
()
==
MONKEYS_AT
)
{
return
variableDeclaratorRest
(
pos
,
optFinal
(
0
),
parseType
(),
ident
(),
true
,
null
);
}
else
{
JCExpression
t
=
term
(
EXPR
|
TYPE
);
if
((
lastmode
&
TYPE
)
!=
0
&&
S
.
token
()
==
IDENTIFIER
)
return
variableDeclaratorRest
(
pos
,
toP
(
F
.
at
(
pos
).
Modifiers
(
Flags
.
FINAL
)),
t
,
ident
(),
true
,
null
);
else
return
t
;
}
return
variableDeclaratorRest
(
S
.
pos
(),
optFinal
(
Flags
.
FINAL
),
parseType
(),
ident
(),
true
,
null
);
}
/** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration}
...
...
src/share/classes/com/sun/tools/javac/resources/compiler.properties
浏览文件 @
29ab714c
...
...
@@ -177,6 +177,8 @@ compiler.err.final.parameter.may.not.be.assigned=\
final parameter {0} may not be assigned
compiler.err.try.resource.may.not.be.assigned
=
\
auto-closeable resource {0} may not be assigned
compiler.err.try.resource.trailing.semi
=
\
illegal trailing semicolon in resources declaration
compiler.err.multicatch.parameter.may.not.be.assigned
=
\
multi-catch parameter {0} may not be assigned
compiler.err.finally.without.try
=
\
...
...
test/tools/javac/TryWithResources/BadTwrSyntax.out
浏览文件 @
29ab714c
BadTwrSyntax.java:14:4
3: compiler.err.illegal.start.of.expr
BadTwrSyntax.java:14:4
2: compiler.err.try.resource.trailing.semi
1 error
test/tools/javac/TryWithResources/DuplicateResource.java
浏览文件 @
29ab714c
/*
* 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,9 +23,9 @@
/*
* @test
* @bug 6911256 6964740 6965277
* @bug 6911256 6964740 6965277
7013420
* @author Maurizio Cimadamore
* @summary Check that lowered
arm
block does not end up creating resource twice
* @summary Check that lowered
try-with-resources
block does not end up creating resource twice
*/
import
java.util.ArrayList
;
...
...
@@ -45,7 +45,7 @@ public class DuplicateResource {
static
ArrayList
<
TestResource
>
resources
=
new
ArrayList
<
TestResource
>();
public
static
void
main
(
String
[]
args
)
{
try
(
new
TestResource
())
{
try
(
TestResource
tr
=
new
TestResource
())
{
//do something
}
catch
(
Exception
e
)
{
throw
new
AssertionError
(
"Shouldn't reach here"
,
e
);
...
...
@@ -59,7 +59,7 @@ public class DuplicateResource {
}
TestResource
resource
=
resources
.
get
(
0
);
if
(!
resource
.
isClosed
)
{
throw
new
AssertionError
(
"Resource used in
ARM
block has not been automatically closed"
);
throw
new
AssertionError
(
"Resource used in
try-with-resources
block has not been automatically closed"
);
}
}
}
test/tools/javac/TryWithResources/
TwrIntersection
.java
→
test/tools/javac/TryWithResources/
ExplicitFinal
.java
浏览文件 @
29ab714c
/*
* Copyright (c) 201
0
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 201
1
, 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,25 +23,34 @@
/*
* @test
* @bug 6911256 6964740 6965277
* @author Maurizio Cimadamore
* @summary Resource of an intersection type crashes Flow
* @compile TwrIntersection.java
* @bug 7013420
* @author Joseph D. Darcy
* @summary Test that resource variables are accepted as explicitly final.
*/
interface
MyCloseable
extends
AutoCloseable
{
void
close
()
throws
java
.
io
.
IOException
;
}
import
java.io.IOException
;
class
ResourceTypeVar
{
public
class
ExplicitFinal
implements
AutoCloseable
{
public
static
void
main
(
String
...
args
)
{
try
(
final
ExplicitFinal
r2
=
new
ExplicitFinal
())
{
r2
.
toString
();
}
catch
(
IOException
ioe
)
{
throw
new
AssertionError
(
"Shouldn't reach here"
,
ioe
);
}
public
void
test
()
{
try
(
getX
())
{
//do something
}
catch
(
java
.
io
.
IOException
e
)
{
// Not reachable
throw
new
AssertionError
(
"Shouldn't reach here"
,
e
);
try
(
final
@SuppressWarnings
(
"unchecked"
)
ExplicitFinal
r3
=
new
ExplicitFinal
())
{
r3
.
toString
();
}
catch
(
IOException
ioe
)
{
throw
new
AssertionError
(
"Shouldn't reach here"
,
ioe
);
}
}
<
X
extends
Number
&
MyCloseable
>
X
getX
()
{
return
null
;
}
try
(
@SuppressWarnings
(
"unchecked"
)
ExplicitFinal
r4
=
new
ExplicitFinal
())
{
r4
.
toString
();
}
catch
(
IOException
ioe
)
{
throw
new
AssertionError
(
"Shouldn't reach here"
,
ioe
);
}
}
public
void
close
()
throws
IOException
{
System
.
out
.
println
(
"Calling close on "
+
this
);
}
}
test/tools/javac/TryWithResources/ImplicitFinal.java
浏览文件 @
29ab714c
/*
* @test /nodynamiccopyright/
* @bug 6911256 6964740 6965277
* @bug 6911256 6964740 6965277
7013420
* @author Maurizio Cimadamore
* @summary Test that resource variables are implicitly final
* @compile/fail/ref=ImplicitFinal.out -XDrawDiagnostics ImplicitFinal.java
...
...
@@ -15,12 +15,25 @@ class ImplicitFinal implements AutoCloseable {
}
catch
(
IOException
ioe
)
{
// Not reachable
throw
new
AssertionError
(
"Shouldn't reach here"
,
ioe
);
}
}
try
(
@SuppressWarnings
(
"unchecked"
)
ImplicitFinal
r1
=
new
ImplicitFinal
())
{
r1
=
null
;
//disallowed
}
catch
(
IOException
ioe
)
{
// Not reachable
throw
new
AssertionError
(
"Shouldn't reach here"
,
ioe
);
}
// A close method, but the class is <em>not</em> Closeable or
// AutoCloseable.
try
(
final
ImplicitFinal
r2
=
new
ImplicitFinal
())
{
r2
=
null
;
//disallowed
}
catch
(
IOException
ioe
)
{
// Not reachable
throw
new
AssertionError
(
"Shouldn't reach here"
,
ioe
);
}
try
(
final
@SuppressWarnings
(
"unchecked"
)
ImplicitFinal
r3
=
new
ImplicitFinal
())
{
r3
=
null
;
//disallowed
}
catch
(
IOException
ioe
)
{
// Not reachable
throw
new
AssertionError
(
"Shouldn't reach here"
,
ioe
);
}
}
public
void
close
()
throws
IOException
{
throw
new
IOException
();
}
...
...
test/tools/javac/TryWithResources/ImplicitFinal.out
浏览文件 @
29ab714c
ImplicitFinal.java:14:13: compiler.err.try.resource.may.not.be.assigned: r
1 error
ImplicitFinal.java:20:13: compiler.err.try.resource.may.not.be.assigned: r1
ImplicitFinal.java:26:13: compiler.err.try.resource.may.not.be.assigned: r2
ImplicitFinal.java:32:13: compiler.err.try.resource.may.not.be.assigned: r3
4 errors
test/tools/javac/TryWithResources/TwrFlow.java
浏览文件 @
29ab714c
/*
* @test /nodynamiccopyright/
* @bug 6911256 6964740
* @bug 6911256 6964740
7013420
* @author Joseph D. Darcy
* @summary Test exception analysis of
ARM
blocks
* @summary Test exception analysis of
try-with-resources
blocks
* @compile/fail/ref=TwrFlow.out -XDrawDiagnostics TwrFlow.java
*/
import
java.io.IOException
;
public
class
TwrFlow
implements
AutoCloseable
{
public
static
void
main
(
String
...
args
)
{
try
(
TwrFlow
armflow
=
new
TwrFlow
())
{
System
.
out
.
println
(
armflow
.
toString
());
}
catch
(
IOException
ioe
)
{
// Not reachable
throw
new
AssertionError
(
"Shouldn't reach here"
,
ioe
);
}
// CustomCloseException should be caught or added to throws clause
// Also check behavior on a resource expression rather than a
// declaration.
TwrFlow
armflowexpr
=
new
TwrFlow
();
try
(
armflowexpr
)
{
System
.
out
.
println
(
armflowexpr
.
toString
());
try
(
TwrFlow
twrFlow
=
new
TwrFlow
())
{
System
.
out
.
println
(
twrFlow
.
toString
());
}
catch
(
IOException
ioe
)
{
// Not reachable
throw
new
AssertionError
(
"Shouldn't reach here"
,
ioe
);
}
...
...
test/tools/javac/TryWithResources/TwrFlow.out
浏览文件 @
29ab714c
TwrFlow.java:14:11: compiler.err.except.never.thrown.in.try: java.io.IOException
TwrFlow.java:24:11: compiler.err.except.never.thrown.in.try: java.io.IOException
TwrFlow.java:12:46: compiler.err.unreported.exception.need.to.catch.or.throw: CustomCloseException
TwrFlow.java:22:26: compiler.err.unreported.exception.need.to.catch.or.throw: CustomCloseException
4 errors
2 errors
test/tools/javac/TryWithResources/TwrIntersection02.java
已删除
100644 → 0
浏览文件 @
e871a245
/*
* @test /nodynamiccopyright/
* @bug 6911256 6964740 6965277
* @author Maurizio Cimadamore
* @summary Check that resources of an intersection type forces union of exception types
* to be caught outside twr block
* @compile/fail/ref=TwrIntersection02.out -XDrawDiagnostics TwrIntersection02.java
*/
class
TwrIntersection02
{
static
class
Exception1
extends
Exception
{}
static
class
Exception2
extends
Exception
{}
interface
MyResource1
extends
AutoCloseable
{
void
close
()
throws
Exception1
;
}
interface
MyResource2
extends
AutoCloseable
{
void
close
()
throws
Exception2
;
}
public
void
test1
()
throws
Exception1
{
try
(
getX
())
{
//do something
}
}
public
void
test2
()
throws
Exception2
{
try
(
getX
())
{
//do something
}
}
<
X
extends
MyResource1
&
MyResource2
>
X
getX
()
{
return
null
;
}
}
test/tools/javac/TryWithResources/TwrIntersection02.out
已删除
100644 → 0
浏览文件 @
e871a245
TwrIntersection02.java:25:21: compiler.err.unreported.exception.need.to.catch.or.throw: TwrIntersection02.Exception2
TwrIntersection02.java:31:21: compiler.err.unreported.exception.need.to.catch.or.throw: TwrIntersection02.Exception1
2 errors
test/tools/javac/TryWithResources/TwrMultiCatch.java
浏览文件 @
29ab714c
/*
* 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,7 +23,7 @@
/*
* @test
* @bug 6911256 6964740
* @bug 6911256 6964740
7013420
* @author Joseph D. Darcy
* @summary Test that TWR and multi-catch play well together
* @compile TwrMultiCatch.java
...
...
@@ -48,9 +48,9 @@ public class TwrMultiCatch implements AutoCloseable {
private
static
void
test
(
TwrMultiCatch
twrMultiCatch
,
Class
<?
extends
Exception
>
expected
)
{
try
(
twrMultiCatch
)
{
System
.
out
.
println
(
t
wrMultiCatch
.
toString
());
}
catch
(
final
CustomCloseException1
|
try
(
TwrMultiCatch
tmc
=
twrMultiCatch
)
{
System
.
out
.
println
(
t
mc
.
toString
());
}
catch
(
CustomCloseException1
|
CustomCloseException2
exception
)
{
if
(!
exception
.
getClass
().
equals
(
expected
)
)
{
throw
new
RuntimeException
(
"Unexpected catch!"
);
...
...
@@ -68,7 +68,7 @@ public class TwrMultiCatch implements AutoCloseable {
try
{
throw
t
;
}
catch
(
final
CustomCloseException1
|
}
catch
(
CustomCloseException1
|
CustomCloseException2
exception
)
{
throw
exception
;
}
catch
(
Throwable
throwable
)
{
...
...
test/tools/javac/TryWithResources/TwrOnNonResource.java
浏览文件 @
29ab714c
/*
* @test /nodynamiccopyright/
* @bug 6911256 6964740
* @bug 6911256 6964740
7013420
* @author Joseph D. Darcy
* @summary Verify invalid TWR block is not accepted.
* @compile/fail -source 6 TwrOnNonResource.java
...
...
@@ -18,18 +18,6 @@ class TwrOnNonResource {
try
(
TwrOnNonResource
aonr
=
new
TwrOnNonResource
())
{
System
.
out
.
println
(
aonr
.
toString
());
}
catch
(
Exception
e
)
{;}
// Also check expression form
TwrOnNonResource
aonr
=
new
TwrOnNonResource
();
try
(
aonr
)
{
System
.
out
.
println
(
aonr
.
toString
());
}
try
(
aonr
)
{
System
.
out
.
println
(
aonr
.
toString
());
}
finally
{;}
try
(
aonr
)
{
System
.
out
.
println
(
aonr
.
toString
());
}
catch
(
Exception
e
)
{;}
}
/*
...
...
test/tools/javac/TryWithResources/TwrOnNonResource.out
浏览文件 @
29ab714c
TwrOnNonResource.java:12:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
TwrOnNonResource.java:15:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
TwrOnNonResource.java:18:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
TwrOnNonResource.java:24:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
TwrOnNonResource.java:27:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
TwrOnNonResource.java:30:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable
6 errors
3 errors
test/tools/javac/
TryWithResources/TwrInference
.java
→
test/tools/javac/
diags/examples/TryResourceTrailingSemi
.java
浏览文件 @
29ab714c
/*
* Copyright (c) 201
0
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 201
1
, 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
...
...
@@ -21,23 +21,15 @@
* questions.
*/
/*
* @test
* @bug 6911256 6964740 6965277
* @author Maurizio Cimadamore
* @summary Verify that method type-inference works as expected in TWR context
* @compile TwrInference.java
*/
class
TwrInference
{
// key: compiler.err.try.resource.trailing.semi
public
void
test
()
{
try
(
getX
())
{
//do something
}
catch
(
Exception
e
)
{
// Not reachable
throw
new
AssertionError
(
"Shouldn't reach here"
,
e
);
class
TryResoureTrailingSemi
implements
AutoCloseable
{
public
static
void
main
(
String
...
args
)
{
try
(
TryResoureTrailingSemi
r
=
new
TryResoureTrailingSemi
();)
{
System
.
out
.
println
(
r
.
toString
());
}
}
<
X
>
X
getX
()
{
return
null
;
}
@Override
public
void
close
()
{
return
;}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录