use of com.avaloq.tools.ddk.xtext.naming.QualifiedNamePattern in project dsl-devkit by dsldevkit.
the class ContainerBasedScope method getSingleElement.
// Using QualifiedName#toLowerCase() not String#toLowerCase()
@SuppressWarnings({ "PMD.UseLocaleWithCaseConversions", "PMD.NPathComplexity" })
@Override
public synchronized IEObjectDescription getSingleElement(final QualifiedName name) {
if (nameFunctions != null && nameFunctions.contains(NameFunctions.exportNameFunction())) {
final boolean ignoreCase = isIgnoreCase();
final QualifiedName lookupName = ignoreCase ? name.toLowerCase() : name;
final IEObjectDescription cachedResult = contentByNameCache.get(lookupName);
if (cachedResult != null) {
if (cachedResult != NULL_DESCRIPTION) {
return cachedResult;
}
// Otherwise check for aliasing and if yes revert to normal behavior or delegate or parent otherwise
} else {
QualifiedName namePattern = criteria.getNamePattern();
if (namePattern != null && ignoreCase) {
namePattern = namePattern.toLowerCase();
}
if (namePattern == null || namePattern.equals(lookupName) || (namePattern instanceof QualifiedNamePattern && ((QualifiedNamePattern) namePattern).matches(lookupName))) {
final ContainerQuery copy = ((ContainerQuery.Builder) criteria).copy().name(lookupName).ignoreCase(ignoreCase);
final Iterable<IEObjectDescription> queryResult = copy.execute(container);
IEObjectDescription description = Iterables.getFirst(queryResult, null);
if (description != null) {
contentByNameCache.put(lookupName, description);
return description;
}
contentByNameCache.put(lookupName, NULL_DESCRIPTION);
}
}
// in case of aliasing revert to normal behavior
return nameFunctions.size() > 1 ? super.getSingleElement(name) : getParent().getSingleElement(name);
} else {
return super.getSingleElement(name);
}
}
use of com.avaloq.tools.ddk.xtext.naming.QualifiedNamePattern in project dsl-devkit by dsldevkit.
the class ContainerBasedScope method getLocalElementsByName.
// Using QualifiedName#toLowerCase() not String#toLowerCase()
@SuppressWarnings("PMD.UseLocaleWithCaseConversions")
@Override
protected Iterable<IEObjectDescription> getLocalElementsByName(final QualifiedName name) {
if (nameFunctions != null && nameFunctions.size() == 1 && nameFunctions.contains(NameFunctions.exportNameFunction())) {
final boolean ignoreCase = isIgnoreCase();
final QualifiedName lookupName = ignoreCase ? name.toLowerCase() : name;
QualifiedName namePattern = criteria.getNamePattern();
if (namePattern != null && ignoreCase) {
namePattern = namePattern.toLowerCase();
}
if (namePattern == null || namePattern.equals(lookupName) || (namePattern instanceof QualifiedNamePattern && ((QualifiedNamePattern) namePattern).matches(lookupName))) {
final ContainerQuery copy = ((ContainerQuery.Builder) criteria).copy().name(lookupName).ignoreCase(ignoreCase);
return copy.execute(container);
}
return Collections.<IEObjectDescription>emptyList();
} else {
return super.getLocalElementsByName(name);
}
}
use of com.avaloq.tools.ddk.xtext.naming.QualifiedNamePattern in project dsl-devkit by dsldevkit.
the class PatternAwareEObjectDescriptionLookUp method getExportedObjects.
@Override
public Iterable<IEObjectDescription> getExportedObjects(final EClass type, final QualifiedName name, final boolean ignoreCase) {
if (Iterables.isEmpty(getExportedObjects())) {
return Collections.emptyList();
}
// NOPMD UseLocaleWithCaseConversions not a String!
QualifiedName lowerCase = name.toLowerCase();
QualifiedNameLookup<IEObjectDescription> lookup = getNameToObjectsLookup();
Collection<IEObjectDescription> values;
final boolean isPattern = lowerCase instanceof QualifiedNamePattern;
if (isPattern) {
values = lookup.get((QualifiedNamePattern) lowerCase, false);
} else {
values = lookup.get(lowerCase);
}
if (values == null) {
return Collections.emptyList();
}
Predicate<IEObjectDescription> predicate = ignoreCase ? new Predicate<IEObjectDescription>() {
@Override
public boolean apply(final IEObjectDescription input) {
return EcoreUtil2.isAssignableFrom(type, input.getEClass());
}
} : new Predicate<IEObjectDescription>() {
@Override
public boolean apply(final IEObjectDescription input) {
if (isPattern) {
return EcoreUtil2.isAssignableFrom(type, input.getEClass()) && ((QualifiedNamePattern) name).matches(name);
} else {
return name.equals(input.getName()) && EcoreUtil2.isAssignableFrom(type, input.getEClass());
}
}
};
return Collections2.filter(values, predicate);
}
Aggregations