Skip to content

Commit

Permalink
JavaModel: get rid of raw Object argument
Browse files Browse the repository at this point in the history
  • Loading branch information
EcljpseB0T authored and jukzi committed Mar 5, 2024
1 parent adf8c4e commit 83809e1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>true</code>
* 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) {
Expand Down Expand Up @@ -433,8 +430,8 @@ static private boolean isExternalFile(IPath path) {
* Helper method - returns the {@link File} item if <code>target</code> is a file (i.e., the target
* returns <code>true</code> to {@link File#isFile()}. Otherwise returns <code>null</code>.
*/
public static File getFile(Object target) {
return isFile(target) ? (File) target : null;
public static File getFile(File target) {
return isFile(target) ? target : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 83809e1

Please sign in to comment.