use of org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration in project xtext-core by eclipse.
the class FileAwareTestLanguageImportScopeProvider method internalGetImportedNamespaceResolvers.
@Override
protected List<ImportNormalizer> internalGetImportedNamespaceResolvers(final EObject context, final boolean ignoreCase) {
final List<ImportNormalizer> resolvers = super.internalGetImportedNamespaceResolvers(context, ignoreCase);
if ((context instanceof PackageDeclaration)) {
QualifiedName _qualifiedName = this.getQualifiedNameConverter().toQualifiedName(((PackageDeclaration) context).getName());
ImportNormalizer _importNormalizer = new ImportNormalizer(_qualifiedName, true, false);
resolvers.add(_importNormalizer);
EList<Import> _imports = ((PackageDeclaration) context).getImports();
for (final Import imp : _imports) {
{
final QualifiedName name = this.getImportedNamespace(imp);
ImportNormalizer _importNormalizer_1 = new ImportNormalizer(name, false, false);
resolvers.add(_importNormalizer_1);
}
}
}
return resolvers;
}
use of org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration in project xtext-core by eclipse.
the class FileAwareTestLanguageResourceRelocationStrategy method applyChange.
@Override
public void applyChange(final ResourceRelocationContext context) {
final Function1<ResourceRelocationChange, Boolean> _function = (ResourceRelocationChange it) -> {
return Boolean.valueOf(this.canHandle(it));
};
final Consumer<ResourceRelocationChange> _function_1 = (ResourceRelocationChange change) -> {
final IChangeSerializer.IModification<Resource> _function_2 = (Resource resource) -> {
final EObject rootElement = IterableExtensions.<EObject>head(resource.getContents());
if ((rootElement instanceof PackageDeclaration)) {
final String newPackage = IterableExtensions.join(IterableExtensions.<String>drop(change.getToURI().trimSegments(1).segmentsList(), 2), ".");
((PackageDeclaration) rootElement).setName(newPackage);
}
};
context.addModification(change, _function_2);
};
IterableExtensions.<ResourceRelocationChange>filter(context.getChanges(), _function).forEach(_function_1);
}
use of org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration in project xtext-core by eclipse.
the class FileAwareTestLanguageImportTest method testNestedPackage.
@Test
public void testNestedPackage() {
final InMemoryURIHandler fs = new InMemoryURIHandler();
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo ");
_builder.newLine();
_builder.append("element X {}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/foo/X.fileawaretestlanguage", _builder.toString());
this._importTestHelper.operator_add(fs, _mappedTo);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package foo.bar ");
_builder_1.newLine();
_builder_1.append("element Y { ref foo.X }");
_builder_1.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("inmemory:/foo/bar/Y.fileawaretestlanguage", _builder_1.toString());
this._importTestHelper.operator_add(fs, _mappedTo_1);
final ResourceSet rs = this._importTestHelper.createResourceSet(fs);
final PackageDeclaration model1 = this._importTestHelper.<PackageDeclaration>contents(rs, "inmemory:/foo/X.fileawaretestlanguage", PackageDeclaration.class);
final PackageDeclaration model2 = this._importTestHelper.<PackageDeclaration>contents(rs, "inmemory:/foo/bar/Y.fileawaretestlanguage", PackageDeclaration.class);
final ChangeSerializer serializer = this.serializerProvider.get();
final IChangeSerializer.IModification<PackageDeclaration> _function = (PackageDeclaration it) -> {
it.setName("foo2");
};
serializer.<PackageDeclaration>addModification(model1, _function);
final IChangeSerializer.IModification<PackageDeclaration> _function_1 = (PackageDeclaration it) -> {
model2.setName("foo2.bar");
model2.setName("foo2.bar");
};
serializer.<PackageDeclaration>addModification(model2, _function_1);
Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._importTestHelper.endRecordChangesToTextDocuments(serializer);
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("-------- inmemory:/foo/X.fileawaretestlanguage (syntax: <offset|text>) ---------");
_builder_2.newLine();
_builder_2.append("package <8:3|foo2> ");
_builder_2.newLine();
_builder_2.append("element X {}");
_builder_2.newLine();
_builder_2.append("--------------------------------------------------------------------------------");
_builder_2.newLine();
_builder_2.append("8 3 \"foo\" -> \"foo2\"");
_builder_2.newLine();
_builder_2.append("------ inmemory:/foo/bar/Y.fileawaretestlanguage (syntax: <offset|text>) -------");
_builder_2.newLine();
_builder_2.append("package <8:7|foo2.bar> ");
_builder_2.newLine();
_builder_2.append("<17:0|import foo2.X");
_builder_2.newLine();
_builder_2.newLine();
_builder_2.append(">element Y { ref <33:5|X> }");
_builder_2.newLine();
_builder_2.append("--------------------------------------------------------------------------------");
_builder_2.newLine();
_builder_2.append(" ");
_builder_2.append("8 7 \"foo.bar\" -> \"foo2.bar\"");
_builder_2.newLine();
_builder_2.append("17 0 \"\" -> \"import foo2.X\\n\\n\"");
_builder_2.newLine();
_builder_2.append("33 5 \"foo.X\" -> \"X\"");
_builder_2.newLine();
this._importTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
use of org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration in project xtext-core by eclipse.
the class FileAwareTestLanguageImportTest method testRenameGlobal1.
@Test
public void testRenameGlobal1() {
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 pkg2");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("import pkg1.Foo");
_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 pkg2");
_builder_2.newLine();
_builder_2.newLine();
_builder_2.append("import <21:8|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("21 8 \"pkg1.Foo\" -> \"newpackage.Foo\"");
_builder_2.newLine();
this._importTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
use of org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration in project xtext-core by eclipse.
the class FileAwareTestLanguageSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == FileAwarePackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case FileAwarePackage.ELEMENT:
sequence_Element(context, (Element) semanticObject);
return;
case FileAwarePackage.IMPORT:
sequence_Import(context, (Import) semanticObject);
return;
case FileAwarePackage.PACKAGE_DECLARATION:
sequence_PackageDeclaration(context, (PackageDeclaration) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Aggregations