Skip to content

Commit

Permalink
Handle setting of position of the new nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
poorna2152 committed Sep 13, 2024
1 parent da8d92b commit 2b10e02
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4450,9 +4450,9 @@ public BLangNode transform(XMLStepExpressionNode xmlStepExpressionNode) {
}

BLangExpression expr = createExpression(xmlStepExpressionNode.expression());
BLangXMLNavigationAccess xmlNavigationAccess =
new BLangXMLNavigationAccess(getPosition(xmlStepExpressionNode), expr, filters,
XMLNavigationAccess.NavAccessType.fromInt(starCount));
BLangXMLNavigationAccess xmlNavigationAccess = new BLangXMLNavigationAccess(
getPosition(xmlStepExpressionNode.expression(), xmlStepExpressionNode.xmlStepStart()), expr, filters,
XMLNavigationAccess.NavAccessType.fromInt(starCount));
if (xmlStepExpressionNode.xmlStepExtend().size() > 0) {
List<BLangXMLStepExtend> extensions =
createBLangXMLStepExtends(xmlStepExpressionNode.xmlStepExtend(), xmlNavigationAccess);
Expand Down Expand Up @@ -7089,24 +7089,26 @@ private List<BLangXMLStepExtend> createBLangXMLStepExtends(NodeList<Node> nodes,
List<BLangXMLStepExtend> extensions = new ArrayList<>();
BLangXMLStepExtend curExpr = null;
for (Node node : nodes) {
Location pos = getPosition(node);
SyntaxKind kind = node.kind();
if (kind == SyntaxKind.XML_STEP_INDEXED_EXTEND) {
curExpr =
new BLangXMLIndexedStepExtend(createExpression(((XMLStepIndexedExtendNode) node).expression()));
new BLangXMLIndexedStepExtend(pos,
createExpression(((XMLStepIndexedExtendNode) node).expression()));
} else if (kind == SyntaxKind.XML_STEP_METHOD_CALL_EXTEND) {
XMLStepMethodCallExtendNode xmlStepMethodCallExtendNode = (XMLStepMethodCallExtendNode) node;
SimpleNameReferenceNode methodName = xmlStepMethodCallExtendNode.methodName();
BLangInvocation bLangInvocation = createBLangInvocation(methodName,
xmlStepMethodCallExtendNode.parenthesizedArgList().arguments(), methodName.location(), false);
bLangInvocation.expr = curExpr == null ? expr : curExpr;
curExpr = new BLangXMLMethodCallStepExtend(bLangInvocation);
curExpr = new BLangXMLMethodCallStepExtend(pos, bLangInvocation);
} else {
XMLNamePatternChainingNode xmlNamePatternChainingNode = (XMLNamePatternChainingNode) node;
List<BLangXMLElementFilter> filters = new ArrayList<>();
for (Node namePattern : xmlNamePatternChainingNode.xmlNamePattern()) {
filters.add(createXMLElementFilter(namePattern));
}
curExpr = new BLangXMLFilterStepExtend(filters);
curExpr = new BLangXMLFilterStepExtend(pos, filters);
}
extensions.add(curExpr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2316,19 +2316,19 @@ public void visit(BLangXMLElementFilter source) {

@Override
public void visit(BLangXMLIndexedStepExtend source) {
BLangXMLIndexedStepExtend clone = new BLangXMLIndexedStepExtend(source.indexExpr);
BLangXMLIndexedStepExtend clone = new BLangXMLIndexedStepExtend(source.pos, source.indexExpr);
source.cloneRef = clone;
}

@Override
public void visit(BLangXMLFilterStepExtend source) {
BLangXMLFilterStepExtend clone = new BLangXMLFilterStepExtend(cloneList(source.filters));
BLangXMLFilterStepExtend clone = new BLangXMLFilterStepExtend(source.pos, cloneList(source.filters));
source.cloneRef = clone;
}

@Override
public void visit(BLangXMLMethodCallStepExtend source) {
BLangXMLMethodCallStepExtend clone = new BLangXMLMethodCallStepExtend(clone(source.invocation));
BLangXMLMethodCallStepExtend clone = new BLangXMLMethodCallStepExtend(source.pos, clone(source.invocation));
source.cloneRef = clone;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.wso2.ballerinalang.compiler.tree.expressions;

import io.ballerina.tools.diagnostics.Location;
import org.ballerinalang.model.tree.NodeKind;
import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer;
import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer;
Expand All @@ -35,7 +36,8 @@ public class BLangXMLFilterStepExtend extends BLangXMLStepExtend {

public final List<BLangXMLElementFilter> filters;

public BLangXMLFilterStepExtend(List<BLangXMLElementFilter> filters) {
public BLangXMLFilterStepExtend(Location pos, List<BLangXMLElementFilter> filters) {
this.pos = pos;
this.filters = filters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.wso2.ballerinalang.compiler.tree.expressions;

import io.ballerina.tools.diagnostics.Location;
import org.ballerinalang.model.tree.NodeKind;
import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer;
import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer;
Expand All @@ -31,7 +32,8 @@
public class BLangXMLIndexedStepExtend extends BLangXMLStepExtend {
public BLangExpression indexExpr;

public BLangXMLIndexedStepExtend(BLangExpression indexExpr) {
public BLangXMLIndexedStepExtend(Location pos, BLangExpression indexExpr) {
this.pos = pos;
this.indexExpr = indexExpr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.wso2.ballerinalang.compiler.tree.expressions;

import io.ballerina.tools.diagnostics.Location;
import org.ballerinalang.model.tree.NodeKind;
import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer;
import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer;
Expand All @@ -32,7 +33,8 @@ public class BLangXMLMethodCallStepExtend extends BLangXMLStepExtend {

public BLangInvocation invocation;

public BLangXMLMethodCallStepExtend(BLangInvocation invocation) {
public BLangXMLMethodCallStepExtend(Location pos, BLangInvocation invocation) {
this.pos = pos;
this.invocation = invocation;
this.invocation.parent = this;
}
Expand Down

0 comments on commit 2b10e02

Please sign in to comment.