Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The offsets of added parameters are wrong in some cases (not always) #118

Open
tsantalis opened this issue Mar 8, 2023 · 7 comments
Open

Comments

@tsantalis
Copy link

In commit tsantalis/RefactoringMiner@5e79668
there are 3 added parameters,
but the offsets are shifted below the actual location of the added parameters

Screenshot from 2023-03-08 06-20-49
Screenshot from 2023-03-08 06-25-32

@onewhl
Copy link
Collaborator

onewhl commented Mar 8, 2023

@tsantalis thank you! @anchouls could you take a look at it, please?

@anchouls
Copy link
Collaborator

anchouls commented Mar 8, 2023

@tsantalis @onewhl UMLParameter parameter in AddParameterRefactoring class (from RefactoringMiner tool) returns an incorrect LocationInfo, specifically an incorrect offset
Screenshot 2023-03-08 at 15 10 17
Screenshot 2023-03-08 at 15 12 26
Correct startOffset = 16267
Screenshot 2023-03-08 at 15 25 35
The lines and columns correctly
Screenshot 2023-03-08 at 15 13 14

@tsantalis
Copy link
Author

tsantalis commented Mar 8, 2023

@anchouls @onewhl
We get the offset directly from the ASTNode

ASTNode node;
this.startOffset = node.getStartPosition();
this.length = node.getLength();
this.endOffset = startOffset + length;

How is it possible that the line number and column number are correct and the offset is not?
The line number and column are computed based on the offset.

@tsantalis
Copy link
Author

Notepad++ gives a

start offset 16614, line 347, column 13
end offset 16643, line 347, column 42

The offsets are closer to what the ASTNode is giving

2023-03-08 12_45_24-_new 1 - Notepad++
2023-03-08 12_50_28-_new 1 - Notepad++

@anchouls
Copy link
Collaborator

anchouls commented Mar 8, 2023

@tsantalis @onewhl

The IDEA doesn't count line breaks when counting characters (unlike Notepad++, VS Code, etc.). Usually, the startOffset also does not include line breaks, and highlighting works well. Why line breaks were counted now is currently an open question.

16613 - 16267 = 346 - number of line breaks

@tsantalis
Copy link
Author

@anchouls @onewhl
Is this related to the DOS vs. Unix line endings?

DOS uses carriage return and line feed ("\r\n") as a line ending, while Unix uses just line feed ("\n")

This file is using CRLF ("\r\n") endings (2 characters).

2023-03-08 15_58_57-_new 1 - Notepad++

@tsantalis
Copy link
Author

@anchouls @onewhl

My students told me that IntelliJ ignores the actual line endings of the file, and commits code using the Unix LF ("\n").

There was a file in our repository with CRLF ("\r\n") line endings, and IntelliJ changed everything to LF ("\n") after the commit.

It seems IntelliJ has some preference or configuration for LF ("\n") by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants