Skip to content

Commit

Permalink
Merge pull request #2984 from jlerbsc/assign
Browse files Browse the repository at this point in the history
Improve boxing/unboxing unit tests and remove useless code in isUnbox…
  • Loading branch information
jlerbsc committed Dec 18, 2020
2 parents e2997f7 + aacec37 commit 1f193dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,7 @@ && hasName() // Consider anonymous classes
* For example : Integer to int
*/
public boolean isUnboxable() {
if (!this.isReferenceType()) {
return false;
}
return Arrays.stream(ResolvedPrimitiveType.values()).anyMatch(pt -> this.asReferenceType().getQualifiedName().equals(pt.getBoxTypeQName()));
return Arrays.stream(ResolvedPrimitiveType.values()).anyMatch(pt -> getQualifiedName().equals(pt.getBoxTypeQName()));
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,19 @@ void numericConditionalExpression() {
code = "class A { public void m() { char r = true ? Character.valueOf(Character.MIN_VALUE) : 1;}}";
ResolvedType rt11 = StaticJavaParser.parse(code).findFirst(ConditionalExpr.class).get().calculateResolvedType();
assertEquals("char", rt11.describe());
// reverse position of the reference type parameter
code = "class A { public void m() { char r = true ? 1 : Character.valueOf(Character.MIN_VALUE);}}";
ResolvedType rt12 = StaticJavaParser.parse(code).findFirst(ConditionalExpr.class).get().calculateResolvedType();
assertEquals("char", rt12.describe());
// Otherwise, binary numeric promotion (§5.6.2) is applied to the operand types,
// and the type of the conditional expression is the promoted type of the second
// and third operands.
code = "class A { public void m() { long r = true ? 1L : 1;}}";
ResolvedType rt12 = StaticJavaParser.parse(code).findFirst(ConditionalExpr.class).get().calculateResolvedType();
assertEquals("long", rt12.describe());
code = "class A { public void m() { long r = true ? 1.0 : 1F;}}";
ResolvedType rt13 = StaticJavaParser.parse(code).findFirst(ConditionalExpr.class).get().calculateResolvedType();
assertEquals("double", rt13.describe());
assertEquals("long", rt13.describe());
code = "class A { public void m() { long r = true ? 1.0 : 1F;}}";
ResolvedType rt14 = StaticJavaParser.parse(code).findFirst(ConditionalExpr.class).get().calculateResolvedType();
assertEquals("double", rt14.describe());

}

Expand Down

0 comments on commit 1f193dd

Please sign in to comment.