Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
06dede83
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看板
提交
06dede83
编写于
11月 01, 2012
作者:
O
ohrstrom
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7153951: Add new lint option -Xlint:auxiliaryclass
Reviewed-by: jjg, mcimadamore, forax
上级
5e89ded1
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
289 addition
and
5 deletion
+289
-5
src/share/classes/com/sun/tools/javac/code/Flags.java
src/share/classes/com/sun/tools/javac/code/Flags.java
+6
-0
src/share/classes/com/sun/tools/javac/code/Lint.java
src/share/classes/com/sun/tools/javac/code/Lint.java
+7
-0
src/share/classes/com/sun/tools/javac/comp/Attr.java
src/share/classes/com/sun/tools/javac/comp/Attr.java
+1
-0
src/share/classes/com/sun/tools/javac/comp/Check.java
src/share/classes/com/sun/tools/javac/comp/Check.java
+16
-0
src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
+7
-5
src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
+9
-0
src/share/classes/com/sun/tools/javac/resources/compiler.properties
...classes/com/sun/tools/javac/resources/compiler.properties
+5
-0
test/tools/javac/diags/examples/AuxiliaryClassWarning/ClassUsingAuxiliary.java
...s/examples/AuxiliaryClassWarning/ClassUsingAuxiliary.java
+29
-0
test/tools/javac/diags/examples/AuxiliaryClassWarning/ClassWithAuxiliary.java
...gs/examples/AuxiliaryClassWarning/ClassWithAuxiliary.java
+29
-0
test/tools/javac/warnings/AuxiliaryClass/ClassUsingAnotherAuxiliary.java
...c/warnings/AuxiliaryClass/ClassUsingAnotherAuxiliary.java
+34
-0
test/tools/javac/warnings/AuxiliaryClass/ClassUsingAnotherAuxiliary.out
...ac/warnings/AuxiliaryClass/ClassUsingAnotherAuxiliary.out
+4
-0
test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary.java
...ls/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary.java
+34
-0
test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary1.out
...ls/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary1.out
+4
-0
test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary2.out
...ls/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary2.out
+4
-0
test/tools/javac/warnings/AuxiliaryClass/ClassWithAuxiliary.java
...ols/javac/warnings/AuxiliaryClass/ClassWithAuxiliary.java
+31
-0
test/tools/javac/warnings/AuxiliaryClass/NotAClassName.java
test/tools/javac/warnings/AuxiliaryClass/NotAClassName.java
+25
-0
test/tools/javac/warnings/AuxiliaryClass/SelfClassWithAux.java
...tools/javac/warnings/AuxiliaryClass/SelfClassWithAux.java
+44
-0
未找到文件。
src/share/classes/com/sun/tools/javac/code/Flags.java
浏览文件 @
06dede83
...
...
@@ -258,6 +258,12 @@ public class Flags {
*/
public
static
final
long
DEFAULT
=
1L
<<
43
;
/**
* Flag that marks class as auxiliary, ie a non-public class following
* the public class in a source file, that could block implicit compilation.
*/
public
static
final
long
AUXILIARY
=
1L
<<
43
;
/** Modifier masks.
*/
public
static
final
int
...
...
src/share/classes/com/sun/tools/javac/code/Lint.java
浏览文件 @
06dede83
...
...
@@ -128,6 +128,13 @@ public class Lint
* Categories of warnings that can be generated by the compiler.
*/
public
enum
LintCategory
{
/**
* Warn when code refers to a auxiliary class that is hidden in a source file (ie source file name is
* different from the class name, and the type is not properly nested) and the referring code
* is not located in the same source file.
*/
AUXILIARYCLASS
(
"auxiliaryclass"
),
/**
* Warn about use of unnecessary casts.
*/
...
...
src/share/classes/com/sun/tools/javac/comp/Attr.java
浏览文件 @
06dede83
...
...
@@ -3050,6 +3050,7 @@ public class Attr extends JCTree.Visitor {
// except for two situations:
owntype
=
sym
.
type
;
if
(
owntype
.
hasTag
(
CLASS
))
{
chk
.
checkForBadAuxiliaryClassAccess
(
tree
.
pos
(),
env
,
(
ClassSymbol
)
sym
);
Type
ownOuter
=
owntype
.
getEnclosingType
();
// (a) If the symbol's type is parameterized, erase it
...
...
src/share/classes/com/sun/tools/javac/comp/Check.java
浏览文件 @
06dede83
...
...
@@ -27,6 +27,7 @@ package com.sun.tools.javac.comp;
import
java.util.*
;
import
java.util.Set
;
import
javax.tools.JavaFileManager
;
import
com.sun.tools.javac.code.*
;
import
com.sun.tools.javac.jvm.*
;
...
...
@@ -77,6 +78,7 @@ public class Check {
private
boolean
suppressAbortOnBadClassFile
;
private
boolean
enableSunApiLintControl
;
private
final
TreeInfo
treeinfo
;
private
final
JavaFileManager
fileManager
;
// The set of lint options currently in effect. It is initialized
// from the context, and then is set/reset as needed by Attr as it
...
...
@@ -109,6 +111,7 @@ public class Check {
Options
options
=
Options
.
instance
(
context
);
lint
=
Lint
.
instance
(
context
);
treeinfo
=
TreeInfo
.
instance
(
context
);
fileManager
=
context
.
get
(
JavaFileManager
.
class
);
Source
source
=
Source
.
instance
(
context
);
allowGenerics
=
source
.
allowGenerics
();
...
...
@@ -3230,6 +3233,19 @@ public class Check {
return
true
;
}
/** Check that an auxiliary class is not accessed from any other file than its own.
*/
void
checkForBadAuxiliaryClassAccess
(
DiagnosticPosition
pos
,
Env
<
AttrContext
>
env
,
ClassSymbol
c
)
{
if
(
lint
.
isEnabled
(
Lint
.
LintCategory
.
AUXILIARYCLASS
)
&&
(
c
.
flags
()
&
AUXILIARY
)
!=
0
&&
rs
.
isAccessible
(
env
,
c
)
&&
!
fileManager
.
isSameFile
(
c
.
sourcefile
,
env
.
toplevel
.
sourcefile
))
{
log
.
warning
(
pos
,
"auxiliary.class.accessed.from.outside.of.its.source.file"
,
c
,
c
.
sourcefile
);
}
}
private
class
ConversionWarner
extends
Warner
{
final
String
uncheckedKey
;
final
Type
found
;
...
...
src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
浏览文件 @
06dede83
...
...
@@ -1022,11 +1022,13 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
// name as a top-level package.
if
(
checkClash
&&
c
.
owner
.
kind
==
PCK
&&
c
.
owner
!=
syms
.
unnamedPackage
&&
reader
.
packageExists
(
c
.
fullname
))
{
log
.
error
(
tree
.
pos
,
"clash.with.pkg.of.same.name"
,
Kinds
.
kindName
(
sym
),
c
);
}
reader
.
packageExists
(
c
.
fullname
))
{
log
.
error
(
tree
.
pos
,
"clash.with.pkg.of.same.name"
,
Kinds
.
kindName
(
sym
),
c
);
}
if
(
c
.
owner
.
kind
==
PCK
&&
(
c
.
flags_field
&
PUBLIC
)
==
0
&&
!
env
.
toplevel
.
sourcefile
.
isNameCompatible
(
c
.
name
.
toString
(),
JavaFileObject
.
Kind
.
SOURCE
))
{
c
.
flags_field
|=
AUXILIARY
;
}
}
catch
(
CompletionFailure
ex
)
{
chk
.
completionError
(
tree
.
pos
(),
ex
);
}
finally
{
...
...
src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
浏览文件 @
06dede83
...
...
@@ -1018,6 +1018,15 @@ public class ClassReader implements Completer {
ClassSymbol
c
=
(
ClassSymbol
)
sym
;
Name
n
=
readName
(
nextChar
());
c
.
sourcefile
=
new
SourceFileObject
(
n
,
c
.
flatname
);
// If the class is a toplevel class, originating from a Java source file,
// but the class name does not match the file name, then it is
// an auxiliary class.
String
sn
=
n
.
toString
();
if
(
c
.
owner
.
kind
==
Kinds
.
PCK
&&
sn
.
endsWith
(
".java"
)
&&
!
sn
.
equals
(
c
.
name
.
toString
()+
".java"
))
{
c
.
flags_field
|=
AUXILIARY
;
}
}
},
...
...
src/share/classes/com/sun/tools/javac/resources/compiler.properties
浏览文件 @
06dede83
...
...
@@ -1847,6 +1847,11 @@ compiler.misc.varargs.argument.mismatch=\
#####
# 0: type, 1: file name
compiler.warn.auxiliary.class.accessed.from.outside.of.its.source.file
=
\
auxiliary class {0} in {1} should not be accessed from outside its own source file
## The first argument ({0}) is a "kindname".
# 0: symbol kind, 1: symbol, 2: symbol
compiler.err.abstract.cant.be.accessed.directly
=
\
...
...
test/tools/javac/diags/examples/AuxiliaryClassWarning/ClassUsingAuxiliary.java
0 → 100644
浏览文件 @
06dede83
/*
* Copyright (c) 2012, 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.
*/
// key: compiler.warn.auxiliary.class.accessed.from.outside.of.its.source.file
// options: -Xlint:auxiliaryclass
class
ClassUsingAuxiliary
{
AuxiliaryClass
ahem
;
}
test/tools/javac/diags/examples/AuxiliaryClassWarning/ClassWithAuxiliary.java
0 → 100644
浏览文件 @
06dede83
/*
* Copyright (c) 2012, 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.
*/
class
ClassWithAuxiliaryClass
{
}
// Auxiliary class that cannot be found through implicit compilation.
class
AuxiliaryClass
{
}
test/tools/javac/warnings/AuxiliaryClass/ClassUsingAnotherAuxiliary.java
0 → 100644
浏览文件 @
06dede83
/*
* Copyright (c) 2012, 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
* @compile ClassUsingAnotherAuxiliary.java NotAClassName.java
* @compile -Xlint:auxiliaryclass ClassUsingAnotherAuxiliary.java NotAClassName.java
* @compile/fail/ref=ClassUsingAnotherAuxiliary.out -XDrawDiagnostics -Werror -Xlint:auxiliaryclass ClassUsingAnotherAuxiliary.java NotAClassName.java
*/
class
ClassUsingAnotherAuxiliary
{
AnAuxiliaryClass
ahem
;
}
test/tools/javac/warnings/AuxiliaryClass/ClassUsingAnotherAuxiliary.out
0 → 100644
浏览文件 @
06dede83
ClassUsingAnotherAuxiliary.java:32:5: compiler.warn.auxiliary.class.accessed.from.outside.of.its.source.file: AnAuxiliaryClass, NotAClassName.java
- compiler.err.warnings.and.werror
1 error
1 warning
test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary.java
0 → 100644
浏览文件 @
06dede83
/*
* Copyright (c) 2012, 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
* @clean ClassUsingAuxiliary ClassWithAuxiliary AuxiliaryClass ClassWithAuxiliary$NotAnAuxiliaryClass ClassWithAuxiliary$NotAnAuxiliaryClassEither
* @run compile ClassUsingAuxiliary.java ClassWithAuxiliary.java
* @run compile/fail/ref=ClassUsingAuxiliary1.out -XDrawDiagnostics -Werror -Xlint:auxiliaryclass ClassUsingAuxiliary.java ClassWithAuxiliary.java
* @run compile/fail/ref=ClassUsingAuxiliary2.out -XDrawDiagnostics -Werror -Xlint:auxiliaryclass ClassUsingAuxiliary.java
*/
class
ClassUsingAuxiliary
{
AuxiliaryClass
ahem
;
}
test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary1.out
0 → 100644
浏览文件 @
06dede83
ClassUsingAuxiliary.java:33:5: compiler.warn.auxiliary.class.accessed.from.outside.of.its.source.file: AuxiliaryClass, ClassWithAuxiliary.java
- compiler.err.warnings.and.werror
1 error
1 warning
test/tools/javac/warnings/AuxiliaryClass/ClassUsingAuxiliary2.out
0 → 100644
浏览文件 @
06dede83
ClassUsingAuxiliary.java:33:5: compiler.warn.auxiliary.class.accessed.from.outside.of.its.source.file: AuxiliaryClass, ClassWithAuxiliary.java
- compiler.err.warnings.and.werror
1 error
1 warning
test/tools/javac/warnings/AuxiliaryClass/ClassWithAuxiliary.java
0 → 100644
浏览文件 @
06dede83
/*
* Copyright (c) 2012, 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.
*/
public
class
ClassWithAuxiliary
{
public
static
class
NotAnAuxiliaryClass
{
}
public
class
NotAnAuxiliaryClassEither
{
}
}
// Auxiliary class that cannot be found through implicit compilation.
class
AuxiliaryClass
{
}
test/tools/javac/warnings/AuxiliaryClass/NotAClassName.java
0 → 100644
浏览文件 @
06dede83
/*
* Copyright (c) 2012, 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.
*/
class
AnAuxiliaryClass
{
}
test/tools/javac/warnings/AuxiliaryClass/SelfClassWithAux.java
0 → 100644
浏览文件 @
06dede83
/*
* Copyright (c) 2012, 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 that an auxiliary class referenced from its own source file,
* does not trigger the warning. Such code does not prevent implicit
* compilation. Also test that references to inner classes do not trigger the warning.
*/
/*
* @test
* @run compile -Werror -Xlint:auxiliaryclass SelfClassWithAux.java ClassWithAuxiliary.java
* @run compile -Werror -Xlint:auxiliaryclass SelfClassWithAux.java
*/
class
SelfClassWithAux
{
Aux
aux
;
ClassWithAuxiliary
.
NotAnAuxiliaryClass
alfa
;
ClassWithAuxiliary
.
NotAnAuxiliaryClassEither
beta
;
}
class
Aux
{
Aux
aux
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录