Skip to content

Commit

Permalink
Recommend the JavaTimeConversion static conversion methods instead of…
Browse files Browse the repository at this point in the history
… decomposition-based conversions.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=313601612
  • Loading branch information
kluever authored and cushon committed May 29, 2020
1 parent ab06403 commit 708a544
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
return describeMatch(tree, fix.build());
}

// We could suggest using JavaTimeConversions.toJavaDuration(jodaDuration), but that
// requires an additional dependency and isn't open-sourced.
fix.replace(
arg0,
String.format(
Expand Down Expand Up @@ -293,8 +291,6 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
return describeMatch(tree, fix.build());
}

// We could suggest using JavaTimeConversions.toJavaInstant(jodaInstant), but that
// requires an additional dependency and isn't open-sourced.
fix.replace(
arg0,
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,25 @@ public void callingJodaDurationMethodWithDurationOverload_privateMethod() {
.doTest();
}

@Test
public void callingJodaInstantMethodWithInstantOverload_privateMethod() {
helper
.addSourceLines(
"TestClass.java",
"import java.time.Instant;",
"public class TestClass {",
" private void bar(org.joda.time.Instant i) {",
" }",
" private void bar(Instant i) {",
" }",
" public void foo(org.joda.time.Instant jodaInstant) {",
" // BUG: Diagnostic contains: bar(Instant.ofEpochMilli(jodaInstant.getMillis()));",
" bar(jodaInstant);",
" }",
"}")
.doTest();
}

@Test
public void callingJodaDurationMethodWithDurationOverload_privateMethod_jodaDurationMillis() {
helper
Expand Down Expand Up @@ -296,19 +315,19 @@ public void callingJodaDurationMethodWithSupertypeJavaDurationOverload() {
}

@Test
public void callingJodaReadableDurationMethodWithDurationOverload_privateMethod() {
public void callingJodaReadableInstantMethodWithInstantOverload_privateMethod() {
helper
.addSourceLines(
"TestClass.java",
"import java.time.Duration;",
"import java.time.Instant;",
"public class TestClass {",
" private void bar(org.joda.time.ReadableDuration d) {",
" private void bar(org.joda.time.ReadableInstant i) {",
" }",
" private void bar(Duration d) {",
" private void bar(Instant i) {",
" }",
" public void foo(org.joda.time.Duration jodaDuration) {",
" // BUG: Diagnostic contains: bar(Duration.ofMillis(jodaDuration.getMillis()));",
" bar(jodaDuration);",
" public void foo(org.joda.time.Instant jodaInstant) {",
" // BUG: Diagnostic contains: bar(Instant.ofEpochMilli(jodaInstant.getMillis()));",
" bar(jodaInstant);",
" }",
"}")
.doTest();
Expand Down

0 comments on commit 708a544

Please sign in to comment.