-
Notifications
You must be signed in to change notification settings - Fork 3
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
SEMI algorithm chooses 1 line to extract #90
Comments
For the given file 1. class Example {
2. DocumentElement getDocumentElement(int startOffset, int endOffset) throws BadLocationException {
3. readLock();
4. checkDocumentDirty();
5. try {
6. for(int i = 0; i < elements.size(); i++) {
7. DocumentElement de = elements.get(i);
8. if(de.getStartOffset() == startOffset &&
9. de.getEndOffset() == endOffset)
10. return de;
11. if(de.getStartOffset() > startOffset) break;
12. }
13. return null;
14. }finally{
15. readUnlock();
16. }
17. }
18. List<DocumentElement> getDocumentElements(int startOffset) throws BadLocationException {
19. readLock();
20. if(documentDirty) {
21. writeLock(); // This line is suggested to extract
22. try {
23. doc.readLock();
24. try {
25. elements.resort();
26. } finally {
27. doc.readUnlock();
28. }
29. }finally {
30. writeUnlock();
31. }
32. documentDirty = false;
33. }
34. try {
35. int elementIndex = elements.binarySearchForOffset(startOffset);
36. if(elementIndex < 0) {
37. return Collections.emptyList();
38. } else {
39. ArrayList<DocumentElement> found = new ArrayList<DocumentElement>();
40. found.add(elements.get(elementIndex));
41. int eli = elementIndex;
42. while(--eli >= 0) {
43. DocumentElement previous = elements.get(eli);
44. if(previous.getStartOffset() == startOffset) {
45. found.add(0, previous);
46. } else {
47. break;
48. }
49. }
50. while(++elementIndex < elements.size()) {
51. DocumentElement next = elements.get(elementIndex);
52. if(next.getStartOffset() == startOffset) {
53. found.add(next);
54. } else {
55. break;
56. }
57. }
58. return found;
59. }
60. }finally{
61. readUnlock();
62. }
63. }
64. } The result of creating extraction opportunities step is following:
After filtering the kept opportunities are:
All kept extraction opportunities are single statements ones. Ranking kept extraction opportunities we get:
Each group consist of a single opportunity. The one with highest score in |
Issues based on findings:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SEMI algorithm chooses 1 line to extract.
Seems we consider extracting more than 3 lines, don't we?
writeLock(); // This line is suggested to extract
Is it ok?
DocumentModel_618deb49bbf23fe675cea45f2e2cf3f69e8231df8d81a2f47123c696ac11dbf1_getDocumentElements_199.zip
The text was updated successfully, but these errors were encountered: