Skip to content

Commit fa4e01d

Browse files
committed
Boot Properties defined in Java Records
1 parent 37cb485 commit fa4e01d

File tree

37 files changed

+1270
-141
lines changed

37 files changed

+1270
-141
lines changed

Diff for: headless-services/commons/commons-java/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<dependency>
2727
<groupId>org.jboss</groupId>
2828
<artifactId>jandex</artifactId>
29-
<version>2.0.5.Final</version>
29+
<version>3.0.5</version>
3030
</dependency>
3131
<!-- HTML <-> Markdown conversion -->
3232
<dependency>

Diff for: headless-services/commons/commons-java/src/main/java/org/springframework/ide/vscode/commons/jandex/BindingKeyUtils.java

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2018 Pivotal, Inc.
2+
* Copyright (c) 2018, 2023 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -18,13 +18,15 @@
1818
import org.jboss.jandex.ClassType;
1919
import org.jboss.jandex.FieldInfo;
2020
import org.jboss.jandex.MethodInfo;
21+
import org.jboss.jandex.MethodParameterInfo;
2122
import org.jboss.jandex.ParameterizedType;
2223
import org.jboss.jandex.PrimitiveType;
2324
import org.jboss.jandex.Type;
2425
import org.jboss.jandex.TypeVariable;
2526
import org.jboss.jandex.UnresolvedTypeVariable;
2627
import org.jboss.jandex.VoidType;
2728
import org.jboss.jandex.WildcardType;
29+
import org.springframework.ide.vscode.commons.java.Flags;
2830

