Skip to content

Commit

Permalink
Introduce fileName() and deprecate filePath()
Browse files Browse the repository at this point in the history
  • Loading branch information
dulajdilshan committed Feb 16, 2023
1 parent ae723d0 commit 12560f8
Show file tree
Hide file tree
Showing 59 changed files with 105 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private String getErrorMessage(List<Diagnostic> diagnosticList) {
StringBuilder errorMessage = new StringBuilder("\n");
for (Diagnostic diagnostic : diagnosticList) {
LineRange lineRange = getOneBasedLineRange(diagnostic.location().lineRange());
errorMessage.append("[").append(lineRange.filePath()).append(":")
errorMessage.append("[").append(lineRange.fileName()).append(":")
.append(lineRange).append("] ").append(diagnostic.message()).append("\n");
}
return errorMessage.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,12 @@ static String getLineRange(TomlNode node) {
return CONFIG_FILE_NAME;
}
LineRange oneBasedLineRange = getOneBasedLineRange(node.location().lineRange());
return oneBasedLineRange.filePath() + ":" + oneBasedLineRange;
return oneBasedLineRange.fileName() + ":" + oneBasedLineRange;
}

static LineRange getOneBasedLineRange(LineRange lineRange) {
return LineRange.from(
lineRange.filePath(),
lineRange.fileName(),
LinePosition.from(lineRange.startLine().line() + 1, lineRange.startLine().offset() + 1),
LinePosition.from(lineRange.endLine().line() + 1, lineRange.endLine().offset() + 1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public Optional<Symbol> symbol(Node node) {
return Optional.empty();
}

BLangCompilationUnit compilationUnit = getCompilationUnit(nodeIdentifierLocation.get().lineRange().filePath());
BLangCompilationUnit compilationUnit = getCompilationUnit(nodeIdentifierLocation.get().lineRange().fileName());
return lookupSymbol(compilationUnit, nodeIdentifierLocation.get().lineRange().startLine());
}

Expand Down Expand Up @@ -293,7 +293,7 @@ private List<Location> getReferences(BSymbol symbol, BLangNode node, boolean wit
*/
@Override
public Optional<TypeSymbol> type(LineRange range) {
BLangCompilationUnit compilationUnit = getCompilationUnit(range.filePath());
BLangCompilationUnit compilationUnit = getCompilationUnit(range.fileName());
NodeFinder nodeFinder = new NodeFinder(true);
BLangNode node = nodeFinder.lookup(compilationUnit, range);

Expand All @@ -306,7 +306,7 @@ public Optional<TypeSymbol> type(LineRange range) {

@Override
public Optional<TypeSymbol> typeOf(LineRange range) {
BLangCompilationUnit compilationUnit = getCompilationUnit(range.filePath());
BLangCompilationUnit compilationUnit = getCompilationUnit(range.fileName());
NodeFinder nodeFinder = new NodeFinder(false);
BLangNode node = nodeFinder.lookup(compilationUnit, range);

Expand Down Expand Up @@ -370,7 +370,7 @@ public List<Diagnostic> diagnostics(LineRange range) {
for (Diagnostic diagnostic : allDiagnostics) {
LineRange lineRange = diagnostic.location().lineRange();

if (lineRange.filePath().equals(range.filePath()) && PositionUtil.withinRange(lineRange, range)) {
if (lineRange.fileName().equals(range.fileName()) && PositionUtil.withinRange(lineRange, range)) {
filteredDiagnostics.add(diagnostic);
}
}
Expand Down Expand Up @@ -495,7 +495,7 @@ private BLangCompilationUnit getCompilationUnit(String srcFile) {
private boolean isCursorNotAtDefinition(BLangCompilationUnit compilationUnit, BSymbol symbolAtCursor,
LinePosition cursorPos) {
return !(compilationUnit.getPackageID().equals(symbolAtCursor.pkgID)
&& compilationUnit.getName().equals(symbolAtCursor.pos.lineRange().filePath())
&& compilationUnit.getName().equals(symbolAtCursor.pos.lineRange().fileName())
&& PositionUtil.withinBlock(cursorPos, symbolAtCursor.pos));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static boolean withinRange(LineRange range, LineRange enclRange) {
int enclStartOffset = enclRange.startLine().offset();
int enclEndOffset = enclRange.endLine().offset();

return enclRange.filePath().equals(range.filePath())
return enclRange.fileName().equals(range.fileName())
&& (startLine == enclStartLine && startOffset >= enclStartOffset || startLine > enclStartLine)
&& (endLine == enclEndLine && endOffset <= enclEndOffset || endLine < enclEndLine);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,7 @@ private boolean isGeneratedClassDefForService(BLangClassDefinition clazz) {
*/
private Location getLocationForLiteral(Location location) {
LineRange lineRange = location.lineRange();
return new BLangDiagnosticLocation(lineRange.filePath(),
return new BLangDiagnosticLocation(lineRange.fileName(),
lineRange.startLine().line(), lineRange.endLine().line(),
lineRange.startLine().offset() + 1, lineRange.endLine().offset() - 1,
location.textRange().startOffset(), location.textRange().length());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected BallerinaSymbol(String name, SymbolKind symbolKind, BSymbol symbol, Co
this.internalSymbol = symbol;
LineRange lineRange = symbol.pos.lineRange();
TextRange textRange = symbol.pos.textRange();
this.position = new BLangDiagnosticLocation(lineRange.filePath(),
this.position = new BLangDiagnosticLocation(lineRange.fileName(),
lineRange.startLine().line(),
lineRange.endLine().line(),
lineRange.startLine().offset(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ public String getErrorMessage() {
private String convertDiagnosticToString(Diagnostic diagnostic) {
LineRange lineRange = diagnostic.location().lineRange();

LineRange oneBasedLineRange = LineRange.from(lineRange.filePath(), LinePosition
LineRange oneBasedLineRange = LineRange.from(lineRange.fileName(), LinePosition
.from(lineRange.startLine().line(), lineRange.startLine().offset() + 1), LinePosition
.from(lineRange.endLine().line(),
lineRange.endLine().offset() + 1));

return diagnostic.diagnosticInfo().severity().toString() + " [" + oneBasedLineRange.filePath() + ":"
return diagnostic.diagnosticInfo().severity().toString() + " [" + oneBasedLineRange.fileName() + ":"
+ oneBasedLineRange + "] " + diagnostic.message();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ static String convertDiagnosticToString(Diagnostic diagnostic) {
LineRange lineRange = diagnostic.location().lineRange();

LineRange oneBasedLineRange = LineRange.from(
lineRange.filePath(),
lineRange.fileName(),
LinePosition.from(lineRange.startLine().line(), lineRange.startLine().offset() + 1),
LinePosition.from(lineRange.endLine().line(), lineRange.endLine().offset() + 1));

return diagnostic.diagnosticInfo().severity().toString() + " [" +
oneBasedLineRange.filePath() + ":" + oneBasedLineRange + "] " + diagnostic.message();
oneBasedLineRange.fileName() + ":" + oneBasedLineRange + "] " + diagnostic.message();
}

public static String getStringFromTomlTableNode(TopLevelNode topLevelNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ private void defineFunction(DataInputStream dataInStream) throws IOException {
Symbols.createFunctionSymbol(flags, names.fromString(funcName), names.fromString(funcOrigName),
this.env.pkgSymbol.pkgID, funcType, this.env.pkgSymbol,
Symbols.isFlagOn(flags, Flags.NATIVE), pos, toOrigin(origin));
invokableSymbol.source = pos.lineRange().filePath();
invokableSymbol.source = pos.lineRange().fileName();
invokableSymbol.retType = funcType.retType;

Scope scopeToDefine = this.env.pkgSymbol.scope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ private BLangDiagnosticLocation getFunctionLastLinePos() {
}
LineRange lineRange = this.env.enclFunc.pos.lineRange();
LinePosition endLine = lineRange.endLine();
return new BLangDiagnosticLocation(lineRange.filePath(), endLine.line(), endLine.line(), endLine.offset(),
return new BLangDiagnosticLocation(lineRange.fileName(), endLine.line(), endLine.line(), endLine.offset(),
endLine.offset(), 0, 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ protected static void generateSetYieldedStatus(MethodVisitor mv, LabelGenerator

StringBuilder yieldLocationData = new StringBuilder(fullyQualifiedFuncName);
if (terminatorPos != null) {
yieldLocationData.append("(").append(terminatorPos.lineRange().filePath()).append(":")
yieldLocationData.append("(").append(terminatorPos.lineRange().fileName()).append(":")
.append(terminatorPos.lineRange().startLine().line() + 1).append(")");
}
mv.visitLdcInsn(yieldLocationData.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ private List<BIROperand> generatePositionArgs(BIRPackage pkg, BIRFunction func,
Location pos) {
BIROperand pkgOperand = generateGlobalConstantOperand(pkg, symbolTable.stringType,
generatePackageId(pkg.packageID));
BIROperand fileNameOperand = getTempLocalVariable(FILE_NAME_STRING, pos, pos.lineRange().filePath(),
BIROperand fileNameOperand = getTempLocalVariable(FILE_NAME_STRING, pos, pos.lineRange().fileName(),
symbolTable.stringType, observeStartBB);
addLocalVarIfAbsent(func, fileNameOperand.variableDcl);
BIROperand startLineOperand = getTempLocalVariable(START_LINE_STRING, pos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ private void generateModuleClasses(BIRPackage module, Map<String, byte[]> jarEnt
String mainClass = "";
if (mainFunc != null) {
mainClass = getModuleLevelClassName(module.packageID, JvmCodeGenUtil
.cleanupPathSeparators(mainFunc.pos.lineRange().filePath()));
.cleanupPathSeparators(mainFunc.pos.lineRange().fileName()));
}

MainMethodGen mainMethodGen = new MainMethodGen(symbolTable, jvmTypeGen, jvmCastGen,
Expand Down Expand Up @@ -568,7 +568,7 @@ private void linkModuleFunctions(BIRPackage birPackage, String initClass, boolea
// function.
BIRFunction initFunc = functions.get(0);
String functionName = Utils.encodeFunctionIdentifier(initFunc.name.value);
JavaClass klass = new JavaClass(initFunc.pos.lineRange().filePath());
JavaClass klass = new JavaClass(initFunc.pos.lineRange().fileName());
klass.functions.add(0, initFunc);
PackageID packageID = birPackage.packageID;
jvmClassMap.put(initClass, klass);
Expand Down Expand Up @@ -602,7 +602,7 @@ private void linkModuleFunctions(BIRPackage birPackage, String initClass, boolea
if (birFunc.pos == null) {
balFileName = MODULE_INIT_CLASS_NAME;
} else {
balFileName = birFunc.pos.lineRange().filePath();
balFileName = birFunc.pos.lineRange().fileName();
}

String cleanedBalFileName = balFileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private byte[] createRecordTypeDescClass(BRecordType recordType, String classNam

ClassWriter cw = new BallerinaClassWriter(COMPUTE_FRAMES);
if (typeDef.pos != null) {
cw.visitSource(typeDef.pos.lineRange().filePath(), null);
cw.visitSource(typeDef.pos.lineRange().fileName(), null);
} else {
cw.visitSource(className, null);
}
Expand Down Expand Up @@ -361,7 +361,7 @@ private byte[] createRecordValueClass(BRecordType recordType, String className,

ClassWriter cw = new BallerinaClassWriter(COMPUTE_FRAMES);
if (typeDef.pos != null) {
cw.visitSource(typeDef.pos.lineRange().filePath(), null);
cw.visitSource(typeDef.pos.lineRange().fileName(), null);
} else {
cw.visitSource(className, null);
}
Expand Down Expand Up @@ -598,7 +598,7 @@ private void createRecordPopulateInitialValuesMethod(ClassWriter cw) {
private byte[] createObjectValueClass(BObjectType objectType, String className, BIRNode.BIRTypeDefinition typeDef,
JvmConstantsGen jvmConstantsGen, AsyncDataCollector asyncDataCollector) {
ClassWriter cw = new BallerinaClassWriter(COMPUTE_FRAMES);
cw.visitSource(typeDef.pos.lineRange().filePath(), null);
cw.visitSource(typeDef.pos.lineRange().fileName(), null);

SymbolTable symbolTable = jvmPackageGen.symbolTable;
JvmTypeGen jvmTypeGen = new JvmTypeGen(jvmConstantsGen, module.packageID, typeHashVisitor, symbolTable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private void populateConfigDataMethod(ClassWriter cw, String moduleClass,

private String getOneBasedLocationString(BIRNode.BIRPackage module, Location location) {
LineRange lineRange = location.lineRange();
String oneBasedLineTrace = lineRange.filePath() + ":" + (lineRange.startLine().line() + 1);
String oneBasedLineTrace = lineRange.fileName() + ":" + (lineRange.startLine().line() + 1);
if (module.packageID.equals(JvmConstants.DEFAULT)) {
return oneBasedLineTrace;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ private void generateFrameClassForFunction(PackageID packageID, BIRNode.BIRFunct
String frameClassName = MethodGenUtils.getFrameClassName(JvmCodeGenUtil.getPackageName(packageID),
func.name.value, attachedType);
ClassWriter cw = new BallerinaClassWriter(COMPUTE_FRAMES);
if (func.pos != null && func.pos.lineRange().filePath() != null) {
cw.visitSource(func.pos.lineRange().filePath(), null);
if (func.pos != null && func.pos.lineRange().fileName() != null) {
cw.visitSource(func.pos.lineRange().fileName(), null);
}
cw.visit(V1_8, Opcodes.ACC_PUBLIC + ACC_SUPER, frameClassName, null, OBJECT,
new String[]{FUNCTION_FRAME});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public static void writePosition(Location pos, ByteBuf buf, ConstantPool cp) {
eLine = pos.lineRange().endLine().line();
sCol = pos.lineRange().startLine().offset();
eCol = pos.lineRange().endLine().offset();
if (pos.lineRange().filePath() != null) {
sourceFileName = pos.lineRange().filePath();
if (pos.lineRange().fileName() != null) {
sourceFileName = pos.lineRange().fileName();
}
}
buf.writeInt(addStringCPEntry(sourceFileName, cp));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9031,7 +9031,7 @@ private void addReturnIfNotPresent(BLangInvokableNode invokableNode) {
Location invPos = invokableNode.pos;
Location returnStmtPos;
if (invPos != null && !invokableNode.name.value.contains(GENERATED_INIT_SUFFIX.value)) {
returnStmtPos = new BLangDiagnosticLocation(invPos.lineRange().filePath(),
returnStmtPos = new BLangDiagnosticLocation(invPos.lineRange().fileName(),
invPos.lineRange().endLine().line(),
invPos.lineRange().endLine().line(),
invPos.lineRange().startLine().offset(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public int compare(Diagnostic d1, Diagnostic d2) {

// Compare file name
// TODO: handle if one is null and other is not
String file1 = lineRange1.filePath();
String file2 = lineRange2.filePath();
String file1 = lineRange1.fileName();
String file2 = lineRange2.fileName();
if (file1 != null && file2 != null) {
int fileComparison = file1.compareTo(file2);
if (fileComparison != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ public BLangNode transform(ModulePartNode modulePart) {
compilationUnit.addTopLevelNode((TopLevelNode) member.apply(this));
}

Location newLocation = new BLangDiagnosticLocation(pos.lineRange().filePath(), 0, 0, 0, 0, 0, 0);
Location newLocation = new BLangDiagnosticLocation(pos.lineRange().fileName(), 0, 0, 0, 0, 0, 0);

compilationUnit.pos = newLocation;
compilationUnit.setPackageID(packageID);
Expand Down Expand Up @@ -6937,7 +6937,7 @@ private Location expandLeft(Location location, Location upTo) {
(location.lineRange().startLine().line() == upTo.lineRange().startLine().line() &&
location.lineRange().startLine().offset() >= upTo.lineRange().startLine().offset());

Location expandedLocation = new BLangDiagnosticLocation(location.lineRange().filePath(),
Location expandedLocation = new BLangDiagnosticLocation(location.lineRange().fileName(),
upTo.lineRange().startLine().line(),
location.lineRange().endLine().line(),
upTo.lineRange().startLine().offset(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ public void visit(BLangTransaction transactionNode) {

// marks the injected import as used
Name transactionPkgName = names.fromString(Names.DOT.value + Names.TRANSACTION_PACKAGE.value);
Name compUnitName = names.fromString(transactionNode.pos.lineRange().filePath());
Name compUnitName = names.fromString(transactionNode.pos.lineRange().fileName());
this.symResolver.resolvePrefixSymbol(env, transactionPkgName, compUnitName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ private BSymbol resolveFullyQualifiedSymbol(Location location, SymbolEnv env, St

if (pkgName != Names.EMPTY) {
BSymbol pkgSymbol = symResolver.resolvePrefixSymbol(env, pkgName,
names.fromString(location.lineRange().filePath()));
names.fromString(location.lineRange().fileName()));

if (pkgSymbol == symTable.notFoundSymbol) {
return symTable.notFoundSymbol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3966,7 +3966,7 @@ private Location getStartLocation(Location location) {
LinePosition linePosition = lineRange.startLine();
int startLine = linePosition.line();
int startColumn = linePosition.offset();
return new BLangDiagnosticLocation(lineRange.filePath(), startLine, startLine, startColumn, startColumn);
return new BLangDiagnosticLocation(lineRange.fileName(), startLine, startLine, startColumn, startColumn);
}

private DiagnosticHintCode getHintCode(boolean isolatedService, boolean isolatedMethod) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ public void visit(BLangFunction funcNode, AnalyzerData data) {
private Location getEndCharPos(Location pos) {
LineRange lineRange = pos.lineRange();
LinePosition endLinePos = lineRange.endLine();
return new BLangDiagnosticLocation(lineRange.filePath(), endLinePos.line(), endLinePos.line(),
return new BLangDiagnosticLocation(lineRange.fileName(), endLinePos.line(), endLinePos.line(),
endLinePos.offset() - 1, endLinePos.offset(),
pos.textRange().startOffset() + pos.textRange().length() - 1, 1);
}
Expand Down
Loading

0 comments on commit 12560f8

Please sign in to comment.