use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.
the class DeclarativeScopeProviderTest method testPolymorphic.
@SuppressWarnings("unused")
@Test
public void testPolymorphic() throws Exception {
final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
private IScope scope_EClass(EClassifier clazz, EReference ref) {
return a;
}
private IScope scope_EClass(EClass clazz, EReference ref) {
return c;
}
private IScope scope_EClass(EReference ctx, EReference ref) {
return b;
}
};
EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
assertEquals(b, provider.getScope(details, details));
assertEquals(c, provider.getScope(details.getEContainingClass(), details));
}
use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.
the class DeclarativeScopeProviderTest method testScopeByType2.
@SuppressWarnings("unused")
@Test
public void testScopeByType2() throws Exception {
final IScope a = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
final IScope b = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
final IScope c = new SimpleScope(IScope.NULLSCOPE, Collections.<IEObjectDescription>emptySet());
AbstractDeclarativeScopeProvider provider = new AbstractDeclarativeScopeProvider() {
private IScope scope_EClass(EClassifier clazz, EReference ref) {
return a;
}
private IScope scope_EClass(EClass clazz, EReference ref) {
return c;
}
private IScope scope_EClass(EReference ctx, EReference ref) {
return b;
}
};
EReference details = EcorePackage.eINSTANCE.getEClass_ESuperTypes();
assertEquals(b, provider.getScope(details, details));
assertEquals(c, provider.getScope(details.getEContainingClass(), details));
}
use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.
the class Formatter2Fragment2 method doGenerateStubFile.
protected void doGenerateStubFile() {
boolean _isGenerateStub = this.isGenerateStub();
boolean _not = (!_isGenerateStub);
if (_not) {
return;
}
boolean _isGenerateXtendStub = this.isGenerateXtendStub();
if (_isGenerateXtendStub) {
final XtendFileAccess xtendFile = this.fileAccessFactory.createXtendFile(this.getFormatter2Stub(this.getGrammar()));
xtendFile.setResourceSet(this.getLanguage().getResourceSet());
final LinkedHashMultimap<EClass, EReference> type2ref = LinkedHashMultimap.<EClass, EReference>create();
this.getLocallyAssignedContainmentReferences(this.getLanguage().getGrammar(), type2ref);
final LinkedHashMultimap<EClass, EReference> inheritedTypes = LinkedHashMultimap.<EClass, EReference>create();
this.getInheritedContainmentReferences(this.getLanguage().getGrammar(), inheritedTypes, CollectionLiterals.<Grammar>newHashSet());
final Set<EClass> types = type2ref.keySet();
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("class ");
String _simpleName = Formatter2Fragment2.this.getFormatter2Stub(Formatter2Fragment2.this.getGrammar()).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _stubSuperClass = Formatter2Fragment2.this.getStubSuperClass();
_builder.append(_stubSuperClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@");
_builder.append(Inject.class, "\t");
_builder.append(" extension ");
TypeReference _grammarAccess = Formatter2Fragment2.this._grammarAccessExtensions.getGrammarAccess(Formatter2Fragment2.this.getGrammar());
_builder.append(_grammarAccess, "\t");
_builder.newLineIfNotEmpty();
{
Iterable<EClass> _take = IterableExtensions.<EClass>take(types, 2);
for (final EClass type : _take) {
_builder.newLine();
_builder.append("\t");
StringConcatenationClient _generateFormatMethod = Formatter2Fragment2.this.generateFormatMethod(type, type2ref.get(type), inheritedTypes.containsKey(type));
_builder.append(_generateFormatMethod, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("// TODO: implement for ");
final Function1<EClass, String> _function = (EClass it) -> {
return it.getName();
};
String _join = IterableExtensions.join(IterableExtensions.<EClass, String>map(IterableExtensions.<EClass>drop(types, 2), _function), ", ");
_builder.append(_join, "\t");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
};
xtendFile.setContent(_client);
xtendFile.writeTo(this.getProjectConfig().getRuntime().getSrc());
} else {
String _name = this.getClass().getName();
String _plus = (_name + " has been configured to generate a Java stub, but that\'s not yet supported. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=481563");
Formatter2Fragment2.LOG.error(_plus);
}
}
use of org.eclipse.emf.ecore.EReference 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.EReference in project xtext-core by eclipse.
the class PortableURIs method resolve.
/**
* Resolves a given portable URI fragment against the given resource.
*
* @param resource the resource from which global scope to look up the EObject
* @param portableFragment the portable fragment pointing to the to be resolved EObject
*
* @return the EObject for the given portableURIFragment
*/
public EObject resolve(final StorageAwareResource resource, final String portableFragment) {
final PortableURIs.PortableFragmentDescription desc = this.fromFragmentString(portableFragment);
final EReference mock = EcoreFactory.eINSTANCE.createEReference();
mock.setEType(desc.descriptionEClass);
final IScope scope = this.globalScopeProvider.getScope(resource, mock, Predicates.<IEObjectDescription>alwaysTrue());
final IEObjectDescription description = IterableExtensions.<IEObjectDescription>head(scope.getElements(desc.descriptionQualifiedName));
if ((description == null)) {
return null;
}
final EObject container = EcoreUtil.resolve(description.getEObjectOrProxy(), resource);
return this.getEObject(container, desc.descriptionRelativeFragment);
}
Aggregations