use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.
the class Ecore2XtextExtensions method allDispatcherRuleClasses.
public static Collection<EClass> allDispatcherRuleClasses(final Ecore2XtextConfiguration it) {
Set<EClass> _xifexpression = null;
EClass _rootElementClass = it.getRootElementClass();
boolean _tripleEquals = (_rootElementClass == null);
if (_tripleEquals) {
final Function1<EPackageInfo, Set<EClassifier>> _function = (EPackageInfo it_1) -> {
return Ecore2XtextExtensions.allReferencedClassifiers(it_1.getEPackage(), false);
};
final Function1<EClassifier, Boolean> _function_1 = (EClassifier c) -> {
return Boolean.valueOf(Ecore2XtextExtensions.needsDispatcherRule(c));
};
_xifexpression = IterableExtensions.<EClass>toSet(Iterables.<EClass>filter(IterableExtensions.<EClassifier>filter(IterableExtensions.<EClassifier>toSet(Iterables.<EClassifier>concat(IterableExtensions.<EPackageInfo, Set<EClassifier>>map(it.getEPackageInfos(), _function))), _function_1), EClass.class));
} else {
final Function1<EClass, Iterable<EClassifier>> _function_2 = (EClass c) -> {
final Function1<EReference, Boolean> _function_3 = (EReference r) -> {
return Boolean.valueOf(Ecore2XtextExtensions.needsAssignment(r));
};
final Function1<EReference, EClassifier> _function_4 = (EReference it_1) -> {
return it_1.getEType();
};
return IterableExtensions.<EReference, EClassifier>map(IterableExtensions.<EReference>filter(c.getEAllReferences(), _function_3), _function_4);
};
_xifexpression = IterableExtensions.<EClass>toSet(Iterables.<EClass>filter(Iterables.<EClassifier>concat(IterableExtensions.<EClass, Iterable<EClassifier>>map(Iterables.<EClass>filter(Ecore2XtextExtensions.allConcreteRuleClassifiers(it), EClass.class), _function_2)), EClass.class));
}
return _xifexpression;
}
use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.
the class Ecore2XtextGrammarCreator method grammar.
public CharSequence grammar(final WizardConfiguration config) {
CharSequence _xblockexpression = null;
{
final Ecore2XtextConfiguration it = config.getEcore2Xtext();
UniqueNameUtil.clearUniqueNames(it.getDefaultEPackageInfo());
StringConcatenation _builder = new StringConcatenation();
_builder.append("// automatically generated by Xtext");
_builder.newLine();
_builder.append("grammar ");
String _name = config.getLanguage().getName();
_builder.append(_name);
_builder.append(" with org.eclipse.xtext.common.Terminals");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
Collection<EPackage> _allReferencedEPackages = Ecore2XtextExtensions.allReferencedEPackages(it);
for (final EPackage it_1 : _allReferencedEPackages) {
_builder.append("import \"");
String _nsURI = it_1.getNsURI();
_builder.append(_nsURI);
_builder.append("\" ");
{
if (((UniqueNameUtil.uniqueName(it_1) != null) && (!Objects.equal(UniqueNameUtil.uniqueName(it_1), "")))) {
_builder.append("as ");
String _uniqueName = UniqueNameUtil.uniqueName(it_1);
_builder.append(_uniqueName);
}
}
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
CharSequence _rules = this.rules(it.getRootElementClass());
_builder.append(_rules);
_builder.newLineIfNotEmpty();
{
List<EClass> _but = this.<EClass>but(Ecore2XtextExtensions.allDispatcherRuleClasses(it), it.getRootElementClass());
for (final EClass it_2 : _but) {
_builder.newLine();
CharSequence _subClassDispatcherRule = this.subClassDispatcherRule(it_2);
_builder.append(_subClassDispatcherRule);
_builder.newLineIfNotEmpty();
}
}
{
List<EClassifier> _but_1 = this.<EClassifier>but(Ecore2XtextExtensions.allConcreteRuleClassifiers(it), it.getRootElementClass());
for (final EClassifier it_3 : _but_1) {
_builder.newLine();
CharSequence _rule = this.rule(it_3);
_builder.append(_rule);
_builder.newLineIfNotEmpty();
}
}
_xblockexpression = _builder;
}
return _xblockexpression;
}
use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.
the class Xtext2EcoreTransformer method collectClassInfosOf.
private void collectClassInfosOf(EClassifierInfos target, EPackage referencedEPackage, AbstractMetamodelDeclaration metaModel, boolean generated) {
for (EClassifier eClassifier : referencedEPackage.getEClassifiers()) {
if (eClassifier instanceof EClass) {
EClass eClass = (EClass) eClassifier;
EClassifierInfo info = EClassifierInfo.createEClassInfo(eClass, generated, getGeneratedEPackageURIs(), GrammarUtil.getGrammar(metaModel));
target.addInfo(metaModel, eClassifier.getName(), info);
} else if (eClassifier instanceof EDataType) {
EDataType eDataType = (EDataType) eClassifier;
EClassifierInfo info = EClassifierInfo.createEDataTypeInfo(eDataType, generated);
target.addInfo(metaModel, eClassifier.getName(), info);
}
}
}
use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.
the class PortableURIs method createPortableFragmentDescription.
protected PortableURIs.PortableFragmentDescription createPortableFragmentDescription(final IEObjectDescription desc, final EObject target) {
final EObject possibleContainer = EcoreUtil.resolve(desc.getEObjectOrProxy(), target);
final String fragmentToTarget = this.getFragment(target, possibleContainer);
EClass _eClass = desc.getEClass();
QualifiedName _qualifiedName = desc.getQualifiedName();
return new PortableURIs.PortableFragmentDescription(_eClass, _qualifiedName, fragmentToTarget);
}
use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.
the class ContextTypePDAProvider method getContextTypePDAs.
@Override
public SerializationContextMap<Pda<ISerState, RuleCall>> getContextTypePDAs(Grammar grammar) {
SerializationContextMap<Pda<ISerState, RuleCall>> cached = cache.get(grammar);
if (cached != null)
return cached;
SerializationContextMap.Builder<Pda<ISerState, RuleCall>> builder = SerializationContextMap.builder();
SerializationContextMap<Pda<ISerState, RuleCall>> contextPDAs = pdaProvider.getContextPDAs(grammar);
for (SerializationContextMap.Entry<Pda<ISerState, RuleCall>> e : contextPDAs.values()) {
List<ISerializationContext> parents = e.getContexts();
Pda<ISerState, RuleCall> contextPDA = e.getValue();
try {
Map<ISerState, Integer> distances = nfaUtil.distanceToFinalStateMap(contextPDA);
Set<EClass> types = collectTypes(contextPDA, distances);
if (types.size() == 1) {
for (ISerializationContext parent : parents) {
TypeContext ctx = new TypeContext(parent, types.iterator().next());
builder.put(ctx, contextPDA);
}
} else {
for (EClass type : types) {
Pda<ISerState, RuleCall> filtered = filterByType(contextPDA, type, distances);
for (ISerializationContext parent : parents) {
TypeContext typeContext = new TypeContext(parent, type);
builder.put(typeContext, filtered);
}
}
}
} catch (Exception x) {
LOG.error("Error extracting PDAs for types for context '" + parents + "': " + x.getMessage(), x);
}
}
SerializationContextMap<Pda<ISerState, RuleCall>> result = builder.create();
cache.put(grammar, result);
return result;
}
Aggregations