Search in sources :

Example 11 with Operation

use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-apimgt by wso2.

the class DynamicHtmlGenTestCase method testPreprocessSwagger.

@Test
public void testPreprocessSwagger() throws Exception {
    DynamicHtmlGen htmlGen = new DynamicHtmlGen();
    Swagger swagger = new Swagger();
    Path path = new Path();
    Operation operation = new Operation();
    List<String> tags = new ArrayList<>();
    tags.add("tag1");
    tags.add("tag2");
    tags.add("tag3");
    tags.add("tag4");
    operation.setTags(tags);
    path.setGet(operation);
    swagger.path("get_sample", path);
    htmlGen.preprocessSwagger(swagger);
    List<String> processedTags = swagger.getPath("get_sample").getGet().getTags();
    Assert.assertEquals(processedTags.size(), 1);
    Assert.assertEquals(processedTags.get(0), "tag1");
}
Also used : Path(io.swagger.models.Path) DynamicHtmlGen(org.wso2.carbon.apimgt.rest.api.common.codegen.DynamicHtmlGen) Swagger(io.swagger.models.Swagger) ArrayList(java.util.ArrayList) CodegenOperation(io.swagger.codegen.CodegenOperation) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Example 12 with Operation

use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project ballerina by ballerina-lang.

the class MatchStatementScopeResolver method isCursorBeforeNode.

/**
 * Check whether the cursor is positioned before the given node start.
 *
 * @param nodePosition          Position of the node
 * @param node                  Node
 * @param treeVisitor           {@link TreeVisitor} current tree visitor instance
 * @param completionContext     Completion operation context
 * @return {@link Boolean}      Whether the cursor is before the node start or not
 */
@Override
public boolean isCursorBeforeNode(DiagnosticPos nodePosition, Node node, TreeVisitor treeVisitor, TextDocumentServiceContext completionContext) {
    if (!(treeVisitor.getBlockOwnerStack().peek() instanceof BLangMatch)) {
        // In the ideal case, this will not get triggered
        return false;
    }
    BLangMatch matchNode = (BLangMatch) treeVisitor.getBlockOwnerStack().peek();
    DiagnosticPos matchNodePos = CommonUtil.toZeroBasedPosition(matchNode.getPosition());
    DiagnosticPos nodePos = CommonUtil.toZeroBasedPosition((DiagnosticPos) node.getPosition());
    List<BLangMatch.BLangMatchStmtPatternClause> patternClauseList = matchNode.getPatternClauses();
    int line = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getLine();
    int col = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getCharacter();
    int nodeLine = nodePos.getStartLine();
    int nodeCol = nodePos.getStartColumn();
    boolean isBeforeNode = false;
    if ((line < nodeLine) || (line == nodeLine && col < nodeCol)) {
        isBeforeNode = true;
    } else if (patternClauseList.indexOf(node) == patternClauseList.size() - 1) {
        isBeforeNode = (line < matchNodePos.getEndLine()) || (line == matchNodePos.getEndLine() && col < matchNodePos.getEndColumn());
    }
    if (isBeforeNode) {
        Map<Name, Scope.ScopeEntry> visibleSymbolEntries = treeVisitor.resolveAllVisibleSymbols(treeVisitor.getSymbolEnv());
        SymbolEnv matchEnv = createMatchEnv(matchNode, treeVisitor.getSymbolEnv());
        treeVisitor.populateSymbols(visibleSymbolEntries, matchEnv);
        treeVisitor.setTerminateVisitor(true);
    }
    return isBeforeNode;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangMatch(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 13 with Operation

use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project ballerina by ballerina-lang.

the class ObjectTypeScopeResolver method isCursorBeforeNode.

/**
 * Check whether the cursor is positioned before the given node start.
 *
 * @param nodePosition      Position of the node
 * @param node              Node
 * @param treeVisitor       {@link TreeVisitor} current tree visitor instance
 * @param completionContext Completion operation context
 * @return {@link Boolean}      Whether the cursor is before the node start or not
 */
@Override
public boolean isCursorBeforeNode(DiagnosticPos nodePosition, Node node, TreeVisitor treeVisitor, TextDocumentServiceContext completionContext) {
    if (!(treeVisitor.getBlockOwnerStack().peek() instanceof BLangObject)) {
        return false;
    }
    BLangObject ownerObject = (BLangObject) treeVisitor.getBlockOwnerStack().peek();
    DiagnosticPos zeroBasedPos = CommonUtil.toZeroBasedPosition(nodePosition);
    DiagnosticPos blockOwnerPos = CommonUtil.toZeroBasedPosition((DiagnosticPos) treeVisitor.getBlockOwnerStack().peek().getPosition());
    int line = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getLine();
    int col = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getCharacter();
    boolean isLastField = false;
    if ((!ownerObject.fields.isEmpty() && node instanceof BLangVariable && ownerObject.fields.indexOf(node) == ownerObject.fields.size() - 1 && ownerObject.functions.isEmpty()) || (!ownerObject.functions.isEmpty() && node instanceof BLangFunction && ownerObject.functions.indexOf(node) == ownerObject.functions.size() - 1)) {
        isLastField = true;
    }
    if ((line < zeroBasedPos.getStartLine() || (line == zeroBasedPos.getStartLine() && col < zeroBasedPos.getStartColumn())) || (isLastField && ((blockOwnerPos.getEndLine() > line && zeroBasedPos.getEndLine() < line) || (blockOwnerPos.getEndLine() == line && blockOwnerPos.getEndColumn() > col)))) {
        Map<Name, Scope.ScopeEntry> visibleSymbolEntries = treeVisitor.resolveAllVisibleSymbols(treeVisitor.getSymbolEnv());
        treeVisitor.populateSymbols(visibleSymbolEntries, null);
        treeVisitor.setTerminateVisitor(true);
        return true;
    }
    return false;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 14 with Operation

use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project ballerina by ballerina-lang.

the class SignatureHelpUtil method getSignatureInfoModel.

/**
 * Get the required signature information filled model.
 *
 * @param bInvokableSymbol                  Invokable symbol
 * @param signatureContext                  Signature operation context
 * @return {@link SignatureInfoModel}       SignatureInfoModel containing signature information
 */
private static SignatureInfoModel getSignatureInfoModel(BInvokableSymbol bInvokableSymbol, TextDocumentServiceContext signatureContext) {
    Map<String, String> paramDescMap = new HashMap<>();
    SignatureInfoModel signatureInfoModel = new SignatureInfoModel();
    List<ParameterInfoModel> paramModels = new ArrayList<>();
    String functionName = signatureContext.get(SignatureKeys.CALLABLE_ITEM_NAME);
    CompilerContext compilerContext = signatureContext.get(DocumentServiceKeys.COMPILER_CONTEXT_KEY);
    BLangPackage bLangPackage = signatureContext.get(DocumentServiceKeys.LS_PACKAGE_CACHE_KEY).findPackage(compilerContext, bInvokableSymbol.pkgID);
    BLangFunction blangFunction = bLangPackage.getFunctions().stream().filter(bLangFunction -> bLangFunction.getName().getValue().equals(functionName)).findFirst().orElse(null);
    if (!blangFunction.getDocumentationAttachments().isEmpty()) {
        // Get the first documentation attachment
        BLangDocumentation bLangDocumentation = blangFunction.getDocumentationAttachments().get(0);
        signatureInfoModel.setSignatureDescription(bLangDocumentation.documentationText.trim());
        bLangDocumentation.attributes.forEach(attribute -> {
            if (attribute.docTag.equals(DocTag.PARAM)) {
                paramDescMap.put(attribute.documentationField.getValue(), attribute.documentationText.trim());
            }
        });
    } else {
        // TODO: Should be deprecated in due course
        // Iterate over the attachments list and extract the attachment Description Map
        blangFunction.getAnnotationAttachments().forEach(annotationAttachment -> {
            BLangExpression expr = annotationAttachment.expr;
            if (expr instanceof BLangRecordLiteral) {
                List<BLangRecordLiteral.BLangRecordKeyValue> recordKeyValues = ((BLangRecordLiteral) expr).keyValuePairs;
                for (BLangRecordLiteral.BLangRecordKeyValue recordKeyValue : recordKeyValues) {
                    BLangExpression key = recordKeyValue.key.expr;
                    BLangExpression value = recordKeyValue.getValue();
                    if (key instanceof BLangSimpleVarRef && ((BLangSimpleVarRef) key).getVariableName().getValue().equals("value") && value instanceof BLangLiteral) {
                        String annotationValue = ((BLangLiteral) value).getValue().toString();
                        if (annotationAttachment.getAnnotationName().getValue().equals("Param")) {
                            String paramName = annotationValue.substring(0, annotationValue.indexOf(UtilSymbolKeys.PKG_DELIMITER_KEYWORD));
                            String annotationDesc = annotationValue.substring(annotationValue.indexOf(UtilSymbolKeys.PKG_DELIMITER_KEYWORD) + 1).trim();
                            paramDescMap.put(paramName, annotationDesc);
                        } else if (annotationAttachment.getAnnotationName().getValue().equals("Description")) {
                            signatureInfoModel.setSignatureDescription(annotationValue);
                        }
                    }
                }
            }
        });
    }
    bInvokableSymbol.getParameters().forEach(bVarSymbol -> {
        ParameterInfoModel parameterInfoModel = new ParameterInfoModel();
        parameterInfoModel.setParamType(bVarSymbol.getType().toString());
        parameterInfoModel.setParamValue(bVarSymbol.getName().getValue());
        parameterInfoModel.setDescription(paramDescMap.get(bVarSymbol.getName().getValue()));
        paramModels.add(parameterInfoModel);
    });
    signatureInfoModel.setParameterInfoModels(paramModels);
    return signatureInfoModel;
}
Also used : BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) HashMap(java.util.HashMap) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) ArrayList(java.util.ArrayList) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 15 with Operation

use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project ballerina by ballerina-lang.

the class SignatureHelpUtil method getSignatureInformation.

/**
 * Get the signature information for the given Ballerina function.
 *
 * @param bInvokableSymbol BLang Invokable symbol
 * @param signatureContext Signature operation context
 * @return {@link SignatureInformation}     Signature information for the function
 */
private static SignatureInformation getSignatureInformation(BInvokableSymbol bInvokableSymbol, TextDocumentServiceContext signatureContext) {
    List<ParameterInformation> parameterInformationList = new ArrayList<>();
    SignatureInformation signatureInformation = new SignatureInformation();
    SignatureInfoModel signatureInfoModel = getSignatureInfoModel(bInvokableSymbol, signatureContext);
    String functionName = bInvokableSymbol.getName().getValue();
    // Join the function parameters to generate the function's signature
    String paramsJoined = signatureInfoModel.getParameterInfoModels().stream().map(parameterInfoModel -> {
        // For each of the parameters, create a parameter info instance
        ParameterInformation parameterInformation = new ParameterInformation(parameterInfoModel.paramValue, parameterInfoModel.description);
        parameterInformationList.add(parameterInformation);
        return parameterInfoModel.toString();
    }).collect(Collectors.joining(", "));
    signatureInformation.setLabel(functionName + "(" + paramsJoined + ")");
    signatureInformation.setParameters(parameterInformationList);
    signatureInformation.setDocumentation(signatureInfoModel.signatureDescription);
    return signatureInformation;
}
Also used : Arrays(java.util.Arrays) HashMap(java.util.HashMap) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) Stack(java.util.Stack) ArrayList(java.util.ArrayList) DocTag(org.ballerinalang.model.elements.DocTag) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo) Map(java.util.Map) Position(org.eclipse.lsp4j.Position) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) DocumentServiceKeys(org.ballerinalang.langserver.DocumentServiceKeys) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) TextDocumentServiceContext(org.ballerinalang.langserver.TextDocumentServiceContext) ParameterInformation(org.eclipse.lsp4j.ParameterInformation) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) SignatureInformation(org.eclipse.lsp4j.SignatureInformation) Collectors(java.util.stream.Collectors) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) Objects(java.util.Objects) List(java.util.List) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) UtilSymbolKeys(org.ballerinalang.langserver.common.UtilSymbolKeys) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) SignatureInformation(org.eclipse.lsp4j.SignatureInformation) ArrayList(java.util.ArrayList) ParameterInformation(org.eclipse.lsp4j.ParameterInformation)

Aggregations

Test (org.testng.annotations.Test)34 HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)29 HashMap (java.util.HashMap)19 ArrayList (java.util.ArrayList)16 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)15 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)12 QueryVariable (org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)11 List (java.util.List)10 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)10 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)9 Map (java.util.Map)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 Operation (io.swagger.models.Operation)7 Attribute (org.wso2.charon3.core.attributes.Attribute)7 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)7 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)7 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)7 Operation (org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation)6 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)6 AttributeSchema (org.wso2.charon3.core.schema.AttributeSchema)6