Skip to content

Commit

Permalink
Introduce vars for function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
poorna2152 committed Nov 5, 2024
1 parent c73721a commit 460672f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,13 +36,14 @@ public class ListenerAndServiceDefAnalysisTask implements AnalysisTask<SyntaxNod
@Override
public void perform(SyntaxNodeAnalysisContext context) {
DiagnosticErrorCode diagnosticCode;
if (context.node().kind() == SyntaxKind.SERVICE_DECLARATION) {
Node node = context.node();
if (node.kind() == SyntaxKind.SERVICE_DECLARATION) {
diagnosticCode = DiagnosticErrorCode.SERVICE_DEF_NOT_ALLOWED;
} else {
diagnosticCode = DiagnosticErrorCode.LISTENER_DECLARATION_NOT_ALLOWED;
}
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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.ballerina.compiler.api.symbols.TypeReferenceTypeSymbol;
import io.ballerina.compiler.api.symbols.TypeSymbol;
import io.ballerina.compiler.api.symbols.VariableSymbol;
import io.ballerina.compiler.syntax.tree.Node;
import io.ballerina.projects.plugins.AnalysisTask;
import io.ballerina.projects.plugins.SyntaxNodeAnalysisContext;
import io.ballerina.tools.diagnostics.DiagnosticFactory;
Expand All @@ -48,16 +49,18 @@ public class VariableDeclarationAnalysisTask implements AnalysisTask<SyntaxNodeA

@Override
public void perform(SyntaxNodeAnalysisContext context) {
Optional<Symbol> symbol = context.semanticModel().symbol(context.node());
Node node = context.node();
Optional<Symbol> symbol = context.semanticModel().symbol(node);
if (symbol.isEmpty() || !(symbol.get() instanceof VariableSymbol)) {
return;
}

TypeSymbol typeSymbol = getRawType(((VariableSymbol) symbol.get()).typeDescriptor());
List<ObjectTypeSymbol> 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);
}

Expand All @@ -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;
}
Expand Down

0 comments on commit 460672f

Please sign in to comment.