use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangSimpleVarRef varRefExpr) {
BLangSimpleVarRef genVarRefExpr = varRefExpr;
// XML qualified name reference. e.g: ns0:foo
if (varRefExpr.pkgSymbol != null && varRefExpr.pkgSymbol.tag == SymTag.XMLNS) {
BLangXMLQName qnameExpr = new BLangXMLQName(varRefExpr.variableName);
qnameExpr.nsSymbol = (BXMLNSSymbol) varRefExpr.pkgSymbol;
qnameExpr.localname = varRefExpr.variableName;
qnameExpr.prefix = varRefExpr.pkgAlias;
qnameExpr.namespaceURI = qnameExpr.nsSymbol.namespaceURI;
qnameExpr.isUsedInXML = false;
qnameExpr.pos = varRefExpr.pos;
qnameExpr.type = symTable.stringType;
result = qnameExpr;
return;
}
BSymbol ownerSymbol = varRefExpr.symbol.owner;
if ((varRefExpr.symbol.tag & SymTag.FUNCTION) == SymTag.FUNCTION && varRefExpr.symbol.type.tag == TypeTags.INVOKABLE) {
genVarRefExpr = new BLangFunctionVarRef(varRefExpr.symbol);
} else if ((ownerSymbol.tag & SymTag.INVOKABLE) == SymTag.INVOKABLE) {
// Local variable in a function/resource/action/worker
genVarRefExpr = new BLangLocalVarRef(varRefExpr.symbol);
} else if ((ownerSymbol.tag & SymTag.CONNECTOR) == SymTag.CONNECTOR) {
// Field variable in a receiver
genVarRefExpr = new BLangFieldVarRef(varRefExpr.symbol);
} else if ((ownerSymbol.tag & SymTag.STRUCT) == SymTag.STRUCT) {
genVarRefExpr = new BLangFieldVarRef(varRefExpr.symbol);
} else if ((ownerSymbol.tag & SymTag.PACKAGE) == SymTag.PACKAGE || (ownerSymbol.tag & SymTag.SERVICE) == SymTag.SERVICE) {
// Package variable | service variable
// We consider both of them as package level variables
genVarRefExpr = new BLangPackageVarRef(varRefExpr.symbol);
// Only locking service level and package level variables
if (!enclLocks.isEmpty()) {
enclLocks.peek().addLockVariable(varRefExpr.symbol);
}
}
genVarRefExpr.type = varRefExpr.type;
result = genVarRefExpr;
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project ballerina by ballerina-lang.
the class BLangParserListener method exitFieldVariableReference.
@Override
public void exitFieldVariableReference(BallerinaParser.FieldVariableReferenceContext ctx) {
if (ctx.exception != null) {
return;
}
FieldContext field = ctx.field();
String fieldName;
FieldType fieldType;
if (field.Identifier() != null) {
fieldName = field.Identifier().getText();
fieldType = FieldType.SINGLE;
} else {
fieldName = field.MUL().getText();
fieldType = FieldType.ALL;
}
this.pkgBuilder.createFieldBasedAccessNode(getCurrentPos(ctx), getWS(ctx), fieldName, fieldType);
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addFieldToObject.
void addFieldToObject(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean exprAvailable, int annotCount, boolean isPrivate) {
Set<Whitespace> wsForSemiColon = removeNthFromLast(ws, 0);
BLangObject objectNode = (BLangObject) this.objectStack.peek();
objectNode.addWS(wsForSemiColon);
BLangVariable field = addVar(pos, ws, identifier, exprAvailable, annotCount);
if (!isPrivate) {
field.flagSet.add(Flag.PUBLIC);
}
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project ballerina by ballerina-lang.
the class TreeVisitor method visit.
@Override
public void visit(BLangObject objectNode) {
BSymbol objectSymbol = objectNode.symbol;
SymbolEnv objectEnv = SymbolEnv.createPkgLevelSymbolEnv(objectNode, objectSymbol.scope, symbolEnv);
blockOwnerStack.push(objectNode);
this.cursorPositionResolver = ObjectTypeScopeResolver.class;
objectNode.fields.forEach(field -> acceptNode(field, objectEnv));
// TODO: visit annotation and doc attachments
objectNode.functions.forEach(f -> acceptNode(f, objectEnv));
blockOwnerStack.pop();
this.cursorPositionResolver = TopLevelNodeScopeResolver.class;
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project jaggery by wso2.
the class RegistryHostObject method search.
private AdvancedSearchResultsBean search(Registry configSystemRegistry, UserRegistry registry, CustomSearchParameterBean parameters) throws CarbonException {
RegistryUtils.recordStatistics(parameters);
AdvancedSearchResultsBean metaDataSearchResultsBean;
ResourceData[] contentSearchResourceData;
String[][] tempParameterValues = parameters.getParameterValues();
// Doing a validation of all the values sent
boolean allEmpty = true;
for (String[] tempParameterValue : tempParameterValues) {
if (tempParameterValue[1] != null & tempParameterValue[1].trim().length() > 0) {
allEmpty = false;
// Validating all the dates
if (tempParameterValue[0].equals("createdAfter") || tempParameterValue[0].equals("createdBefore") || tempParameterValue[0].equals("updatedAfter") || tempParameterValue[0].equals("updatedBefore")) {
if (!SearchUtils.validateDateInput(tempParameterValue[1])) {
String message = tempParameterValue[0] + " contains illegal characters";
return SearchUtils.getEmptyResultBeanWithErrorMsg(message);
}
} else if (tempParameterValue[0].equals("mediaType")) {
if (SearchUtils.validateMediaTypeInput(tempParameterValue[1])) {
String message = tempParameterValue[0] + " contains illegal characters";
return SearchUtils.getEmptyResultBeanWithErrorMsg(message);
}
} else if (tempParameterValue[0].equals("content")) {
if (SearchUtils.validateContentInput(tempParameterValue[1])) {
String message = tempParameterValue[0] + " contains illegal characters";
return SearchUtils.getEmptyResultBeanWithErrorMsg(message);
}
} else if (tempParameterValue[0].equals("tags")) {
boolean containsTag = false;
for (String str : tempParameterValue[1].split(",")) {
if (str.trim().length() > 0) {
containsTag = true;
break;
}
}
if (!containsTag) {
String message = tempParameterValue[0] + " contains illegal characters";
return SearchUtils.getEmptyResultBeanWithErrorMsg(message);
}
if (SearchUtils.validateTagsInput(tempParameterValue[1])) {
String message = tempParameterValue[0] + " contains illegal characters";
return SearchUtils.getEmptyResultBeanWithErrorMsg(message);
}
} else {
if (SearchUtils.validatePathInput(tempParameterValue[1])) {
String message = tempParameterValue[0] + " contains illegal characters";
return SearchUtils.getEmptyResultBeanWithErrorMsg(message);
}
}
}
}
if (allEmpty) {
return SearchUtils.getEmptyResultBeanWithErrorMsg("At least one field must be filled");
}
boolean onlyContent = true;
for (String[] tempParameterValue : tempParameterValues) {
if (!tempParameterValue[0].equals("content") && !tempParameterValue[0].equals("leftOp") && !tempParameterValue[0].equals("rightOp") && tempParameterValue[1] != null && tempParameterValue[1].length() > 0) {
onlyContent = false;
break;
}
}
for (String[] tempParameterValue : tempParameterValues) {
if (tempParameterValue[0].equals("content") && tempParameterValue[1] != null && tempParameterValue[1].length() > 0) {
try {
contentSearchResourceData = search(registry, tempParameterValue[1]);
} catch (Exception e) {
metaDataSearchResultsBean = new AdvancedSearchResultsBean();
metaDataSearchResultsBean.setErrorMessage(e.getMessage());
return metaDataSearchResultsBean;
}
// If there are no resource paths returned from content, then there is no point of searching for more
if (contentSearchResourceData != null && contentSearchResourceData.length > 0) {
// Map<String, ResourceData> resourceDataMap = new HashMap<String, ResourceData>();
Map<String, ResourceData> aggregatedMap = new HashMap<String, ResourceData>();
for (ResourceData resourceData : contentSearchResourceData) {
aggregatedMap.put(resourceData.getResourcePath(), resourceData);
}
metaDataSearchResultsBean = AdvancedSearchResultsBeanPopulator.populate(configSystemRegistry, registry, parameters);
if (metaDataSearchResultsBean != null) {
ResourceData[] metaDataResourceData = metaDataSearchResultsBean.getResourceDataList();
if (metaDataResourceData != null && metaDataResourceData.length > 0) {
List<String> invalidKeys = new ArrayList<String>();
for (String key : aggregatedMap.keySet()) {
boolean keyFound = false;
for (ResourceData resourceData : metaDataResourceData) {
if (resourceData.getResourcePath().equals(key)) {
keyFound = true;
break;
}
}
if (!keyFound) {
invalidKeys.add(key);
}
}
for (String invalidKey : invalidKeys) {
aggregatedMap.remove(invalidKey);
}
} else if (!onlyContent) {
aggregatedMap.clear();
}
}
ArrayList<ResourceData> sortedList = new ArrayList<ResourceData>(aggregatedMap.values());
SearchUtils.sortResourceDataList(sortedList);
metaDataSearchResultsBean = new AdvancedSearchResultsBean();
metaDataSearchResultsBean.setResourceDataList(sortedList.toArray(new ResourceData[sortedList.size()]));
return metaDataSearchResultsBean;
} else {
metaDataSearchResultsBean = new AdvancedSearchResultsBean();
metaDataSearchResultsBean.setResourceDataList(contentSearchResourceData);
return metaDataSearchResultsBean;
}
}
}
return AdvancedSearchResultsBeanPopulator.populate(configSystemRegistry, registry, parameters);
}
Aggregations