Search in sources :

Example 31 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance 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 32 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance 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 33 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project ballerina by ballerina-lang.

the class SignatureHelpUtil method getFunctionSignatureHelp.

/**
 * Get the functionSignatureHelp instance.
 *
 * @param context                   Signature help context
 * @return {@link SignatureHelp}    Signature help for the completion
 */
public static SignatureHelp getFunctionSignatureHelp(TextDocumentServiceContext context) {
    // Get the functions List
    List<SymbolInfo> functions = context.get(SignatureKeys.FILTERED_FUNCTIONS);
    List<SignatureInformation> signatureInformationList = functions.stream().map(symbolInfo -> getSignatureInformation((BInvokableSymbol) symbolInfo.getScopeEntry().symbol, context)).filter(Objects::nonNull).collect(Collectors.toList());
    SignatureHelp signatureHelp = new SignatureHelp();
    signatureHelp.setSignatures(signatureInformationList);
    signatureHelp.setActiveParameter(context.get(SignatureKeys.PARAMETER_COUNT));
    signatureHelp.setActiveSignature(0);
    return signatureHelp;
}
Also used : SignatureInformation(org.eclipse.lsp4j.SignatureInformation) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo)

Example 34 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance 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)

Example 35 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project core-util by WSO2Telco.

the class OAuthApplicationDataStubFactory method generateStub.

/**
 * This is used to create a stub which will be triggered through object pool factory, which will create an
 * instance of it.
 *
 * @return OAuth2TokenValidationServiceStub stub that is used to call an external service.
 * @throws PCRException will be thrown when initialization failed.
 */
private OAuthAdminServiceStub generateStub() throws PCRException {
    OAuthAdminServiceStub stub;
    try {
        URL hostURL = new URL(config.getHostUrl());
        // ConfigurationContext myConfigContext =
        // ConfigurationContextFactory.createConfigurationContextFromFileSystem(
        // "repo", CarbonUtils.getCarbonConfigDirPath() + File.separator + "axis2" + File.separator +
        // "axis2.xml");
        stub = new OAuthAdminServiceStub(null, hostURL.toString());
        ServiceClient client = stub._getServiceClient();
        client.getServiceContext().getConfigurationContext().setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
        HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
        auth.setPreemptiveAuthentication(true);
        String username = config.getUsername();
        String password = config.getPassword();
        auth.setUsername(username);
        auth.setPassword(password);
        Options options = client.getOptions();
        options.setProperty(HTTPConstants.AUTHENTICATE, auth);
        options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE);
        client.setOptions(options);
    } catch (AxisFault axisFault) {
        log.error("Error occurred while creating the OAuth2TokenValidationServiceStub.");
        throw new PCRException("Error occurred while creating the OAuth2TokenValidationServiceStub.", axisFault);
    } catch (MalformedURLException e) {
        log.error("Malformed URL error");
        throw new PCRException("Malformed URL error", e);
    }
    return stub;
}
Also used : AxisFault(org.apache.axis2.AxisFault) Options(org.apache.axis2.client.Options) HttpTransportProperties(org.apache.axis2.transport.http.HttpTransportProperties) MalformedURLException(java.net.MalformedURLException) OAuthAdminServiceStub(org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub) ServiceClient(org.apache.axis2.client.ServiceClient) PCRException(com.wso2telco.core.pcrservice.exception.PCRException) URL(java.net.URL)

Aggregations

ArrayList (java.util.ArrayList)28 Test (org.junit.Test)23 Response (javax.ws.rs.core.Response)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)20 HashMap (java.util.HashMap)15 Path (javax.ws.rs.Path)15 RuntimeService (org.activiti.engine.RuntimeService)15 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)15 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)14 Produces (javax.ws.rs.Produces)13 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)13 IOException (java.io.IOException)12 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)12 GET (javax.ws.rs.GET)11 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)11 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8