8265899: Use pattern matching for instanceof at module jdk.compiler(part 1)
Reviewed-by: mcimadamore
This commit is contained in:
parent
a6f2863e64
commit
41daa88dcc
src/jdk.compiler/share/classes/com/sun/tools/javac
api
ClientCodeWrapper.javaJavacScope.javaJavacTaskImpl.javaJavacTaskPool.javaJavacTool.javaJavacTrees.java
file
main
model
platform
tree
util
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2021, 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
|
||||
@ -119,9 +119,9 @@ public class ClientCodeWrapper {
|
||||
public JavaFileManager wrap(JavaFileManager fm) {
|
||||
if (isTrusted(fm))
|
||||
return fm;
|
||||
if (fm instanceof StandardJavaFileManager)
|
||||
return new WrappedStandardJavaFileManager((StandardJavaFileManager) fm);
|
||||
return new WrappedJavaFileManager(fm);
|
||||
return (fm instanceof StandardJavaFileManager standardJavaFileManager) ?
|
||||
new WrappedStandardJavaFileManager(standardJavaFileManager) :
|
||||
new WrappedJavaFileManager(fm);
|
||||
}
|
||||
|
||||
public FileObject wrap(FileObject fo) {
|
||||
@ -131,10 +131,8 @@ public class ClientCodeWrapper {
|
||||
}
|
||||
|
||||
FileObject unwrap(FileObject fo) {
|
||||
if (fo instanceof WrappedFileObject)
|
||||
return ((WrappedFileObject) fo).clientFileObject;
|
||||
else
|
||||
return fo;
|
||||
return (fo instanceof WrappedFileObject wrappedFileObject) ?
|
||||
wrappedFileObject.clientFileObject : fo;
|
||||
}
|
||||
|
||||
public JavaFileObject wrap(JavaFileObject fo) {
|
||||
@ -151,10 +149,8 @@ public class ClientCodeWrapper {
|
||||
}
|
||||
|
||||
JavaFileObject unwrap(JavaFileObject fo) {
|
||||
if (fo instanceof WrappedJavaFileObject)
|
||||
return ((JavaFileObject) ((WrappedJavaFileObject) fo).clientFileObject);
|
||||
else
|
||||
return fo;
|
||||
return (fo instanceof WrappedJavaFileObject wrappedJavaFileObject) ?
|
||||
((JavaFileObject) wrappedJavaFileObject.clientFileObject) : fo;
|
||||
}
|
||||
|
||||
public <T /*super JavaFileObject*/> DiagnosticListener<T> wrap(DiagnosticListener<T> dl) {
|
||||
@ -170,10 +166,8 @@ public class ClientCodeWrapper {
|
||||
}
|
||||
|
||||
TaskListener unwrap(TaskListener l) {
|
||||
if (l instanceof WrappedTaskListener)
|
||||
return ((WrappedTaskListener) l).clientTaskListener;
|
||||
else
|
||||
return l;
|
||||
return (l instanceof WrappedTaskListener wrappedTaskListener) ?
|
||||
wrappedTaskListener.clientTaskListener : l;
|
||||
}
|
||||
|
||||
Collection<TaskListener> unwrap(Collection<? extends TaskListener> listeners) {
|
||||
@ -185,12 +179,8 @@ public class ClientCodeWrapper {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> Diagnostic<T> unwrap(final Diagnostic<T> diagnostic) {
|
||||
if (diagnostic instanceof JCDiagnostic) {
|
||||
JCDiagnostic d = (JCDiagnostic) diagnostic;
|
||||
return (Diagnostic<T>) new DiagnosticSourceUnwrapper(d);
|
||||
} else {
|
||||
return diagnostic;
|
||||
}
|
||||
return (diagnostic instanceof JCDiagnostic jcDiagnostic) ?
|
||||
(Diagnostic<T>) new DiagnosticSourceUnwrapper(jcDiagnostic) : diagnostic;
|
||||
}
|
||||
|
||||
protected boolean isTrusted(Object o) {
|
||||
|
@ -127,12 +127,9 @@ public class JavacScope implements com.sun.source.tree.Scope {
|
||||
}
|
||||
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof JavacScope) {
|
||||
JavacScope s = (JavacScope) other;
|
||||
return (env.equals(s.env)
|
||||
&& isStarImportScope() == s.isStarImportScope());
|
||||
} else
|
||||
return false;
|
||||
return other instanceof JavacScope javacScope
|
||||
&& env.equals(javacScope.env)
|
||||
&& isStarImportScope() == javacScope.isStarImportScope();
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2021, 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
|
||||
@ -232,7 +232,7 @@ public class JavacTaskImpl extends BasicJavacTask {
|
||||
void cleanup() {
|
||||
if (compiler != null)
|
||||
compiler.close();
|
||||
if (fileManager instanceof BaseFileManager && ((BaseFileManager) fileManager).autoClose) {
|
||||
if (fileManager instanceof BaseFileManager baseFileManager && baseFileManager.autoClose) {
|
||||
try {
|
||||
fileManager.close();
|
||||
} catch (IOException ignore) {
|
||||
@ -321,10 +321,10 @@ public class JavacTaskImpl extends BasicJavacTask {
|
||||
}
|
||||
else {
|
||||
for (CompilationUnitTree cu : trees) {
|
||||
if (cu instanceof JCCompilationUnit) {
|
||||
if (cu instanceof JCCompilationUnit compilationUnit) {
|
||||
if (roots == null)
|
||||
roots = new ListBuffer<>();
|
||||
roots.append((JCCompilationUnit)cu);
|
||||
roots.append(compilationUnit);
|
||||
notYetEntered.remove(cu.getSourceFile());
|
||||
}
|
||||
else
|
||||
|
@ -295,10 +295,9 @@ public class JavacTaskPool {
|
||||
TreeScanner<Void, Symtab> pollutionScanner = new TreeScanner<Void, Symtab>() {
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
public Void scan(Tree tree, Symtab syms) {
|
||||
if (tree instanceof LetExpr) {
|
||||
LetExpr le = (LetExpr) tree;
|
||||
scan(le.defs, syms);
|
||||
scan(le.expr, syms);
|
||||
if (tree instanceof LetExpr letExpr) {
|
||||
scan(letExpr.defs, syms);
|
||||
scan(letExpr.expr, syms);
|
||||
return null;
|
||||
} else {
|
||||
return super.scan(tree, syms);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2021, 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
|
||||
@ -173,8 +173,8 @@ public final class JavacTool implements JavaCompiler {
|
||||
|
||||
if (fileManager == null) {
|
||||
fileManager = getStandardFileManager(diagnosticListener, null, null);
|
||||
if (fileManager instanceof BaseFileManager) {
|
||||
((BaseFileManager) fileManager).autoClose = true;
|
||||
if (fileManager instanceof BaseFileManager baseFileManager) {
|
||||
baseFileManager.autoClose = true;
|
||||
}
|
||||
}
|
||||
fileManager = ccw.wrap(fileManager);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2021, 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
|
||||
@ -188,16 +188,16 @@ public class JavacTrees extends DocTrees {
|
||||
|
||||
// called reflectively from Trees.instance(CompilationTask task)
|
||||
public static JavacTrees instance(JavaCompiler.CompilationTask task) {
|
||||
if (!(task instanceof BasicJavacTask))
|
||||
if (!(task instanceof BasicJavacTask basicJavacTask))
|
||||
throw new IllegalArgumentException();
|
||||
return instance(((BasicJavacTask)task).getContext());
|
||||
return instance(basicJavacTask.getContext());
|
||||
}
|
||||
|
||||
// called reflectively from Trees.instance(ProcessingEnvironment env)
|
||||
public static JavacTrees instance(ProcessingEnvironment env) {
|
||||
if (!(env instanceof JavacProcessingEnvironment))
|
||||
if (!(env instanceof JavacProcessingEnvironment javacProcessingEnvironment))
|
||||
throw new IllegalArgumentException();
|
||||
return instance(((JavacProcessingEnvironment)env).getContext());
|
||||
return instance(javacProcessingEnvironment.getContext());
|
||||
}
|
||||
|
||||
public static JavacTrees instance(Context context) {
|
||||
@ -234,8 +234,8 @@ public class JavacTrees extends DocTrees {
|
||||
syms = Symtab.instance(context);
|
||||
fileManager = context.get(JavaFileManager.class);
|
||||
JavacTask t = context.get(JavacTask.class);
|
||||
if (t instanceof JavacTaskImpl)
|
||||
javacTaskImpl = (JavacTaskImpl) t;
|
||||
if (t instanceof JavacTaskImpl taskImpl)
|
||||
javacTaskImpl = taskImpl;
|
||||
}
|
||||
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
@ -264,8 +264,8 @@ public class JavacTrees extends DocTrees {
|
||||
@Override @DefinedBy(Api.COMPILER_TREE) @SuppressWarnings("fallthrough")
|
||||
public long getEndPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) {
|
||||
DCDocComment dcComment = (DCDocComment) comment;
|
||||
if (tree instanceof DCEndPosTree) {
|
||||
int endPos = ((DCEndPosTree) tree).getEndPos(dcComment);
|
||||
if (tree instanceof DCEndPosTree<?> dcEndPosTree) {
|
||||
int endPos = dcEndPosTree.getEndPos(dcComment);
|
||||
|
||||
if (endPos != Position.NOPOS) {
|
||||
return endPos;
|
||||
@ -431,11 +431,11 @@ public class JavacTrees extends DocTrees {
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
public Element getElement(DocTreePath path) {
|
||||
DocTree tree = path.getLeaf();
|
||||
if (tree instanceof DCReference)
|
||||
return attributeDocReference(path.getTreePath(), ((DCReference) tree));
|
||||
if (tree instanceof DCReference dcReference)
|
||||
return attributeDocReference(path.getTreePath(), dcReference);
|
||||
if (tree instanceof DCIdentifier) {
|
||||
if (path.getParentPath().getLeaf() instanceof DCParam) {
|
||||
return attributeParamIdentifier(path.getTreePath(), (DCParam) path.getParentPath().getLeaf());
|
||||
if (path.getParentPath().getLeaf() instanceof DCParam dcParam) {
|
||||
return attributeParamIdentifier(path.getTreePath(), dcParam);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -444,14 +444,14 @@ public class JavacTrees extends DocTrees {
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
public TypeMirror getType(DocTreePath path) {
|
||||
DocTree tree = path.getLeaf();
|
||||
if (tree instanceof DCReference) {
|
||||
JCTree qexpr = ((DCReference)tree).qualifierExpression;
|
||||
if (tree instanceof DCReference dcReference) {
|
||||
JCTree qexpr = dcReference.qualifierExpression;
|
||||
if (qexpr != null) {
|
||||
Log.DeferredDiagnosticHandler deferredDiagnosticHandler =
|
||||
new Log.DeferredDiagnosticHandler(log);
|
||||
try {
|
||||
Env<AttrContext> env = getAttrContext(path.getTreePath());
|
||||
Type t = attr.attribType(((DCReference) tree).qualifierExpression, env);
|
||||
Type t = attr.attribType(dcReference.qualifierExpression, env);
|
||||
if (t != null && !t.isErroneous()) {
|
||||
return t;
|
||||
}
|
||||
@ -549,8 +549,8 @@ public class JavacTrees extends DocTrees {
|
||||
} else {
|
||||
Type e = t;
|
||||
// If this is an array type convert to element type
|
||||
while (e instanceof ArrayType)
|
||||
e = ((ArrayType) e).elemtype;
|
||||
while (e instanceof ArrayType arrayType)
|
||||
e = arrayType.elemtype;
|
||||
tsym = e.tsym;
|
||||
memberName = (Name) ref.memberName;
|
||||
}
|
||||
@ -808,10 +808,9 @@ public class JavacTrees extends DocTrees {
|
||||
public String getDocComment(TreePath path) {
|
||||
CompilationUnitTree t = path.getCompilationUnit();
|
||||
Tree leaf = path.getLeaf();
|
||||
if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) {
|
||||
JCCompilationUnit cu = (JCCompilationUnit) t;
|
||||
if (cu.docComments != null) {
|
||||
return cu.docComments.getCommentText((JCTree) leaf);
|
||||
if (t instanceof JCTree.JCCompilationUnit compilationUnit && leaf instanceof JCTree tree) {
|
||||
if (compilationUnit.docComments != null) {
|
||||
return compilationUnit.docComments.getCommentText(tree);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -821,10 +820,9 @@ public class JavacTrees extends DocTrees {
|
||||
public DocCommentTree getDocCommentTree(TreePath path) {
|
||||
CompilationUnitTree t = path.getCompilationUnit();
|
||||
Tree leaf = path.getLeaf();
|
||||
if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) {
|
||||
JCCompilationUnit cu = (JCCompilationUnit) t;
|
||||
if (cu.docComments != null) {
|
||||
return cu.docComments.getCommentTree((JCTree) leaf);
|
||||
if (t instanceof JCTree.JCCompilationUnit compilationUnit && leaf instanceof JCTree tree) {
|
||||
if (compilationUnit.docComments != null) {
|
||||
return compilationUnit.docComments.getCommentTree(tree);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -853,22 +851,17 @@ public class JavacTrees extends DocTrees {
|
||||
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
public boolean isAccessible(Scope scope, TypeElement type) {
|
||||
if (scope instanceof JavacScope && type instanceof ClassSymbol) {
|
||||
Env<AttrContext> env = ((JavacScope) scope).env;
|
||||
return resolve.isAccessible(env, (ClassSymbol)type, true);
|
||||
} else
|
||||
return false;
|
||||
return (scope instanceof JavacScope javacScope)
|
||||
&& (type instanceof ClassSymbol classSymbol)
|
||||
&& resolve.isAccessible(javacScope.env, classSymbol, true);
|
||||
}
|
||||
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
public boolean isAccessible(Scope scope, Element member, DeclaredType type) {
|
||||
if (scope instanceof JavacScope
|
||||
&& member instanceof Symbol
|
||||
&& type instanceof com.sun.tools.javac.code.Type) {
|
||||
Env<AttrContext> env = ((JavacScope) scope).env;
|
||||
return resolve.isAccessible(env, (com.sun.tools.javac.code.Type)type, (Symbol)member, true);
|
||||
} else
|
||||
return false;
|
||||
return (scope instanceof JavacScope javacScope)
|
||||
&& (member instanceof Symbol symbol)
|
||||
&& (type instanceof com.sun.tools.javac.code.Type codeType)
|
||||
&& resolve.isAccessible(javacScope.env, codeType, symbol, true);
|
||||
}
|
||||
|
||||
private Env<AttrContext> getAttrContext(TreePath path) {
|
||||
@ -1071,10 +1064,9 @@ public class JavacTrees extends DocTrees {
|
||||
static JavaFileObject asJavaFileObject(FileObject fileObject) {
|
||||
JavaFileObject jfo = null;
|
||||
|
||||
if (fileObject instanceof JavaFileObject) {
|
||||
jfo = (JavaFileObject) fileObject;
|
||||
if (fileObject instanceof JavaFileObject javaFileObject) {
|
||||
checkHtmlKind(fileObject, Kind.HTML);
|
||||
return jfo;
|
||||
return javaFileObject;
|
||||
}
|
||||
|
||||
checkHtmlKind(fileObject);
|
||||
@ -1217,17 +1209,16 @@ public class JavacTrees extends DocTrees {
|
||||
*/
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
public TypeMirror getOriginalType(javax.lang.model.type.ErrorType errorType) {
|
||||
if (errorType instanceof com.sun.tools.javac.code.Type.ErrorType) {
|
||||
return ((com.sun.tools.javac.code.Type.ErrorType)errorType).getOriginalType();
|
||||
if (errorType instanceof com.sun.tools.javac.code.Type.ErrorType targetErrorType) {
|
||||
return targetErrorType.getOriginalType();
|
||||
}
|
||||
if (errorType instanceof com.sun.tools.javac.code.Type.ClassType &&
|
||||
if (errorType instanceof com.sun.tools.javac.code.Type.ClassType classType &&
|
||||
errorType.getKind() == TypeKind.ERROR) {
|
||||
ClassType ct = (ClassType) errorType;
|
||||
return extraType2OriginalMap.computeIfAbsent(ct, tt ->
|
||||
new ClassType(ct.getEnclosingType(), ct.typarams_field,
|
||||
ct.tsym, ct.getMetadata()) {
|
||||
return extraType2OriginalMap.computeIfAbsent(classType, tt ->
|
||||
new ClassType(classType.getEnclosingType(), classType.typarams_field,
|
||||
classType.tsym, classType.getMetadata()) {
|
||||
@Override
|
||||
public Type baseType() { return ct; }
|
||||
public Type baseType() { return classType; }
|
||||
@Override
|
||||
public TypeKind getKind() {
|
||||
return TypeKind.DECLARED;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2021, 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
|
||||
@ -229,8 +229,8 @@ public class JRTIndex {
|
||||
}
|
||||
|
||||
public boolean isInJRT(FileObject fo) {
|
||||
if (fo instanceof PathFileObject) {
|
||||
Path path = ((PathFileObject) fo).getPath();
|
||||
if (fo instanceof PathFileObject pathFileObject) {
|
||||
Path path = pathFileObject.getPath();
|
||||
return (path.getFileSystem() == jrtfs);
|
||||
} else {
|
||||
return false;
|
||||
|
@ -790,8 +790,8 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
|
||||
return null;
|
||||
}
|
||||
|
||||
if (file instanceof PathFileObject) {
|
||||
return ((PathFileObject) file).inferBinaryName(path);
|
||||
if (file instanceof PathFileObject pathFileObject) {
|
||||
return pathFileObject.inferBinaryName(path);
|
||||
} else
|
||||
throw new IllegalArgumentException(file.getClass().getName());
|
||||
}
|
||||
@ -800,8 +800,8 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
|
||||
public boolean isSameFile(FileObject a, FileObject b) {
|
||||
nullCheck(a);
|
||||
nullCheck(b);
|
||||
if (a instanceof PathFileObject && b instanceof PathFileObject)
|
||||
return ((PathFileObject) a).isSameFile((PathFileObject) b);
|
||||
if (a instanceof PathFileObject pathFileObjectA && b instanceof PathFileObject pathFileObjectB)
|
||||
return pathFileObjectA.isSameFile(pathFileObjectB);
|
||||
return a.equals(b);
|
||||
}
|
||||
|
||||
@ -908,8 +908,8 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
|
||||
dir = getClassOutDir();
|
||||
} else {
|
||||
String baseName = fileName.basename();
|
||||
if (sibling != null && sibling instanceof PathFileObject) {
|
||||
return ((PathFileObject) sibling).getSibling(baseName);
|
||||
if (sibling != null && sibling instanceof PathFileObject pathFileObject) {
|
||||
return pathFileObject.getSibling(baseName);
|
||||
} else {
|
||||
Path p = getPath(baseName);
|
||||
Path real = fsInfo.getCanonicalFile(p);
|
||||
@ -943,8 +943,8 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
|
||||
Iterable<? extends File> files)
|
||||
{
|
||||
ArrayList<PathFileObject> result;
|
||||
if (files instanceof Collection<?>)
|
||||
result = new ArrayList<>(((Collection<?>)files).size());
|
||||
if (files instanceof Collection<?> collection)
|
||||
result = new ArrayList<>(collection.size());
|
||||
else
|
||||
result = new ArrayList<>();
|
||||
for (File f: files) {
|
||||
@ -957,17 +957,16 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
|
||||
}
|
||||
|
||||
@Override @DefinedBy(Api.COMPILER)
|
||||
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromPaths(
|
||||
Collection<? extends Path> paths)
|
||||
{
|
||||
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromPaths(Collection<? extends Path> paths) {
|
||||
ArrayList<PathFileObject> result;
|
||||
if (paths instanceof Collection<?>)
|
||||
result = new ArrayList<>(((Collection<?>)paths).size());
|
||||
else
|
||||
if (paths != null) {
|
||||
result = new ArrayList<>(paths.size());
|
||||
for (Path p: paths)
|
||||
result.add(PathFileObject.forSimplePath(this,
|
||||
fsInfo.getCanonicalFile(p), p));
|
||||
} else {
|
||||
result = new ArrayList<>();
|
||||
for (Path p: paths)
|
||||
result.add(PathFileObject.forSimplePath(this,
|
||||
fsInfo.getCanonicalFile(p), p));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1100,13 +1099,10 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || !(o instanceof PathAndContainer)) {
|
||||
return false;
|
||||
}
|
||||
PathAndContainer that = (PathAndContainer) o;
|
||||
return path.equals(that.path)
|
||||
&& container.equals(that.container)
|
||||
&& index == that.index;
|
||||
return (o instanceof PathAndContainer pathAndContainer)
|
||||
&& path.equals(pathAndContainer.path)
|
||||
&& container.equals(pathAndContainer.container)
|
||||
&& index == pathAndContainer.index;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1160,9 +1156,9 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
|
||||
@Override @DefinedBy(Api.COMPILER)
|
||||
public Location getLocationForModule(Location location, JavaFileObject fo) throws IOException {
|
||||
checkModuleOrientedOrOutputLocation(location);
|
||||
if (!(fo instanceof PathFileObject))
|
||||
if (!(fo instanceof PathFileObject pathFileObject))
|
||||
return null;
|
||||
Path p = Locations.normalize(((PathFileObject) fo).path);
|
||||
Path p = Locations.normalize(pathFileObject.path);
|
||||
// need to find p in location
|
||||
return locations.getLocationForModule(location, p);
|
||||
}
|
||||
@ -1190,8 +1186,8 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
|
||||
|
||||
@Override @DefinedBy(Api.COMPILER)
|
||||
public Path asPath(FileObject file) {
|
||||
if (file instanceof PathFileObject) {
|
||||
return ((PathFileObject) file).path;
|
||||
if (file instanceof PathFileObject pathFileObject) {
|
||||
return pathFileObject.path;
|
||||
} else
|
||||
throw new IllegalArgumentException(file.getName());
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2021, 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
|
||||
@ -1232,10 +1232,9 @@ public class Locations {
|
||||
|
||||
for (Set<Location> set : listLocationsForModules()) {
|
||||
for (Location locn : set) {
|
||||
if (locn instanceof ModuleLocationHandler) {
|
||||
ModuleLocationHandler l = (ModuleLocationHandler) locn;
|
||||
if (!moduleTable.nameMap.containsKey(l.moduleName)) {
|
||||
moduleTable.add(l);
|
||||
if (locn instanceof ModuleLocationHandler moduleLocationHandler) {
|
||||
if (!moduleTable.nameMap.containsKey(moduleLocationHandler.moduleName)) {
|
||||
moduleTable.add(moduleLocationHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2200,8 +2199,8 @@ public class Locations {
|
||||
|
||||
protected LocationHandler getHandler(Location location) {
|
||||
Objects.requireNonNull(location);
|
||||
return (location instanceof LocationHandler)
|
||||
? (LocationHandler) location
|
||||
return (location instanceof LocationHandler locationHandler)
|
||||
? locationHandler
|
||||
: handlersForLocation.get(location);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2009, 2021, 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
|
||||
@ -532,7 +532,7 @@ public abstract class PathFileObject implements JavaFileObject {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return (other instanceof PathFileObject && path.equals(((PathFileObject) other).path));
|
||||
return (other instanceof PathFileObject pathFileObject && path.equals(pathFileObject.path));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2021, 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
|
||||
@ -73,9 +73,7 @@ public abstract class RelativePath implements Comparable<RelativePath> {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof RelativePath))
|
||||
return false;
|
||||
return path.equals(((RelativePath) other).path);
|
||||
return (other instanceof RelativePath relativePath) && path.equals(relativePath.path);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2021, 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
|
||||
@ -478,11 +478,10 @@ public class Arguments {
|
||||
|
||||
// The following checks are to help avoid accidental confusion between
|
||||
// directories of modules and exploded module directories.
|
||||
if (fm instanceof StandardJavaFileManager) {
|
||||
StandardJavaFileManager sfm = (StandardJavaFileManager) fileManager;
|
||||
if (sfm.hasLocation(StandardLocation.CLASS_OUTPUT)) {
|
||||
Path outDir = sfm.getLocationAsPaths(StandardLocation.CLASS_OUTPUT).iterator().next();
|
||||
if (sfm.hasLocation(StandardLocation.MODULE_SOURCE_PATH)) {
|
||||
if (fm instanceof StandardJavaFileManager standardJavaFileManager) {
|
||||
if (standardJavaFileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
|
||||
Path outDir = standardJavaFileManager.getLocationAsPaths(StandardLocation.CLASS_OUTPUT).iterator().next();
|
||||
if (standardJavaFileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH)) {
|
||||
// multi-module mode
|
||||
if (Files.exists(outDir.resolve("module-info.class"))) {
|
||||
log.error(Errors.MultiModuleOutdirCannotBeExplodedModule(outDir));
|
||||
@ -565,12 +564,12 @@ public class Arguments {
|
||||
|
||||
boolean lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option);
|
||||
if (lintOptions && source.compareTo(Source.DEFAULT) < 0 && !options.isSet(Option.RELEASE)) {
|
||||
if (fm instanceof BaseFileManager) {
|
||||
if (fm instanceof BaseFileManager baseFileManager) {
|
||||
if (source.compareTo(Source.JDK8) <= 0) {
|
||||
if (((BaseFileManager) fm).isDefaultBootClassPath())
|
||||
if (baseFileManager.isDefaultBootClassPath())
|
||||
log.warning(LintCategory.OPTIONS, Warnings.SourceNoBootclasspath(source.name));
|
||||
} else {
|
||||
if (((BaseFileManager) fm).isDefaultSystemModulesPath())
|
||||
if (baseFileManager.isDefaultSystemModulesPath())
|
||||
log.warning(LintCategory.OPTIONS, Warnings.SourceNoSystemModulesPath(source.name));
|
||||
}
|
||||
}
|
||||
@ -914,10 +913,10 @@ public class Arguments {
|
||||
|
||||
private void report(DiagnosticInfo diag) {
|
||||
// Would be good to have support for -XDrawDiagnostics here
|
||||
if (diag instanceof JCDiagnostic.Error) {
|
||||
log.error((JCDiagnostic.Error)diag);
|
||||
} else if (diag instanceof JCDiagnostic.Warning){
|
||||
log.warning((JCDiagnostic.Warning)diag);
|
||||
if (diag instanceof JCDiagnostic.Error errorDiag) {
|
||||
log.error(errorDiag);
|
||||
} else if (diag instanceof JCDiagnostic.Warning warningDiag){
|
||||
log.warning(warningDiag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2021, 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
|
||||
@ -51,9 +51,8 @@ public class DelegatingJavaFileManager implements JavaFileManager {
|
||||
JavaFileManager releaseFM,
|
||||
JavaFileManager originalFM) {
|
||||
context.put(JavaFileManager.class, (JavaFileManager) null);
|
||||
JavaFileManager nue = originalFM instanceof StandardJavaFileManager
|
||||
? new DelegatingSJFM(releaseFM,
|
||||
(StandardJavaFileManager) originalFM)
|
||||
JavaFileManager nue = originalFM instanceof StandardJavaFileManager standardJavaFileManager
|
||||
? new DelegatingSJFM(releaseFM, standardJavaFileManager)
|
||||
: new DelegatingJavaFileManager(releaseFM, originalFM);
|
||||
context.put(JavaFileManager.class, nue);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2021, 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
|
||||
@ -1086,8 +1086,8 @@ public class JavaCompiler {
|
||||
for (List<JCTree> defs = unit.defs;
|
||||
defs.nonEmpty();
|
||||
defs = defs.tail) {
|
||||
if (defs.head instanceof JCClassDecl)
|
||||
cdefs.append((JCClassDecl)defs.head);
|
||||
if (defs.head instanceof JCClassDecl classDecl)
|
||||
cdefs.append(classDecl);
|
||||
}
|
||||
}
|
||||
rootClasses = cdefs.toList();
|
||||
@ -1577,8 +1577,8 @@ public class JavaCompiler {
|
||||
//emit standard Java source file, only for compilation
|
||||
//units enumerated explicitly on the command line
|
||||
JCClassDecl cdef = (JCClassDecl)env.tree;
|
||||
if (untranslated instanceof JCClassDecl &&
|
||||
rootClasses.contains((JCClassDecl)untranslated)) {
|
||||
if (untranslated instanceof JCClassDecl classDecl &&
|
||||
rootClasses.contains(classDecl)) {
|
||||
results.add(new Pair<>(env, cdef));
|
||||
}
|
||||
return;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2021, 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
|
||||
@ -258,11 +258,11 @@ public class Main {
|
||||
|
||||
// init file manager
|
||||
fileManager = context.get(JavaFileManager.class);
|
||||
JavaFileManager undel = fileManager instanceof DelegatingJavaFileManager ?
|
||||
((DelegatingJavaFileManager) fileManager).getBaseFileManager() : fileManager;
|
||||
if (undel instanceof BaseFileManager) {
|
||||
((BaseFileManager) undel).setContext(context); // reinit with options
|
||||
ok &= ((BaseFileManager) undel).handleOptions(args.getDeferredFileManagerOptions());
|
||||
JavaFileManager undel = fileManager instanceof DelegatingJavaFileManager delegatingJavaFileManager ?
|
||||
delegatingJavaFileManager.getBaseFileManager() : fileManager;
|
||||
if (undel instanceof BaseFileManager baseFileManager) {
|
||||
baseFileManager.setContext(context); // reinit with options
|
||||
ok &= baseFileManager.handleOptions(args.getDeferredFileManagerOptions());
|
||||
}
|
||||
|
||||
// handle this here so it works even if no other options given
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2021, 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
|
||||
@ -246,8 +246,8 @@ public class AnnotationProxyMaker {
|
||||
}
|
||||
|
||||
public void visitError(Attribute.Error e) {
|
||||
if (e instanceof Attribute.UnresolvedClass)
|
||||
value = new MirroredTypeExceptionProxy(((Attribute.UnresolvedClass)e).classType);
|
||||
if (e instanceof Attribute.UnresolvedClass unresolvedClass)
|
||||
value = new MirroredTypeExceptionProxy(unresolvedClass.classType);
|
||||
else
|
||||
value = null; // indicates a type mismatch
|
||||
}
|
||||
@ -302,8 +302,8 @@ public class AnnotationProxyMaker {
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return type != null &&
|
||||
obj instanceof MirroredTypeExceptionProxy &&
|
||||
type.equals(((MirroredTypeExceptionProxy) obj).type);
|
||||
obj instanceof MirroredTypeExceptionProxy proxy &&
|
||||
type.equals(proxy.type);
|
||||
}
|
||||
|
||||
protected RuntimeException generateException() {
|
||||
@ -347,9 +347,8 @@ public class AnnotationProxyMaker {
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return types != null &&
|
||||
obj instanceof MirroredTypesExceptionProxy &&
|
||||
types.equals(
|
||||
((MirroredTypesExceptionProxy) obj).types);
|
||||
obj instanceof MirroredTypesExceptionProxy proxy &&
|
||||
types.equals(proxy.types);
|
||||
}
|
||||
|
||||
protected RuntimeException generateException() {
|
||||
|
@ -115,7 +115,7 @@ public class JavacElements implements Elements {
|
||||
enter = Enter.instance(context);
|
||||
resolve = Resolve.instance(context);
|
||||
JavacTask t = context.get(JavacTask.class);
|
||||
javacTaskImpl = t instanceof JavacTaskImpl ? (JavacTaskImpl) t : null;
|
||||
javacTaskImpl = t instanceof JavacTaskImpl taskImpl ? taskImpl : null;
|
||||
log = Log.instance(context);
|
||||
Source source = Source.instance(context);
|
||||
allowModules = Feature.MODULES.allowedInSource(source);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2021, 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
|
||||
@ -329,18 +329,17 @@ public class JavacTypes implements javax.lang.model.util.Types {
|
||||
|| elem.getModifiers().contains(Modifier.PRIVATE))
|
||||
return Collections.emptySet();
|
||||
|
||||
if (!(elem instanceof MethodSymbol))
|
||||
if (!(elem instanceof MethodSymbol methodSymbol))
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
MethodSymbol m = (MethodSymbol) elem;
|
||||
ClassSymbol origin = (ClassSymbol) m.owner;
|
||||
ClassSymbol origin = (ClassSymbol) methodSymbol.owner;
|
||||
|
||||
Set<MethodSymbol> results = new LinkedHashSet<>();
|
||||
for (Type t : types.closure(origin.type)) {
|
||||
if (t != origin.type) {
|
||||
ClassSymbol c = (ClassSymbol) t.tsym;
|
||||
for (Symbol sym : c.members().getSymbolsByName(m.name)) {
|
||||
if (sym.kind == MTH && m.overrides(sym, origin, types, true)) {
|
||||
for (Symbol sym : c.members().getSymbolsByName(methodSymbol.name)) {
|
||||
if (sym.kind == MTH && methodSymbol.overrides(sym, origin, types, true)) {
|
||||
results.add((MethodSymbol) sym);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2021, 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
|
||||
@ -239,8 +239,8 @@ public class JDKPlatformProvider implements PlatformProvider {
|
||||
|
||||
@Override
|
||||
public String inferBinaryName(Location location, JavaFileObject file) {
|
||||
if (file instanceof SigJavaFileObject) {
|
||||
file = ((SigJavaFileObject) file).getDelegate();
|
||||
if (file instanceof SigJavaFileObject sigJavaFileObject) {
|
||||
file = sigJavaFileObject.getDelegate();
|
||||
}
|
||||
return super.inferBinaryName(location, file);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2021, 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
|
||||
@ -500,8 +500,8 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
|
||||
print(" ");
|
||||
print(attrs, " ");
|
||||
DocTree last = node.getAttributes().get(attrs.size() - 1);
|
||||
if (node.isSelfClosing() && last instanceof AttributeTree
|
||||
&& ((AttributeTree) last).getValueKind() == ValueKind.UNQUOTED)
|
||||
if (node.isSelfClosing() && last instanceof AttributeTree attributeTree
|
||||
&& attributeTree.getValueKind() == ValueKind.UNQUOTED)
|
||||
print(" ");
|
||||
}
|
||||
if (node.isSelfClosing())
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2021, 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
|
||||
@ -2178,7 +2178,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
|
||||
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
public JCPattern getPattern() {
|
||||
return pattern instanceof JCPattern ? (JCPattern) pattern : null;
|
||||
return pattern instanceof JCPattern jcPattern ? jcPattern : null;
|
||||
}
|
||||
|
||||
@DefinedBy(Api.COMPILER_TREE)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2021, 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
|
||||
@ -701,9 +701,9 @@ public class Pretty extends JCTree.Visitor {
|
||||
if ((tree.mods.flags & VARARGS) != 0) {
|
||||
JCTree vartype = tree.vartype;
|
||||
List<JCAnnotation> tas = null;
|
||||
if (vartype instanceof JCAnnotatedType) {
|
||||
tas = ((JCAnnotatedType)vartype).annotations;
|
||||
vartype = ((JCAnnotatedType)vartype).underlyingType;
|
||||
if (vartype instanceof JCAnnotatedType annotatedType) {
|
||||
tas = annotatedType.annotations;
|
||||
vartype = annotatedType.underlyingType;
|
||||
}
|
||||
printExpr(((JCArrayTypeTree) vartype).elemtype);
|
||||
if (tas != null) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2021, 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
|
||||
@ -131,8 +131,8 @@ public class TreeMaker implements JCTree.Factory {
|
||||
|| node instanceof JCModuleDecl
|
||||
|| node instanceof JCSkip
|
||||
|| node instanceof JCErroneous
|
||||
|| (node instanceof JCExpressionStatement
|
||||
&& ((JCExpressionStatement)node).expr instanceof JCErroneous),
|
||||
|| (node instanceof JCExpressionStatement expressionStatement
|
||||
&& expressionStatement.expr instanceof JCErroneous),
|
||||
() -> node.getClass().getSimpleName());
|
||||
JCCompilationUnit tree = new JCCompilationUnit(defs);
|
||||
tree.pos = pos;
|
||||
@ -886,8 +886,8 @@ public class TreeMaker implements JCTree.Factory {
|
||||
} else if (value instanceof Byte) {
|
||||
result = Literal(BYTE, value).
|
||||
setType(syms.byteType.constType(value));
|
||||
} else if (value instanceof Character) {
|
||||
int v = (int) (((Character) value).toString().charAt(0));
|
||||
} else if (value instanceof Character charVal) {
|
||||
int v = charVal.toString().charAt(0);
|
||||
result = Literal(CHAR, v).
|
||||
setType(syms.charType.constType(v));
|
||||
} else if (value instanceof Double) {
|
||||
@ -899,8 +899,8 @@ public class TreeMaker implements JCTree.Factory {
|
||||
} else if (value instanceof Short) {
|
||||
result = Literal(SHORT, value).
|
||||
setType(syms.shortType.constType(value));
|
||||
} else if (value instanceof Boolean) {
|
||||
int v = ((Boolean) value) ? 1 : 0;
|
||||
} else if (value instanceof Boolean boolVal) {
|
||||
int v = boolVal ? 1 : 0;
|
||||
result = Literal(BOOLEAN, v).
|
||||
setType(syms.booleanType.constType(v));
|
||||
} else {
|
||||
@ -921,15 +921,15 @@ public class TreeMaker implements JCTree.Factory {
|
||||
result = QualIdent(e.value);
|
||||
}
|
||||
public void visitError(Attribute.Error e) {
|
||||
if (e instanceof UnresolvedClass) {
|
||||
result = ClassLiteral(((UnresolvedClass) e).classType).setType(syms.classType);
|
||||
if (e instanceof UnresolvedClass unresolvedClass) {
|
||||
result = ClassLiteral(unresolvedClass.classType).setType(syms.classType);
|
||||
} else {
|
||||
result = Erroneous();
|
||||
}
|
||||
}
|
||||
public void visitCompound(Attribute.Compound compound) {
|
||||
if (compound instanceof Attribute.TypeCompound) {
|
||||
result = visitTypeCompoundInternal((Attribute.TypeCompound) compound);
|
||||
if (compound instanceof Attribute.TypeCompound typeCompound) {
|
||||
result = visitTypeCompoundInternal(typeCompound);
|
||||
} else {
|
||||
result = visitCompoundInternal(compound);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2021, 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
|
||||
@ -148,8 +148,8 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
|
||||
throw new IllegalArgumentException(); // d should have source set
|
||||
if (fullname)
|
||||
return fo.getName();
|
||||
else if (fo instanceof PathFileObject)
|
||||
return ((PathFileObject) fo).getShortName();
|
||||
else if (fo instanceof PathFileObject pathFileObject)
|
||||
return pathFileObject.getShortName();
|
||||
else
|
||||
return PathFileObject.getSimpleName(fo);
|
||||
}
|
||||
@ -178,50 +178,50 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
|
||||
* @return string representation of the diagnostic argument
|
||||
*/
|
||||
protected String formatArgument(JCDiagnostic d, Object arg, Locale l) {
|
||||
if (arg instanceof JCDiagnostic) {
|
||||
if (arg instanceof JCDiagnostic diagnostic) {
|
||||
String s = null;
|
||||
depth++;
|
||||
try {
|
||||
s = formatMessage((JCDiagnostic)arg, l);
|
||||
s = formatMessage(diagnostic, l);
|
||||
}
|
||||
finally {
|
||||
depth--;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
else if (arg instanceof JCExpression) {
|
||||
return expr2String((JCExpression)arg);
|
||||
else if (arg instanceof JCExpression expression) {
|
||||
return expr2String(expression);
|
||||
}
|
||||
else if (arg instanceof Iterable<?> && !(arg instanceof Path)) {
|
||||
return formatIterable(d, (Iterable<?>)arg, l);
|
||||
else if (arg instanceof Iterable<?> iterable && !(arg instanceof Path)) {
|
||||
return formatIterable(d, iterable, l);
|
||||
}
|
||||
else if (arg instanceof Type) {
|
||||
return printer.visit((Type)arg, l);
|
||||
else if (arg instanceof Type type) {
|
||||
return printer.visit(type, l);
|
||||
}
|
||||
else if (arg instanceof Symbol) {
|
||||
return printer.visit((Symbol)arg, l);
|
||||
else if (arg instanceof Symbol symbol) {
|
||||
return printer.visit(symbol, l);
|
||||
}
|
||||
else if (arg instanceof JavaFileObject) {
|
||||
return ((JavaFileObject)arg).getName();
|
||||
else if (arg instanceof JavaFileObject javaFileObject) {
|
||||
return javaFileObject.getName();
|
||||
}
|
||||
else if (arg instanceof Profile) {
|
||||
return ((Profile)arg).name;
|
||||
else if (arg instanceof Profile profile) {
|
||||
return profile.name;
|
||||
}
|
||||
else if (arg instanceof Option) {
|
||||
return ((Option)arg).primaryName;
|
||||
else if (arg instanceof Option option) {
|
||||
return option.primaryName;
|
||||
}
|
||||
else if (arg instanceof Formattable) {
|
||||
return ((Formattable)arg).toString(l, messages);
|
||||
else if (arg instanceof Formattable formattable) {
|
||||
return formattable.toString(l, messages);
|
||||
}
|
||||
else if (arg instanceof Target) {
|
||||
return ((Target)arg).name;
|
||||
else if (arg instanceof Target target) {
|
||||
return target.name;
|
||||
}
|
||||
else if (arg instanceof Source) {
|
||||
return ((Source)arg).name;
|
||||
else if (arg instanceof Source source) {
|
||||
return source.name;
|
||||
}
|
||||
else if (arg instanceof Tag) {
|
||||
else if (arg instanceof Tag tag) {
|
||||
return messages.getLocalizedString(l, "compiler.misc.tree.tag." +
|
||||
StringUtils.toLowerCase(((Tag) arg).name()));
|
||||
StringUtils.toLowerCase(tag.name()));
|
||||
}
|
||||
else {
|
||||
return String.valueOf(arg);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2021, 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
|
||||
@ -44,8 +44,8 @@ public class Constants {
|
||||
* null) are returned unchanged.
|
||||
*/
|
||||
public static Object decode(Object value, Type type) {
|
||||
if (value instanceof Integer) {
|
||||
int i = (Integer) value;
|
||||
if (value instanceof Integer intVal) {
|
||||
int i = intVal;
|
||||
switch (type.getTag()) {
|
||||
case BOOLEAN: return i != 0;
|
||||
case CHAR: return (char) i;
|
||||
@ -69,8 +69,8 @@ public class Constants {
|
||||
case DOUBLE: return formatDouble((Double) value);
|
||||
case CHAR: return formatChar((Character) value);
|
||||
}
|
||||
if (value instanceof String)
|
||||
return formatString((String) value);
|
||||
if (value instanceof String str)
|
||||
return formatString(str);
|
||||
return value + "";
|
||||
}
|
||||
|
||||
@ -80,13 +80,13 @@ public class Constants {
|
||||
* Java source.
|
||||
*/
|
||||
public static String format(Object value) {
|
||||
if (value instanceof Byte) return formatByte((Byte) value);
|
||||
if (value instanceof Short) return formatShort((Short) value);
|
||||
if (value instanceof Long) return formatLong((Long) value);
|
||||
if (value instanceof Float) return formatFloat((Float) value);
|
||||
if (value instanceof Double) return formatDouble((Double) value);
|
||||
if (value instanceof Character) return formatChar((Character) value);
|
||||
if (value instanceof String) return formatString((String) value);
|
||||
if (value instanceof Byte byteVal) return formatByte(byteVal);
|
||||
if (value instanceof Short shortVal) return formatShort(shortVal);
|
||||
if (value instanceof Long longVal) return formatLong(longVal);
|
||||
if (value instanceof Float floatVal) return formatFloat(floatVal);
|
||||
if (value instanceof Double doubleVal) return formatDouble(doubleVal);
|
||||
if (value instanceof Character charVal) return formatChar(charVal);
|
||||
if (value instanceof String strVal) return formatString(strVal);
|
||||
if (value instanceof Integer ||
|
||||
value instanceof Boolean) return value.toString();
|
||||
else
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2021, 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
|
||||
@ -145,8 +145,7 @@ public class Context {
|
||||
public <T> T get(Key<T> key) {
|
||||
checkState(ht);
|
||||
Object o = ht.get(key);
|
||||
if (o instanceof Factory<?>) {
|
||||
Factory<?> fac = (Factory<?>)o;
|
||||
if (o instanceof Factory<?> fac) {
|
||||
o = fac.make(this);
|
||||
if (o instanceof Factory<?>)
|
||||
throw new AssertionError("T extends Context.Factory");
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2021, 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
|
||||
@ -202,7 +202,7 @@ public abstract class Dependencies {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof Node && data.equals(((Node) obj).data);
|
||||
return obj instanceof Node node && data.equals(node.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -401,8 +401,8 @@ public abstract class Dependencies {
|
||||
|
||||
@Override
|
||||
public void visitNode(Node node, Void arg) {
|
||||
if (node instanceof CompletionNode) {
|
||||
if (((CompletionNode) node).ck != ck) {
|
||||
if (node instanceof CompletionNode completionNode) {
|
||||
if (completionNode.ck != ck) {
|
||||
dependencyNodeMap.remove(node.data);
|
||||
}
|
||||
}
|
||||
@ -410,8 +410,8 @@ public abstract class Dependencies {
|
||||
|
||||
@Override
|
||||
public void visitDependency(GraphUtils.DependencyKind dk, Node from, Node to, Void arg) {
|
||||
if (to instanceof CompletionNode) {
|
||||
if (((CompletionNode) to).ck != ck) {
|
||||
if (to instanceof CompletionNode completionNode) {
|
||||
if (completionNode.ck != ck) {
|
||||
from.depsByKind.get(dk).remove(to);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2021, 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
|
||||
@ -183,10 +183,9 @@ public class DiagnosticSource {
|
||||
protected char[] initBuf(JavaFileObject fileObject) throws IOException {
|
||||
char[] buf;
|
||||
CharSequence cs = fileObject.getCharContent(true);
|
||||
if (cs instanceof CharBuffer) {
|
||||
CharBuffer cb = (CharBuffer) cs;
|
||||
buf = JavacFileManager.toArray(cb);
|
||||
bufLen = cb.limit();
|
||||
if (cs instanceof CharBuffer charBuffer) {
|
||||
buf = JavacFileManager.toArray(charBuffer);
|
||||
bufLen = charBuffer.limit();
|
||||
} else {
|
||||
buf = cs.toString().toCharArray();
|
||||
bufLen = buf.length;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2021, 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
|
||||
@ -287,8 +287,8 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
//replace all nested FragmentKey with full-blown JCDiagnostic objects
|
||||
return DiagnosticInfo.of(diagnosticInfo.type, diagnosticInfo.prefix, diagnosticInfo.code,
|
||||
Stream.of(diagnosticInfo.args).map(o -> {
|
||||
return (o instanceof Fragment) ?
|
||||
fragment((Fragment)o) : o;
|
||||
return (o instanceof Fragment frag) ?
|
||||
fragment(frag) : o;
|
||||
}).toArray());
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2021, 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
|
||||
@ -358,11 +358,11 @@ public class List<A> extends AbstractCollection<A> implements java.util.List<A>
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof List<?>)
|
||||
return equals(this, (List<?>)other);
|
||||
if (other instanceof java.util.List<?>) {
|
||||
if (other instanceof List<?> javacList)
|
||||
return equals(this, javacList);
|
||||
if (other instanceof java.util.List<?> javaUtilList) {
|
||||
List<A> t = this;
|
||||
Iterator<?> oIter = ((java.util.List<?>) other).iterator();
|
||||
Iterator<?> oIter = javaUtilList.iterator();
|
||||
while (t.tail != null && oIter.hasNext()) {
|
||||
Object o = oIter.next();
|
||||
if ( !(t.head == null ? o == null : t.head.equals(o)))
|
||||
|
@ -548,8 +548,8 @@ public class Log extends AbstractLog {
|
||||
private void getCodeRecursive(ListBuffer<String> buf, JCDiagnostic d) {
|
||||
buf.add(d.getCode());
|
||||
for (Object o : d.getArgs()) {
|
||||
if (o instanceof JCDiagnostic) {
|
||||
getCodeRecursive(buf, (JCDiagnostic)o);
|
||||
if (o instanceof JCDiagnostic diagnostic) {
|
||||
getCodeRecursive(buf, diagnostic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2021, 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
|
||||
@ -49,10 +49,9 @@ public class Pair<A, B> {
|
||||
}
|
||||
|
||||
public boolean equals(Object other) {
|
||||
return
|
||||
other instanceof Pair<?,?> &&
|
||||
Objects.equals(fst, ((Pair<?,?>)other).fst) &&
|
||||
Objects.equals(snd, ((Pair<?,?>)other).snd);
|
||||
return other instanceof Pair<?,?> pair &&
|
||||
Objects.equals(fst, pair.fst) &&
|
||||
Objects.equals(snd, pair.snd);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2021, 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
|
||||
@ -155,13 +155,13 @@ public final class RawDiagnosticFormatter extends AbstractDiagnosticFormatter {
|
||||
String s;
|
||||
if (arg instanceof Formattable) {
|
||||
s = arg.toString();
|
||||
} else if (arg instanceof JCExpression) {
|
||||
} else if (arg instanceof JCExpression expression) {
|
||||
Assert.checkNonNull(rawDiagnosticPosHelper);
|
||||
s = "@" + rawDiagnosticPosHelper.getPosition((JCExpression)arg);
|
||||
} else if (arg instanceof PathFileObject) {
|
||||
s = ((PathFileObject) arg).getShortName();
|
||||
} else if (arg instanceof Tag) {
|
||||
s = "compiler.misc.tree.tag." + StringUtils.toLowerCase(((Tag) arg).name());
|
||||
s = "@" + rawDiagnosticPosHelper.getPosition(expression);
|
||||
} else if (arg instanceof PathFileObject pathFileObject) {
|
||||
s = pathFileObject.getShortName();
|
||||
} else if (arg instanceof Tag tag) {
|
||||
s = "compiler.misc.tree.tag." + StringUtils.toLowerCase(tag.name());
|
||||
} else if (arg instanceof Source && arg == Source.DEFAULT &&
|
||||
CODES_NEEDING_SOURCE_NORMALIZATION.contains(diag.getCode())) {
|
||||
s = "DEFAULT";
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2009, 2021, 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
|
||||
@ -180,17 +180,17 @@ public class RichDiagnosticFormatter extends
|
||||
* @param arg the argument to be translated
|
||||
*/
|
||||
protected void preprocessArgument(Object arg) {
|
||||
if (arg instanceof Type) {
|
||||
preprocessType((Type)arg);
|
||||
if (arg instanceof Type type) {
|
||||
preprocessType(type);
|
||||
}
|
||||
else if (arg instanceof Symbol) {
|
||||
preprocessSymbol((Symbol)arg);
|
||||
else if (arg instanceof Symbol symbol) {
|
||||
preprocessSymbol(symbol);
|
||||
}
|
||||
else if (arg instanceof JCDiagnostic) {
|
||||
preprocessDiagnostic((JCDiagnostic)arg);
|
||||
else if (arg instanceof JCDiagnostic diagnostic) {
|
||||
preprocessDiagnostic(diagnostic);
|
||||
}
|
||||
else if (arg instanceof Iterable<?> && !(arg instanceof Path)) {
|
||||
for (Object o : (Iterable<?>)arg) {
|
||||
else if (arg instanceof Iterable<?> iterable && !(arg instanceof Path)) {
|
||||
for (Object o : iterable) {
|
||||
preprocessArgument(o);
|
||||
}
|
||||
}
|
||||
@ -556,8 +556,8 @@ public class RichDiagnosticFormatter extends
|
||||
if (indexOf(t, WhereClauseKind.TYPEVAR) == -1) {
|
||||
//access the bound type and skip error types
|
||||
Type bound = t.getUpperBound();
|
||||
while ((bound instanceof ErrorType))
|
||||
bound = ((ErrorType)bound).getOriginalType();
|
||||
while ((bound instanceof ErrorType errorType))
|
||||
bound = errorType.getOriginalType();
|
||||
//retrieve the bound list - if the type variable
|
||||
//has not been attributed the bound is not set
|
||||
List<Type> bounds = (bound != null) &&
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2021, 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
|
||||
@ -203,10 +203,9 @@ public class SharedNameTable extends Name.Table {
|
||||
*/
|
||||
@DefinedBy(Api.LANGUAGE_MODEL)
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof Name)
|
||||
return
|
||||
table == ((Name)other).table && index == ((Name) other).getIndex();
|
||||
else return false;
|
||||
return (other instanceof Name name)
|
||||
&& table == name.table
|
||||
&& index == name.getIndex();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user