Skip to content

Commit

Permalink
Fix language id computation for JDT URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Dec 10, 2024
1 parent 783bb4b commit 8d2ba77
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ LanguageComputer languageComputer() {

@Override
public LanguageId computeLanguage(URI uri) {
Path path = Paths.get(uri);
Path path = Paths.get(uri.getPath());
String fileName = path.getFileName().toString();
switch (Files.getFileExtension(fileName)) {
case "properties":
Expand All @@ -379,7 +379,9 @@ public LanguageId computeLanguage(URI uri) {
return LanguageId.BOOT_PROPERTIES_YAML;
case "java":
return LanguageId.JAVA;
case "xml":
case "class":
return LanguageId.CLASS;
case "xml":
return LanguageId.XML;
case "factories":
return LanguageId.SPRING_FACTORIES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*******************************************************************************
* Copyright (c) 2024 Broadcom, 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
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.cron;

import static org.junit.Assert.assertEquals;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2024 Broadcom, 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
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.test;


import static org.assertj.core.api.Assertions.assertThat;

import java.net.URI;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest;
import org.springframework.ide.vscode.boot.bootiful.HoverTestConf;
import org.springframework.ide.vscode.commons.languageserver.util.LanguageComputer;
import org.springframework.ide.vscode.commons.util.text.LanguageId;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@ExtendWith(SpringExtension.class)
@BootLanguageServerTest
@Import(HoverTestConf.class)
public class LanguageComputerTest {

@Autowired
LanguageComputer languageComputer;

@Test
void jdtUri() {
assertThat(languageComputer).isNotNull();
URI uri = URI.create("jdt://contents/spring-data-commons-1.11.4.RELEASE.jar/org.springframework.data.mapping.model/PropertyNameFieldNamingStrategy.class?%3Dboot13_with_mongo%2F%5C%2FUsers%5C%2Faboyko%5C%2F.m2%5C%2Frepository%5C%2Forg%5C%2Fspringframework%5C%2Fdata%5C%2Fspring-data-commons%5C%2F1.11.4.RELEASE%5C%2Fspring-data-commons-1.11.4.RELEASE.jar%3Corg.springframework.data.mapping.model%28PropertyNameFieldNamingStrategy.class");
assertThat(languageComputer.computeLanguage(uri)).isEqualTo(LanguageId.CLASS);

uri = URI.create("file:///project/org.springframework.data.mapping.model/PropertyNameFieldNamingStrategy.java");
assertThat(languageComputer.computeLanguage(uri)).isEqualTo(LanguageId.JAVA);

}

}

0 comments on commit 8d2ba77

Please sign in to comment.