use of org.eclipse.xtext.nodemodel.BidiIterable 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);
}
Aggregations