Skip to content

Commit 99b5741

Browse files
committed
Boot properties can have java.lang.Object as sequence type
1 parent 61052cb commit 99b5741

File tree

5 files changed

+65
-6
lines changed

5 files changed

+65
-6
lines changed

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/metadata/types/TypeUtil.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2023 Pivotal, Inc.
2+
* Copyright (c) 2016, 2025 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
@@ -468,6 +468,10 @@ public boolean isIndexable(Type type) {
468468
public boolean isSequencable(Type type) {
469469
return isIndexable(type);
470470
}
471+
472+
public boolean isObjectOrSequence(Type type) {
473+
return OBJECT_TYPE_NAME.equals(type.getErasure());
474+
}
471475

472476
private static boolean isArray(Type type) {
473477
return type!=null && type.getErasure().endsWith("[]");

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/properties/reconcile/PropertyNavigator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016-2017 Pivotal, Inc.
2+
* Copyright (c) 2016, 2025 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
@@ -92,7 +92,7 @@ public Type navigate(int offset, Type type) {
9292
} else if (navOp=='[') {
9393
if (typeUtil.isBracketable(type)) {
9494
return bracketNavigate(offset, type);
95-
} else {
95+
} else if (!typeUtil.isObjectOrSequence(type)) {
9696
problemCollector.accept(problem(ApplicationPropertiesProblemType.PROP_INVALID_INDEXED_NAVIGATION,
9797
"Can't use '[..]' navigation for property '"+textBetween(region.getStart(), offset)+"' of type "+type,
9898
offset, region.getEnd()-offset));

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/yaml/reconcile/ApplicationYamlASTReconciler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2019 Pivotal, Inc.
2+
* Copyright (c) 2016, 2025 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
@@ -341,6 +341,8 @@ private void reconcile(YamlFileAST root, SequenceNode seq, Type type) {
341341
reconcile(root, element, domainType);
342342
}
343343
}
344+
} else if (typeUtil.isObjectOrSequence(type)) {
345+
// skip reconciling further as it can be anything - no schema
344346
} else {
345347
expectTypeFoundSequence(type, seq);
346348
}

headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationPropertiesEditorTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2024 Pivotal, Inc.
2+
* Copyright (c) 2016, 2025 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
@@ -2309,6 +2309,30 @@ void testSetOfEnumsCompletions() throws Exception {
23092309
"my.color-set=red,BLUE<*>"
23102310
);
23112311
}
2312+
2313+
@Test
2314+
void sequenceOrObject() throws Exception {
2315+
data("my.any", "java.util.Map<java.lang.String,java.lang.Object>", null, "Some map");
2316+
2317+
Editor editor = newEditor(
2318+
"""
2319+
my.any.entry.value.name=Freddy
2320+
my.any.entry.value.age=the-age
2321+
my.any.entry.value.bad=123
2322+
"""
2323+
);
2324+
editor.assertProblems();
2325+
2326+
editor = newEditor(
2327+
"""
2328+
my.any.entry[0].value.name=Freddy
2329+
my.any.entry[0].value.age=the-age
2330+
my.any.entry[0].value.bad=123
2331+
"""
2332+
);
2333+
editor.assertProblems();
2334+
}
2335+
23122336

23132337
////////////// harness code below /////////////////////////
23142338

headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationYamlEditorTest.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2024 Pivotal, Inc.
2+
* Copyright (c) 2016, 2025 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
@@ -5060,6 +5060,35 @@ void test_NoQuickfixForDeprecatedProperty() throws Exception {
50605060
editor.assertNoCodeAction(problem);
50615061
assertEquals(DiagnosticSeverity.Error, problem.getSeverity());
50625062
}
5063+
5064+
@Test
5065+
void sequenceOrObject() throws Exception {
5066+
IJavaProject p = createPredefinedMavenProject("map-of-pojo");
5067+
useProject(p);
5068+
data("my.any", "java.util.Map<java.lang.String,java.lang.Object>", null, "Some map");
5069+
5070+
Editor editor = newEditor(
5071+
"my:\n" +
5072+
" any:\n" +
5073+
" entry:\n" +
5074+
" - value:\n" +
5075+
" name: Freddy\n" +
5076+
" age: the-age\n" +
5077+
" bad: 123"
5078+
);
5079+
editor.assertProblems();
5080+
5081+
editor = newEditor(
5082+
"my:\n" +
5083+
" any:\n" +
5084+
" entry:\n" +
5085+
" value:\n" +
5086+
" name: Freddy\n" +
5087+
" age: the-age\n" +
5088+
" bad: 123"
5089+
);
5090+
editor.assertProblems();
5091+
}
50635092

50645093
///////////////// cruft ////////////////////////////////////////////////////////
50655094

0 commit comments

Comments
 (0)