Handle deletion scenario for cleaning up empty exported packages#2292
Conversation
|
This is an enhancement to the previous task mentioned here |
de3f8af to
83fbd43
Compare
83fbd43 to
5cbdda6
Compare
| } | ||
| } | ||
| } catch (CoreException e) { | ||
| e.printStackTrace(); |
There was a problem hiding this comment.
Printing the stack trace instead of proper logging or handling the issue can cause the action to fail silently.
| if (member instanceof IFile memberFile) { | ||
| String fileName = memberFile.getName(); | ||
| String extension = memberFile.getFileExtension(); | ||
| if ("class".equals(extension)) { //$NON-NLS-1$ |
There was a problem hiding this comment.
Please check whether any constants exist in the PDE code for the file extensions that can be reused here, or create them at the class level instead of hardcoding them here.
| } | ||
|
|
||
| @Override | ||
| public void addElement(Object element, RefactoringArguments arguments) { |
There was a problem hiding this comment.
Can the "element" be of a type other than IType and IPackageFragment? That should be handled in the 'else' case (probably via logging).
| ManifestEditorContributor_externStringsActionName=Externalize Strings... | ||
|
|
||
| ManifestTypeRenameParticipant_composite=Rename classes referenced in plug-in manifest files | ||
| ManifestTypeDeleteParticipant_composite=Delete classes referenced in plug-in manifest files |
There was a problem hiding this comment.
Check the usage of this message and update it, as it's talking about deleting class references from the manifest, which isn't the case in this PR.
| @Override | ||
| public void addElement(Object element, RefactoringArguments arguments) { | ||
| if (element instanceof IType type) { | ||
| fElements.put(element, type.getFullyQualifiedName()); |
There was a problem hiding this comment.
It is better to initialize "fElements" at declaration time to prevent any potential NPE here. Also, initializing it to empty in ManifestTypeDeleteParticipant#initialize will break the sharing behavior of ISharableParticipant in my view.
| @Override | ||
| protected boolean initialize(Object element) { | ||
| if (element instanceof IType type) { | ||
| IJavaProject javaProject = (IJavaProject) type.getAncestor(IJavaElement.JAVA_PROJECT); |
There was a problem hiding this comment.
"getAncestor" can return null.
| IJavaProject javaProject = (IJavaProject) type.getAncestor(IJavaElement.JAVA_PROJECT); | ||
| IProject project = javaProject.getProject(); | ||
| if (WorkspaceModelManager.isPluginProject(project)) { | ||
| fProject = javaProject.getProject(); |
There was a problem hiding this comment.
"javaProject.getProject()" is called twice. Here and at line 45.
| IProject project = javaProject.getProject(); | ||
| if (WorkspaceModelManager.isPluginProject(project)) { | ||
| fProject = javaProject.getProject(); | ||
| fElements = new HashMap<>(); |
There was a problem hiding this comment.
See PDEDeleteParticipant, line 46 comment.
| */ | ||
| private boolean willPackageBeEmpty(IPackageFragment pkg, List<IType> deletedTypes) throws CoreException { | ||
| IJavaElement[] javaChildren = pkg.getChildren(); | ||
| if (javaChildren.length > deletedTypes.size()) { |
There was a problem hiding this comment.
I think the entire logic here assumes 1:1 mapping between IType and compilation units, which is not the case in JDT. For inner classes, multiple types exist in the same compilation unit. Deleting one inner class shouldn't mark the entire .java file as deleted. The logic should be updated to handle this.
|
@noopur2507 |
HannesWell
left a comment
There was a problem hiding this comment.
Thank you @nburnwal09 for this.
In general it looks good and works well.
But I have multiple comments below to stream-line the code.
Furthermore please make sure to properly format all new files and edited lines.
Additionally, do you think it makes sense to include the extra change from #2312 here too?
Then the changes could be reviewed together and more holistically.
I realised about package deletion part later(after raising this PR). Also as that is for package deletion (although the goal of removing the package from manifest is the same), I thought of taking that as a different commit. |
In this case I think it's similar and related enough to be together in one change. |
Sure @HannesWell I will merge the changes in this PR. |
|
@HannesWell |
HannesWell
left a comment
There was a problem hiding this comment.
Thank you @nburnwal09 for the updates, they look good.
I made a second pass through this considering the now included ManifestPackageDeleteParticipant and also looked again at the previous changes.
Please see the comments below.
With them resolved, I expect this to be ready.
Please squash all changes into one commit named, e.g.:
Handle class and package deletion for removing empty exported packages.
Furthermore, just a nitpick, please add new lines at the end of the new files. Github/git shows annoying markers at files without newline at the end.
e69bc62 to
83389c3
Compare
|
@HannesWell |
No problem and thanks for the update. I plan to review it later today. @MohananRahul could you please hold-off M3 promotion planed for today? I'd like to have this (and maybe another change) included. I can run the promotion myself later today or tomorrow morning (if an extra I-build is not reasonable). |
Enhancement added for handling class/type deletion scenario.
When all classes in a package are deleted via delete operation, the package(having no java files or any other resources) should be automatically removed from the Export-Package header in MANIFEST.MF if it was previously exported.
Addressing #2290
type.delete.refactor.mov
preview.part.mov