Skip to content

Commit

Permalink
Revert "Update UseDiamondOperator to ignore NewClass initializers for…
Browse files Browse the repository at this point in the history
… variables having a null or unknown type. (issue #1297)"

This reverts commit 3592bfc.
  • Loading branch information
pway99 authored and PatrickViry committed May 30, 2022
1 parent 86d3c60 commit f5af972
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.tree.*;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaVarKeyword;
import org.openrewrite.java.tree.Space;
import org.openrewrite.java.tree.TypeUtils;
import org.openrewrite.marker.Markers;

import java.time.Duration;
Expand Down Expand Up @@ -57,14 +60,6 @@ protected TreeVisitor<?, ExecutionContext> getVisitor() {

return new JavaIsoVisitor<ExecutionContext>() {

@Override
public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations multiVariable, ExecutionContext executionContext) {
if (multiVariable.getType() == null || multiVariable.getType() instanceof JavaType.Unknown) {
return multiVariable;
}
return super.visitVariableDeclarations(multiVariable, executionContext);
}

@Override
public J.NewClass visitNewClass(J.NewClass newClass, ExecutionContext executionContext) {
J.NewClass n = super.visitNewClass(newClass, executionContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.openrewrite.java.cleanup

import org.junit.jupiter.api.Test
import org.openrewrite.Issue
import org.openrewrite.Recipe
import org.openrewrite.java.JavaParser
import org.openrewrite.java.JavaRecipeTest
Expand Down Expand Up @@ -55,23 +54,6 @@ interface UseDiamondOperatorTest: JavaRecipeTest {
"""
)

@Issue("https://github.com/openrewrite/rewrite/issues/1297")
@Test
fun `do not use diamond operators for variables having null or unknown types`(jp: JavaParser) = assertUnchanged(
jp,
before = """
import lombok.val;
import java.util.ArrayList;
class Test<X, Y> {
void test() {
val ls = new ArrayList<String>();
UnknownThing o = new UnknownThing<String>();
}
}
"""
)

@Test
fun noLeftSide(jp: JavaParser) = assertUnchanged(
parser = jp,
Expand Down

0 comments on commit f5af972

Please sign in to comment.