2931
class BindingKeyUtils {
3032

@@ -43,10 +45,15 @@ public static String getBindingKey(AnnotationInstance annotation) {
4345
public static String getBindingKey(FieldInfo field) {
4446
StringBuilder sb = new StringBuilder();
4547
sb.append(getBindingKey(field.declaringClass()));
46-
sb.append('.');
47-
sb.append(field.name());
48-
sb.append(')');
49-
sb.append(getGeneralTypeBindingKey(field.type()));
48+
if (field.declaringClass().isRecord() && !Flags.isStatic(field.flags())) {
49+
sb.append('#');
50+
sb.append(field.name());
51+
} else {
52+
sb.append('.');
53+
sb.append(field.name());
54+
sb.append(')');
55+
sb.append(getGeneralTypeBindingKey(field.type()));
56+
}
5057
return sb.toString();
5158
}
5259

@@ -56,8 +63,8 @@ public static String getBindingKey(MethodInfo method) {
5663
sb.append('.');
5764
sb.append(method.name());
5865
sb.append('(');
59-
for (Type parameter : method.parameters()) {
60-
sb.append(getGeneralTypeBindingKey(parameter));
66+
for (MethodParameterInfo parameter : method.parameters()) {
67+
sb.append(getGeneralTypeBindingKey(parameter.type()));
6168
}
6269
sb.append(')');
6370
sb.append(getGeneralTypeBindingKey(method.returnType()));

Diff for: headless-services/commons/commons-java/src/main/java/org/springframework/ide/vscode/commons/jandex/MethodImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016-2018 Pivotal, Inc.
2+
* Copyright (c) 2016, 2023 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -89,7 +89,7 @@ public String toString() {
8989

9090
@Override
9191
public Stream<IJavaType> parameters() {
92-
return method.parameters().stream().map(Wrappers::wrap);
92+
return method.parameters().stream().map(p -> Wrappers.wrap(p.type()));
9393
}
9494

9595
@Override

Diff for: headless-services/commons/commons-java/src/main/java/org/springframework/ide/vscode/commons/jandex/TypeImpl.java

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2018 Pivotal, Inc.
2+
* Copyright (c) 2016, 2023 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -73,8 +73,7 @@ public boolean exists() {
7373

7474
@Override
7575
public Stream<IAnnotation> getAnnotations() {
76-
// TODO: check correctness!
77-
List<AnnotationInstance> annotations = info.annotations().get(info.name());
76+
List<AnnotationInstance> annotations = info.annotations();
7877
return annotations == null ? Stream.empty() : annotations.stream().map(a -> Wrappers.wrap(a, javadocProvider));
7978
}
8079

@@ -97,6 +96,10 @@ public boolean isInterface() {
9796
public boolean isAnnotation() {
9897
return Flags.isAnnotation(info.flags());
9998
}
99+
100+
public boolean isRecord() {
101+
return info.isRecord();
102+
}
100103

101104
@Override
102105
public String getFullyQualifiedName() {
@@ -111,9 +114,15 @@ public IField getField(String name) {
111114

112115
@Override
113116
public Stream<IField> getFields() {
114-
return info.fields().stream().map(f -> {
115-
return Wrappers.wrap(this, f, javadocProvider);
116-
});
117+
if (info.isRecord()) {
118+
return info.recordComponents().stream().map(rc -> {
119+
return Wrappers.wrap(this, rc.field(), javadocProvider);
120+
});
121+
} else {
122+
return info.fields().stream().map(f -> {
123+
return Wrappers.wrap(this, f, javadocProvider);
124+
});
125+
}
117126
}
118127

119128
@Override

Diff for: headless-services/commons/commons-java/src/main/java/org/springframework/ide/vscode/commons/java/IType.java

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public interface IType extends IMember {
2424
boolean isEnum();
2525
boolean isInterface();
2626
boolean isAnnotation();
27+
boolean isRecord();
2728

2829
/**
2930
* Returns the fully qualified name of this type,

Diff for: headless-services/commons/commons-java/src/main/java/org/springframework/ide/vscode/commons/jdtls/Wrappers.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019, 2021 Pivotal, Inc.
2+
* Copyright (c) 2019, 2023 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -524,6 +524,11 @@ public String[] getSuperInterfaceNames() {
524524
return data.getSuperInterfaceNames();
525525
}
526526

527+
@Override
528+
public boolean isRecord() {
529+
return data.isRecord();
530+
}
531+
527532
};
528533
}
529534

@@ -630,6 +635,11 @@ public String[] getSuperInterfaceNames() {
630635
return descriptor.getSuperInterfaceNames();
631636
}
632637

638+
@Override
639+
public boolean isRecord() {
640+
return descriptor.isRecord();
641+
}
642+
633643
};
634644
}
635645

Diff for: headless-services/commons/commons-lsp-extensions/src/main/java/org/springframework/ide/vscode/commons/protocol/java/TypeDescriptorData.java

+15-27
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
package org.springframework.ide.vscode.commons.protocol.java;
1212

1313
import java.util.Arrays;
14+
import java.util.Objects;
1415

1516
public class TypeDescriptorData extends MemberData {
1617

@@ -19,6 +20,7 @@ public class TypeDescriptorData extends MemberData {
1920
private boolean annotation;
2021
private boolean interfaze;
2122
private boolean enam;
23+
private boolean record;
2224
private String superClassName;
2325
private String[] superInterfaceNames;
2426

@@ -78,17 +80,20 @@ public void setSuperInterfaceNames(String[] superInterfaceNames) {
7880
this.superInterfaceNames = superInterfaceNames;
7981
}
8082

83+
public boolean isRecord() {
84+
return record;
85+
}
86+
87+
public void setRecord(boolean record) {
88+
this.record = record;
89+
}
90+
8191
@Override
8292
public int hashCode() {
8393
final int prime = 31;
8494
int result = super.hashCode();
85-
result = prime * result + (annotation ? 1231 : 1237);
86-
result = prime * result + (clazz ? 1231 : 1237);
87-
result = prime * result + (enam ? 1231 : 1237);
88-
result = prime * result + ((fqName == null) ? 0 : fqName.hashCode());
89-
result = prime * result + (interfaze ? 1231 : 1237);
90-
result = prime * result + ((superClassName == null) ? 0 : superClassName.hashCode());
9195
result = prime * result + Arrays.hashCode(superInterfaceNames);
96+
result = prime * result + Objects.hash(annotation, clazz, enam, fqName, interfaze, record, superClassName);
9297
return result;
9398
}
9499

@@ -101,27 +106,10 @@ public boolean equals(Object obj) {
101106
if (getClass() != obj.getClass())
102107
return false;
103108
TypeDescriptorData other = (TypeDescriptorData) obj;
104-
if (annotation != other.annotation)
105-
return false;
106-
if (clazz != other.clazz)
107-
return false;
108-
if (enam != other.enam)
109-
return false;
110-
if (fqName == null) {
111-
if (other.fqName != null)
112-
return false;
113-
} else if (!fqName.equals(other.fqName))
114-
return false;
115-
if (interfaze != other.interfaze)
116-
return false;
117-
if (superClassName == null) {
118-
if (other.superClassName != null)
119-
return false;
120-
} else if (!superClassName.equals(other.superClassName))
121-
return false;
122-
if (!Arrays.equals(superInterfaceNames, other.superInterfaceNames))
123-
return false;
124-
return true;
109+
return annotation == other.annotation && clazz == other.clazz && enam == other.enam
110+
&& Objects.equals(fqName, other.fqName) && interfaze == other.interfaze && record == other.record
111+
&& Objects.equals(superClassName, other.superClassName)
112+
&& Arrays.equals(superInterfaceNames, other.superInterfaceNames);
125113
}
126114

127115
}

Diff for: headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/META-INF/MANIFEST.MF

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ Require-Bundle: org.springframework.tooling.jdt.ls.commons,
1212
org.apache.commons.lang3,
1313
org.junit,
1414
org.apache.commons.io,
15-
com.google.guava;bundle-version="21.0.0"
15+
com.google.guava;bundle-version="21.0.0",
16+
org.eclipse.jdt.ui
1617

0 commit comments

Comments
 (0)