diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java index d3096680b90..e01baa3150c 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java @@ -2496,8 +2496,8 @@ private static IJavaModelStatus validateLibraryEntry(IPath path, IJavaProject pr } } } - } else if (target instanceof File){ - File file = JavaModel.getFile(target); + } else if (target instanceof File tf){ + File file = JavaModel.getFile(tf); if (file == null) { if (container != null) { return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalExternalFolderInContainer, new String[] {path.toOSString(), container})); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModel.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModel.java index ec3a3edd157..05d2c55f435 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModel.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModel.java @@ -394,12 +394,9 @@ public static Object getExternalTarget(IPath path, boolean checkResourceExistenc * Helper method - returns whether an object is a file (i.e., it returns true * to {@link File#isFile()}. */ -public static boolean isFile(Object target) { - if (target instanceof File) { - IPath path = Path.fromOSString(((File) target).getPath()); - return isExternalFile(path); - } - return false; +public static boolean isFile(File target) { + IPath path = Path.fromOSString(target.getPath()); + return isExternalFile(path); } public static boolean isJimage(File file) { @@ -433,8 +430,8 @@ static private boolean isExternalFile(IPath path) { * Helper method - returns the {@link File} item if target is a file (i.e., the target * returns true to {@link File#isFile()}. Otherwise returns null. */ -public static File getFile(Object target) { - return isFile(target) ? (File) target : null; +public static File getFile(File target) { + return isFile(target) ? target : null; } @Override diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java index 840501bd856..fd30106aca8 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java @@ -2843,8 +2843,8 @@ public IClasspathEntry resolveVariableEntry(IClasspathEntry entry, boolean usePr entry.isExported()); } } - if (target instanceof File) { - File externalFile = JavaModel.getFile(target); + if (target instanceof File tf) { + File externalFile = JavaModel.getFile(tf); if (externalFile != null) { // external binary archive return JavaCore.newLibraryEntry( diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java index 8490fe56140..4ae24748647 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java @@ -743,10 +743,10 @@ public void computePackageFragmentRoots( if (target instanceof IResource){ // internal target root = getPackageFragmentRoot((IResource) target, entryPath, resolvedEntry.getExtraAttributes()); - } else if (target instanceof File) { + } else if (target instanceof File tf) { // external target - if (JavaModel.isFile(target)) { - if (JavaModel.isJimage((File) target)) { + if (JavaModel.isFile(tf)) { + if (JavaModel.isJimage(tf)) { PerProjectInfo info = getPerProjectInfo(); ObjectVector imageRoots; if (info.jrtRoots == null || !info.jrtRoots.containsKey(entryPath)) { @@ -770,13 +770,13 @@ public void computePackageFragmentRoots( } } accumulatedRoots.addAll(imageRoots); - } else if (JavaModel.isJmod((File) target)) { + } else if (JavaModel.isJmod(tf)) { root = new JModPackageFragmentRoot(entryPath, this, resolvedEntry.getExtraAttributes()); } else { root = new JarPackageFragmentRoot(null, entryPath, this, resolvedEntry.getExtraAttributes()); } - } else if (((File) target).isDirectory()) { + } else if ((tf).isDirectory()) { root = new ExternalPackageFragmentRoot(entryPath, this); } } @@ -2278,7 +2278,7 @@ public IPackageFragmentRoot getPackageFragmentRoot0(IPath externalLibraryPath, I return this.new JImageModuleFragmentBridge(externalLibraryPath, extraAttributes); } Object target = JavaModel.getTarget(externalLibraryPath, true/*check existency*/); - if (target instanceof File && JavaModel.isFile(target)) { + if (target instanceof File tf && JavaModel.isFile(tf)) { if (JavaModel.isJmod((File) target)) { return new JModPackageFragmentRoot(externalLibraryPath, this, extraAttributes); }