Search in sources :

Example 1 with TypeDeclaration

use of org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration in project xtext-core by eclipse.

the class CodeActionService method fixUnsortedMembers.

private Command fixUnsortedMembers(final Diagnostic d, final Document doc, final XtextResource res, final CodeActionParams params) {
    final IChangeSerializer.IModification<Resource> _function = (Resource copiedResource) -> {
        final Model model = IterableExtensions.<Model>head(Iterables.<Model>filter(copiedResource.getContents(), Model.class));
        EList<TypeDeclaration> _types = model.getTypes();
        for (final TypeDeclaration type : _types) {
            final Comparator<Member> _function_1 = (Member a, Member b) -> {
                String _name = a.getName();
                String _name_1 = b.getName();
                return (_name.compareTo(_name_1));
            };
            ECollections.<Member>sort(type.getMembers(), _function_1);
        }
    };
    final WorkspaceEdit edit = this.recordWorkspaceEdit(doc, res, _function);
    Command _command = new Command();
    final Procedure1<Command> _function_1 = (Command it) -> {
        it.setCommand("my.textedit.command");
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("Sort Members");
        it.setTitle(_builder.toString());
        it.setArguments(Collections.<Object>unmodifiableList(CollectionLiterals.<Object>newArrayList(edit)));
    };
    return ObjectExtensions.<Command>operator_doubleArrow(_command, _function_1);
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) Comparator(java.util.Comparator) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) EList(org.eclipse.emf.common.util.EList) Command(org.eclipse.lsp4j.Command) Model(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Model) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TypeDeclaration(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration) Member(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Member)

Example 2 with TypeDeclaration

use of org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration in project xtext-core by eclipse.

the class TypeReferenceImpl method setTypeRef.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setTypeRef(TypeDeclaration newTypeRef) {
    TypeDeclaration oldTypeRef = typeRef;
    typeRef = newTypeRef;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, TestLanguagePackage.TYPE_REFERENCE__TYPE_REF, oldTypeRef, typeRef));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) TypeDeclaration(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration)

Example 3 with TypeDeclaration

use of org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration in project xtext-core by eclipse.

the class CodeActionService method fixUnsortedMembers.

private CodeAction fixUnsortedMembers(Diagnostic d, ICodeActionService2.Options options) {
    WorkspaceEdit wsEdit = recordWorkspaceEdit(options, (Resource copiedResource) -> {
        Model model = Iterables.getFirst(Iterables.filter(copiedResource.getContents(), Model.class), null);
        if (model != null) {
            for (TypeDeclaration type : Iterables.filter(model.getElements(), TypeDeclaration.class)) {
                ECollections.sort(type.getMembers(), (Member a, Member b) -> a.getName().compareTo(b.getName()));
            }
        }
    });
    CodeAction codeAction = new CodeAction();
    codeAction.setTitle("Sort Members");
    codeAction.setDiagnostics(Lists.newArrayList(d));
    codeAction.setEdit(wsEdit);
    return codeAction;
}
Also used : CodeAction(org.eclipse.lsp4j.CodeAction) Resource(org.eclipse.emf.ecore.resource.Resource) Model(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Model) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) TypeDeclaration(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration) Member(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Member)

Example 4 with TypeDeclaration

use of org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration in project xtext-core by eclipse.

the class TestLanguageGenerator method doGenerate.

