Skip to content
Merged
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
25 changes: 0 additions & 25 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,31 +223,6 @@
</build>

<profiles>
<profile>
<id>jdk17</id>
<activation>
<jdk>[17,21)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/Java21InputAstVisitor.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<excludePackageNames>com.google.googlejavaformat.java.java21</excludePackageNames>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>native</id>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,7 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept
}
OpsBuilder builder = new OpsBuilder(javaInput, javaOutput);
// Output the compilation unit.
JavaInputAstVisitor visitor;
if (Runtime.version().feature() >= 21) {
visitor =
createVisitor(
"com.google.googlejavaformat.java.java21.Java21InputAstVisitor", builder, options);
} else {
visitor = new JavaInputAstVisitor(builder, options.indentationMultiplier());
}
JavaInputAstVisitor visitor = new JavaInputAstVisitor(builder, options.indentationMultiplier());
visitor.scan(unit, null);
builder.sync(javaInput.getText().length());
builder.drain();
Expand All @@ -167,18 +160,6 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept
javaOutput.flush();
}

private static JavaInputAstVisitor createVisitor(
final String className, final OpsBuilder builder, final JavaFormatterOptions options) {
try {
return Class.forName(className)
.asSubclass(JavaInputAstVisitor.class)
.getConstructor(OpsBuilder.class, int.class)
.newInstance(builder, options.indentationMultiplier());
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
}
}

static boolean errorDiagnostic(Diagnostic<?> input) {
if (input.getKind() != Diagnostic.Kind.ERROR) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.CompoundAssignmentTree;
import com.sun.source.tree.ConditionalExpressionTree;
import com.sun.source.tree.ConstantCaseLabelTree;
import com.sun.source.tree.ContinueTree;
import com.sun.source.tree.DeconstructionPatternTree;
import com.sun.source.tree.DefaultCaseLabelTree;
import com.sun.source.tree.DirectiveTree;
import com.sun.source.tree.DoWhileLoopTree;
import com.sun.source.tree.EmptyStatementTree;
Expand Down Expand Up @@ -125,6 +128,8 @@
import com.sun.source.tree.OpensTree;
import com.sun.source.tree.ParameterizedTypeTree;
import com.sun.source.tree.ParenthesizedTree;
import com.sun.source.tree.PatternCaseLabelTree;
import com.sun.source.tree.PatternTree;
import com.sun.source.tree.PrimitiveTypeTree;
import com.sun.source.tree.ProvidesTree;
import com.sun.source.tree.RequiresTree;
Expand Down Expand Up @@ -359,6 +364,12 @@ private boolean inExpression() {

@Override
public Void scan(Tree tree, Void unused) {
// Pre-visit AST for preview features, since com.sun.source.tree.AnyPattern can't be
// accessed directly without --enable-preview.
if (tree instanceof JCTree.JCAnyPattern) {
visitJcAnyPattern((JCTree.JCAnyPattern) tree);
return null;
}
inExpression.addLast(tree instanceof ExpressionTree || inExpression.peekLast());
int previous = builder.depth();
try {
Expand Down Expand Up @@ -2001,7 +2012,7 @@ public Void visitCase(CaseTree node, Void unused) {
builder.close();
}

final ExpressionTree guard = getGuard(node);
final ExpressionTree guard = node.getGuard();
if (guard != null) {
builder.breakToFill(" ");
token("when");
Expand Down Expand Up @@ -2041,10 +2052,6 @@ public Void visitCase(CaseTree node, Void unused) {
return null;
}

protected ExpressionTree getGuard(final CaseTree node) {
return null;
}

@Override
public Void visitSwitch(SwitchTree node, Void unused) {
sync(node);
Expand Down Expand Up @@ -3775,7 +3782,11 @@ protected int declareOne(
}

protected void variableName(Name name) {
visit(name);
if (name.isEmpty()) {
token("_");
} else {
visit(name);
}
}

private void maybeAddDims(Deque<List<? extends AnnotationTree>> annotations) {
Expand Down Expand Up @@ -4153,4 +4164,46 @@ public Void visitSwitchExpression(SwitchExpressionTree node, Void aVoid) {
visitSwitch(node.getExpression(), node.getCases());
return null;
}

@Override
public Void visitDefaultCaseLabel(DefaultCaseLabelTree node, Void unused) {
token("default");
return null;
}

@Override
public Void visitPatternCaseLabel(PatternCaseLabelTree node, Void unused) {
scan(node.getPattern(), null);
return null;
}

@Override
public Void visitConstantCaseLabel(ConstantCaseLabelTree node, Void aVoid) {
scan(node.getConstantExpression(), null);
return null;
}

@Override
public Void visitDeconstructionPattern(DeconstructionPatternTree node, Void unused) {
scan(node.getDeconstructor(), null);
builder.open(plusFour);
token("(");
builder.breakOp();
boolean afterFirstToken = false;
for (PatternTree pattern : node.getNestedPatterns()) {
if (afterFirstToken) {
token(",");
builder.breakOp(" ");
}
afterFirstToken = true;
scan(pattern, null);
}
builder.close();
token(")");
return null;
}

private void visitJcAnyPattern(JCTree.JCAnyPattern unused) {
token("_");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,5 @@
{
"name": "com.sun.tools.javac.parser.UnicodeReader",
"allDeclaredMethods": true
},
{
"name": "com.google.googlejavaformat.java.java21.Java21InputAstVisitor",
"methods": [
{
"name": "<init>",
"parameterTypes": ["com.google.googlejavaformat.OpsBuilder", "int"]
}
]
}
]
Loading