Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
4a8cb00a
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看板
提交
4a8cb00a
编写于
5月 01, 2013
作者:
R
rfield
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8011591: BootstrapMethodError when capturing constructor ref to local classes
Reviewed-by: mcimadamore
上级
5e807c5d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
142 addition
and
18 deletion
+142
-18
src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java
...hare/classes/com/sun/tools/javac/comp/LambdaToMethod.java
+60
-18
test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestNewInnerImplicitArgs.java
...nceExecution/MethodReferenceTestNewInnerImplicitArgs.java
+82
-0
未找到文件。
src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java
浏览文件 @
4a8cb00a
...
...
@@ -40,10 +40,9 @@ import com.sun.tools.javac.code.Symbol.MethodSymbol;
import
com.sun.tools.javac.code.Symbol.VarSymbol
;
import
com.sun.tools.javac.code.Symtab
;
import
com.sun.tools.javac.code.Type
;
import
com.sun.tools.javac.code.Type.ClassType
;
import
com.sun.tools.javac.code.Type.MethodType
;
import
com.sun.tools.javac.code.Types
;
import
com.sun.tools.javac.comp.LambdaToMethod.LambdaAnalyzer.*
;
import
com.sun.tools.javac.comp.LambdaToMethod.LambdaAnalyzer
Preprocessor
.*
;
import
com.sun.tools.javac.comp.Lower.BasicFreeVarCollector
;
import
com.sun.tools.javac.jvm.*
;
import
com.sun.tools.javac.util.*
;
...
...
@@ -81,7 +80,7 @@ public class LambdaToMethod extends TreeTranslator {
private
Env
<
AttrContext
>
attrEnv
;
/** the analyzer scanner */
private
LambdaAnalyzer
analyzer
;
private
LambdaAnalyzer
Preprocessor
analyzer
;
/** map from lambda trees to translation contexts */
private
Map
<
JCTree
,
TranslationContext
<?>>
contextMap
;
...
...
@@ -156,7 +155,7 @@ public class LambdaToMethod extends TreeTranslator {
make
=
TreeMaker
.
instance
(
context
);
types
=
Types
.
instance
(
context
);
transTypes
=
TransTypes
.
instance
(
context
);
analyzer
=
new
LambdaAnalyzer
();
analyzer
=
new
LambdaAnalyzer
Preprocessor
();
}
// </editor-fold>
...
...
@@ -206,7 +205,7 @@ public class LambdaToMethod extends TreeTranslator {
public
void
visitClassDef
(
JCClassDecl
tree
)
{
if
(
tree
.
sym
.
owner
.
kind
==
PCK
)
{
//analyze class
analyzer
.
analyze
Class
(
tree
);
tree
=
analyzer
.
analyzeAndPreprocess
Class
(
tree
);
}
KlassInfo
prevKlassInfo
=
kInfo
;
try
{
...
...
@@ -531,16 +530,25 @@ public class LambdaToMethod extends TreeTranslator {
/** Make an attributed class instance creation expression.
* @param ctype The class type.
* @param args The constructor arguments.
* @param cons The constructor symbol
*/
JCNewClass
makeNewClass
(
Type
ctype
,
List
<
JCExpression
>
args
)
{
JCNewClass
makeNewClass
(
Type
ctype
,
List
<
JCExpression
>
args
,
Symbol
cons
)
{
JCNewClass
tree
=
make
.
NewClass
(
null
,
null
,
make
.
QualIdent
(
ctype
.
tsym
),
args
,
null
);
tree
.
constructor
=
rs
.
resolveConstructor
(
null
,
attrEnv
,
ctype
,
TreeInfo
.
types
(
args
),
List
.<
Type
>
nil
());
tree
.
constructor
=
cons
;
tree
.
type
=
ctype
;
return
tree
;
}
/** Make an attributed class instance creation expression.
* @param ctype The class type.
* @param args The constructor arguments.
*/
JCNewClass
makeNewClass
(
Type
ctype
,
List
<
JCExpression
>
args
)
{
return
makeNewClass
(
ctype
,
args
,
rs
.
resolveConstructor
(
null
,
attrEnv
,
ctype
,
TreeInfo
.
types
(
args
),
List
.<
Type
>
nil
()));
}
private
void
addDeserializationCase
(
int
implMethodKind
,
Symbol
refSym
,
Type
targetType
,
MethodSymbol
samSym
,
DiagnosticPosition
pos
,
List
<
Object
>
staticArgs
,
MethodType
indyType
)
{
String
functionalInterfaceClass
=
classSig
(
targetType
);
...
...
@@ -1019,8 +1027,9 @@ public class LambdaToMethod extends TreeTranslator {
* This visitor collects information about translation of a lambda expression.
* More specifically, it keeps track of the enclosing contexts and captured locals
* accessed by the lambda being translated (as well as other useful info).
* It also translates away problems for LambdaToMethod.
*/
class
LambdaAnalyzer
extends
TreeScanne
r
{
class
LambdaAnalyzer
Preprocessor
extends
TreeTranslato
r
{
/** the frame stack - used to reconstruct translation info about enclosing scopes */
private
List
<
Frame
>
frameStack
;
...
...
@@ -1047,10 +1056,10 @@ public class LambdaToMethod extends TreeTranslator {
private
Map
<
ClassSymbol
,
Symbol
>
clinits
=
new
HashMap
<
ClassSymbol
,
Symbol
>();
private
void
analyze
Class
(
JCClassDecl
tree
)
{
private
JCClassDecl
analyzeAndPreprocess
Class
(
JCClassDecl
tree
)
{
frameStack
=
List
.
nil
();
localClassDefs
=
new
HashMap
<
Symbol
,
JCClassDecl
>();
scan
(
tree
);
return
translate
(
tree
);
}
@Override
...
...
@@ -1154,7 +1163,7 @@ public class LambdaToMethod extends TreeTranslator {
frameStack
.
head
.
addLocal
(
param
.
sym
);
}
contextMap
.
put
(
tree
,
context
);
s
can
(
tree
.
body
);
s
uper
.
visitLambda
(
tree
);
context
.
complete
();
}
finally
{
...
...
@@ -1220,12 +1229,47 @@ public class LambdaToMethod extends TreeTranslator {
};
fvc
.
scan
(
localCDef
);
}
}
}
/**
* Method references to local class constructors, may, if the local
* class references local variables, have implicit constructor
* parameters added in Lower; As a result, the invokedynamic bootstrap
* information added in the LambdaToMethod pass will have the wrong
* signature. Hooks between Lower and LambdaToMethod have been added to
* handle normal "new" in this case. This visitor converts potentially
* effected method references into a lambda containing a normal "new" of
* the class.
*
* @param tree
*/
@Override
public
void
visitReference
(
JCMemberReference
tree
)
{
scan
(
tree
.
getQualifierExpression
());
contextMap
.
put
(
tree
,
makeReferenceContext
(
tree
));
if
(
tree
.
getMode
()
==
ReferenceMode
.
NEW
&&
tree
.
kind
!=
ReferenceKind
.
ARRAY_CTOR
&&
tree
.
sym
.
owner
.
isLocal
())
{
MethodSymbol
consSym
=
(
MethodSymbol
)
tree
.
sym
;
List
<
Type
>
ptypes
=
((
MethodType
)
consSym
.
type
).
getParameterTypes
();
Type
classType
=
consSym
.
owner
.
type
;
// Make new-class call
List
<
JCVariableDecl
>
params
=
make
.
Params
(
ptypes
,
owner
());
JCNewClass
nc
=
makeNewClass
(
classType
,
make
.
Idents
(
params
));
nc
.
pos
=
tree
.
pos
;
// Make lambda holding the new-class call
JCLambda
slam
=
make
.
Lambda
(
params
,
nc
);
slam
.
descriptorType
=
tree
.
descriptorType
;
slam
.
targets
=
tree
.
targets
;
slam
.
type
=
tree
.
type
;
slam
.
pos
=
tree
.
pos
;
// Now it is a lambda, process as such
visitLambda
(
slam
);
}
else
{
super
.
visitReference
(
tree
);
contextMap
.
put
(
tree
,
makeReferenceContext
(
tree
));
}
}
@Override
...
...
@@ -1240,10 +1284,8 @@ public class LambdaToMethod extends TreeTranslator {
}
localContext
=
localContext
.
prev
;
}
scan
(
tree
.
selected
);
}
else
{
super
.
visitSelect
(
tree
);
}
super
.
visitSelect
(
tree
);
}
@Override
...
...
test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestNewInnerImplicitArgs.java
0 → 100644
浏览文件 @
4a8cb00a
/*
* Copyright (c) 2013, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle 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 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 8011591
* @summary BootstrapMethodError when capturing constructor ref to local classes
* @run testng MethodReferenceTestNewInnerImplicitArgs
*/
import
org.testng.annotations.Test
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
/**
* Test the case that a constructor has implicit parameters added to
* access local variables and that this constructor is used in a
* method reference.
* @author Robert Field
*/
@Test
public
class
MethodReferenceTestNewInnerImplicitArgs
{
static
class
S
{
String
b
;
S
(
String
s
,
String
s2
)
{
b
=
s
+
s2
;
}
}
interface
I
{
S
m
();
}
interface
I2
{
S
m
(
int
i
,
int
j
);
}
public
static
void
testConstructorReferenceImplicitParameters
()
{
String
title
=
"Hey"
;
String
a2
=
"!!!"
;
class
MS
extends
S
{
MS
()
{
super
(
title
,
a2
);
}
}
I
result
=
MS:
:
new
;
assertEquals
(
result
.
m
().
b
,
"Hey!!!"
);
class
MS2
extends
S
{
MS2
(
int
x
,
int
y
)
{
super
(
title
+
x
,
a2
+
y
);
}
}
I2
result2
=
MS2:
:
new
;
assertEquals
(
result2
.
m
(
8
,
4
).
b
,
"Hey8!!!4"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录