Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2025 Google, Inc. and others.
* Copyright (c) 2011, 2026 Google, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -30,6 +30,7 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaModelMarker;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
Expand Down Expand Up @@ -579,6 +580,10 @@ public static void deleteFiles(IFolder folder) throws Exception {
* Force deletes {@link IResource}.
*/
public static void forceDeleteResource(IResource resource) {
if (resource.getAdapter(IJavaElement.class) instanceof ICompilationUnit cu) {
forceDeleteCompilationUnit(cu);
return;
}
while (resource.exists()) {
try {
resource.refreshLocal(IResource.DEPTH_INFINITE, null);
Expand All @@ -597,6 +602,10 @@ public static void forceDeleteResource(IResource resource) {
*/
public static void forceDeleteCompilationUnit(ICompilationUnit cu) {
while (cu.exists()) {
try {
cu.discardWorkingCopy();
} catch (Throwable e) {
}
try {
cu.getResource().refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (Throwable e) {
Expand Down
Loading