Search in sources :

Example 1 with Import

use of org.eclipse.xtext.testlanguages.fileAware.fileAware.Import in project xtext-core by eclipse.

the class FileAwareTestLanguageFormatter method _format.

protected void _format(final PackageDeclaration pkg, @Extension final IFormattableDocument document) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.setNewLines(2);
    };
    document.append(this.textRegionExtensions.regionFor(pkg).feature(FileAwarePackage.Literals.PACKAGE_DECLARATION__NAME), _function);
    EList<Import> _imports = pkg.getImports();
    for (final Import imp : _imports) {
        {
            document.<Import>format(imp);
            final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
                int _xifexpression = (int) 0;
                Import _last = IterableExtensions.<Import>last(pkg.getImports());
                boolean _tripleEquals = (imp == _last);
                if (_tripleEquals) {
                    _xifexpression = 2;
                } else {
                    _xifexpression = 1;
                }
                it.setNewLines(_xifexpression);
            };
            document.<Import>append(imp, _function_1);
        }
    }
    EList<Element> _contents = pkg.getContents();
    for (final Element element : _contents) {
        document.<Element>format(element);
    }
}
Also used : Import(org.eclipse.xtext.testlanguages.fileAware.fileAware.Import) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) Element(org.eclipse.xtext.testlanguages.fileAware.fileAware.Element)

Example 2 with Import

use of org.eclipse.xtext.testlanguages.fileAware.fileAware.Import 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;
}
Also used : Import(org.eclipse.xtext.testlanguages.fileAware.fileAware.Import) ImportNormalizer(org.eclipse.xtext.scoping.impl.ImportNormalizer) QualifiedName(org.eclipse.xtext.naming.QualifiedName) PackageDeclaration(org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration)

Example 3 with Import

use of org.eclipse.xtext.testlanguages.fileAware.fileAware.Import 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));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Import(org.eclipse.xtext.testlanguages.fileAware.fileAware.Import) Element(org.eclipse.xtext.testlanguages.fileAware.fileAware.Element) Parameter(org.eclipse.xtext.Parameter) PackageDeclaration(org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration) EPackage(org.eclipse.emf.ecore.EPackage)

Example 4 with Import

use of org.eclipse.xtext.testlanguages.fileAware.fileAware.Import in project xtext-core by eclipse.

the class FileAwareTestLanguageReferenceUpdater method update.

@Override
public void update(final IReferenceUpdaterContext context) {
    super.update(context);
    EObject _head = IterableExtensions.<EObject>head(context.getResource().getContents());
    final PackageDeclaration pkg = ((PackageDeclaration) _head);
    final QualifiedName pkgName = this.names.getFullyQualifiedName(pkg);
    final Function1<Import, Element> _function = (Import it) -> {
        return it.getElement();
    };
    final Map<Element, Import> actual = IterableExtensions.<Element, Import>toMap(pkg.getImports(), _function);
    final Function1<IUpdatableReference, EObject> _function_1 = (IUpdatableReference it) -> {
        return it.getTargetEObject();
    };
    final Iterable<Element> targets = Iterables.<Element>filter(ListExtensions.<IUpdatableReference, EObject>map(context.getUpdatableReferences(), _function_1), Element.class);
    final Function1<Element, Boolean> _function_2 = (Element it) -> {
        boolean _startsWith = this.names.getFullyQualifiedName(it).startsWith(pkgName);
        return Boolean.valueOf((!_startsWith));
    };
    final Set<Element> expected = IterableExtensions.<Element>toSet(IterableExtensions.<Element>filter(targets, _function_2));
    final Function1<Element, Boolean> _function_3 = (Element it) -> {
        boolean _containsKey = actual.containsKey(it);
        return Boolean.valueOf((!_containsKey));
    };
    final Set<Element> toAdd = IterableExtensions.<Element>toSet(IterableExtensions.<Element>filter(expected, _function_3));
    final Function2<Element, Import, Boolean> _function_4 = (Element $0, Import $1) -> {
        boolean _contains = expected.contains($0);
        return Boolean.valueOf((!_contains));
    };
    final Map<Element, Import> toDelete = MapExtensions.<Element, Import>filter(actual, _function_4);
    if (((!toAdd.isEmpty()) || (!toDelete.isEmpty()))) {
        final Runnable _function_5 = () -> {
            final Consumer<Import> _function_6 = (Import it) -> {
                EcoreUtil.remove(it);
            };
            toDelete.values().forEach(_function_6);
            final Consumer<Element> _function_7 = (Element e) -> {
                EList<Import> _imports = pkg.getImports();
                Import _createImport = this._fileAwareFactory.createImport();
                final Procedure1<Import> _function_8 = (Import it) -> {
                    it.setElement(e);
                };
                Import _doubleArrow = ObjectExtensions.<Import>operator_doubleArrow(_createImport, _function_8);
                _imports.add(_doubleArrow);
            };
            toAdd.forEach(_function_7);
        };
        context.modifyModel(_function_5);
    }
}
Also used : Import(org.eclipse.xtext.testlanguages.fileAware.fileAware.Import) IUpdatableReference(org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Element(org.eclipse.xtext.testlanguages.fileAware.fileAware.Element) Consumer(java.util.function.Consumer) EObject(org.eclipse.emf.ecore.EObject) PackageDeclaration(org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration)

Aggregations

Import (org.eclipse.xtext.testlanguages.fileAware.fileAware.Import)4 Element (org.eclipse.xtext.testlanguages.fileAware.fileAware.Element)3 PackageDeclaration (org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration)3 QualifiedName (org.eclipse.xtext.naming.QualifiedName)2 Consumer (java.util.function.Consumer)1 EObject (org.eclipse.emf.ecore.EObject)1 EPackage (org.eclipse.emf.ecore.EPackage)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)1 IUpdatableReference (org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference)1 ImportNormalizer (org.eclipse.xtext.scoping.impl.ImportNormalizer)1 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)1