Skip to content

Commit 30fa1cc

Browse files
authored
Merge pull request #65 from openjavaformat/parameter-array-dims-annotation
Accept an annotated C-style array dimension on a parameter
2 parents 34ddeaa + 4ed1716 commit 30fa1cc

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎open-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,18 +2684,29 @@ private void visitToDeclare(
26842684
Optional<String> trailing,
26852685
Optional<BreakTag> annotationBreakForRecords) {
26862686
sync(node);
2687+
Optional<TypeWithDims> typeWithDims;
2688+
Tree type;
2689+
if (node.getType() != null) {
2690+
TypeWithDims extractedDims = DimensionHelpers.extractDims(node.getType(), SortedDims.YES);
2691+
typeWithDims = Optional.of(extractedDims);
2692+
type = extractedDims.node;
2693+
} else {
2694+
// "var" and an untyped lambda parameter have no type tree
2695+
typeWithDims = Optional.empty();
2696+
type = null;
2697+
}
26872698
declareOne(
26882699
kind,
26892700
annotationsDirection,
26902701
Optional.of(node.getModifiers()),
2691-
node.getType(),
2702+
type,
26922703
node.getName(),
26932704
"",
26942705
equals,
26952706
initializer,
26962707
trailing,
26972708
/* receiverExpression= */ Optional.empty(),
2698-
/* typeWithDims= */ Optional.empty(),
2709+
typeWithDims,
26992710
annotationBreakForRecords);
27002711
}
27012712

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import java.lang.annotation.ElementType;
2+
import java.lang.annotation.Target;
3+
4+
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
5+
@interface MyTypeAnno {}
6+
7+
public class GjfFailure {
8+
void m(int a @MyTypeAnno []) {}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import java.lang.annotation.ElementType;
2+
import java.lang.annotation.Target;
3+
4+
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
5+
@interface MyTypeAnno {}
6+
7+
public class GjfFailure {
8+
void m(int a @MyTypeAnno []) {}
9+
}

0 commit comments

Comments
 (0)