Skip to content

Commit

Permalink
Reproduce user's issue
Browse files Browse the repository at this point in the history
  • Loading branch information
algomaster99 committed Nov 1, 2022
1 parent 2c4fc67 commit a566d5e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import spoon.reflect.path.CtRole;
import spoon.reflect.reference.CtArrayTypeReference;
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.visitor.filter.TypeFilter;
import spoon.support.reflect.reference.CtArrayTypeReferenceImpl;
import spoon.test.GitHubIssue;
import spoon.test.SpoonTestHelpers;
Expand Down Expand Up @@ -324,4 +325,19 @@ void testKeepGenericType(Factory factory) {
assertThat(printed, containsRegexMatch("List<.*List<\\? extends T>>"));
assertThat(printed, containsRegexMatch("List<.*List<\\? super T>>"));
}

@GitHubIssue(issueNumber = 4881, fixed = true)
void bracketsShouldBeMinimallyPrintedForTypeCastOnFieldRead() {
// contract: the brackets should be minimally printed for type cast on field read
// arrange
Launcher launcher = createLauncherWithOptimizeParenthesesPrinter();
launcher.addInputResource("src/test/resources/printer-test/TypeCastOnFieldRead.java");

// act
CtModel model = launcher.buildModel();

// assert
CtLocalVariable<Integer> localVariable = model.getElements(new TypeFilter<>(CtLocalVariable.class)).get(0);
assertThat(localVariable.toString(), equalTo("int myInt = (int) myDouble"));
}
}
6 changes: 6 additions & 0 deletions src/test/resources/printer-test/TypeCastOnFieldRead.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class TypeCastOnFieldRead {
double myDouble = 0.0;
public void where() {
int myInt = (int) myDouble;
}
}

0 comments on commit a566d5e

Please sign in to comment.