Search in sources :

Example 1 with Parameter

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

the class SignatureHelpServiceImpl method getSignatureHelp.

private SignatureHelp getSignatureHelp(final OperationCall call, final String operationName, final int offset) {
    final List<Integer> separatorIndices = CollectionLiterals.<Integer>newArrayList();
    BidiIterable<INode> _children = NodeModelUtils.getNode(call).getChildren();
    for (final INode node : _children) {
        {
            final String text = node.getText();
            if ((Objects.equal(SignatureHelpServiceImpl.OPENING_CHAR, text) && (node.getOffset() >= offset))) {
                return ISignatureHelpService.EMPTY;
            } else {
                if ((Objects.equal(SignatureHelpServiceImpl.CLOSING_CHAR, text) && (node.getOffset() < offset))) {
                    return ISignatureHelpService.EMPTY;
                } else {
                    boolean _equals = Objects.equal(SignatureHelpServiceImpl.SEPARATOR_CHAR, text);
                    if (_equals) {
                        separatorIndices.add(Integer.valueOf(node.getOffset()));
                    }
                }
            }
        }
    }
    final int paramCount = call.getParams().size();
    final int separatorCount = separatorIndices.size();
    if ((((separatorCount + 1) == paramCount) || (separatorCount == paramCount))) {
        final List<INode> paramNodes = NodeModelUtils.findNodesForFeature(call, this._testLanguagePackage.getOperation_Params());
        for (int i = 0; (i < separatorCount); i++) {
            {
                final INode paramNode = paramNodes.get(i);
                int _offset = paramNode.getOffset();
                int _length = paramNode.getLength();
                int _plus = (_offset + _length);
                Integer _get = separatorIndices.get(i);
                boolean _greaterThan = (_plus > (_get).intValue());
                if (_greaterThan) {
                    return ISignatureHelpService.EMPTY;
                }
            }
        }
    } else {
        return ISignatureHelpService.EMPTY;
    }
    int _xifexpression = (int) 0;
    if ((paramCount == 0)) {
        _xifexpression = 0;
    } else {
        int _xifexpression_1 = (int) 0;
        boolean _contains = separatorIndices.contains(Integer.valueOf(offset));
        if (_contains) {
            int _indexOf = separatorIndices.indexOf(Integer.valueOf(offset));
            _xifexpression_1 = (_indexOf + 2);
        } else {
            int _binarySearch = Arrays.binarySearch(((int[]) Conversions.unwrapArray(separatorIndices, int.class)), offset);
            _xifexpression_1 = (-_binarySearch);
        }
        _xifexpression = _xifexpression_1;
    }
    final int currentParameter = _xifexpression;
    final Function1<Operation, Boolean> _function = (Operation it) -> {
        int _size = it.getParams().size();
        return Boolean.valueOf((currentParameter <= _size));
    };
    final Iterable<Operation> visibleOperations = IterableExtensions.<Operation>filter(this.getVisibleOperationsWithName(call, operationName), _function);
    int _xifexpression_2 = (int) 0;
    boolean _contains_1 = separatorIndices.contains(Integer.valueOf(offset));
    if (_contains_1) {
        _xifexpression_2 = 2;
    } else {
        _xifexpression_2 = 1;
    }
    final int paramOffset = _xifexpression_2;
    Integer _xifexpression_3 = null;
    if ((paramCount == 0)) {
        Integer _xblockexpression = null;
        {
            final Function1<Operation, Integer> _function_1 = (Operation it) -> {
                return Integer.valueOf(it.getParams().size());
            };
            final Iterable<Integer> paramSize = IterableExtensions.<Operation, Integer>map(visibleOperations, _function_1);
            Integer _xifexpression_4 = null;
            if (((!IterableExtensions.<Integer>exists(paramSize, ((Function1<Integer, Boolean>) (Integer it) -> {
                return Boolean.valueOf(((it).intValue() == 0));
            }))) && IterableExtensions.<Operation>exists(visibleOperations, ((Function1<Operation, Boolean>) (Operation it) -> {
                boolean _isEmpty = it.getParams().isEmpty();
                return Boolean.valueOf((!_isEmpty));
            })))) {
                _xifexpression_4 = Integer.valueOf(0);
            } else {
                _xifexpression_4 = null;
            }
            _xblockexpression = _xifexpression_4;
        }
        _xifexpression_3 = _xblockexpression;
    } else {
        _xifexpression_3 = Integer.valueOf((currentParameter - paramOffset));
    }
    final Integer activeParamIndex = _xifexpression_3;
    SignatureHelp _signatureHelp = new SignatureHelp();
    final Procedure1<SignatureHelp> _function_1 = (SignatureHelp it) -> {
        it.setActiveParameter(activeParamIndex);
        it.setActiveSignature(Integer.valueOf(0));
        final Function1<Operation, SignatureInformation> _function_2 = (Operation operation) -> {
            SignatureInformation _signatureInformation = new SignatureInformation();
            final Procedure1<SignatureInformation> _function_3 = (SignatureInformation it_1) -> {
                it_1.setLabel(this.getLabel(operation));
                final Function1<Parameter, ParameterInformation> _function_4 = (Parameter param) -> {
                    ParameterInformation _parameterInformation = new ParameterInformation();
                    final Procedure1<ParameterInformation> _function_5 = (ParameterInformation it_2) -> {
                        StringConcatenation _builder = new StringConcatenation();
                        String _name = param.getName();
                        _builder.append(_name);
                        _builder.append(": ");
                        String _label = this.getLabel(param.getType());
                        _builder.append(_label);
                        it_2.setLabel(_builder.toString());
                    };
                    return ObjectExtensions.<ParameterInformation>operator_doubleArrow(_parameterInformation, _function_5);
                };
                it_1.setParameters(ListExtensions.<Parameter, ParameterInformation>map(operation.getParams(), _function_4));
            };
            return ObjectExtensions.<SignatureInformation>operator_doubleArrow(_signatureInformation, _function_3);
        };
        it.setSignatures(IterableExtensions.<SignatureInformation>sortWith(IterableExtensions.<SignatureInformation>toList(IterableExtensions.<Operation, SignatureInformation>map(visibleOperations, _function_2)), SignatureHelpServiceImpl.SIGNATURE_INFO_ORDERING));
    };
    return ObjectExtensions.<SignatureHelp>operator_doubleArrow(_signatureHelp, _function_1);
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) BidiIterable(org.eclipse.xtext.nodemodel.BidiIterable) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) Operation(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Operation) ParameterInformation(org.eclipse.lsp4j.ParameterInformation) SignatureInformation(org.eclipse.lsp4j.SignatureInformation) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Parameter(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Parameter)

Example 2 with Parameter

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

StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 Parameter (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Parameter)2 EList (org.eclipse.emf.common.util.EList)1 ParameterInformation (org.eclipse.lsp4j.ParameterInformation)1 SignatureHelp (org.eclipse.lsp4j.SignatureHelp)1 SignatureInformation (org.eclipse.lsp4j.SignatureInformation)1 Operation (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Operation)1 PrimitiveType (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.PrimitiveType)1 Type (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Type)1 TypeDeclaration (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration)1 BidiIterable (org.eclipse.xtext.nodemodel.BidiIterable)1 INode (org.eclipse.xtext.nodemodel.INode)1 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)1