Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions com.avaloq.tools.ddk.check.ui.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ Require-Bundle: com.avaloq.tools.ddk.check.ui,
org.eclipse.xtext.common.types.ui,
org.eclipse.jdt.core,
org.eclipse.ui.ide,
org.eclipse.ui.workbench.texteditor,
org.eclipse.core.resources,
org.eclipse.debug.ui,
org.eclipse.debug.core,
org.eclipse.jdt.debug,
org.eclipse.jface.text,
org.eclipse.ui,
com.avaloq.tools.ddk.xtext.format.ui,
com.avaloq.tools.ddk.checkcfg.ui,
org.eclipse.core.runtime,
org.eclipse.ui.workbench;resolution:=optional,
org.objectweb.asm;resolution:=optional,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
/*******************************************************************************
* Copyright (c) 2026 Avaloq Group AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Avaloq Group AG - initial API and implementation
*******************************************************************************/
package com.avaloq.tools.ddk.check.ui.test.editor;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.ui.actions.ToggleBreakpointAction;
import org.eclipse.jdt.debug.core.JDIDebugModel;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.text.source.IVerticalRulerExtension;
import org.eclipse.jface.text.source.IVerticalRulerInfo;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
import org.eclipse.ui.texteditor.IUpdate;
import org.eclipse.xtext.ui.XtextProjectHelper;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.avaloq.tools.ddk.xtext.ui.editor.breakpoints.BreakpointRulerActionContributor;
import com.avaloq.tools.ddk.xtext.ui.editor.breakpoints.BreakpointRulerMenu;
import com.avaloq.tools.ddk.xtext.ui.util.Function;
import com.avaloq.tools.ddk.xtext.ui.util.UiThreadDispatcher;


/**
* Tests the breakpoint actions of the vertical ruler in the Check, Format and Check Configuration editors.
*/
@SuppressWarnings("nls")
class BreakpointRulerActionsTest {

private static final String CATALOG = "package com.test catalog c for grammar g { live error \"First Check\"{ for g { issue }}}";
private static final String TOGGLE = "Toggle Breakpoint";
private static final String PROPERTIES = "Breakpoint Properties...";
private static final long TIMEOUT_MILLIS = 10_000;
private static final long POLL_MILLIS = 100;

private IProject project;

@BeforeEach
void setUp() throws CoreException {
project = ResourcesPlugin.getWorkspace().getRoot().getProject("BreakpointRulerActionsTest");
IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName());
// Without the Xtext nature the editor asks whether to add it, in a modal dialog.
description.setNatureIds(new String[] {XtextProjectHelper.NATURE_ID});
project.create(description, null);
project.open(null);
}

@AfterEach
void tearDown() throws CoreException {
UiThreadDispatcher.dispatchAndWait(() -> {
getActivePage().closeAllEditors(false);
});
DebugPlugin.getDefault().getBreakpointManager().removeBreakpoints(DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(), true);
project.delete(true, true, null);
}

@Test
void testCheckEditorHasBreakpointRulerActions() throws CoreException {
assertHasBreakpointRulerActions(openEditor("c.check", CATALOG));
}

@Test
void testFormatEditorHasBreakpointRulerActions() throws CoreException {
assertHasBreakpointRulerActions(openEditor("f.format", "formatter for g"));
}

@Test
void testCheckConfigurationEditorHasNoBreakpointRulerActions() throws CoreException {
XtextEditor editor = openEditor("c.checkcfg", "check configuration c {}");

assertFalse(editor.getAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK) instanceof ToggleBreakpointAction, "Double-clicking the ruler must not toggle a breakpoint");
assertNull(editor.getAction(BreakpointRulerActionContributor.ENABLE_DISABLE_ACTION_ID), "The enable/disable action must not be installed");
assertNull(editor.getAction(BreakpointRulerActionContributor.PROPERTIES_ACTION_ID), "The properties action must not be installed");
assertEquals(List.of(), getRulerMenuLabels(), "The ruler menu must not offer breakpoint actions");
}

@Test
void testActionsFollowTheBreakpointOnTheRulerLine() throws CoreException {
XtextEditor editor = openEditor("c.check", CATALOG);
IAction enableDisable = editor.getAction(BreakpointRulerActionContributor.ENABLE_DISABLE_ACTION_ID);
IAction properties = editor.getAction(BreakpointRulerActionContributor.PROPERTIES_ACTION_ID);
clickRulerOnFirstLine(editor);

assertFalse(updateAndGetEnabled(enableDisable), "Without a breakpoint the enable/disable action must be disabled");
assertFalse(updateAndGetEnabled(properties), "Without a breakpoint the properties action must be disabled");

final IBreakpoint breakpoint = JDIDebugModel.createStratumBreakpoint(project.getFile("c.check"), "Check", null, null, "com.test.*", 1, 0, 1, 0, true, null);
waitUntilEnabled(enableDisable);

assertTrue(updateAndGetEnabled(properties), "With a breakpoint the properties action must be enabled");
assertEquals(List.of(TOGGLE, "Disable Breakpoint", PROPERTIES), getRulerMenuLabels(), "The ruler menu must offer the breakpoint actions");

UiThreadDispatcher.dispatchAndWait(enableDisable::run);
assertFalse(breakpoint.isEnabled(), "The action must disable the breakpoint");
assertEquals(List.of(TOGGLE, "Enable Breakpoint", PROPERTIES), getRulerMenuLabels(), "The ruler menu must offer to enable the breakpoint");

UiThreadDispatcher.dispatchAndWait(enableDisable::run);
assertTrue(breakpoint.isEnabled(), "The action must enable the breakpoint");
}

