Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*******************************************************************************
* 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.xtext.ui.editor.findrefs;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.xtext.resource.IReferenceDescription;
import org.eclipse.xtext.resource.IResourceDescription;
import org.eclipse.xtext.resource.IResourceDescriptions;
import org.eclipse.xtext.ui.editor.findrefs.ReferenceSearchResult;
import org.junit.jupiter.api.Test;


/**
* Tests for {@link FastReferenceSearchResultContentProvider}.
*/
@SuppressWarnings("nls")
public class FastReferenceSearchResultContentProviderTest {

private static final URI FIRST_SOURCE = URI.createURI("platform:/resource/project/a.test#/0");
private static final URI SECOND_SOURCE = URI.createURI("platform:/resource/project/b.test#/0");
@Test
public void inputChangedToleratesReferencesAcceptedWhileRepopulating() {
List<IReferenceDescription> matchingReferences = new ArrayList<>();
matchingReferences.add(reference(FIRST_SOURCE));
ReferenceSearchResult searchResult = mock(ReferenceSearchResult.class);
when(searchResult.getMatchingReferences()).thenReturn(matchingReferences);

// the search thread accepts another reference while the UI thread is repopulating from the live list
IResourceDescription resourceDescription = mock(IResourceDescription.class);
when(resourceDescription.getURI()).thenReturn(FIRST_SOURCE.trimFragment());
IResourceDescriptions resourceDescriptions = mock(IResourceDescriptions.class);
when(resourceDescriptions.getResourceDescription(any())).thenAnswer(invocation -> {
if (matchingReferences.size() == 1) {
matchingReferences.add(reference(SECOND_SOURCE));
}
return resourceDescription;
});

FastReferenceSearchResultContentProvider provider = new FastReferenceSearchResultContentProvider(resourceDescriptions);
TreeViewer viewer = mock(TreeViewer.class);
assertDoesNotThrow(() -> provider.inputChanged(viewer, null, searchResult));
}

private static IReferenceDescription reference(final URI sourceEObjectUri) {
IReferenceDescription reference = mock(IReferenceDescription.class);
when(reference.getSourceEObjectUri()).thenReturn(sourceEObjectUri);
return reference;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

import com.avaloq.tools.ddk.xtext.ui.editor.findrefs.FastReferenceSearchResultContentProviderTest;
import com.avaloq.tools.ddk.xtext.ui.quickfix.WorkbenchResolutionAdaptorRunTest;
import com.avaloq.tools.ddk.xtext.ui.quickfix.WorkbenchResolutionAdaptorTest;
import com.avaloq.tools.ddk.xtext.ui.templates.ResourceNameTemplateVariableResolverTest;
Expand All @@ -31,7 +32,8 @@
WorkbenchResolutionAdaptorTest.class,
TemplateProposalProviderHelperTest.class,
ResourceNameTemplateVariableResolverTest.class,
SimpleEnumTemplateVariableResolverTest.class
SimpleEnumTemplateVariableResolverTest.class,
FastReferenceSearchResultContentProviderTest.class
// @Format-On
})
public class XtextUiTestSuite {
Expand Down
2 changes: 1 addition & 1 deletion com.avaloq.tools.ddk.xtext.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.xtext.ui
Bundle-SymbolicName: com.avaloq.tools.ddk.xtext.ui;singleton:=true
Bundle-Version: 17.3.3.qualifier
Bundle-Version: 17.3.4.qualifier
Bundle-Vendor: Avaloq Group AG
Bundle-RequiredExecutionEnvironment: JavaSE-21
Bundle-ActivationPolicy: lazy
Expand Down
2 changes: 1 addition & 1 deletion com.avaloq.tools.ddk.xtext.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.3-SNAPSHOT</version>
<version>17.3.4-SNAPSHOT</version>
<groupId>com.avaloq.tools.ddk</groupId>
<artifactId>com.avaloq.tools.ddk.xtext.ui</artifactId>
<packaging>eclipse-plugin</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,11 @@ public void inputChanged(final Viewer v, final Object oldInput, final Object new
if (newInput instanceof ReferenceSearchResult && v instanceof TreeViewer) {
((ReferenceSearchResult) newInput).addListener(this);
this.viewer = (TreeViewer) v;
for (IReferenceDescription referenceDescription : ((ReferenceSearchResult) newInput).getMatchingReferences()) {
addReference(referenceDescription);
// iterate a copy: the search job may still be appending to the live list
for (IReferenceDescription referenceDescription : Lists.newArrayList(((ReferenceSearchResult) newInput).getMatchingReferences())) {
if (referenceDescription != null) {
addReference(referenceDescription);
}
}
}
}
Expand Down