Skip to content

Commit

Permalink
Merge pull request #19532 from rdhananjaya/improve-identifier-pos
Browse files Browse the repository at this point in the history
Add missing pos and WS to identifier node
  • Loading branch information
nadeeshaan authored Nov 5, 2019
2 parents e7e99eb + dc9d290 commit b167099
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -857,26 +857,6 @@ private static BVarSymbol duplicateParamSymbol(BVarSymbol paramSymbol, BInvokabl
return newParamSymbol;
}

static BLangInvocation createLambdaInvocation(DiagnosticPos pos, BInvokableSymbol invokableSymbol,
BLangSimpleVarRef varRef, List<BLangSimpleVariable> requiredArgs,
SymbolResolver symResolver) {
final BLangInvocation invokeLambda = (BLangInvocation) TreeBuilder.createInvocationNode();
invokeLambda.pos = pos;
BLangIdentifier invocationName = (BLangIdentifier) TreeBuilder.createIdentifierNode();
invocationName.setValue(BLangBuiltInMethod.CALL.getName());
invokeLambda.name = invocationName;
invokeLambda.argExprs.addAll(generateArgExprsForLambdas(pos, requiredArgs, invokableSymbol.params,
symResolver));
invokeLambda.requiredArgs.addAll(generateArgExprsForLambdas(pos, requiredArgs, invokableSymbol.params,
symResolver));
invokeLambda.builtInMethod = BLangBuiltInMethod.CALL;
invokeLambda.type = ((BInvokableType) invokableSymbol.type).retType;
invokeLambda.expr = varRef;
invokeLambda.builtinMethodInvocation = true;
invokeLambda.symbol = varRef.symbol;
return invokeLambda;
}