private void assertHasBreakpointRulerActions(final XtextEditor editor) {
assertInstanceOf(ToggleBreakpointAction.class, editor.getAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK), "Double-clicking the ruler must toggle a breakpoint");
assertNotNull(editor.getAction(BreakpointRulerActionContributor.ENABLE_DISABLE_ACTION_ID), "The enable/disable action must be installed");
assertNotNull(editor.getAction(BreakpointRulerActionContributor.PROPERTIES_ACTION_ID), "The properties action must be installed");
assertEquals(3, getRulerMenuLabels().size(), "The ruler menu must offer the three breakpoint actions");
}

private XtextEditor openEditor(final String fileName, final String content) throws CoreException {
IFile file = project.getFile(fileName);
file.create(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), true, null);
return UiThreadDispatcher.dispatchAndWait(new Function<XtextEditor>() {
@Override
public XtextEditor run() {
try {
IEditorPart part = IDE.openEditor(getActivePage(), file);
return assertInstanceOf(XtextEditor.class, part);
} catch (PartInitException e) {
throw new IllegalStateException(e);
}
}
});
}

/**
* Makes the first line the ruler line of the last mouse activity, as a click on the ruler does.
*
* @param editor
* the editor, must not be {@code null}
*/
private void clickRulerOnFirstLine(final XtextEditor editor) {
UiThreadDispatcher.dispatchAndWait(() -> {
IVerticalRulerInfo rulerInfo = editor.getAdapter(IVerticalRulerInfo.class);
assertInstanceOf(IVerticalRulerExtension.class, rulerInfo).setLocationOfLastMouseButtonActivity(0, 1);
assertEquals(0, rulerInfo.getLineOfLastMouseButtonActivity(), "The ruler line must be the first line");
});
}

private boolean updateAndGetEnabled(final IAction action) {
return UiThreadDispatcher.dispatchAndWait(new Function<Boolean>() {
@Override
public Boolean run() {
((IUpdate) action).update();
return action.isEnabled();
}
});
}

