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