forked from redhat-developer/intellij-quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: New Feature: outline extension BuildItems
Fixes redhat-developer#1094 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
869ead4
commit 2418c84
Showing
4 changed files
with
131 additions
and
4 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...a/com/redhat/devtools/intellij/quarkus/psi/internal/builditems/QuarkusBuildItemUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.redhat.devtools.intellij.quarkus.psi.internal.builditems; | ||
|
||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.progress.ProgressIndicator; | ||
import com.intellij.psi.PsiClass; | ||
import com.intellij.psi.PsiModifier; | ||
import com.intellij.psi.search.ProjectScope; | ||
import com.intellij.psi.search.searches.DefinitionsScopedSearch; | ||
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.PsiTypeUtils; | ||
import com.redhat.devtools.intellij.quarkus.QuarkusConstants; | ||
import com.redhat.microprofile.psi.internal.quarkus.renarde.java.RenardeConstants; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class QuarkusBuildItemUtils { | ||
|
||
private QuarkusBuildItemUtils() { | ||
|
||
} | ||
|
||
/** | ||
* Returns a set of all classes in the given project that extend Renarde's | ||
* <code>Controller</code> class. | ||
* | ||
* @param project the project to search in | ||
* @param monitor the progress monitor | ||
* @return a set of all classes in the given project that extend Renarde's | ||
* <code>Controller</code> class | ||
*/ | ||
public static Set<PsiClass> getAllBuildItemClasses(Module project, ProgressIndicator monitor) { | ||
PsiClass buildItemType = PsiTypeUtils.findType(project, QuarkusConstants.QUARKUS_BUILD_ITEM_CLASS_NAME); | ||
if (buildItemType == null) { | ||
return Collections.emptySet(); | ||
} | ||
|
||
Set<PsiClass> types = new HashSet<>(); | ||
DefinitionsScopedSearch.search(buildItemType, ProjectScope.getAllScope(project.getProject()), true) | ||
.forEach(element -> { | ||
if (element instanceof PsiClass type && isValidBuildItem(type)) { | ||
types.add(type); | ||
} | ||
}); | ||
return types; | ||
} | ||
|
||
|
||
public static boolean isValidBuildItem(PsiClass psiClass) { | ||
return psiClass.hasModifierProperty(PsiModifier.FINAL) | ||
|| psiClass.hasModifierProperty(PsiModifier.ABSTRACT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...icroprofile/psi/internal/quarkus/builditems/java/BuildItemWorkspaceSymbolParticipant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.microprofile.psi.internal.quarkus.builditems.java; | ||
|
||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.progress.ProgressIndicator; | ||
import com.intellij.openapi.util.TextRange; | ||
import com.intellij.psi.PsiClass; | ||
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.symbols.IJavaWorkspaceSymbolsParticipant; | ||
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.jaxrs.IJaxRsInfoProvider; | ||
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.jaxrs.JaxRsContext; | ||
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.jaxrs.JaxRsMethodInfo; | ||
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils; | ||
import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.jaxrs.java.JaxRsInfoProviderRegistry; | ||
import com.redhat.devtools.intellij.quarkus.psi.internal.builditems.QuarkusBuildItemUtils; | ||
import org.eclipse.lsp4j.Location; | ||
import org.eclipse.lsp4j.Range; | ||
import org.eclipse.lsp4j.SymbolInformation; | ||
import org.eclipse.lsp4j.SymbolKind; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* Collects workspace symbols for Quarkus BuildItem. | ||
*/ | ||
public class BuildItemWorkspaceSymbolParticipant implements IJavaWorkspaceSymbolsParticipant { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(BuildItemWorkspaceSymbolParticipant.class.getName()); | ||
|
||
@Override | ||
public void collectSymbols(Module project, IPsiUtils utils, List<SymbolInformation> symbols, ProgressIndicator monitor) { | ||
if (monitor.isCanceled()) { | ||
return; | ||
} | ||
|
||
QuarkusBuildItemUtils.getAllBuildItemClasses(project, monitor) | ||
.forEach(buildType -> { | ||
symbols.add(createSymbol(buildType, utils )); | ||
}); | ||
} | ||
|
||
private static SymbolInformation createSymbol(PsiClass buildItemType, IPsiUtils utils) { | ||
Location location = utils.toLocation(buildItemType); | ||
|
||
StringBuilder nameBuilder = new StringBuilder("&"); | ||
nameBuilder.append(buildItemType.getName()); | ||
|
||
SymbolInformation symbol = new SymbolInformation(); | ||
symbol.setName(nameBuilder.toString()); | ||
symbol.setKind(SymbolKind.Class); | ||
symbol.setLocation(location); | ||
return symbol; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters