Skip to content

Commit

Permalink
Merge branch 'master' into e423
Browse files Browse the repository at this point in the history
  • Loading branch information
kriegaex committed Nov 4, 2023
2 parents 7aba1e2 + 24ce189 commit 0964d24
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<IWorkbenchWindow> 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

}

0 comments on commit 0964d24

Please sign in to comment.