use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.
the class JavaLinkingTest method testGetXtendClassDirectly.
@Test
public void testGetXtendClassDirectly() throws Exception {
IFile xtendFile = testHelper.createFile("test/XtendClass", "package test\nclass XtendClass {}");
waitForBuild();
assertNumberOfMarkers(xtendFile, 0);
ResourceSet resourceSet = resourceSetProvider.get(testHelper.getProject());
IJvmTypeProvider jvmTypeProvider = typeProviderFactory.findOrCreateTypeProvider(resourceSet);
JvmType xtendType = jvmTypeProvider.findTypeByName("test.XtendClass");
assertNotNull(xtendType);
assertEquals("test.XtendClass", xtendType.getQualifiedName());
Resource xtendResource = xtendType.eResource();
assertEquals("platform:/resource" + xtendFile.getFullPath(), xtendResource.getURI().toString());
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.
the class JavaLinkingTest method testNavigateToXtendClass.
@Test
public void testNavigateToXtendClass() throws Exception {
IFile xtendFile = testHelper.createFile("test/XtendClass", "package test\nclass XtendClass {}");
IFile javaFile = testHelper.createFileImpl(WorkbenchTestHelper.TESTPROJECT_NAME + "/src/test/JavaClass.java", "package test;\npublic class JavaClass extends XtendClass {}");
waitForBuild();
assertNumberOfMarkers(xtendFile, 0);
assertNumberOfMarkers(javaFile, 0);
ResourceSet resourceSet = resourceSetProvider.get(testHelper.getProject());
IJvmTypeProvider jvmTypeProvider = typeProviderFactory.findOrCreateTypeProvider(resourceSet);
JvmType javaType = jvmTypeProvider.findTypeByName("test.JavaClass");
assertNotNull(javaType);
assertTrue(javaType instanceof JvmDeclaredType);
JvmDeclaredType declaredJavaType = (JvmDeclaredType) javaType;
JvmTypeReference superType = declaredJavaType.getSuperTypes().get(0);
JvmType xtendType = superType.getType();
assertNotNull(xtendType);
assertEquals("test.XtendClass", xtendType.getQualifiedName());
Resource xtendResource = xtendType.eResource();
assertEquals("platform:/resource" + xtendFile.getFullPath(), xtendResource.getURI().toString());
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.
the class AbstractXtendOutlineTreeBuilder method buildInheritedMembers.
protected void buildInheritedMembers(final JvmDeclaredType inferredType, final IXtendOutlineContext context) {
ResourceSet _resourceSet = inferredType.eResource().getResourceSet();
final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, _resourceSet);
final LightweightTypeReference typeReference = owner.toLightweightTypeReference(inferredType);
final List<LightweightTypeReference> superTypes = typeReference.getAllSuperTypes();
IXtendOutlineContext superTypeContext = context;
for (final LightweightTypeReference superTypeRef : superTypes) {
{
superTypeContext = superTypeContext.increaseInheritanceDepth();
final ResolvedFeatures resolvedFeatures = new ResolvedFeatures(superTypeRef);
List<IResolvedField> _declaredFields = resolvedFeatures.getDeclaredFields();
for (final IResolvedField jvmField : _declaredFields) {
boolean _skipFeature = this.skipFeature(jvmField.getDeclaration());
boolean _not = (!_skipFeature);
if (_not) {
this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, jvmField, superTypeContext);
}
}
List<IResolvedConstructor> _declaredConstructors = resolvedFeatures.getDeclaredConstructors();
for (final IResolvedConstructor constructor : _declaredConstructors) {
boolean _skipFeature_1 = this.skipFeature(constructor.getDeclaration());
boolean _not_1 = (!_skipFeature_1);
if (_not_1) {
this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, constructor, superTypeContext);
}
}
List<IResolvedOperation> _declaredOperations = resolvedFeatures.getDeclaredOperations();
for (final IResolvedOperation operation : _declaredOperations) {
if (((!this.skipFeature(operation.getDeclaration())) && (!superTypeContext.isProcessed(operation.getDeclaration())))) {
this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, operation, superTypeContext);
}
}
final JvmType declaredType = superTypeRef.getType();
if ((declaredType instanceof JvmDeclaredType)) {
final IXtendOutlineContext nestedTypeContext = superTypeContext.hideInherited();
final Consumer<JvmDeclaredType> _function = (JvmDeclaredType it) -> {
this.buildJvmType(it, nestedTypeContext);
};
Iterables.<JvmDeclaredType>filter(((JvmDeclaredType) declaredType).getMembers(), JvmDeclaredType.class).forEach(_function);
}
}
}
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.
the class RelatedXtextResourceUpdater method applyChange.
@Override
public void applyChange(Deltas deltas, IAcceptor<IEmfResourceChange> changeAcceptor) {
XtextResource res = (XtextResource) lifecycleManager.openAndApplyReferences(getResourceSet(), getResource());
if (!referenceUpdater.isAffected(deltas, getResource())) {
return;
}
ITextRegionAccess base = textRegionBuilderProvider.get().forNodeModel(res).create();
ITextRegionDiffBuilder rewriter = new StringBasedTextRegionAccessDiffBuilder(base);
ReferenceUpdaterContext context = new ReferenceUpdaterContext(deltas, rewriter, getResource());
referenceUpdater.update(context);
if (!context.getModifications().isEmpty()) {
ChangeRecorder rec = new ChangeRecorder(res);
for (Runnable run : context.getModifications()) {
run.run();
}
ChangeDescription recording = rec.endRecording();
ResourceSet rs = res.getResourceSet();
ResourceSetRecording tree = changeTreeProvider.createChangeTree(rs, Collections.emptyList(), recording);
ResourceRecording recordedResource = tree.getRecordedResource(res);
if (recordedResource != null) {
serializer.serializeChanges(recordedResource, rewriter);
}
}
for (IUpdatableReference upd : context.getUpdatableReferences()) {
referenceUpdater.updateReference(rewriter, upd);
}
ITextRegionAccessDiff rewritten = rewriter.create();
List<ITextReplacement> rep = formatter.format(rewritten);
TextDocumentChange change = new TextDocumentChange(rewritten, getResource().getUri(), rep);
changeAcceptor.accept(change);
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.
the class FileAwareTestLanguageImportTest method testMoveToNewPackage.
@Test
public void testMoveToNewPackage() {
final InMemoryURIHandler fs = new InMemoryURIHandler();
StringConcatenation _builder = new StringConcatenation();
_builder.append("package pkg1");
_builder.newLine();
_builder.newLine();
_builder.append("element Foo {");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.fileawaretestlanguage", _builder.toString());
this._importTestHelper.operator_add(fs, _mappedTo);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package pkg1");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("element Bar {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("ref Foo");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("inmemory:/file2.fileawaretestlanguage", _builder_1.toString());
this._importTestHelper.operator_add(fs, _mappedTo_1);
final ResourceSet rs = this._importTestHelper.createResourceSet(fs);
final PackageDeclaration model = this._importTestHelper.<PackageDeclaration>contents(rs, "inmemory:/file1.fileawaretestlanguage", PackageDeclaration.class);
final ChangeSerializer serializer = this.serializerProvider.get();
final IChangeSerializer.IModification<PackageDeclaration> _function = (PackageDeclaration it) -> {
model.setName("newpackage");
};
serializer.<PackageDeclaration>addModification(model, _function);
Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._importTestHelper.endRecordChangesToTextDocuments(serializer);
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("-------- inmemory:/file1.fileawaretestlanguage (syntax: <offset|text>) ---------");
_builder_2.newLine();
_builder_2.append("package <8:4|newpackage>");
_builder_2.newLine();
_builder_2.newLine();
_builder_2.append("element Foo {");
_builder_2.newLine();
_builder_2.append("}");
_builder_2.newLine();
_builder_2.append("--------------------------------------------------------------------------------");
_builder_2.newLine();
_builder_2.append("8 4 \"pkg1\" -> \"newpackage\"");
_builder_2.newLine();
_builder_2.append("-------- inmemory:/file2.fileawaretestlanguage (syntax: <offset|text>) ---------");
_builder_2.newLine();
_builder_2.append("package pkg1");
_builder_2.newLine();
_builder_2.newLine();
_builder_2.append("<14:0|import newpackage.Foo");
_builder_2.newLine();
_builder_2.newLine();
_builder_2.append(">element Bar {");
_builder_2.newLine();
_builder_2.append("\t");
_builder_2.append("ref Foo");
_builder_2.newLine();
_builder_2.append("}");
_builder_2.newLine();
_builder_2.append("--------------------------------------------------------------------------------");
_builder_2.newLine();
_builder_2.append("14 0 \"\" -> \"import newpackage...\"");
_builder_2.newLine();
this._importTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
Aggregations