use of org.eclipse.xtext.ide.tests.testlanguage.testLanguage.OperationCall in project xtext-core by eclipse.
the class SignatureHelpServiceImpl method getSignatureHelp.
@Override
public SignatureHelp getSignatureHelp(final XtextResource resource, final int offset) {
Preconditions.<XtextResource>checkNotNull(resource, "resource");
Preconditions.checkArgument((offset >= 0), ("offset >= 0. Was: " + Integer.valueOf(offset)));
final EObject object = this.offsetHelper.resolveContainedElementAt(resource, offset);
if ((object instanceof OperationCall)) {
final String operationName = this.getOperationName(((OperationCall) object));
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(operationName);
boolean _not = (!_isNullOrEmpty);
if (_not) {
return this.getSignatureHelp(((OperationCall) object), operationName, offset);
}
}
return ISignatureHelpService.EMPTY;
}
use of org.eclipse.xtext.ide.tests.testlanguage.testLanguage.OperationCall 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));
}
use of org.eclipse.xtext.ide.tests.testlanguage.testLanguage.OperationCall in project xtext-core by eclipse.
the class OperationImpl method basicSetOperationCall.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetOperationCall(OperationCall newOperationCall, NotificationChain msgs) {
OperationCall oldOperationCall = operationCall;
operationCall = newOperationCall;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, TestLanguagePackage.OPERATION__OPERATION_CALL, oldOperationCall, newOperationCall);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
use of org.eclipse.xtext.ide.tests.testlanguage.testLanguage.OperationCall in project xtext-core by eclipse.
the class SignatureHelpServiceImpl method getSignatureHelp.
private SignatureHelp getSignatureHelp(OperationCall call, String operationName, int offset) {
// If the offset exceeds either the opening or the closing characters'
// offset we should not
// provide signature help at all.
List<Integer> separatorIndices = new ArrayList<>();
for (INode node : NodeModelUtils.getNode(call).getChildren()) {
String text = node.getText();
if (SignatureHelpServiceImpl.OPENING_CHAR.equals(text) && node.getOffset() >= offset) {
return ISignatureHelpService.EMPTY;
} else {
if (SignatureHelpServiceImpl.CLOSING_CHAR.equals(text) && node.getOffset() < offset) {
return ISignatureHelpService.EMPTY;
} else {
if (SignatureHelpServiceImpl.SEPARATOR_CHAR.equals(text)) {
separatorIndices.add(node.getOffset());
}
}
}
}
// Here we will distinguish between three different AST states:
// 1. Valid state: when the number of parameter separators equals with
// the number of (parameters - 1)
// and each separator is surrounded by two parameters.
// 2. Broken recoverable state: the number of parameters equals with the
// number of separators and the
// last separator offset is greater than the last parameter (offset +
// length) and each separator is
// surrounded by two parameters. Expect the last separator.
// 3. Broken inconsistent state: non of the above cases.
int paramCount = call.getParams().size();
int separatorCount = separatorIndices.size();
if (separatorCount + 1 == paramCount || separatorCount == paramCount) {
List<INode> paramNodes = NodeModelUtils.findNodesForFeature(call, TestLanguagePackage.Literals.OPERATION__PARAMS);
// Parameter count could be greater than separator count.
for (int i = 0; i < separatorCount; i++) {
INode paramNode = paramNodes.get(i);
// should not be provided.
if (paramNode.getOffset() + paramNode.getLength() > separatorIndices.get(i).intValue()) {
return ISignatureHelpService.EMPTY;
}
}
} else {
return ISignatureHelpService.EMPTY;
}
final int currentParameter;
if (paramCount != 0) {
if (separatorIndices.contains(offset)) {
currentParameter = separatorIndices.indexOf(offset) + 2;
} else {
// Here we can execute a binary search for sure, because the
// nodes where visited in order.
currentParameter = -Collections.binarySearch(separatorIndices, offset);
}
} else {
currentParameter = 0;
}
Iterable<Operation> visibleOperations = Iterables.filter(getVisibleOperationsWithName(call, operationName), it -> currentParameter <= it.getParams().size());
int paramOffset = separatorIndices.contains(offset) ? 2 : 1;
final Integer activeParamIndex;
if (paramCount == 0) {
Iterable<Integer> paramSize = Iterables.transform(visibleOperations, it -> it.getParams().size());
// parameter on use-side.
if (!Iterables.any(paramSize, it -> it.intValue() == 0) && Iterables.any(visibleOperations, it -> !it.getParams().isEmpty())) {
activeParamIndex = 0;
} else {
activeParamIndex = null;
}
} else {
activeParamIndex = currentParameter - paramOffset;
}
SignatureHelp signatureHelp = new SignatureHelp();
signatureHelp.setActiveParameter(activeParamIndex);
signatureHelp.setActiveSignature(0);
signatureHelp.setSignatures(IterableExtensions.sortWith(IterableExtensions.toList(Iterables.transform(visibleOperations, (Operation operation) -> {
SignatureInformation signatureInformation = new SignatureInformation(getLabel(operation));
signatureInformation.setParameters(Lists.transform(operation.getParams(), (Parameter param) -> new ParameterInformation(param.getName() + ": " + getLabel(param.getType()))));
return signatureInformation;
})), SignatureHelpServiceImpl.SIGNATURE_INFO_ORDERING));
return signatureHelp;
}
use of org.eclipse.xtext.ide.tests.testlanguage.testLanguage.OperationCall in project xtext-core by eclipse.
the class SignatureHelpServiceImpl method getSignatureHelp.
@Override
public SignatureHelp getSignatureHelp(Document document, XtextResource resource, SignatureHelpParams params, CancelIndicator cancelIndicator) {
int offset = document.getOffSet(params.getPosition());
Preconditions.checkNotNull(resource, "resource");
Preconditions.checkArgument(offset >= 0, "offset >= 0. Was: " + offset);
EObject object = offsetHelper.resolveContainedElementAt(resource, offset);
if (object instanceof OperationCall) {
String operationName = getOperationName((OperationCall) object);
if (!Strings.isNullOrEmpty(operationName)) {
return getSignatureHelp((OperationCall) object, operationName, offset);
}
}
return ISignatureHelpService.EMPTY;
}
Aggregations