Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public void visitClass(ClassNode clazz) {
randomId(), compName.getPrefix(), Markers.EMPTY,
compName.withPrefix(EMPTY), emptyList(), null, typeMapping.variableType(compName.getSimpleName(), rc.getType()));
J.VariableDeclarations varDecl = new J.VariableDeclarations(randomId(), compPrefix, Markers.EMPTY,
emptyList(), emptyList(), typeExpr, null, emptyList(), singletonList(JRightPadded.build(namedVar)));
emptyList(), emptyList(), typeExpr, null, singletonList(JRightPadded.build(namedVar)));
componentDecls.add(JRightPadded.build((Statement) varDecl)
.withAfter(i == components.size() - 1 ? sourceBefore(")") : sourceBefore(",")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
import org.openrewrite.groovy.GroovyVisitor;
import org.openrewrite.groovy.tree.*;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.ToBeRemoved;
import org.openrewrite.java.style.IntelliJ;
import org.openrewrite.java.style.WrappingAndBracesStyle;
import org.openrewrite.java.tree.*;
import org.openrewrite.marker.Markers;
import org.openrewrite.style.NamedStyles;
import org.openrewrite.style.Style;
import org.openrewrite.style.StyleHelper;

import java.util.List;
Expand All @@ -39,7 +37,7 @@ public class MergeSpacesVisitor extends GroovyVisitor<Object> {
private final WrappingAndBracesStyle wrappingAndBracesStyle;

public MergeSpacesVisitor(List<NamedStyles> styles) {
this.wrappingAndBracesStyle = getStyle(WrappingAndBracesStyle.class, styles, IntelliJ::wrappingAndBraces);
this.wrappingAndBracesStyle = StyleHelper.getStyle(WrappingAndBracesStyle.class, styles, (Supplier<WrappingAndBracesStyle>) IntelliJ::wrappingAndBraces);
}

@Override
Expand Down Expand Up @@ -1772,15 +1770,6 @@ public J visitErroneous(J.Erroneous erroneous, @Nullable Object ctx) {
return u.withMarkers(visitMarkers(u.getMarkers(), newErroneous.getMarkers()));
}

@ToBeRemoved(after = "2026-03-01", reason = "Replace me with org.openrewrite.style.StyleHelper.getStyle now available in parent runtime")
private static <S extends Style> S getStyle(Class<S> styleClass, List<NamedStyles> styles, Supplier<S> defaultStyle) {
S style = NamedStyles.merge(styleClass, styles);
if (style != null) {
return StyleHelper.merge(defaultStyle.get(), style);
}
return defaultStyle.get();
}

private boolean evaluate(Supplier<Boolean> supplier, boolean defaultValue) {
try {
return supplier.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,20 @@
import org.jspecify.annotations.Nullable;
import org.openrewrite.Tree;
import org.openrewrite.groovy.marker.AsStyleTypeCast;
import org.openrewrite.internal.ToBeRemoved;
import org.openrewrite.java.style.*;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JLeftPadded;
import org.openrewrite.java.tree.JRightPadded;
import org.openrewrite.java.tree.Space;
import org.openrewrite.style.NamedStyles;
import org.openrewrite.style.Style;
import org.openrewrite.style.StyleHelper;

import java.util.List;
import java.util.function.Supplier;

public class SpacesVisitor<P> extends org.openrewrite.java.format.SpacesVisitor<P> {
public SpacesVisitor(List<NamedStyles> styles, @Nullable Tree stopAfter) {
this(getStyle(SpacesStyle.class, styles, IntelliJ::spaces), getStyle(EmptyForInitializerPadStyle.class, styles), getStyle(EmptyForIteratorPadStyle.class, styles), getStyle(WrappingAndBracesStyle.class, styles, IntelliJ::wrappingAndBraces), stopAfter);
this(StyleHelper.getStyle(SpacesStyle.class, styles, (Supplier<SpacesStyle>) IntelliJ::spaces), StyleHelper.getStyle(EmptyForInitializerPadStyle.class, styles), StyleHelper.getStyle(EmptyForIteratorPadStyle.class, styles), StyleHelper.getStyle(WrappingAndBracesStyle.class, styles, (Supplier<WrappingAndBracesStyle>) IntelliJ::wrappingAndBraces), stopAfter);
}

public SpacesVisitor(SpacesStyle spacesStyle, @Nullable EmptyForInitializerPadStyle emptyForInitializerPadStyle, @Nullable EmptyForIteratorPadStyle emptyForIteratorPadStyle, WrappingAndBracesStyle wrappingAndBracesStyle, @Nullable Tree stopAfter) {
Expand Down Expand Up @@ -85,22 +83,4 @@ public Space visitSpace(@Nullable Space space, Space.Location loc, P ctx) {
}
return super.visitSpace(space, loc, ctx);
}

@ToBeRemoved(after = "2026-03-01", reason = "Replace me with org.openrewrite.style.StyleHelper.getStyle now available in parent runtime")
private static <S extends Style> @Nullable S getStyle(Class<S> styleClass, List<NamedStyles> styles) {
S style = NamedStyles.merge(styleClass, styles);
if (style != null) {
return (S) style.applyDefaults();
}
return null;
}

@ToBeRemoved(after = "2026-03-01", reason = "Replace me with org.openrewrite.style.StyleHelper.getStyle now available in parent runtime")
private static <S extends Style> S getStyle(Class<S> styleClass, List<NamedStyles> styles, Supplier<S> defaultStyle) {
S style = NamedStyles.merge(styleClass, styles);
if (style != null) {
return StyleHelper.merge(defaultStyle.get(), style);
}
return defaultStyle.get();
}
}
18 changes: 0 additions & 18 deletions rewrite-hcl/src/main/java/org/openrewrite/hcl/tree/Hcl.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.openrewrite.hcl.HclVisitor;
import org.openrewrite.hcl.internal.HclPrinter;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.ToBeRemoved;
import org.openrewrite.marker.Markers;

import java.lang.ref.WeakReference;
Expand Down Expand Up @@ -1556,23 +1555,6 @@ class TemplateInterpolation implements Hcl, Expression {

HclRightPadded<Expression> paddedExpression;

@JsonCreator
@ToBeRemoved(after = "2026-04-01", reason = "Temporary constructor to aid deserialization of older models")
TemplateInterpolation(UUID id,
Space prefix,
Markers markers,
@Nullable Expression expression,
@Nullable HclRightPadded<Expression> paddedExpression) {
this.id = id;
this.prefix = prefix;
this.markers = markers;
if (expression != null) {
this.paddedExpression = HclRightPadded.withElement(null, expression);
} else {
this.paddedExpression = requireNonNull(paddedExpression);
}
}

public Expression getExpression() {
return paddedExpression.getElement();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1596,8 +1596,6 @@ private J.VariableDeclarations visitVariables(List<VariableTree> nodes, Space fm
typeExpr = new J.AnnotatedType(randomId(), prefix, Markers.EMPTY, ListUtils.mapFirst(typeExprAnnotations, a -> a.withPrefix(EMPTY)), typeExpr);
}

List<JLeftPadded<Space>> beforeDimensions = emptyList();

Space varargs = null;
if (typeExpr != null && typeExpr.getMarkers().findFirst(JavaVarKeyword.class).isEmpty()) {
int varargStart = indexOfNextNonWhitespace(cursor, source);
Expand Down Expand Up @@ -1632,7 +1630,7 @@ private J.VariableDeclarations visitVariables(List<VariableTree> nodes, Space fm
);
}

return new J.VariableDeclarations(randomId(), fmt, Markers.EMPTY, modifierResults.getLeadingAnnotations(), modifierResults.getModifiers(), typeExpr, varargs, beforeDimensions, vars);
return new J.VariableDeclarations(randomId(), fmt, Markers.EMPTY, modifierResults.getLeadingAnnotations(), modifierResults.getModifiers(), typeExpr, varargs, vars);
}

private List<JLeftPadded<Space>> arrayDimensions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1568,8 +1568,6 @@ private J.VariableDeclarations visitVariables(List<VariableTree> nodes, Space fm
typeExpr = new J.AnnotatedType(randomId(), prefix, Markers.EMPTY, ListUtils.mapFirst(typeExprAnnotations, a -> a.withPrefix(EMPTY)), typeExpr);
}

List<JLeftPadded<Space>> beforeDimensions = emptyList();

Space varargs = null;
if (typeExpr != null) {
int varargStart = indexOfNextNonWhitespace(cursor, source);
Expand Down Expand Up @@ -1604,7 +1602,7 @@ private J.VariableDeclarations visitVariables(List<VariableTree> nodes, Space fm
);
}

return new J.VariableDeclarations(randomId(), fmt, Markers.EMPTY, modifierResults.getLeadingAnnotations(), modifierResults.getModifiers(), typeExpr, varargs, beforeDimensions, vars);
return new J.VariableDeclarations(randomId(), fmt, Markers.EMPTY, modifierResults.getLeadingAnnotations(), modifierResults.getModifiers(), typeExpr, varargs, vars);
}

private List<JLeftPadded<Space>> arrayDimensions() {
Expand Down
1 change: 0 additions & 1 deletion rewrite-java-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dependencies {
implementation(project(":rewrite-java"))
implementation(project(":rewrite-test"))

testImplementation("io.github.classgraph:classgraph:latest.release")
testImplementation("org.junit-pioneer:junit-pioneer:latest.release")
testRuntimeOnly(project(":rewrite-java-21"))
testRuntimeOnly("org.apache.hbase:hbase-shaded-client:2.4.11")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.openrewrite.java;

import io.github.classgraph.ClassGraph;
import io.github.classgraph.ScanResult;
import org.intellij.lang.annotations.Language;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -25,12 +23,9 @@
import org.openrewrite.DocumentExample;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.Issue;
import org.openrewrite.SourceFile;
import org.openrewrite.java.search.FindCompileErrors;
import org.openrewrite.java.tree.J;
import org.openrewrite.test.RewriteTest;

import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
Expand Down Expand Up @@ -207,45 +202,6 @@ void runtimeClasspathIncludesIsolatedClassLoaderEntries(@TempDir Path temp) thro
}
}

@Issue("https://github.com/openrewrite/rewrite/issues/3222")
@Test
void parseFromByteArray() {
try (ScanResult scan = new ClassGraph().scan()) {
byte[][] classes = scan.getResourcesMatchingWildcard("javaparser-byte-array-tests/**.class").stream()
.map(it -> {
try {
return it.read().array();
} catch (IOException e) {
throw new RuntimeException(e);
}
})
.toArray(byte[][]::new);

JavaParser parser = JavaParser.fromJavaVersion()
.classpath(classes)
.build();

@Language("java")
String source = """
import example.InterfaceA;
public class User implements InterfaceA, InterfaceB {
@Override
public void methodA() {}

@Override
public void methodB() {}
}
""";
Stream<SourceFile> compilationUnits = parser.parse(new InMemoryExecutionContext(Throwable::printStackTrace), source);
assertThat(compilationUnits.map(J.CompilationUnit.class::cast)).singleElement()
.satisfies(cu -> assertThat(cu.getClasses()).singleElement()
.satisfies(cd -> assertThat(cd.getImplements()).satisfiesExactly(
i -> assertThat(i.getType()).hasToString("example.InterfaceA"),
i -> assertThat(i.getType()).hasToString("InterfaceB")
)));
}
}

@ParameterizedTest
// language=java
@ValueSource(strings = {
Expand Down
Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

11 changes: 0 additions & 11 deletions rewrite-java/src/main/java/org/openrewrite/java/JavaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.intellij.lang.annotations.Language;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.internal.ToBeRemoved;
import org.openrewrite.java.internal.JavaTypeCache;
import org.openrewrite.java.internal.JavaTypeFactory;
import org.openrewrite.java.internal.parser.RewriteClasspathJarClasspathLoader;
Expand Down Expand Up @@ -341,16 +340,6 @@ public B classpathFromResources(ExecutionContext ctx, String... classpath) {
return (B) this;
}

/**
* @deprecated prefer {@link #classpath} and {@link #classpathFromResources(ExecutionContext, String...)}.
*/
@Deprecated
@ToBeRemoved(after = "2025-12-31", reason = "Use classpath or classpathFromResources instead.")
public B classpath(byte[]... classpath) {
this.classBytesClasspath = Arrays.asList(classpath);
return (B) this;
}

public B styles(Iterable<? extends NamedStyles> styles) {
for (NamedStyles style : styles) {
this.styles.add(style);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
import org.openrewrite.Cursor;
import org.openrewrite.SourceFile;
import org.openrewrite.Tree;
import org.openrewrite.internal.ToBeRemoved;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaSourceFile;
import org.openrewrite.marker.Markers;
import org.openrewrite.style.NamedStyles;
import org.openrewrite.style.StyleHelper;

import java.util.*;

Expand Down Expand Up @@ -77,7 +76,7 @@ public J visit(@Nullable Tree tree, P p, Cursor cursor) {
tree = new RemoveTrailingWhitespaceVisitor<>(stopAfter).visitNonNull(tree, p, cursor.fork());

if (tree instanceof JavaSourceFile) {
return addStyleMarker((JavaSourceFile) tree, styles);
return StyleHelper.addStyleMarker((JavaSourceFile) tree, styles);
}

return (J) tree;
Expand Down Expand Up @@ -113,31 +112,10 @@ public J visit(@Nullable Tree tree, P p) {
tree = new RemoveTrailingWhitespaceVisitor<>(stopAfter).visitNonNull(tree, p);

if (tree instanceof J.CompilationUnit) {
return addStyleMarker((JavaSourceFile) tree, styles);
return StyleHelper.addStyleMarker((JavaSourceFile) tree, styles);
}
}
//noinspection DataFlowIssue
return (J) tree;
}

@ToBeRemoved(after = "2026-03-01", reason = "Replace me with org.openrewrite.style.StyleHelper.addStyleMarker now available in parent runtime")
private static <T extends SourceFile> T addStyleMarker(T t, List<NamedStyles> styles) {
if (!styles.isEmpty()) {
Set<NamedStyles> newNamedStyles = new HashSet<>(styles);
boolean styleAlreadyPresent = false;
for (NamedStyles namedStyle : t.getMarkers().findAll(NamedStyles.class)) {
styleAlreadyPresent = !newNamedStyles.add(namedStyle) || styleAlreadyPresent;
}
// As the order or NamedStyles matters, we cannot simply use addIfAbsent.
if (!styleAlreadyPresent) {
Markers markers = t.getMarkers().removeByType(NamedStyles.class);
for (NamedStyles namedStyle : newNamedStyles) {
markers = markers.add(namedStyle);
}

return t.withMarkers(markers);
}
}
return t;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
import org.openrewrite.Tree;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.StringUtils;
import org.openrewrite.internal.ToBeRemoved;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.style.BlankLinesStyle;
import org.openrewrite.java.style.IntelliJ;
import org.openrewrite.java.tree.*;
import org.openrewrite.style.NamedStyles;
import org.openrewrite.style.Style;
import org.openrewrite.style.StyleHelper;

import java.util.HashSet;
Expand All @@ -48,7 +46,7 @@ public BlankLinesVisitor(SourceFile sourceFile, @Nullable Tree stopAfter) {
}

public BlankLinesVisitor(List<NamedStyles> styles, @Nullable Tree stopAfter) {
this.style = getStyle(BlankLinesStyle.class, styles, IntelliJ::blankLines);
this.style = StyleHelper.getStyle(BlankLinesStyle.class, styles, (Supplier<BlankLinesStyle>) IntelliJ::blankLines);
this.stopAfter = stopAfter;
}

Expand Down Expand Up @@ -360,13 +358,4 @@ private static int getNewLineCount(String whitespace) {
}
return super.postVisit(tree, p);
}

@ToBeRemoved(after = "2026-03-01", reason = "Replace me with org.openrewrite.style.StyleHelper.getStyle now available in parent runtime")
private static <S extends Style> S getStyle(Class<S> styleClass, List<NamedStyles> styles, Supplier<S> defaultStyle) {
S style = NamedStyles.merge(styleClass, styles);
if (style != null) {
return StyleHelper.merge(defaultStyle.get(), style);
}
return defaultStyle.get();
}
}
Loading
Loading