@Override public String toString() { return this.getValue(); } }
private boolean checkMatchingConfigKey(BLangRecordLiteral.BLangRecordKeyValue keyValue, String key) { return ((BLangSimpleVarRef) (keyValue.key).expr).variableName.getValue().equals(key); } }
@Override public String toString() { StringBuilder br = new StringBuilder(); if (pkgAlias != null && !pkgAlias.getValue().isEmpty()) { br.append(String.valueOf(pkgAlias)).append(":"); } br.append(String.valueOf(variableName)); return br.toString(); }
private String getTypeName(BLangType bLangType) throws LSCompletionException { if (bLangType instanceof BLangValueType) { return bLangType.toString(); } else if (bLangType instanceof BLangUserDefinedType) { BLangUserDefinedType userDefinedType = (BLangUserDefinedType) bLangType; String pkgAlias = userDefinedType.getPackageAlias().getValue(); String typeName = userDefinedType.getTypeName().getValue(); return pkgAlias.isEmpty() ? typeName : (pkgAlias + UtilSymbolKeys.PKG_DELIMITER_KEYWORD + typeName); } else { throw new LSCompletionException("Error identifying the type of anonymous function parameter"); } }
private static void validateParamDetailsSize(List<BLangSimpleVariable> paramDetails, int min, int max, BLangFunction resource, DiagnosticLog dlog) { if (paramDetails == null || paramDetails.size() < min || paramDetails.size() > max) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, resource.pos, INVALID_RESOURCE_SIGNATURE_FOR + resource.getName().getValue() + RESOURCE_IN_SERVICE + ": Unexpected parameter count"); } }
@Override public void visit(BLangResource resourceNode) { if (resourceNode.name.getValue() .equals(this.context.get(NodeContextKeys.NODE_OWNER_KEY))) { if (resourceNode.requiredParams != null) { resourceNode.requiredParams.forEach(this::acceptNode); } if (resourceNode.body != null) { this.acceptNode(resourceNode.body); } } }
private static void validateParamDetailsSize(List<BLangSimpleVariable> paramDetails, int expectedSize, BLangFunction resource, DiagnosticLog dlog) { if (paramDetails == null || paramDetails.size() != expectedSize) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, resource.pos, INVALID_RESOURCE_SIGNATURE_FOR + resource.getName().getValue() + RESOURCE_IN_SERVICE + ": Expected parameter count = " + expectedSize); } }
@Override public void visit(BLangSimpleVarRef varRefExpr) { if (varRefExpr.variableName.getValue() .equals(this.context.get(NodeContextKeys.VAR_NAME_OF_NODE_KEY))) { this.context.put(NodeContextKeys.NODE_KEY, varRefExpr); terminateVisitor = true; } }
@Override public void visit(BLangSimpleVariable varNode) { if (varNode.name.getValue() .equals(this.context.get(NodeContextKeys.VAR_NAME_OF_NODE_KEY))) { this.context.put(NodeContextKeys.NODE_KEY, varNode); terminateVisitor = true; } }
private static void validateEndpointParameter(BLangFunction resource, DiagnosticLog dlog, List<BLangSimpleVariable> paramDetails, boolean isClient) { if (paramDetails == null || paramDetails.isEmpty() || (!isClient && !WebSocketConstants.WEBSOCKET_CALLER_NAME.equals( paramDetails.get(0).type.toString())) || (isClient && !WebSocketConstants.WEBSOCKET_CLIENT_ENDPOINT_NAME.equals( paramDetails.get(0).type.toString()))) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, resource.pos, INVALID_RESOURCE_SIGNATURE_FOR + resource.getName().getValue() + RESOURCE_IN_SERVICE + ": The first parameter should be an endpoint"); } }
@Override public void visit(BLangTypeDefinition typeDefinition) { if (typeDefinition.name.getValue() .equals(this.context.get(NodeContextKeys.VAR_NAME_OF_NODE_KEY))) { this.context.put(NodeContextKeys.NODE_KEY, typeDefinition); terminateVisitor = true; } if (typeDefinition.typeNode != null) { this.acceptNode(typeDefinition.typeNode); } }
@Override public void visit(BLangConstant constant) { if (constant.name.getValue().equals(this.context.get(NodeContextKeys.VAR_NAME_OF_NODE_KEY))) { this.context.put(NodeContextKeys.NODE_KEY, constant); terminateVisitor = true; } if (constant.typeNode != null) { this.acceptNode(constant.typeNode); } }
private static void validateOnErrorResource(BLangFunction resource, DiagnosticLog dlog, boolean isClient) { List<BLangSimpleVariable> paramDetails = resource.getParameters(); validateParamDetailsSize(paramDetails, 2, resource, dlog); validateEndpointParameter(resource, dlog, paramDetails, isClient); if (paramDetails.size() < 2 || !"error".equals(paramDetails.get(1).type.toString())) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, resource.pos, String.format( "Invalid resource signature for %s resource in service : The second parameter should be an error", resource.getName().getValue())); } }
@Override public void visit(BLangConstant constant) { addTopLevelNodeToContext(constant, constant.name.getValue(), constant.symbol.pkgID, ContextConstants.VARIABLE, ContextConstants.VARIABLE, constant.symbol.owner); setPreviousNode(constant); if (constant.typeNode != null) { this.acceptNode(constant.typeNode); } }
private static void validateOnPingPongResource(BLangFunction resource, DiagnosticLog dlog, boolean isClient) { List<BLangSimpleVariable> paramDetails = resource.getParameters(); validateParamDetailsSize(paramDetails, 2, resource, dlog); validateEndpointParameter(resource, dlog, paramDetails, isClient); if (paramDetails.size() < 2 || !"byte[]".equals(paramDetails.get(1).type.toString())) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, resource.pos, INVALID_RESOURCE_SIGNATURE_FOR + resource.getName().getValue() + RESOURCE_IN_SERVICE + ": The second parameter should be a byte[]"); } }
@Override public void visit(BLangSimpleVariableDef varDefNode) { if (varDefNode.getVariable().getName().getValue().startsWith("0")) { return; } varDefNode.getVariable().accept(this); }
@Override public void visit(BLangAnnotationAttachment annAttachmentNode) { SymbolEnv annotationAttachmentEnv = new SymbolEnv(annAttachmentNode, symbolEnv.scope); PackageID packageID = annAttachmentNode.annotationSymbol.pkgID; if (packageID.getOrgName().getValue().equals("ballerina") && packageID.getName().getValue().equals("grpc") && annAttachmentNode.annotationName.getValue().equals("ServiceDescriptor")) { return; } CompletionVisitorUtil.isCursorWithinBlock(annAttachmentNode.getPosition(), annotationAttachmentEnv, this.lsContext, this); }
private static void validateOnOpenResource(BLangFunction resource, DiagnosticLog dlog, boolean isClient) { if (!isClient || !resource.getName().getValue().equals(WebSocketConstants.RESOURCE_NAME_ON_OPEN)) { List<BLangSimpleVariable> paramDetails = resource.getParameters(); validateParamDetailsSize(paramDetails, 1, resource, dlog); validateEndpointParameter(resource, dlog, paramDetails, isClient); } else { dlog.logDiagnostic(Diagnostic.Kind.ERROR, resource.pos, "onOpen resource is not supported for " + WebSocketConstants.WEBSOCKET_CLIENT_SERVICE); } }
@Override public void visit(BLangTypeDefinition typeDefinition) { addTopLevelNodeToContext(typeDefinition, typeDefinition.name.getValue(), typeDefinition.symbol.pkgID, typeDefinition.symbol.kind.name(), typeDefinition.symbol.kind.name(), typeDefinition.symbol.owner); setPreviousNode(typeDefinition); if (typeDefinition.typeNode != null) { this.acceptNode(typeDefinition.typeNode); } }
@Override public void visit(BLangFieldBasedAccess fieldBasedAccess) { BSymbol fbaSymbol = fieldBasedAccess.symbol; if (isReferenced(fieldBasedAccess.field.getValue(), fbaSymbol.owner, fbaSymbol.pkgID, fbaSymbol.owner.pkgID)) { addLocation(fieldBasedAccess, fbaSymbol.owner.pkgID.name.getValue(), fieldBasedAccess.pos.getSource().pkgID.name.getValue()); } if (fieldBasedAccess.expr != null) { this.acceptNode(fieldBasedAccess.expr); } }