process method
Implementation
List<RawWidgetDj> process() {
var rawWidgetDjs = <RawWidgetDj>[];
var itemPath = file.uri.toFilePath();
currentFileName = itemPath;
var fileHandler = File(itemPath);
var fileLines = fileHandler.readAsLinesSync().toList();
var parameterLines = <String>[];
// 0 => Not Found Yet
// 1 => Constructor comments running
// 2 => Constructor
// 3 => After Constructor
var constructorFound = 0;
String? constructorName;
var constructorLess = false;
var initialIsOptional = false;
fileLines.forEach((line) {
var parsedLine = WhiteSpaceRemover(line: line).removeFromStart();
var _constructorName = _isConstructorLine(line);
if (constructorFound == 0 && _constructorName != null) {
initialIsOptional = false;
constructorName = _constructorName;
constructorFound = 1;
constructorLess = false;
currentConstructorName = constructorName!;
if (KEEP_ONLY_WIDGET != null && constructorName != KEEP_ONLY_WIDGET) {
constructorFound = 0;
}
} else if (constructorFound == 1 && !parsedLine.startsWith('///')) {
constructorFound = 2;
constructorLess = !line.contains(constructorName!) ||
line.contains('super') ||
(line.endsWith('{') && line.contains(')'));
if (line.endsWith('({')) {
initialIsOptional = true;
}
// Check if this is a single line constructor
if (line.contains(constructorName! + '(') &&
line.contains(')') &&
!line.contains('()') &&
!line.contains('=')) {
if (fileDebugLvl > 5) {
print("Parsing single line constructor: '$line'");
}
var singleConstructorLine = line;
if (singleConstructorLine.contains(':')) {
singleConstructorLine = singleConstructorLine.split(':').first;
}
var regExStr = 'Map<.*>';
var regEx = RegExp(regExStr);
if (regEx.hasMatch(singleConstructorLine)) {
if (fileDebugLvl > 5) {
print('Map Warning!');
}
var match = regEx.firstMatch(singleConstructorLine);
if (match != null) {
var match_0 = match.group(0);
if (match_0 != null) {
if (fileDebugLvl > 5) {
print("Map is: '$match_0'");
}
singleConstructorLine =
singleConstructorLine.replaceAll(match_0, 'dynamic');
}
}
}
// get all the parameters
var paramsLinePart = singleConstructorLine
.split(constructorName! + '(')
.last
.split(')')
.first;
paramsLinePart =
paramsLinePart.replaceAll('{', '').replaceAll('}', '');
if (fileDebugLvl > 5) {
print('parsedLine $paramsLinePart');
}
var params = paramsLinePart
.split(',')
.map((e) => WhiteSpaceRemover(line: e).remove() + ',')
.toList();
// parse them
var parsedParameters = processParameterLines(
params,
intialIsOptional: true,
);
if (fileDebugLvl > 5) {
print('params: $params; parsed: ${parsedParameters.length}');
}
// get widget
var rawWidgetDj = RawWidgetDj(
parameters: parsedParameters,
name: constructorName!,
originFilePath: itemPath,
);
rawWidgetDjs.add(rawWidgetDj);
// and let the world know that we have got constructor
constructorFound = 0;
parameterLines = [];
constructorName = null;
}
} else if (constructorFound == 2 &&
(line.isEmpty ||
(line.endsWith('{') && line.contains(')')) ||
(line.contains('=') && line.contains(')')) ||
(line.contains('{') && line.endsWith('})')))) {
constructorFound = 0;
rawWidgetDjs.add(
processWidgetParams(
constructorName!,
parameterLines,
itemPath,
initialIsOptional: initialIsOptional,
),
);
parameterLines = [];
constructorName = null;
}
if (constructorFound == 2 && !constructorLess) {
if (fileDebugLvl > 5 &&
KEEP_ONLY_WIDGET != null &&
KEEP_ONLY_WIDGET == constructorName) {
print("line: '$line'");
}
parameterLines.add(line);
}
});
return rawWidgetDjs;
}