private static List<BLangExpression> generateArgExprsForLambdas(DiagnosticPos pos, List<BLangSimpleVariable> args,
List<BVarSymbol> formalParams,
SymbolResolver symResolver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.ballerinalang.model.symbols.SymbolKind;
import org.ballerinalang.model.tree.AnnotatableNode;
import org.ballerinalang.model.tree.AnnotationAttachmentNode;
import org.ballerinalang.model.tree.IdentifierNode;
import org.ballerinalang.model.tree.NodeKind;
import org.ballerinalang.model.types.TypeKind;
import org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver;
Expand Down Expand Up @@ -305,12 +304,11 @@ private void addVarArgsAnnotation(BLangFunction mainFunc) {
if (annSymbol instanceof BAnnotationSymbol) {
annoAttachment.annotationSymbol = (BAnnotationSymbol) annSymbol;
}
IdentifierNode identifierNode = TreeBuilder.createIdentifierNode();
if (identifierNode instanceof BLangIdentifier) {
annoAttachment.annotationName = (BLangIdentifier) identifierNode;
}
BLangIdentifier identifierNode = (BLangIdentifier) TreeBuilder.createIdentifierNode();
annoAttachment.annotationName = identifierNode;
annoAttachment.annotationName.value = DEFAULTABLE_ANN;
annoAttachment.pos = pos;
annoAttachment.annotationName.pos = pos;
BLangRecordLiteral literalNode = (BLangRecordLiteral) TreeBuilder.createRecordLiteralNode();

annoAttachment.expr = literalNode;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public void visit(BLangImportPackage importPkgNode) {
public void visit(BLangXMLNS xmlnsNode) {
String nsURI = (String) ((BLangLiteral) xmlnsNode.namespaceURI).value;

if (xmlnsNode.prefix.value != null && nsURI.isEmpty()) {
if (!nullOrEmpty(xmlnsNode.prefix.value) && nsURI.isEmpty()) {
dlog.error(xmlnsNode.pos, DiagnosticCode.INVALID_NAMESPACE_DECLARATION, xmlnsNode.prefix);
}

Expand All @@ -531,6 +531,10 @@ public void visit(BLangXMLNS xmlnsNode) {
defineSymbol(xmlnsNode.prefix.pos, xmlnsSymbol);
}

private boolean nullOrEmpty(String value) {
return value == null || value.isEmpty();
}

public void visit(BLangXMLNSStatement xmlnsStmtNode) {
defineNode(xmlnsStmtNode.xmlnsDecl, env);
}
Expand Down Expand Up @@ -1619,7 +1623,8 @@ private StatementNode createAssignmentStmt(BLangSimpleVariable variable, BVarSym
private BLangSimpleVariable createReceiver(DiagnosticPos pos, BLangIdentifier name) {
BLangSimpleVariable receiver = (BLangSimpleVariable) TreeBuilder.createSimpleVariableNode();
receiver.pos = pos;
IdentifierNode identifier = createIdentifier(Names.SELF.getValue());
BLangIdentifier identifier = (BLangIdentifier) createIdentifier(Names.SELF.getValue());
identifier.pos = pos;
receiver.setName(identifier);
BLangUserDefinedType structTypeNode = (BLangUserDefinedType) TreeBuilder.createUserDefinedTypeNode();
structTypeNode.pkgAlias = new BLangIdentifier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
public class BLangIdentifier extends BLangNode implements IdentifierNode {

public String value = "";
public String originalValue;
public boolean isLiteral;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ public class BLangXMLQName extends BLangExpression implements XMLQNameNode {
public BLangXMLQName() {
}

public BLangXMLQName(String localname) {
this.localname = new BLangIdentifier();
this.prefix = new BLangIdentifier();
this.localname.value = localname;
}

public BLangXMLQName(String localname, String prefix) {
this.localname = new BLangIdentifier();
this.localname.value = localname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.ballerinalang.model.elements.AttachPoint;
import org.ballerinalang.model.elements.PackageID;
import org.ballerinalang.model.tree.AnnotationAttachmentNode;
import org.ballerinalang.model.tree.IdentifierNode;
import org.ballerinalang.model.tree.NodeKind;
import org.ballerinalang.model.tree.ServiceNode;
import org.ballerinalang.model.tree.expressions.LiteralNode;
Expand Down Expand Up @@ -182,16 +181,15 @@ private void addDescriptorAnnotation(ServiceNode serviceNode, String rootDescrip
if (annSymbol instanceof BAnnotationSymbol) {
annoAttachment.annotationSymbol = (BAnnotationSymbol) annSymbol;
}
IdentifierNode identifierNode = TreeBuilder.createIdentifierNode();
if (identifierNode instanceof BLangIdentifier) {
annoAttachment.annotationName = (BLangIdentifier) identifierNode;
}
annoAttachment.annotationName = (BLangIdentifier) TreeBuilder.createIdentifierNode();
annoAttachment.annotationName.value = ANN_SERVICE_DESCRIPTOR;
annoAttachment.annotationName.pos = pos;
annoAttachment.pos = pos;
BLangRecordLiteral literalNode = (BLangRecordLiteral) TreeBuilder.createRecordLiteralNode();
annoAttachment.expr = literalNode;
BLangIdentifier pkgAlias = (BLangIdentifier) TreeBuilder.createIdentifierNode();
pkgAlias.setValue(PROTOCOL_PACKAGE_GRPC);
pkgAlias.pos = pos;
annoAttachment.pkgAlias = pkgAlias;
annoAttachment.attachPoints.add(AttachPoint.Point.SERVICE);
literalNode.pos = pos;
Expand Down Expand Up @@ -247,9 +245,11 @@ private void addDescriptorAnnotation(ServiceNode serviceNode, String rootDescrip
functionRef.type = symTable.mapType;
BLangIdentifier funcName = (BLangIdentifier) TreeBuilder.createIdentifierNode();
funcName.setValue(DESCRIPTOR_MAP);
funcName.pos = pos;
functionRef.name = funcName;
BLangIdentifier funcPkgAlias = (BLangIdentifier) TreeBuilder.createIdentifierNode();
funcPkgAlias.setValue("");
funcPkgAlias.pos = pos;
functionRef.pkgAlias = funcPkgAlias;
}

Expand All @@ -260,6 +260,7 @@ private void addDescriptorAnnotation(ServiceNode serviceNode, String rootDescrip
BLangSimpleVarRef mapKeyLiteral = (BLangSimpleVarRef) TreeBuilder.createSimpleVariableReferenceNode();
BLangIdentifier keyName = (BLangIdentifier) TreeBuilder.createIdentifierNode();
keyName.setValue(ANN_FIELD_DESC_MAP);
keyName.pos = pos;
mapKeyLiteral.variableName = keyName;
mapKeyLiteral.type = symTable.mapType;
mapKeyLiteral.pos = pos;
Expand Down

0 comments on commit b167099

Please sign in to comment.