-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] Handle content for the most common code elements #1
- Loading branch information
Showing
26 changed files
with
746 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/test/resources/clean/left_modified/change_declared_type/Base.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public class Adder { | ||
public int add(int a, int b) { | ||
int result = a + b; | ||
return result; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/test/resources/clean/left_modified/change_declared_type/Expected.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public class Adder { | ||
public long add(long a, long b) { | ||
long result = a + b; | ||
return result; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/test/resources/clean/left_modified/change_declared_type/Left.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public class Adder { | ||
public long add(long a, long b) { | ||
long result = a + b; | ||
return result; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/test/resources/clean/left_modified/change_declared_type/Right.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public class Adder { | ||
public int add(int a, int b) { | ||
int result = a + b; | ||
return result; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/test/resources/clean/left_modified/rename_class/Base.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public class BadClass { | ||
public static void main(String[] args) { | ||
BadClass bc = new BadClass(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/test/resources/clean/left_modified/rename_class/Expected.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public class GoodClass { | ||
public static void main(String[] args) { | ||
GoodClass bc = new GoodClass(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/test/resources/clean/left_modified/rename_class/Left.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public class GoodClass { | ||
public static void main(String[] args) { | ||
GoodClass bc = new GoodClass(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/test/resources/clean/left_modified/rename_class/Right.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public class BadClass { | ||
public static void main(String[] args) { | ||
BadClass bc = new BadClass(); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/test/resources/clean/left_modified/rename_method/Base.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import java.util.EmptyStackException; | ||
|
||
/** | ||
* An array-based implementation of the Stack interface. | ||
* | ||
* @author Simon Larsén | ||
*/ | ||
public class ArrayStack<T> implements Stack<T> { | ||
private static final int INITIAL_CAPACITY = 10; | ||
private Object[] elements; | ||
private int size; | ||
|
||
/** | ||
* Creat an empty ArrayStack. | ||
*/ | ||
public ArrayStack() { | ||
elements = new Object[INITIAL_CAPACITY]; | ||
} | ||
|
||
@Override | ||
public void push(T element) { | ||
ensureCapacity(size + 1); | ||
elements[size++] = element; | ||
} | ||
|
||
@Override | ||
public T pop() { | ||
T elem = checkedTop(); | ||
// null element to avoid blocking GC | ||
elements[size--] = null; | ||
return elem; | ||
} | ||
|
||
@Override | ||
public T top() { | ||
return checkedTop(); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return size; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return size == 0; | ||
} | ||
|
||
/** | ||
* Checked fetching of the top element, throws an EmptyStackException if | ||
* the stack is empty. | ||
*/ | ||
private T checkedTop() { | ||
if (size == 0) { | ||
throw new EmptyStackException(); | ||
} | ||
|
||
return (T) elements[size - 1]; | ||
} | ||
|
||
/** | ||
* Ensure that the capacity is at least minCapacity. | ||
*/ | ||
private void ensureCapacity(int minCapacity) { | ||
if (minCapacity > elements.length) { | ||
grow(); | ||
} | ||
} | ||
|
||
/** | ||
* Replace the current backing array with a larger one and copy over the | ||
* elements to the now array. | ||
*/ | ||
private void grow() { | ||
Object[] newElements = new Object[elements.length << 1]; | ||
System.arraycopy(elements, 0, newElements, 0, elements.length); | ||
elements = newElements; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/test/resources/clean/left_modified/rename_method/Expected.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import java.util.EmptyStackException; | ||
|
||
/** | ||
* An array-based implementation of the Stack interface. | ||
* | ||
* @author Simon Larsén | ||
*/ | ||
public class ArrayStack<T> implements Stack<T> { | ||
private static final int INITIAL_CAPACITY = 10; | ||
private Object[] elements; | ||
private int size; | ||
|
||
/** | ||
* Creat an empty ArrayStack. | ||
*/ | ||
public ArrayStack() { | ||
elements = new Object[INITIAL_CAPACITY]; | ||
} | ||
|
||
@Override | ||
public void push(T element) { | ||
ensureCapacity(size + 1); | ||
elements[size++] = element; | ||
} | ||
|
||
@Override | ||
public T pop() { | ||
T elem = checkedGetTop(); | ||
// null element to avoid blocking GC | ||
elements[size--] = null; | ||
return elem; | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return size; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return size == 0; | ||
} | ||
|
||
/** | ||
* Checked fetching of the top element, throws an EmptyStackException if | ||
* the stack is empty. | ||
*/ | ||
private T checkedGetTop() { | ||
if (size == 0) { | ||
throw new EmptyStackException(); | ||
} | ||
|
||
return (T) elements[size - 1]; | ||
} | ||
|
||
/** | ||
* Ensure that the capacity is at least minCapacity. | ||
*/ | ||
private void ensureCapacity(int minCapacity) { | ||
if (minCapacity > elements.length) { | ||
grow(); | ||
} | ||
} | ||
|
||
/** | ||
* Replace the current backing array with a larger one and copy over the | ||
* elements to the now array. | ||
*/ | ||
private void grow() { | ||
Object[] newElements = new Object[elements.length << 1]; | ||
System.arraycopy(elements, 0, newElements, 0, elements.length); | ||
elements = newElements; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/test/resources/clean/left_modified/rename_method/Left.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import java.util.EmptyStackException; | ||
|
||
/** | ||
* An array-based implementation of the Stack interface. | ||
* | ||
* @author Simon Larsén | ||
*/ | ||
public class ArrayStack<T> implements Stack<T> { | ||
private static final int INITIAL_CAPACITY = 10; | ||
private Object[] elements; | ||
private int size; | ||
|
||
/** | ||
* Creat an empty ArrayStack. | ||
*/ | ||
public ArrayStack() { | ||
elements = new Object[INITIAL_CAPACITY]; | ||
} | ||
|
||
@Override | ||
public void push(T element) { | ||
ensureCapacity(size + 1); | ||
elements[size++] = element; | ||
} | ||
|
||
@Override | ||
public T pop() { | ||
T elem = checkedGetTop(); | ||
// null element to avoid blocking GC | ||
elements[size--] = null; | ||
return elem; | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return size; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return size == 0; | ||
} | ||
|
||
/** | ||
* Checked fetching of the top element, throws an EmptyStackException if | ||
* the stack is empty. | ||
*/ | ||
private T checkedGetTop() { | ||
if (size == 0) { | ||
throw new EmptyStackException(); | ||
} | ||
|
||
return (T) elements[size - 1]; | ||
} | ||
|
||
/** | ||
* Ensure that the capacity is at least minCapacity. | ||
*/ | ||
private void ensureCapacity(int minCapacity) { | ||
if (minCapacity > elements.length) { | ||
grow(); | ||
} | ||
} | ||
|
||
/** | ||
* Replace the current backing array with a larger one and copy over the | ||
* elements to the now array. | ||
*/ | ||
private void grow() { | ||
Object[] newElements = new Object[elements.length << 1]; | ||
System.arraycopy(elements, 0, newElements, 0, elements.length); | ||
elements = newElements; | ||
} | ||
} |
Oops, something went wrong.