1
1
/*
2
- * Copyright (c) 2005, 2020 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2005, 2021 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -188,16 +188,16 @@ public class JavacTrees extends DocTrees {
188
188
189
189
// called reflectively from Trees.instance(CompilationTask task)
190
190
public static JavacTrees instance (JavaCompiler .CompilationTask task ) {
191
- if (!(task instanceof BasicJavacTask ))
191
+ if (!(task instanceof BasicJavacTask basicJavacTask ))
192
192
throw new IllegalArgumentException ();
193
- return instance ((( BasicJavacTask ) task ) .getContext ());
193
+ return instance (basicJavacTask .getContext ());
194
194
}
195
195
196
196
// called reflectively from Trees.instance(ProcessingEnvironment env)
197
197
public static JavacTrees instance (ProcessingEnvironment env ) {
198
- if (!(env instanceof JavacProcessingEnvironment ))
198
+ if (!(env instanceof JavacProcessingEnvironment javacProcessingEnvironment ))
199
199
throw new IllegalArgumentException ();
200
- return instance ((( JavacProcessingEnvironment ) env ) .getContext ());
200
+ return instance (javacProcessingEnvironment .getContext ());
201
201
}
202
202
203
203
public static JavacTrees instance (Context context ) {
@@ -234,8 +234,8 @@ private void init(Context context) {
234
234
syms = Symtab .instance (context );
235
235
fileManager = context .get (JavaFileManager .class );
236
236
JavacTask t = context .get (JavacTask .class );
237
- if (t instanceof JavacTaskImpl )
238
- javacTaskImpl = ( JavacTaskImpl ) t ;
237
+ if (t instanceof JavacTaskImpl taskImpl )
238
+ javacTaskImpl = taskImpl ;
239
239
}
240
240
241
241
@ Override @ DefinedBy (Api .COMPILER_TREE )
@@ -264,8 +264,8 @@ public long getStartPosition(CompilationUnitTree file, DocCommentTree comment, D
264
264
@ Override @ DefinedBy (Api .COMPILER_TREE ) @ SuppressWarnings ("fallthrough" )
265
265
public long getEndPosition (CompilationUnitTree file , DocCommentTree comment , DocTree tree ) {
266
266
DCDocComment dcComment = (DCDocComment ) comment ;
267
- if (tree instanceof DCEndPosTree ) {
268
- int endPos = (( DCEndPosTree ) tree ) .getEndPos (dcComment );
267
+ if (tree instanceof DCEndPosTree <?> dcEndPosTree ) {
268
+ int endPos = dcEndPosTree .getEndPos (dcComment );
269
269
270
270
if (endPos != Position .NOPOS ) {
271
271
return endPos ;
@@ -431,11 +431,11 @@ public Symbol getElement(TreePath path) {
431
431
@ Override @ DefinedBy (Api .COMPILER_TREE )
432
432
public Element getElement (DocTreePath path ) {
433
433
DocTree tree = path .getLeaf ();
434
- if (tree instanceof DCReference )
435
- return attributeDocReference (path .getTreePath (), (( DCReference ) tree ) );
434
+ if (tree instanceof DCReference dcReference )
435
+ return attributeDocReference (path .getTreePath (), dcReference );
436
436
if (tree instanceof DCIdentifier ) {
437
- if (path .getParentPath ().getLeaf () instanceof DCParam ) {
438
- return attributeParamIdentifier (path .getTreePath (), ( DCParam ) path . getParentPath (). getLeaf () );
437
+ if (path .getParentPath ().getLeaf () instanceof DCParam dcParam ) {
438
+ return attributeParamIdentifier (path .getTreePath (), dcParam );
439
439
}
440
440
}
441
441
return null ;
@@ -444,14 +444,14 @@ public Element getElement(DocTreePath path) {
444
444
@ Override @ DefinedBy (Api .COMPILER_TREE )
445
445
public TypeMirror getType (DocTreePath path ) {
446
446
DocTree tree = path .getLeaf ();
447
- if (tree instanceof DCReference ) {
448
- JCTree qexpr = (( DCReference ) tree ) .qualifierExpression ;
447
+ if (tree instanceof DCReference dcReference ) {
448
+ JCTree qexpr = dcReference .qualifierExpression ;
449
449
if (qexpr != null ) {
450
450
Log .DeferredDiagnosticHandler deferredDiagnosticHandler =
451
451
new Log .DeferredDiagnosticHandler (log );
452
452
try {
453
453
Env <AttrContext > env = getAttrContext (path .getTreePath ());
454
- Type t = attr .attribType ((( DCReference ) tree ) .qualifierExpression , env );
454
+ Type t = attr .attribType (dcReference .qualifierExpression , env );
455
455
if (t != null && !t .isErroneous ()) {
456
456
return t ;
457
457
}
@@ -549,8 +549,8 @@ private Symbol attributeDocReference(TreePath path, DCReference ref) {
549
549
} else {
550
550
Type e = t ;
551
551
// If this is an array type convert to element type
552
- while (e instanceof ArrayType )
553
- e = (( ArrayType ) e ) .elemtype ;
552
+ while (e instanceof ArrayType arrayType )
553
+ e = arrayType .elemtype ;
554
554
tsym = e .tsym ;
555
555
memberName = (Name ) ref .memberName ;
556
556
}
@@ -808,10 +808,9 @@ public JavacScope getScope(TreePath path) {
808
808
public String getDocComment (TreePath path ) {
809
809
CompilationUnitTree t = path .getCompilationUnit ();
810
810
Tree leaf = path .getLeaf ();
811
- if (t instanceof JCTree .JCCompilationUnit && leaf instanceof JCTree ) {
812
- JCCompilationUnit cu = (JCCompilationUnit ) t ;
813
- if (cu .docComments != null ) {
814
- return cu .docComments .getCommentText ((JCTree ) leaf );
811
+ if (t instanceof JCTree .JCCompilationUnit compilationUnit && leaf instanceof JCTree tree ) {
812
+ if (compilationUnit .docComments != null ) {
813
+ return compilationUnit .docComments .getCommentText (tree );
815
814
}
816
815
}
817
816
return null ;
@@ -821,10 +820,9 @@ public String getDocComment(TreePath path) {
821
820
public DocCommentTree getDocCommentTree (TreePath path ) {
822
821
CompilationUnitTree t = path .getCompilationUnit ();
823
822
Tree leaf = path .getLeaf ();
824
- if (t instanceof JCTree .JCCompilationUnit && leaf instanceof JCTree ) {
825
- JCCompilationUnit cu = (JCCompilationUnit ) t ;
826
- if (cu .docComments != null ) {
827
- return cu .docComments .getCommentTree ((JCTree ) leaf );
823
+ if (t instanceof JCTree .JCCompilationUnit compilationUnit && leaf instanceof JCTree tree ) {
824
+ if (compilationUnit .docComments != null ) {
825
+ return compilationUnit .docComments .getCommentTree (tree );
828
826
}
829
827
}
830
828
return null ;
@@ -853,22 +851,17 @@ public DocCommentTree getDocCommentTree(Element e, String relativeFileName) thro
853
851
854
852
@ Override @ DefinedBy (Api .COMPILER_TREE )
855
853
public boolean isAccessible (Scope scope , TypeElement type ) {
856
- if (scope instanceof JavacScope && type instanceof ClassSymbol ) {
857
- Env <AttrContext > env = ((JavacScope ) scope ).env ;
858
- return resolve .isAccessible (env , (ClassSymbol )type , true );
859
- } else
860
- return false ;
854
+ return (scope instanceof JavacScope javacScope )
855
+ && (type instanceof ClassSymbol classSymbol )
856
+ && resolve .isAccessible (javacScope .env , classSymbol , true );
861
857
}
862
858
863
859
@ Override @ DefinedBy (Api .COMPILER_TREE )
864
860
public boolean isAccessible (Scope scope , Element member , DeclaredType type ) {
865
- if (scope instanceof JavacScope
866
- && member instanceof Symbol
867
- && type instanceof com .sun .tools .javac .code .Type ) {
868
- Env <AttrContext > env = ((JavacScope ) scope ).env ;
869
- return resolve .isAccessible (env , (com .sun .tools .javac .code .Type )type , (Symbol )member , true );
870
- } else
871
- return false ;
861
+ return (scope instanceof JavacScope javacScope )
862
+ && (member instanceof Symbol symbol )
863
+ && (type instanceof com .sun .tools .javac .code .Type codeType )
864
+ && resolve .isAccessible (javacScope .env , codeType , symbol , true );
872
865
}
873
866
874
867
private Env <AttrContext > getAttrContext (TreePath path ) {
@@ -1071,10 +1064,9 @@ public void visitVarDef(JCVariableDecl tree) {
1071
1064
static JavaFileObject asJavaFileObject (FileObject fileObject ) {
1072
1065
JavaFileObject jfo = null ;
1073
1066
1074
- if (fileObject instanceof JavaFileObject ) {
1075
- jfo = (JavaFileObject ) fileObject ;
1067
+ if (fileObject instanceof JavaFileObject javaFileObject ) {
1076
1068
checkHtmlKind (fileObject , Kind .HTML );
1077
- return jfo ;
1069
+ return javaFileObject ;
1078
1070
}
1079
1071
1080
1072
checkHtmlKind (fileObject );
@@ -1217,17 +1209,16 @@ protected Copier createCopier(TreeMaker maker) {
1217
1209
*/
1218
1210
@ Override @ DefinedBy (Api .COMPILER_TREE )
1219
1211
public TypeMirror getOriginalType (javax .lang .model .type .ErrorType errorType ) {
1220
- if (errorType instanceof com .sun .tools .javac .code .Type .ErrorType ) {
1221
- return (( com . sun . tools . javac . code . Type . ErrorType ) errorType ) .getOriginalType ();
1212
+ if (errorType instanceof com .sun .tools .javac .code .Type .ErrorType targetErrorType ) {
1213
+ return targetErrorType .getOriginalType ();
1222
1214
}
1223
- if (errorType instanceof com .sun .tools .javac .code .Type .ClassType &&
1215
+ if (errorType instanceof com .sun .tools .javac .code .Type .ClassType classType &&
1224
1216
errorType .getKind () == TypeKind .ERROR ) {
1225
- ClassType ct = (ClassType ) errorType ;
1226
- return extraType2OriginalMap .computeIfAbsent (ct , tt ->
1227
- new ClassType (ct .getEnclosingType (), ct .typarams_field ,
1228
- ct .tsym , ct .getMetadata ()) {
1217
+ return extraType2OriginalMap .computeIfAbsent (classType , tt ->
1218
+ new ClassType (classType .getEnclosingType (), classType .typarams_field ,
1219
+ classType .tsym , classType .getMetadata ()) {
1229
1220
@ Override
1230
- public Type baseType () { return ct ; }
1221
+ public Type baseType () { return classType ; }
1231
1222
@ Override
1232
1223
public TypeKind getKind () {
1233
1224
return TypeKind .DECLARED ;
0 commit comments