use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class ChangeSerializerWithEmfTest method testChangeRefToXML.
@Test
public void testChangeRefToXML() {
final InMemoryURIHandler fs = new InMemoryURIHandler();
StringConcatenation _builder = new StringConcatenation();
_builder.append("#21 MyPackage.MyClass1");
Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _builder.toString());
this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
_builder_1.newLine();
_builder_1.append("<ecore:EPackage xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("xmlns:ecore=\"http://www.eclipse.org/emf/2002/Ecore\" name=\"MyPackage\">");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("<eClassifiers xsi:type=\"ecore:EClass\" name=\"MyClass1\" eSuperTypes=\"#//MyClass2\"/>");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("<eClassifiers xsi:type=\"ecore:EClass\" name=\"MyClass2\"/>");
_builder_1.newLine();
_builder_1.append("</ecore:EPackage>");
_builder_1.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("inmemory:/file2.ecore", _builder_1.toString());
this._changeSerializerTestHelper.operator_add(fs, _mappedTo_1);
final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
final EClassRef model = this._changeSerializerTestHelper.<EClassRef>contents(rs, "inmemory:/file1.pstl", EClassRef.class);
final ChangeSerializer serializer = this.serializerProvider.get();
final IChangeSerializer.IModification<EClassRef> _function = (EClassRef it) -> {
EClassifier _get = model.getRef().getEPackage().getEClassifiers().get(1);
model.setRef(((EClass) _get));
};
serializer.<EClassRef>addModification(model, _function);
Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
_builder_2.newLine();
_builder_2.append("#21 <4:18|MyPackage.MyClass2>");
_builder_2.newLine();
_builder_2.append("--------------------------------------------------------------------------------");
_builder_2.newLine();
_builder_2.append("4 18 \"MyPackage.MyClass1\" -> \"MyPackage.MyClass2\"");
_builder_2.newLine();
this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class ChangeSerializerWithEmfTest method testChangeInXML.
@Test
public void testChangeInXML() {
final InMemoryURIHandler fs = new InMemoryURIHandler();
StringConcatenation _builder = new StringConcatenation();
_builder.append("#21 MyPackage.MyClass1");
Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _builder.toString());
this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
_builder_1.newLine();
_builder_1.append("<ecore:EPackage xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("xmlns:ecore=\"http://www.eclipse.org/emf/2002/Ecore\" name=\"MyPackage\">");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("<eClassifiers xsi:type=\"ecore:EClass\" name=\"MyClass1\"/>");
_builder_1.newLine();
_builder_1.append("</ecore:EPackage>");
_builder_1.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("inmemory:/file2.ecore", _builder_1.toString());
this._changeSerializerTestHelper.operator_add(fs, _mappedTo_1);
final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
final EPackage model = this._changeSerializerTestHelper.<EPackage>contents(rs, "inmemory:/file2.ecore", EPackage.class);
final ChangeSerializer serializer = this.serializerProvider.get();
final IChangeSerializer.IModification<EPackage> _function = (EPackage it) -> {
EClassifier _head = IterableExtensions.<EClassifier>head(model.getEClassifiers());
((EClass) _head).setName("NewClass");
};
serializer.<EPackage>addModification(model, _function);
Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("---------------------------- inmemory:/file2.ecore -----------------------------");
_builder_2.newLine();
_builder_2.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
_builder_2.newLine();
_builder_2.append("<ecore:EPackage xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
_builder_2.newLine();
_builder_2.append(" ");
_builder_2.append("xmlns:ecore=\"http://www.eclipse.org/emf/2002/Ecore\" name=\"MyPackage\">");
_builder_2.newLine();
_builder_2.append(" ");
_builder_2.append("<eClassifiers xsi:type=\"ecore:EClass\" name=\"NewClass\"/>");
_builder_2.newLine();
_builder_2.append("</ecore:EPackage>");
_builder_2.newLine();
_builder_2.append("--------------------------------------------------------------------------------");
_builder_2.newLine();
_builder_2.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
_builder_2.newLine();
_builder_2.append("#21 <4:18|MyPackage.NewClass>");
_builder_2.newLine();
_builder_2.append("--------------------------------------------------------------------------------");
_builder_2.newLine();
_builder_2.append("4 18 \"MyPackage.MyClass1\" -> \"MyPackage.NewClass\"");
_builder_2.newLine();
this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class XtextReferableElementsUnloader method caseEPackage.
private void caseEPackage(EPackage ePackage) {
// guard against infinite recursion
// EPackage.eSetProxyURI and friends tries to be smart thus
// we have to make sure to compute all URIs before they are
// set
Resource resource = ePackage.eResource();
URI resourceURI = resource.getURI();
List<EClassifier> classifiers = ePackage.getEClassifiers();
List<URI> uris = new ArrayList<URI>(classifiers.size());
for (int i = 0, size = classifiers.size(); i < size; i++) {
uris.add(resourceURI.appendFragment(resource.getURIFragment(classifiers.get(i))));
}
// and we have to set them in a proper order
unload(ePackage);
for (int i = 0, size = classifiers.size(); i < size; i++) {
InternalEObject classifier = (InternalEObject) classifiers.get(i);
classifier.eSetProxyURI(uris.get(i));
}
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class EClassifierInfos method getCompatibleTypeNameOf.
public EClassifier getCompatibleTypeNameOf(Collection<EClassifier> classifiers, boolean useParent) {
final Collection<EClassifierInfo> types = Sets.newLinkedHashSet();
for (EClassifier classifier : classifiers) {
final EClassifierInfo info = getInfoOrNull(classifier);
if (info == null)
return null;
types.add(info);
}
final EClassifierInfo compatibleType = getCompatibleTypeOf(types);
if (compatibleType != null)
return compatibleType.getEClassifier();
return GrammarUtil.findEObject(grammar);
}
use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.
the class TypeHierarchyHelper method pushFeaturesUp.
private void pushFeaturesUp(EClassInfo info, Collection<EClass> traversedClasses) {
EClass eClass = info.getEClass();
if (info.isGenerated()) {
if (traversedClasses.add(eClass)) {
if (eClass.getESuperTypes().isEmpty())
return;
for (EClass superType : eClass.getESuperTypes()) {
EClassInfo superInfo = (EClassInfo) infos.getInfoOrNull(superType);
pushFeaturesUp(superInfo, traversedClasses);
}
Map<String, EStructuralFeature> allFeatures = Maps.newLinkedHashMap();
Set<String> skippedNames = Sets.newLinkedHashSet();
for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {
if (feature.getEContainingClass() != eClass) {
if (allFeatures.containsKey(feature.getName())) {
allFeatures.remove(feature.getName());
} else if (skippedNames.add(feature.getName())) {
allFeatures.put(feature.getName(), feature);
}
}
}
Iterator<EStructuralFeature> iter = eClass.getEStructuralFeatures().iterator();
while (iter.hasNext()) {
EStructuralFeature declared = iter.next();
EStructuralFeature existing = allFeatures.get(declared.getName());
if (existing != null) {
EClassifier compatibleType = EcoreUtil2.getCompatibleType(declared.getEType(), existing.getEType(), grammar);
if (compatibleType != null) {
iter.remove();
existing.setEType(compatibleType);
}
}
}
}
}
}
Aggregations