Search in sources :

Example 1 with Model

use of org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Model 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 Model

use of org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Model 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 3 with Model

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

the class TestLanguageSemanticSequencer 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 == TestLanguagePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case TestLanguagePackage.MODEL:
                sequence_Model(context, (Model) semanticObject);
                return;
            case TestLanguagePackage.OPERATION:
                sequence_Operation(context, (Operation) semanticObject);
                return;
            case TestLanguagePackage.OPERATION_CALL:
                sequence_OperationCall(context, (OperationCall) semanticObject);
                return;
            case TestLanguagePackage.PACKAGE_DECLARATION:
                sequence_PackageDeclaration(context, (PackageDeclaration) semanticObject);
                return;
            case TestLanguagePackage.PARAMETER:
                sequence_Parameter(context, (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Parameter) semanticObject);
                return;
            case TestLanguagePackage.PRIMITIVE_TYPE:
                if (rule == grammarAccess.getPrimitiveTypeRule()) {
                    sequence_PrimitiveType(context, (PrimitiveType) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRule()) {
                    sequence_PrimitiveType_Type(context, (PrimitiveType) semanticObject);
                    return;
                } else
                    break;
            case TestLanguagePackage.PROPERTY:
                sequence_Property(context, (Property) semanticObject);
                return;
            case TestLanguagePackage.TYPE_DECLARATION:
                sequence_TypeDeclaration(context, (TypeDeclaration) semanticObject);
                return;
            case TestLanguagePackage.TYPE_REFERENCE:
                if (rule == grammarAccess.getTypeReferenceRule()) {
                    sequence_TypeReference(context, (TypeReference) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRule()) {
                    sequence_Type_TypeReference(context, (TypeReference) semanticObject);
                    return;
                } else
                    break;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Operation(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Operation) EPackage(org.eclipse.emf.ecore.EPackage) OperationCall(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.OperationCall) Model(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Model) Parameter(org.eclipse.xtext.Parameter) PrimitiveType(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.PrimitiveType) TypeReference(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeReference) Property(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Property) TypeDeclaration(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration) PackageDeclaration(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.PackageDeclaration)

Aggregations

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