Search in sources :

Example 1 with Element

use of org.eclipse.xtext.testlanguages.fileAware.fileAware.Element 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 Element

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

the class FileAwareTestLanguageImportScopeProvider method getImportedNamespace.

private QualifiedName getImportedNamespace(final Import imp) {
    final Element ele = imp.getElement();
    boolean _eIsProxy = ele.eIsProxy();
    if (_eIsProxy) {
        final String name = IterableExtensions.<INode>head(NodeModelUtils.findNodesForFeature(imp, FileAwarePackage.Literals.IMPORT__ELEMENT)).getText().trim();
        return this.getQualifiedNameConverter().toQualifiedName(name);
    } else {
        return this.getQualifiedNameProvider().getFullyQualifiedName(ele);
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) Element(org.eclipse.xtext.testlanguages.fileAware.fileAware.Element)

Example 3 with Element

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

the class ImportImpl method setElement.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setElement(Element newElement) {
    Element oldElement = element;
    element = newElement;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, FileAwarePackage.IMPORT__ELEMENT, oldElement, element));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) Element(org.eclipse.xtext.testlanguages.fileAware.fileAware.Element)

Example 4 with Element

use of org.eclipse.xtext.testlanguages.fileAware.fileAware.Element 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 5 with Element

use of org.eclipse.xtext.testlanguages.fileAware.fileAware.Element 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

Element (org.eclipse.xtext.testlanguages.fileAware.fileAware.Element)5 Import (org.eclipse.xtext.testlanguages.fileAware.fileAware.Import)3 PackageDeclaration (org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration)2 Consumer (java.util.function.Consumer)1 EObject (org.eclipse.emf.ecore.EObject)1 EPackage (org.eclipse.emf.ecore.EPackage)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)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 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 INode (org.eclipse.xtext.nodemodel.INode)1 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)1