diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/metadata/types/TypeUtil.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/metadata/types/TypeUtil.java index fe9d3a87b4..bd6365c704 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/metadata/types/TypeUtil.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/metadata/types/TypeUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2023 Pivotal, Inc. + * Copyright (c) 2016, 2025 Pivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -468,6 +468,10 @@ public boolean isIndexable(Type type) { public boolean isSequencable(Type type) { return isIndexable(type); } + + public boolean isObjectOrSequence(Type type) { + return OBJECT_TYPE_NAME.equals(type.getErasure()); + } private static boolean isArray(Type type) { return type!=null && type.getErasure().endsWith("[]"); diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/properties/reconcile/PropertyNavigator.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/properties/reconcile/PropertyNavigator.java index 0c51241837..3317e7f3c1 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/properties/reconcile/PropertyNavigator.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/properties/reconcile/PropertyNavigator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016-2017 Pivotal, Inc. + * Copyright (c) 2016, 2025 Pivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -92,7 +92,7 @@ public Type navigate(int offset, Type type) { } else if (navOp=='[') { if (typeUtil.isBracketable(type)) { return bracketNavigate(offset, type); - } else { + } else if (!typeUtil.isObjectOrSequence(type)) { problemCollector.accept(problem(ApplicationPropertiesProblemType.PROP_INVALID_INDEXED_NAVIGATION, "Can't use '[..]' navigation for property '"+textBetween(region.getStart(), offset)+"' of type "+type, offset, region.getEnd()-offset)); diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/yaml/reconcile/ApplicationYamlASTReconciler.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/yaml/reconcile/ApplicationYamlASTReconciler.java index 307de4b795..f6a190ad33 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/yaml/reconcile/ApplicationYamlASTReconciler.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/yaml/reconcile/ApplicationYamlASTReconciler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2019 Pivotal, Inc. + * Copyright (c) 2016, 2025 Pivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -341,6 +341,8 @@ private void reconcile(YamlFileAST root, SequenceNode seq, Type type) { reconcile(root, element, domainType); } } + } else if (typeUtil.isObjectOrSequence(type)) { + // skip reconciling further as it can be anything - no schema } else { expectTypeFoundSequence(type, seq); } diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationPropertiesEditorTest.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationPropertiesEditorTest.java index 084536cf08..7e38f75fad 100644 --- a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationPropertiesEditorTest.java +++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationPropertiesEditorTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2024 Pivotal, Inc. + * Copyright (c) 2016, 2025 Pivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -2309,6 +2309,30 @@ void testSetOfEnumsCompletions() throws Exception { "my.color-set=red,BLUE<*>" ); } + + @Test + void sequenceOrObject() throws Exception { + data("my.any", "java.util.Map", null, "Some map"); + + Editor editor = newEditor( + """ + my.any.entry.value.name=Freddy + my.any.entry.value.age=the-age + my.any.entry.value.bad=123 + """ + ); + editor.assertProblems(); + + editor = newEditor( + """ + my.any.entry[0].value.name=Freddy + my.any.entry[0].value.age=the-age + my.any.entry[0].value.bad=123 + """ + ); + editor.assertProblems(); + } + ////////////// harness code below ///////////////////////// diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationYamlEditorTest.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationYamlEditorTest.java index 414b7068b5..6c9bb68738 100644 --- a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationYamlEditorTest.java +++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationYamlEditorTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2024 Pivotal, Inc. + * Copyright (c) 2016, 2025 Pivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -5060,6 +5060,35 @@ void test_NoQuickfixForDeprecatedProperty() throws Exception { editor.assertNoCodeAction(problem); assertEquals(DiagnosticSeverity.Error, problem.getSeverity()); } + + @Test + void sequenceOrObject() throws Exception { + IJavaProject p = createPredefinedMavenProject("map-of-pojo"); + useProject(p); + data("my.any", "java.util.Map", null, "Some map"); + + Editor editor = newEditor( + "my:\n" + + " any:\n" + + " entry:\n" + + " - value:\n" + + " name: Freddy\n" + + " age: the-age\n" + + " bad: 123" + ); + editor.assertProblems(); + + editor = newEditor( + "my:\n" + + " any:\n" + + " entry:\n" + + " value:\n" + + " name: Freddy\n" + + " age: the-age\n" + + " bad: 123" + ); + editor.assertProblems(); + } ///////////////// cruft ////////////////////////////////////////////////////////