Search in sources :

Example 1 with OperationCall

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;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) OperationCall(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.OperationCall) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 2 with OperationCall

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));
}
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)

Example 3 with OperationCall

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;
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) OperationCall(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.OperationCall)

Example 4 with OperationCall

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;
}
Also used : TestLanguagePackage(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TestLanguagePackage) Operation(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Operation) Arrays(java.util.Arrays) Iterables(com.google.common.collect.Iterables) TypeReference(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeReference) Inject(com.google.inject.Inject) NodeModelUtils(org.eclipse.xtext.nodemodel.util.NodeModelUtils) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) Document(org.eclipse.xtext.ide.server.Document) Lists(com.google.common.collect.Lists) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) INode(org.eclipse.xtext.nodemodel.INode) Objects(com.google.common.base.Objects) Parameter(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Parameter) XtextResource(org.eclipse.xtext.resource.XtextResource) PrimitiveType(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.PrimitiveType) ParameterInformation(org.eclipse.lsp4j.ParameterInformation) ISignatureHelpService(org.eclipse.xtext.ide.server.signatureHelp.ISignatureHelpService) EObject(org.eclipse.emf.ecore.EObject) SignatureInformation(org.eclipse.lsp4j.SignatureInformation) EObjectAtOffsetHelper(org.eclipse.xtext.resource.EObjectAtOffsetHelper) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) List(java.util.List) IterableExtensions(org.eclipse.xtext.xbase.lib.IterableExtensions) OperationCall(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.OperationCall) IScopeProvider(org.eclipse.xtext.scoping.IScopeProvider) TypeDeclaration(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration) Preconditions(com.google.common.base.Preconditions) SignatureHelpParams(org.eclipse.lsp4j.SignatureHelpParams) Comparator(java.util.Comparator) Collections(java.util.Collections) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Joiner(com.google.common.base.Joiner) INode(org.eclipse.xtext.nodemodel.INode) ArrayList(java.util.ArrayList) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) Operation(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Operation) ParameterInformation(org.eclipse.lsp4j.ParameterInformation) SignatureInformation(org.eclipse.lsp4j.SignatureInformation) Parameter(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Parameter)

Example 5 with OperationCall

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;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) OperationCall(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.OperationCall)

Aggregations

OperationCall (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.OperationCall)5 EObject (org.eclipse.emf.ecore.EObject)3 Operation (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Operation)2 PrimitiveType (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.PrimitiveType)2 TypeDeclaration (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration)2 TypeReference (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeReference)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 Joiner (com.google.common.base.Joiner)1 Objects (com.google.common.base.Objects)1 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Inject (com.google.inject.Inject)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 EPackage (org.eclipse.emf.ecore.EPackage)1