diff --git a/org.eclipse.ajdt.ui/src/org/eclipse/ajdt/internal/ui/editor/quickfix/AJQuickFixProcessor.java b/org.eclipse.ajdt.ui/src/org/eclipse/ajdt/internal/ui/editor/quickfix/AJQuickFixProcessor.java index 2c5683f288..feeccfcd41 100644 --- a/org.eclipse.ajdt.ui/src/org/eclipse/ajdt/internal/ui/editor/quickfix/AJQuickFixProcessor.java +++ b/org.eclipse.ajdt.ui/src/org/eclipse/ajdt/internal/ui/editor/quickfix/AJQuickFixProcessor.java @@ -26,7 +26,7 @@ import org.eclipse.jdt.ui.text.java.IProblemLocation; import org.eclipse.jdt.ui.text.java.IQuickAssistProcessor; import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.IWorkbenchWindow; /** * Adapted from org.eclipse.jdt.internal.ui.text.correction.QuickFixProcessor @@ -57,7 +57,10 @@ public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IPro if (AspectJPlugin.isAJProject(project)) { // We're looking at a problem in an AspectJ Project - IEditorPart ed = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + IWorkbenchWindow workbenchWindow = getActiveWorkbenchWindow(); + if (workbenchWindow == null) + return null; + IEditorPart ed = workbenchWindow.getActivePage().getActiveEditor(); if ((ed instanceof AspectJEditor)) { // Only apply to the Java editor return null; diff --git a/org.eclipse.ajdt.ui/src/org/eclipse/ajdt/internal/ui/editor/quickfix/QuickFixProcessor.java b/org.eclipse.ajdt.ui/src/org/eclipse/ajdt/internal/ui/editor/quickfix/QuickFixProcessor.java index b05950e4f2..8ff3564a1b 100755 --- a/org.eclipse.ajdt.ui/src/org/eclipse/ajdt/internal/ui/editor/quickfix/QuickFixProcessor.java +++ b/org.eclipse.ajdt.ui/src/org/eclipse/ajdt/internal/ui/editor/quickfix/QuickFixProcessor.java @@ -14,6 +14,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import org.eclipse.ajdt.internal.ui.editor.AspectJEditor; import org.eclipse.core.runtime.CoreException; @@ -40,7 +42,9 @@ import org.eclipse.jdt.ui.text.java.IQuickAssistProcessor; import org.eclipse.jdt.ui.text.java.IQuickFixProcessor; import org.eclipse.jdt.ui.text.java.correction.ICommandAccess; +import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; /** @@ -229,8 +233,10 @@ public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IPro } // AspectJ Change Begin - IEditorPart ed = PlatformUI.getWorkbench().getActiveWorkbenchWindow() - .getActivePage().getActiveEditor(); + IWorkbenchWindow workbenchWindow = getActiveWorkbenchWindow(); + if (workbenchWindow == null) + return null; + IEditorPart ed = workbenchWindow.getActivePage().getActiveEditor(); if (!(ed instanceof AspectJEditor)) { // we only want to provide corrections for the AspectJ editor // otherwise we get double completions in the Java editor @@ -571,4 +577,19 @@ public boolean hasAssists(IInvocationContext context) throws CoreException { return false; } // end AspectJ Change + + // begin AspectJ Change - utility method + public static IWorkbenchWindow getActiveWorkbenchWindow() { + CompletableFuture future = new CompletableFuture<>(); + Display.getDefault().syncExec(() -> future.complete(PlatformUI.getWorkbench().getActiveWorkbenchWindow())); + IWorkbenchWindow workbenchWindow; + try { + workbenchWindow = future.get(); + } catch (InterruptedException | ExecutionException e) { + return null; + } + return workbenchWindow; + } + // end AspectJ Change + }