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
Expand Up @@ -21,6 +21,7 @@
import com.avaloq.tools.ddk.xtext.naming.QualifiedNameSegmentTreeLookupTest;
import com.avaloq.tools.ddk.xtext.resource.AbstractSelectorFragmentProviderTest;
import com.avaloq.tools.ddk.xtext.resource.BugAig1084;
import com.avaloq.tools.ddk.xtext.resource.PatternAwareEObjectDescriptionLookUpTest;
import com.avaloq.tools.ddk.xtext.resource.ResourceDescriptionDeltaTest;
import com.avaloq.tools.ddk.xtext.util.RuntimeProjectUtilTest;

Expand All @@ -40,7 +41,8 @@
QualifiedNamePatternTest.class,
BugAig1084.class,
RuntimeProjectUtilTest.class,
QualifiedNameSegmentTreeLookupTest.class})
QualifiedNameSegmentTreeLookupTest.class,
PatternAwareEObjectDescriptionLookUpTest.class})
// @Format-On
public class XtextTestSuite {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*******************************************************************************
* 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.resource;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;
import java.util.Set;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.EObjectDescription;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.junit.jupiter.api.Test;

import com.avaloq.tools.ddk.xtext.naming.QualifiedNamePattern;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;


@SuppressWarnings({"PMD.JUnitAssertionsShouldIncludeMessage", "nls"})
public class PatternAwareEObjectDescriptionLookUpTest {

private static final String FOO = "Foo";
private static final String FOO_BAR = "FooBar";
private static final String FOO_PREFIX = "Foo*";
private static final String OTHER = "Other";

private final PatternAwareEObjectDescriptionLookUp lookUp = new PatternAwareEObjectDescriptionLookUp(List.of(//
description(FOO), description(FOO_BAR), description("foobar"), description(OTHER)));
@Test
public void testCaseSensitivePatternMatchesCandidateNames() {
assertEquals(ImmutableSet.of(FOO, FOO_BAR), names(lookUp.getExportedObjects(EcorePackage.Literals.ECLASS, QualifiedNamePattern.create(FOO_PREFIX), false)));
}
@Test
public void testCaseSensitiveExactPattern() {
assertEquals(ImmutableSet.of(OTHER), names(lookUp.getExportedObjects(EcorePackage.Literals.ECLASS, QualifiedNamePattern.create(OTHER), false)));
}

@Test
public void testCaseInsensitivePattern() {
assertEquals(ImmutableSet.of(FOO, FOO_BAR, "foobar"), names(lookUp.getExportedObjects(EcorePackage.Literals.ECLASS, QualifiedNamePattern.create("foo*"), true)));
}

@Test
public void testCaseSensitivePlainName() {
assertEquals(ImmutableSet.of(FOO_BAR), names(lookUp.getExportedObjects(EcorePackage.Literals.ECLASS, QualifiedName.create(FOO_BAR), false)));
}

@Test
public void testPatternRespectsType() {
assertEquals(ImmutableSet.of(), names(lookUp.getExportedObjects(EcorePackage.Literals.EDATA_TYPE, QualifiedNamePattern.create(FOO_PREFIX), false)));
}

private static IEObjectDescription description(final String name) {
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName(name);
return EObjectDescription.create(QualifiedName.create(name), eClass);
}

private static Set<String> names(final Iterable<IEObjectDescription> descriptions) {
return ImmutableSet.copyOf(Iterables.transform(descriptions, d -> d.getName().toString()));
}
}
2 changes: 1 addition & 1 deletion com.avaloq.tools.ddk.xtext/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
Bundle-SymbolicName: com.avaloq.tools.ddk.xtext;singleton:=true
Bundle-Version: 17.4.1.qualifier
Bundle-Version: 17.4.2.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/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.4.1-SNAPSHOT</version>
<version>17.4.2-SNAPSHOT</version>
<groupId>com.avaloq.tools.ddk</groupId>
<artifactId>com.avaloq.tools.ddk.xtext</artifactId>
<packaging>eclipse-plugin</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Iterable<IEObjectDescription> getExportedObjects(final EClass type, final
return Collections.emptyList();
}
Predicate<IEObjectDescription> predicate = ignoreCase ? input -> EcoreUtil2.isAssignableFrom(type, input.getEClass())
: input -> isPattern ? EcoreUtil2.isAssignableFrom(type, input.getEClass()) && ((QualifiedNamePattern) name).matches(name)
: input -> isPattern ? EcoreUtil2.isAssignableFrom(type, input.getEClass()) && ((QualifiedNamePattern) name).matches(input.getName())
: name.equals(input.getName()) && EcoreUtil2.isAssignableFrom(type, input.getEClass());
return Collections2.filter(values, predicate);
}
Expand Down