Skip to content

Commit

Permalink
feat: mark @BuildStep-annotated methods as implicitly used
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Aug 10, 2023
1 parent afe404b commit bd549b4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class QuarkusConstants {

public static final String QUARKUS_ARC_CONFIG_PROPERTIES_DEFAULT_NAMING_STRATEGY = "quarkus.arc.config-properties-default-naming-strategy";

public static final String QUARKUS_DEPLOYMENT_BUILDSTEP_ANNOTATION = "io.quarkus.deployment.annotations.BuildStep";

public static final String QUARKUS_CORE_PREFIX = "io.quarkus:quarkus-core:";
public static final String QUARKUS_PREFIX = "quarkus";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright (c) 2023 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.devtools.intellij.quarkus.psi.internal;

import com.intellij.codeInsight.daemon.ImplicitUsageProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.jaxrs.JaxRsConstants;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.AnnotationUtils;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.restclient.MicroProfileRestClientConstants;
import org.jetbrains.annotations.NotNull;

import static com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.AnnotationUtils.hasAnyAnnotation;
import static com.redhat.devtools.intellij.quarkus.QuarkusConstants.QUARKUS_DEPLOYMENT_BUILDSTEP_ANNOTATION;

/**
* Automatically declares as used, methods annotated with {@link io.quarkus.deployment.annotations.BuildStep} annotations, such as:
* <p>
* {@code
* @BuildStep
* AdditionalBeanBuildItem producePrettyTime() {
* return new AdditionalBeanBuildItem(PrettyTimeProducer.class);
* }
* }
* </p>
*/
public class QuarkusBuildImplicitUsageProvider implements ImplicitUsageProvider {

@Override
public boolean isImplicitUsage(@NotNull PsiElement element) {
return isImplicitRead(element) || isImplicitWrite(element);
}

@Override
public boolean isImplicitRead(@NotNull PsiElement element) {
return element instanceof PsiMethod &&
!((PsiMethod)element).isConstructor() &&
AnnotationUtils.hasAnyAnnotation(element, QUARKUS_DEPLOYMENT_BUILDSTEP_ANNOTATION);
}

@Override
public boolean isImplicitWrite(@NotNull PsiElement element) {
return false;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/lsp4ij-quarkus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
serviceImplementation="com.redhat.devtools.intellij.lsp4mp4ij.settings.UserDefinedMicroProfileSettings"/>

<implicitUsageProvider implementation="com.redhat.devtools.intellij.lsp4mp4ij.psi.core.JavaEEImplicitUsageProvider"/>

<implicitUsageProvider implementation="com.redhat.devtools.intellij.quarkus.psi.internal.QuarkusBuildImplicitUsageProvider"/>
<!-- Quarkus -->
<lang.documentationProvider id="LSPTextHoverProperties" language="Properties" implementationClass="com.redhat.devtools.intellij.lsp4ij.operations.hover.LSPTextHover" order="first"/>
<externalAnnotator language="Properties"
Expand Down

0 comments on commit bd549b4

Please sign in to comment.