From 460672fcf303648a2cdd5110f8626182a4108ee7 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Tue, 5 Nov 2024 15:12:00 +0530 Subject: [PATCH] Introduce vars for function calls --- .../ListenerAndServiceDefAnalysisTask.java | 6 ++-- .../VariableDeclarationAnalysisTask.java | 30 +++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/mi/plugin/ListenerAndServiceDefAnalysisTask.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/mi/plugin/ListenerAndServiceDefAnalysisTask.java index 6f56f15..5d5db24 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/mi/plugin/ListenerAndServiceDefAnalysisTask.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/mi/plugin/ListenerAndServiceDefAnalysisTask.java @@ -18,6 +18,7 @@ package io.ballerina.stdlib.mi.plugin; +import io.ballerina.compiler.syntax.tree.Node; import io.ballerina.compiler.syntax.tree.SyntaxKind; import io.ballerina.projects.plugins.AnalysisTask; import io.ballerina.projects.plugins.SyntaxNodeAnalysisContext; @@ -35,13 +36,14 @@ public class ListenerAndServiceDefAnalysisTask implements AnalysisTask symbol = context.semanticModel().symbol(context.node()); + Node node = context.node(); + Optional symbol = context.semanticModel().symbol(node); if (symbol.isEmpty() || !(symbol.get() instanceof VariableSymbol)) { return; } TypeSymbol typeSymbol = getRawType(((VariableSymbol) symbol.get()).typeDescriptor()); List objectTypeSymbols = new ArrayList<>(); - if (typeSymbol.typeKind() == TypeDescKind.UNION) { + TypeDescKind typeDescKind = typeSymbol.typeKind(); + if (typeDescKind == TypeDescKind.UNION) { objectTypeSymbols = getObjectTypeMembers((BallerinaUnionTypeSymbol) typeSymbol); - } else if (typeSymbol.typeKind() == TypeDescKind.OBJECT) { + } else if (typeDescKind == TypeDescKind.OBJECT) { objectTypeSymbols.add((ObjectTypeSymbol) typeSymbol); } @@ -70,25 +73,26 @@ public void perform(SyntaxNodeAnalysisContext context) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(diagnosticCode.diagnosticId(), diagnosticCode.message(), DiagnosticSeverity.ERROR); - context.reportDiagnostic(DiagnosticFactory.createDiagnostic(diagnosticInfo, context.node().location())); + context.reportDiagnostic(DiagnosticFactory.createDiagnostic(diagnosticInfo, node.location())); return; } } private TypeSymbol getRawType(TypeSymbol typeDescriptor) { - if (typeDescriptor.typeKind() == TypeDescKind.INTERSECTION) { + TypeDescKind typeDescKind = typeDescriptor.typeKind(); + if (typeDescKind == TypeDescKind.INTERSECTION) { return getRawType(((IntersectionTypeSymbol) typeDescriptor).effectiveTypeDescriptor()); } - if (typeDescriptor.typeKind() == TypeDescKind.TYPE_REFERENCE) { - TypeReferenceTypeSymbol typeRef = (TypeReferenceTypeSymbol) typeDescriptor; - if (typeRef.typeDescriptor().typeKind() == TypeDescKind.INTERSECTION) { - return getRawType(((IntersectionTypeSymbol) typeRef.typeDescriptor()).effectiveTypeDescriptor()); + if (typeDescKind == TypeDescKind.TYPE_REFERENCE) { + TypeSymbol typeSymbol = ((TypeReferenceTypeSymbol) typeDescriptor).typeDescriptor(); + TypeDescKind refTypeDescKind = typeSymbol.typeKind(); + if (refTypeDescKind == TypeDescKind.INTERSECTION) { + return getRawType(((IntersectionTypeSymbol) typeSymbol).effectiveTypeDescriptor()); } - TypeSymbol rawType = typeRef.typeDescriptor(); - if (rawType.typeKind() == TypeDescKind.TYPE_REFERENCE) { - return getRawType(rawType); + if (refTypeDescKind == TypeDescKind.TYPE_REFERENCE) { + return getRawType(typeSymbol); } - return rawType; + return typeSymbol; } return typeDescriptor; }