Skip to content

Commit 9aeba4d

Browse files
committed
Merge branch 'main' into jkschneider/csharp-support
2 parents 6c19c52 + 7820741 commit 9aeba4d

68 files changed

Lines changed: 1639 additions & 300 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle.kts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import java.util.Calendar
2+
13
plugins {
24
id("org.openrewrite.build.root") version "latest.release"
35
id("org.openrewrite.build.java-base") version "latest.release"
@@ -23,6 +25,29 @@ allprojects {
2325
description = "Eliminate tech-debt. Automatically."
2426
}
2527

28+
subprojects {
29+
tasks.withType<JavaExec>().configureEach {
30+
if (name == "generateAntlrSources") {
31+
doLast {
32+
val idx = args?.indexOf("-o") ?: return@doLast
33+
if (idx < 0 || idx + 1 >= args!!.size) return@doLast
34+
val rootPrefix = rootProject.projectDir.absolutePath + "/"
35+
val year = Calendar.getInstance().get(Calendar.YEAR)
36+
val licenseHeader = "/*\n" + rootProject.file("gradle/licenseHeader.txt")
37+
.readText().trim()
38+
.replace("\${year}", year.toString())
39+
.lines()
40+
.joinToString("\n") { " * $it".trimEnd() } + "\n */\n"
41+
project.file(args!![idx + 1]).walk().filter { it.extension == "java" }.forEach { file ->
42+
file.writeText(licenseHeader + file.readLines().joinToString("\n") { line ->
43+
line.trimEnd().replace("// Generated from $rootPrefix", "// Generated from ")
44+
} + "\n")
45+
}
46+
}
47+
}
48+
}
49+
}
50+
2651
// Use this task locally between different dependency check runs to have updated analysis:
2752
// OSSINDEX_PASSWORD=... OSSINDEX_USERNAME=... gradle cleanReports dCAg --no-parallel
2853
tasks.register<Delete>("cleanReports") {

rewrite-core/src/main/java/org/openrewrite/Singleton.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,8 @@ public class Singleton extends Recipe {
8181
"The easiest way is to use Lombok's `@Value` annotation on your recipe class, which automatically " +
8282
"generates correct `equals()` and `hashCode()` implementations based on all fields.";
8383

84-
@Nullable Integer recipeIndex;
85-
8684
public boolean isSingleton(ExecutionContext ctx) {
87-
if (recipeIndex == null) {
88-
recipeIndex = ctx.getCycleDetails().getRecipePosition();
89-
}
85+
Integer recipeIndex = ctx.computeMessageIfAbsent(getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(this)), key -> ctx.getCycleDetails().getRecipePosition());
9086
return recipeIndex == ctx.getCycleDetails().getRecipePosition();
9187
}
9288

rewrite-core/src/main/java/org/openrewrite/config/DeclarativeRecipe.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,16 @@ private void initializeDeclarativeRecipe(DeclarativeRecipe declarativeRecipe, St
161161
}
162162
}
163163

164-
@SuppressWarnings("NotNullFieldNotInitialized")
165164
@JsonIgnore
166-
private transient Accumulator accumulator;
165+
private transient ThreadLocal<Accumulator> accumulator = new ThreadLocal<>();
167166

168167
@Override
169168
public Accumulator getInitialValue(ExecutionContext ctx) {
170169
Accumulator acc = new Accumulator();
171170
for (Recipe precondition : preconditions) {
172171
registerNestedScanningRecipes(precondition, acc, ctx);
173172
}
174-
accumulator = acc;
173+
accumulator.set(acc);
175174
return acc;
176175
}
177176

@@ -509,7 +508,8 @@ private TreeVisitor<?, ExecutionContext> orVisitors(Recipe recipe) {
509508
//noinspection rawtypes
510509
ScanningRecipe scanning = (ScanningRecipe) recipe;
511510
//noinspection unchecked
512-
conditions.add(scanning.getVisitor(accumulator.recipeToAccumulator.get(scanning)));
511+
Accumulator acc = accumulator.get();
512+
conditions.add(scanning.getVisitor(acc != null ? acc.recipeToAccumulator.get(scanning) : null));
513513
} else {
514514
conditions.add(recipe.getVisitor());
515515
}
@@ -602,6 +602,18 @@ private static class LazyLoadedRecipe extends Recipe {
602602
String description = "Recipe that is loaded lazily.";
603603
}
604604

605+
@Override
606+
public void onComplete(ExecutionContext ctx) {
607+
accumulator.remove();
608+
}
609+
610+
@Override
611+
public DeclarativeRecipe clone() {
612+
DeclarativeRecipe cloned = (DeclarativeRecipe) super.clone();
613+
cloned.accumulator = new ThreadLocal<>();
614+
return cloned;
615+
}
616+
605617
@Override
606618
protected RecipeDescriptor createRecipeDescriptor() {
607619
List<RecipeDescriptor> preconditionDescriptors = new ArrayList<>();

rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/UpgradePluginVersion.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.openrewrite.java.MethodMatcher;
3232
import org.openrewrite.java.tree.Expression;
3333
import org.openrewrite.java.tree.J;
34+
import org.openrewrite.java.tree.JavaType;
3435
import org.openrewrite.maven.MavenDownloadingException;
3536
import org.openrewrite.maven.internal.MavenPomDownloader;
3637
import org.openrewrite.maven.table.MavenMetadataFailures;
@@ -392,16 +393,15 @@ public J visitVariable(J.VariableDeclarations.NamedVariable variable, ExecutionC
392393
return Preconditions.or(propertiesVisitor, Preconditions.check(Preconditions.or(new IsBuildGradle<>(), new IsSettingsGradle<>()), javaVisitor));
393394
}
394395

395-
@SuppressWarnings("DataFlowIssue")
396396
private @Nullable String literalValue(Expression expr) {
397-
AtomicReference<String> value = new AtomicReference<>(null);
398-
new JavaVisitor<Integer>() {
397+
return new JavaVisitor<AtomicReference<@Nullable String>>() {
399398
@Override
400-
public J visitLiteral(J.Literal literal, Integer integer) {
401-
value.set((String) literal.getValue());
399+
public J visitLiteral(J.Literal literal, AtomicReference<@Nullable String> value) {
400+
if (literal.getType() == JavaType.Primitive.String) {
401+
value.compareAndSet(null, (String) literal.getValue());
402+
}
402403
return literal;
403404
}
404-
}.visit(expr, 0);
405-
return value.get();
405+
}.reduce(expr, new AtomicReference<>(null)).get();
406406
}
407407
}

rewrite-hcl/src/main/java/org/openrewrite/hcl/internal/grammar/HCLLexer.java

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2025 the original author or authors.
2+
* Copyright 2026 the original author or authors.
33
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,11 +13,13 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
// Generated from ~/git/rewrite/rewrite-hcl/src/main/antlr/HCLLexer.g4 by ANTLR 4.13.2
16+
// Generated from rewrite-hcl/src/main/antlr/HCLLexer.g4 by ANTLR 4.13.2
1717
package org.openrewrite.hcl.internal.grammar;
1818
import java.util.Stack;
1919
import org.antlr.v4.runtime.Lexer;
2020
import org.antlr.v4.runtime.CharStream;
21+
import org.antlr.v4.runtime.Token;
22+
import org.antlr.v4.runtime.TokenStream;
2123
import org.antlr.v4.runtime.*;
2224
import org.antlr.v4.runtime.atn.*;
2325
import org.antlr.v4.runtime.dfa.DFA;
@@ -31,14 +33,14 @@ public class HCLLexer extends Lexer {
3133
protected static final PredictionContextCache _sharedContextCache =
3234
new PredictionContextCache();
3335
public static final int
34-
FOR_BRACE=1, FOR_BRACK=2, IF=3, IN=4, BooleanLiteral=5, NULL=6, LBRACE=7,
35-
RBRACE=8, ASSIGN=9, Identifier=10, WS=11, COMMENT=12, LINE_COMMENT=13,
36-
NEWLINE=14, NumericLiteral=15, QUOTE=16, HEREDOC_START=17, PLUS=18, AND=19,
37-
EQ=20, LT=21, DOUBLE_COLON=22, COLON=23, LBRACK=24, LPAREN=25, MINUS=26,
38-
OR=27, NEQ=28, GT=29, QUESTION=30, RBRACK=31, RPAREN=32, MUL=33, NOT=34,
39-
LEQ=35, DOT=36, DIV=37, GEQ=38, ARROW=39, COMMA=40, MOD=41, ELLIPSIS=42,
40-
TILDE=43, TEMPLATE_INTERPOLATION_START=44, TemplateStringLiteral=45, TemplateStringLiteralChar=46,
41-
HP_WS=47, HP_COMMENT=48, HP_LINE_COMMENT=49, HTemplateLiteral=50, HTemplateLiteralChar=51,
36+
FOR_BRACE=1, FOR_BRACK=2, IF=3, IN=4, BooleanLiteral=5, NULL=6, LBRACE=7,
37+
RBRACE=8, ASSIGN=9, Identifier=10, WS=11, COMMENT=12, LINE_COMMENT=13,
38+
NEWLINE=14, NumericLiteral=15, QUOTE=16, HEREDOC_START=17, PLUS=18, AND=19,
39+
EQ=20, LT=21, DOUBLE_COLON=22, COLON=23, LBRACK=24, LPAREN=25, MINUS=26,
40+
OR=27, NEQ=28, GT=29, QUESTION=30, RBRACK=31, RPAREN=32, MUL=33, NOT=34,
41+
LEQ=35, DOT=36, DIV=37, GEQ=38, ARROW=39, COMMA=40, MOD=41, ELLIPSIS=42,
42+
TILDE=43, TEMPLATE_INTERPOLATION_START=44, TemplateStringLiteral=45, TemplateStringLiteralChar=46,
43+
HP_WS=47, HP_COMMENT=48, HP_LINE_COMMENT=49, HTemplateLiteral=50, HTemplateLiteralChar=51,
4244
H_NEWLINE=52;
4345
public static final int
4446
TEMPLATE=1, HEREDOC_PREAMBLE=2, HEREDOC=3;
@@ -52,41 +54,41 @@ public class HCLLexer extends Lexer {
5254

5355
private static String[] makeRuleNames() {
5456
return new String[] {
55-
"FOR_BRACE", "FOR_BRACK", "IF", "IN", "BooleanLiteral", "NULL", "LBRACE",
56-
"RBRACE", "ASSIGN", "StringLiteralChar", "Identifier", "WS", "COMMENT",
57-
"LINE_COMMENT", "NEWLINE", "LetterOrDigit", "Letter", "EscapeSequence",
58-
"HexDigit", "NumericLiteral", "ExponentPart", "QUOTE", "HEREDOC_START",
59-
"PLUS", "AND", "EQ", "LT", "DOUBLE_COLON", "COLON", "LBRACK", "LPAREN",
60-
"MINUS", "OR", "NEQ", "GT", "QUESTION", "RBRACK", "RPAREN", "MUL", "NOT",
61-
"LEQ", "DOT", "DIV", "GEQ", "ARROW", "COMMA", "MOD", "ELLIPSIS", "TILDE",
62-
"TEMPLATE_INTERPOLATION_START", "TemplateStringLiteral", "TemplateStringLiteralChar",
63-
"END_QUOTE", "HP_NEWLINE", "HP_WS", "HP_COMMENT", "HP_LINE_COMMENT",
64-
"HPIdentifier", "H_NEWLINE", "H_TEMPLATE_INTERPOLATION_START", "HTemplateLiteral",
57+
"FOR_BRACE", "FOR_BRACK", "IF", "IN", "BooleanLiteral", "NULL", "LBRACE",
58+
"RBRACE", "ASSIGN", "StringLiteralChar", "Identifier", "WS", "COMMENT",
59+
"LINE_COMMENT", "NEWLINE", "LetterOrDigit", "Letter", "EscapeSequence",
60+
"HexDigit", "NumericLiteral", "ExponentPart", "QUOTE", "HEREDOC_START",
61+
"PLUS", "AND", "EQ", "LT", "DOUBLE_COLON", "COLON", "LBRACK", "LPAREN",
62+
"MINUS", "OR", "NEQ", "GT", "QUESTION", "RBRACK", "RPAREN", "MUL", "NOT",
63+
"LEQ", "DOT", "DIV", "GEQ", "ARROW", "COMMA", "MOD", "ELLIPSIS", "TILDE",
64+
"TEMPLATE_INTERPOLATION_START", "TemplateStringLiteral", "TemplateStringLiteralChar",
65+
"END_QUOTE", "HP_NEWLINE", "HP_WS", "HP_COMMENT", "HP_LINE_COMMENT",
66+
"HPIdentifier", "H_NEWLINE", "H_TEMPLATE_INTERPOLATION_START", "HTemplateLiteral",
6567
"HTemplateLiteralChar"
6668
};
6769
}
6870
public static final String[] ruleNames = makeRuleNames();
6971

7072
private static String[] makeLiteralNames() {
7173
return new String[] {
72-
null, null, null, "'if'", "'in'", null, "'null'", "'{'", "'}'", "'='",
73-
null, null, null, null, null, null, null, null, "'+'", "'&&'", "'=='",
74-
"'<'", "'::'", "':'", "'['", "'('", "'-'", "'||'", "'!='", "'>'", "'?'",
75-
"']'", "')'", "'*'", "'!'", "'<='", "'.'", "'/'", "'>='", "'=>'", "','",
76-
"'%'", "'...'", "'~'", null, null, null, null, null, null, null, null,
74+
null, null, null, "'if'", "'in'", null, "'null'", "'{'", "'}'", "'='",
75+
null, null, null, null, null, null, null, null, "'+'", "'&&'", "'=='",
76+
"'<'", "'::'", "':'", "'['", "'('", "'-'", "'||'", "'!='", "'>'", "'?'",
77+
"']'", "')'", "'*'", "'!'", "'<='", "'.'", "'/'", "'>='", "'=>'", "','",
78+
"'%'", "'...'", "'~'", null, null, null, null, null, null, null, null,
7779
"'\\n'"
7880
};
7981
}
8082
private static final String[] _LITERAL_NAMES = makeLiteralNames();
8183
private static String[] makeSymbolicNames() {
8284
return new String[] {
83-
null, "FOR_BRACE", "FOR_BRACK", "IF", "IN", "BooleanLiteral", "NULL",
84-
"LBRACE", "RBRACE", "ASSIGN", "Identifier", "WS", "COMMENT", "LINE_COMMENT",
85-
"NEWLINE", "NumericLiteral", "QUOTE", "HEREDOC_START", "PLUS", "AND",
86-
"EQ", "LT", "DOUBLE_COLON", "COLON", "LBRACK", "LPAREN", "MINUS", "OR",
87-
"NEQ", "GT", "QUESTION", "RBRACK", "RPAREN", "MUL", "NOT", "LEQ", "DOT",
88-
"DIV", "GEQ", "ARROW", "COMMA", "MOD", "ELLIPSIS", "TILDE", "TEMPLATE_INTERPOLATION_START",
89-
"TemplateStringLiteral", "TemplateStringLiteralChar", "HP_WS", "HP_COMMENT",
85+
null, "FOR_BRACE", "FOR_BRACK", "IF", "IN", "BooleanLiteral", "NULL",
86+
"LBRACE", "RBRACE", "ASSIGN", "Identifier", "WS", "COMMENT", "LINE_COMMENT",
87+
"NEWLINE", "NumericLiteral", "QUOTE", "HEREDOC_START", "PLUS", "AND",
88+
"EQ", "LT", "DOUBLE_COLON", "COLON", "LBRACK", "LPAREN", "MINUS", "OR",
89+
"NEQ", "GT", "QUESTION", "RBRACK", "RPAREN", "MUL", "NOT", "LEQ", "DOT",
90+
"DIV", "GEQ", "ARROW", "COMMA", "MOD", "ELLIPSIS", "TILDE", "TEMPLATE_INTERPOLATION_START",
91+
"TemplateStringLiteral", "TemplateStringLiteralChar", "HP_WS", "HP_COMMENT",
9092
"HP_LINE_COMMENT", "HTemplateLiteral", "HTemplateLiteralChar", "H_NEWLINE"
9193
};
9294
}
@@ -596,4 +598,4 @@ private boolean TemplateStringLiteralChar_sempred(RuleContext _localctx, int pre
596598
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
597599
}
598600
}
599-
}
601+
}

0 commit comments

Comments
 (0)