@Override
public void doGenerate(final Resource resource, final IFileSystemAccess2 fsa, final IGeneratorContext context) {
    String _scheme = fsa.getURI("").scheme();
    boolean _equals = Objects.equal(_scheme, "inmemory");
    if (_equals) {
        return;
    }
    List<TypeDeclaration> _list = IteratorExtensions.<TypeDeclaration>toList(Iterators.<TypeDeclaration>filter(resource.getAllContents(), TypeDeclaration.class));
    for (final TypeDeclaration type : _list) {
        String _name = type.getName();
        String _plus = (_name + ".java");
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("public class ");
        String _name_1 = type.getName();
        _builder.append(_name_1);
        _builder.append(" {");
        _builder.newLineIfNotEmpty();
        {
            Iterable<Property> _filter = Iterables.<Property>filter(type.getMembers(), Property.class);
            for (final Property p : _filter) {
                _builder.append("\t");
                _builder.append("private ");
                String _java = this.toJava(p.getType());
                _builder.append(_java, "\t");
                _builder.append(" ");
                String _name_2 = p.getName();
                _builder.append(_name_2, "\t");
                _builder.append(";");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("public void set");
                String _firstUpper = StringExtensions.toFirstUpper(p.getName());
                _builder.append(_firstUpper, "\t");
                _builder.append("(");
                String _java_1 = this.toJava(p.getType());
                _builder.append(_java_1, "\t");
                _builder.append(" ");
                String _name_3 = p.getName();
                _builder.append(_name_3, "\t");
                _builder.append(") {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("\t");
                _builder.append("this.");
                String _name_4 = p.getName();
                _builder.append(_name_4, "\t\t");
                _builder.append(" = ");
                String _name_5 = p.getName();
                _builder.append(_name_5, "\t\t");
                _builder.append(";");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
                _builder.append("\t");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("public ");
                String _java_2 = this.toJava(p.getType());
                _builder.append(_java_2, "\t");
                _builder.append(" get");
                String _firstUpper_1 = StringExtensions.toFirstUpper(p.getName());
                _builder.append(_firstUpper_1, "\t");
                _builder.append("() {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("\t");
                _builder.append("return this.");
                String _name_6 = p.getName();
                _builder.append(_name_6, "\t\t");
                _builder.append(";");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("}");
                _builder.newLine();
            }
        }
        _builder.append("}");
        _builder.newLine();
        fsa.generateFile(_plus, _builder);
    }
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TypeDeclaration(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration) Property(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Property)

Example 5 with TypeDeclaration

use of org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration in project xtext-core by eclipse.

the class SignatureHelpServiceImpl method _getLabel.

private String _getLabel(final Operation it) {
    StringConcatenation _builder = new StringConcatenation();
    String _name = EcoreUtil2.<TypeDeclaration>getContainerOfType(it, TypeDeclaration.class).getName();
    _builder.append(_name);
    _builder.append(".");
    String _name_1 = it.getName();
    _builder.append(_name_1);
    _builder.append("(");
    {
        EList<Parameter> _params = it.getParams();
        boolean _hasElements = false;
        for (final Parameter p : _params) {
            if (!_hasElements) {
                _hasElements = true;
            } else {
                _builder.appendImmediate(", ", "");
            }
            String _name_2 = p.getName();
            _builder.append(_name_2);
            _builder.append(": ");
            String _label = this.getLabel(p.getType());
            _builder.append(_label);
        }
    }
    _builder.append("): ");
    {
        Type _returnType = it.getReturnType();
        boolean _tripleEquals = (_returnType == null);
        if (_tripleEquals) {
            _builder.append("void");
        } else {
            String _label_1 = this.getLabel(it.getReturnType());
            _builder.append(_label_1);
        }
    }
    return _builder.toString();
}
Also used : Type(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Type) PrimitiveType(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.PrimitiveType) EList(org.eclipse.emf.common.util.EList) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Parameter(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Parameter) TypeDeclaration(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration)

Aggregations

TypeDeclaration (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration)8 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 Model (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Model)3 EList (org.eclipse.emf.common.util.EList)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)2 Member (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Member)2 PrimitiveType (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.PrimitiveType)2 Property (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Property)2 Comparator (java.util.Comparator)1 EPackage (org.eclipse.emf.ecore.EPackage)1 CodeAction (org.eclipse.lsp4j.CodeAction)1 Command (org.eclipse.lsp4j.Command)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 QuickFix (org.eclipse.xtext.ide.editor.quickfix.QuickFix)1 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)1 Operation (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Operation)1