org.contextmapper.tactic.dsl.TacticDslExtensions Maven / Gradle / Ivy
/**
* Copyright 2013 The Sculptor Project Team, including the original
* author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.contextmapper.tactic.dsl;
import com.google.common.base.Objects;
import com.google.common.collect.Iterators;
import java.util.Iterator;
import org.contextmapper.tactic.dsl.tacticdsl.Attribute;
import org.contextmapper.tactic.dsl.tacticdsl.ComplexType;
import org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
/**
* Extensions for model elements of the domain model.
* Usage in Xtend files:
*
* @Inject extension TacticDslExtensions
*
* // ...
*
* element.rootContainer.eAllOfClass(typeof(DslService))
*
*/
@SuppressWarnings("all")
public class TacticDslExtensions {
/**
* Extensions for model elements of the domain model.
* Usage in Xtend files:
*
* @Inject extension SculptordslExtensions
*
* // ...
*
* element.rootContainer.eAllOfClass(typeof(DslService))
*
*/
public static Iterator eAllOfClass(final EObject obj, final Class clazz) {
TreeIterator _eAll = null;
if (obj!=null) {
_eAll=EcoreUtil2.eAll(obj);
}
return Iterators.filter(_eAll, clazz);
}
/**
* @return DslSimpleDomainObjects whose type matches attr.type
*/
public static Iterable domainObjectsForAttributeType(final Attribute attr) {
final Function1 _function = (SimpleDomainObject it) -> {
String _name = it.getName();
String _type = attr.getType();
return Boolean.valueOf(Objects.equal(_name, _type));
};
return IterableExtensions.filter(EcoreUtil2.eAllOfType(EcoreUtil.getRootContainer(attr), SimpleDomainObject.class), _function);
}
/**
* @return the first DslSimpleDomainObject whose type matches complexType, or null
*/
public static SimpleDomainObject firstDomainObjectForType(final ComplexType complexType) {
SimpleDomainObject _xblockexpression = null;
{
final Function1 _function = (SimpleDomainObject it) -> {
String _name = it.getName();
String _type = complexType.getType();
return Boolean.valueOf(Objects.equal(_name, _type));
};
final SimpleDomainObject res = IterableExtensions.findFirst(EcoreUtil2.eAllOfType(EcoreUtil.getRootContainer(complexType), SimpleDomainObject.class), _function);
_xblockexpression = res;
}
return _xblockexpression;
}
}