use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.
the class AssignmentStmtContextSorter method getVariableType.
/**
* Get the variable type.
*
* @param ctx Document Service context (Completion context)
* @return {@link String} type of the variable
*/
@Override
String getVariableType(TextDocumentServiceContext ctx) {
String variableName = ctx.get(DocumentServiceKeys.PARSER_RULE_CONTEXT_KEY).getStart().getText();
List<SymbolInfo> visibleSymbols = ctx.get(CompletionKeys.VISIBLE_SYMBOLS_KEY);
SymbolInfo filteredSymbol = visibleSymbols.stream().filter(symbolInfo -> {
BSymbol bSymbol = symbolInfo.getScopeEntry().symbol;
String symbolName = symbolInfo.getSymbolName();
return bSymbol instanceof BVarSymbol && symbolName.equals(variableName);
}).findFirst().orElse(null);
if (filteredSymbol != null) {
return filteredSymbol.getScopeEntry().symbol.type.toString();
}
return "";
}
use of org.wso2.carbon.bpel.ui.bpel2svg.Link 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;
}
use of org.wso2.carbon.bpel.ui.bpel2svg.Link 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;
}
use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.
the class BallerinaWebSubConnectionListener method autoRespondToIntentVerification.
/**
* Method to automatically respond to intent verification requests for subscriptions/unsubscriptions if a resource
* named {@link WebSubSubscriberConstants#RESOURCE_NAME_VERIFY_INTENT} is not specified.
*
* @param httpCarbonMessage the message/request received
*/
private void autoRespondToIntentVerification(HTTPCarbonMessage httpCarbonMessage) {
String annotatedTopic = httpCarbonMessage.getProperty(WebSubSubscriberConstants.ANNOTATED_TOPIC).toString();
PrintStream console = System.out;
if (httpCarbonMessage.getProperty(HttpConstants.QUERY_STR) != null) {
String queryString = (String) httpCarbonMessage.getProperty(HttpConstants.QUERY_STR);
BMap<String, BString> params = new BMap<>();
try {
HTTPCarbonMessage response = HttpUtil.createHttpCarbonMessage(false);
response.waitAndReleaseAllEntities();
URIUtil.populateQueryParamMap(queryString, params);
String mode = params.get(WebSubSubscriberConstants.PARAM_HUB_MODE).stringValue();
if ((WebSubSubscriberConstants.SUBSCRIBE.equals(mode) || WebSubSubscriberConstants.UNSUBSCRIBE.equals(mode)) && annotatedTopic.equals(params.get(WebSubSubscriberConstants.PARAM_HUB_TOPIC).stringValue())) {
String challenge = params.get(WebSubSubscriberConstants.PARAM_HUB_CHALLENGE).stringValue();
response.addHttpContent(new DefaultLastHttpContent(Unpooled.wrappedBuffer(challenge.getBytes(StandardCharsets.UTF_8))));
response.setProperty(HttpConstants.HTTP_STATUS_CODE, 202);
console.println("ballerina: Intent Verification agreed - Mode [" + mode + "], Topic [" + annotatedTopic + "], Lease Seconds [" + params.get(WebSubSubscriberConstants.PARAM_HUB_LEASE_SECONDS) + "]");
} else {
console.println("ballerina: Intent Verification denied - Mode [" + mode + "] for Incorrect Topic [" + annotatedTopic + "]");
response.setProperty(HttpConstants.HTTP_STATUS_CODE, 404);
}
HttpUtil.sendOutboundResponse(httpCarbonMessage, response);
} catch (UnsupportedEncodingException e) {
throw new BallerinaException("Error responding to intent verification request: " + e.getMessage());
}
}
}
use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.
the class AbstractAPIManager method getTiers.
/**
* Returns a list of pre-defined # {@link org.wso2.carbon.apimgt.api.model.Tier} in the system.
*
* @return Set<Tier>
*/
public Set<Tier> getTiers(String tenantDomain) throws APIManagementException {
Set<Tier> tiers = new TreeSet<Tier>(new TierNameComparator());
Map<String, Tier> tierMap = APIUtil.getTiersFromPolicies(PolicyConstants.POLICY_LEVEL_SUB, tenantId);
tiers.addAll(tierMap.values());
return tiers;
}
Aggregations