/**
* Waits until the editor shows the breakpoint, which enables the given action.
*
* @param action
* the action, must not be {@code null}
*/
private void waitUntilEnabled(final IAction action) {
long deadline = System.currentTimeMillis() + TIMEOUT_MILLIS;
while (!updateAndGetEnabled(action)) {
assertTrue(System.currentTimeMillis() < deadline, "The editor must show the breakpoint on the ruler line");
try {
Thread.sleep(POLL_MILLIS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException(e);
}
}
}

/**
* Returns the labels, without mnemonics and accelerators, that the breakpoint contribution adds to the ruler menu of the active editor.
*
* @return the labels, never {@code null}
*/
private List<String> getRulerMenuLabels() {
return UiThreadDispatcher.dispatchAndWait(new Function<List<String>>() {
@Override
public List<String> run() {
Menu menu = new Menu(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
try {
new BreakpointRulerMenu().fill(menu, 0);
List<String> labels = new ArrayList<>();
for (MenuItem item : menu.getItems()) {
labels.add(item.getText().replace("&", "").split("\t")[0]);
}
return labels;
} finally {
menu.dispose();
}
}
});
}

private static IWorkbenchPage getActivePage() {
return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
}
}
2 changes: 1 addition & 1 deletion com.avaloq.tools.ddk.check.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: com.avaloq.tools.ddk.check.ui
Bundle-SymbolicName: com.avaloq.tools.ddk.check.ui;singleton:=true
Bundle-Version: 17.3.4.qualifier
Bundle-Version: 17.3.5.qualifier
Bundle-Vendor: Avaloq Group AG
Bundle-RequiredExecutionEnvironment: JavaSE-21
Bundle-Activator: com.avaloq.tools.ddk.check.ui.internal.Activator
Expand Down
41 changes: 7 additions & 34 deletions com.avaloq.tools.ddk.check.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -469,41 +469,14 @@
<adapter type="org.eclipse.debug.ui.actions.IToggleBreakpointsTarget"/>
</factory>
</extension>
<extension point="org.eclipse.ui.editorActions">
<editorContribution targetID="com.avaloq.tools.ddk.check.Check"
id="com.avaloq.tools.ddk.check.Check.rulerActions">
<action
label="Not Used"
class="com.avaloq.tools.ddk.check.ui.CheckExecutableExtensionFactory:org.eclipse.debug.ui.actions.RulerToggleBreakpointActionDelegate"
style="push"
actionID="RulerDoubleClick"
id="com.avaloq.tools.ddk.check.Check.doubleClickBreakpointAction"/>
</editorContribution>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:com.avaloq.tools.ddk.check.Check.RulerContext?after=debug">
<dynamic
class="com.avaloq.tools.ddk.xtext.ui.editor.breakpoints.BreakpointRulerMenu"
id="com.avaloq.tools.ddk.check.Check.rulerBreakpointActions"/>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.popupMenus">
<viewerContribution
targetID="com.avaloq.tools.ddk.check.Check.RulerContext"
id="com.avaloq.tools.ddk.check.Check.RulerPopupActions">
<action
label="Toggle Breakpoint"
class="com.avaloq.tools.ddk.check.ui.CheckExecutableExtensionFactory:org.eclipse.debug.ui.actions.RulerToggleBreakpointActionDelegate"
menubarPath="debug"
id="com.avaloq.tools.ddk.check.Check.rulerContextMenu.toggleBreakpointAction">
</action>
<action
label="Not used"
class="com.avaloq.tools.ddk.check.ui.CheckExecutableExtensionFactory:org.eclipse.debug.ui.actions.RulerEnableDisableBreakpointActionDelegate"
menubarPath="debug"
id="com.avaloq.tools.ddk.check.Check.rulerContextMenu.enableDisableBreakpointAction">
</action>
<action
label="Breakpoint Properties"
helpContextId="breakpoint_properties_action_context"
class="com.avaloq.tools.ddk.check.ui.CheckExecutableExtensionFactory:org.eclipse.jdt.debug.ui.actions.JavaBreakpointPropertiesRulerActionDelegate"
menubarPath="group.properties"
id="com.avaloq.tools.ddk.check.Check.rulerContextMenu.openBreapointPropertiesAction">
</action>
</viewerContribution>
<objectContribution
id="com.avaloq.tools.ddk.check.ui.contribution1"
objectClass="org.eclipse.jdt.core.IJavaProject">
Expand Down
2 changes: 1 addition & 1 deletion com.avaloq.tools.ddk.check.ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<version>18.0.1-SNAPSHOT</version>
<relativePath>../ddk-parent</relativePath>
</parent>
<version>17.3.4-SNAPSHOT</version>
<version>17.3.5-SNAPSHOT</version>
<groupId>com.avaloq.tools.ddk</groupId>
<artifactId>com.avaloq.tools.ddk.check.ui</artifactId>
<packaging>eclipse-plugin</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.xtext.ui.LanguageSpecific;
import org.eclipse.xtext.ui.editor.DirtyStateEditorSupport;
import org.eclipse.xtext.ui.editor.IURIEditorOpener;
import org.eclipse.xtext.ui.editor.actions.IActionContributor;
import org.eclipse.xtext.ui.editor.contentassist.ITemplateProposalProvider;
import org.eclipse.xtext.ui.editor.handler.ValidateActionHandler;
import org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper;
Expand All @@ -43,6 +44,7 @@
import com.avaloq.tools.ddk.check.ui.templates.CheckTemplateProposalProvider;
import com.avaloq.tools.ddk.xtext.common.types.ui.access.jdt.JdtFallbackTypeProviderFactory;
import com.avaloq.tools.ddk.xtext.ui.editor.FixedDirtyStateEditorSupport;
import com.avaloq.tools.ddk.xtext.ui.editor.breakpoints.BreakpointRulerActionContributor;
import com.avaloq.tools.ddk.xtext.ui.templates.KeywordAwareCrossReferenceTemplateVariableResolver;


Expand Down Expand Up @@ -130,6 +132,16 @@ public void configureLanguageSpecificURIEditorOpener(final com.google.inject.Bin
binder.bind(IURIEditorOpener.class).annotatedWith(LanguageSpecific.class).to(PlatformPluginAwareEditorOpener.class);
}

/**
* Installs the breakpoint actions of the vertical ruler on the editor.
*
* @param binder
* the binder
*/
public void configureBreakpointRulerActions(final com.google.inject.Binder binder) {
binder.bind(IActionContributor.class).annotatedWith(com.google.inject.name.Names.named("breakpointRulerActions")).to(BreakpointRulerActionContributor.class); //$NON-NLS-1$
}

/**
* Binds a JDT type provider factory capable of creating bundle aware type providers.
*
Expand Down
2 changes: 1 addition & 1 deletion com.avaloq.tools.ddk.checkcfg.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: com.avaloq.tools.ddk.checkcfg.ui
Bundle-SymbolicName: com.avaloq.tools.ddk.checkcfg.ui;singleton:=true
Bundle-Version: 17.3.4.qualifier
Bundle-Version: 17.3.5.qualifier
Bundle-Vendor: Avaloq Group AG
Bundle-RequiredExecutionEnvironment: JavaSE-21
Bundle-Activator: com.avaloq.tools.ddk.checkcfg.ui.internal.Activator
Expand Down
Loading