-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
19 changed files
with
863 additions
and
193 deletions.
There are no files selected for viewing
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
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
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
86 changes: 86 additions & 0 deletions
86
...ava/com/redhat/devtools/intellij/qute/psi/internal/extensions/roq/DataMappingSupport.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,86 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.qute.psi.internal.extensions.roq; | ||
|
||
import com.intellij.openapi.progress.ProgressIndicator; | ||
import com.intellij.psi.PsiAnnotation; | ||
import com.intellij.psi.PsiClass; | ||
import com.intellij.psi.PsiElement; | ||
import com.redhat.devtools.intellij.qute.psi.template.datamodel.AbstractAnnotationTypeReferenceDataModelProvider; | ||
import com.redhat.devtools.intellij.qute.psi.template.datamodel.SearchContext; | ||
import com.redhat.devtools.intellij.qute.psi.utils.AnnotationUtils; | ||
import com.redhat.qute.commons.datamodel.resolvers.ValueResolverInfo; | ||
import com.redhat.qute.commons.datamodel.resolvers.ValueResolverKind; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
import java.util.logging.Logger; | ||
|
||
import static com.redhat.devtools.intellij.qute.psi.internal.QuteJavaConstants.VALUE_ANNOTATION_NAME; | ||
import static com.redhat.devtools.intellij.qute.psi.internal.extensions.roq.RoqJavaConstants.DATA_MAPPING_ANNOTATION; | ||
|
||
/** | ||
* Roq @DataMapping annotation support. | ||
* | ||
* @author Angelo ZERR | ||
*/ | ||
public class DataMappingSupport extends AbstractAnnotationTypeReferenceDataModelProvider { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(DataMappingSupport.class.getName()); | ||
|
||
private static final String INJECT_NAMESPACE = "inject"; | ||
|
||
private static final String[] ANNOTATION_NAMES = {DATA_MAPPING_ANNOTATION}; | ||
|
||
@Override | ||
protected String[] getAnnotationNames() { | ||
return ANNOTATION_NAMES; | ||
} | ||
|
||
@Override | ||
protected void processAnnotation(PsiElement javaElement, PsiAnnotation annotation, String annotationName, | ||
SearchContext context, ProgressIndicator monitor) { | ||
if (!(javaElement instanceof PsiClass)) { | ||
return; | ||
} | ||
// @DataMapping(value = "events", parentArray = true) | ||
// public record Events(List<Event> list) { | ||
// becomes --> inject:events | ||
|
||
PsiClass type = (PsiClass) javaElement; | ||
String value = getDataMappingAnnotationValue(type); | ||
if (StringUtils.isNoneBlank(value)) { | ||
collectResolversForInject(type, value, context.getDataModelProject().getValueResolvers()); | ||
} | ||
} | ||
|
||
@Nullable | ||
private static String getDataMappingAnnotationValue(PsiClass javaElement) { | ||
PsiAnnotation namedAnnotation = AnnotationUtils.getAnnotation(javaElement, | ||
DATA_MAPPING_ANNOTATION); | ||
if (namedAnnotation != null) { | ||
return AnnotationUtils.getAnnotationMemberValue(namedAnnotation, VALUE_ANNOTATION_NAME); | ||
} | ||
return null; | ||
} | ||
|
||
private static void collectResolversForInject(PsiClass type, String named, List<ValueResolverInfo> resolvers) { | ||
ValueResolverInfo resolver = new ValueResolverInfo(); | ||
resolver.setNamed(named); | ||
resolver.setSourceType(type.getQualifiedName()); | ||
resolver.setSignature(type.getQualifiedName()); | ||
resolver.setNamespace(INJECT_NAMESPACE); | ||
resolver.setKind(ValueResolverKind.InjectedBean); | ||
resolvers.add(resolver); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...a/com/redhat/devtools/intellij/qute/psi/internal/extensions/roq/RoqDataModelProvider.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,72 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.qute.psi.internal.extensions.roq; | ||
|
||
import java.util.Arrays; | ||
|
||
|
||
import com.intellij.java.library.JavaLibraryUtil; | ||
import com.intellij.openapi.progress.ProgressIndicator; | ||
import com.intellij.util.Query; | ||
import com.redhat.devtools.intellij.qute.psi.template.datamodel.AbstractDataModelProvider; | ||
import com.redhat.devtools.intellij.qute.psi.template.datamodel.SearchContext; | ||
import com.redhat.qute.commons.datamodel.DataModelParameter; | ||
import com.redhat.qute.commons.datamodel.DataModelTemplate; | ||
import com.redhat.qute.commons.datamodel.DataModelTemplateMatcher; | ||
|
||
/** | ||
* Inject 'site' and 'page' as data model parameters for all Qute templates | ||
* which belong to a Roq application. | ||
*/ | ||
public class RoqDataModelProvider extends AbstractDataModelProvider { | ||
|
||
@Override | ||
public void beginSearch(SearchContext context, ProgressIndicator monitor) { | ||
if (!RoqUtils.isRoqProject(context.getJavaProject())) { | ||
// It is not a Roq application, don't inject site and page. | ||
return; | ||
} | ||
//quarkus-roq-frontmatter | ||
|
||
DataModelTemplate<DataModelParameter> roqTemplate = new DataModelTemplate<DataModelParameter>(); | ||
roqTemplate.setTemplateMatcher(new DataModelTemplateMatcher(Arrays.asList("**/**"))); | ||
|
||
// site | ||
DataModelParameter site = new DataModelParameter(); | ||
site.setKey("site"); | ||
site.setSourceType(RoqJavaConstants.SITE_CLASS); | ||
roqTemplate.addParameter(site); | ||
|
||
// page | ||
DataModelParameter page = new DataModelParameter(); | ||
page.setKey("page"); | ||
page.setSourceType(RoqJavaConstants.PAGE_CLASS); | ||
roqTemplate.addParameter(page); | ||
|
||
context.getDataModelProject().getTemplates().add(roqTemplate); | ||
} | ||
|
||
@Override | ||
public void collectDataModel(Object match, SearchContext context, ProgressIndicator monitor) { | ||
// Do nothing | ||
} | ||
|
||
@Override | ||
protected String[] getPatterns() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected Query<? extends Object> createSearchPattern(SearchContext context, String pattern) { | ||
return null; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
.../java/com/redhat/devtools/intellij/qute/psi/internal/extensions/roq/RoqJavaConstants.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,38 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.qute.psi.internal.extensions.roq; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* Roq Java constants. | ||
* | ||
* @author Angelo ZERR | ||
* | ||
*/ | ||
public class RoqJavaConstants { | ||
|
||
private RoqJavaConstants() { | ||
} | ||
|
||
public static final String ROQ_ARTIFACT_ID = "quarkus-roq-frontmatter"; | ||
|
||
public static final Collection<String> ROQ_MAVEN_COORS = List.of("io.quarkiverse.roq:quarkus-roq-frontmatter"); | ||
|
||
public static final String DATA_MAPPING_ANNOTATION = "io.quarkiverse.roq.data.runtime.annotations.DataMapping"; | ||
|
||
public static final String SITE_CLASS = "io.quarkiverse.roq.frontmatter.runtime.model.Site"; | ||
|
||
public static final String PAGE_CLASS = "io.quarkiverse.roq.frontmatter.runtime.model.Page"; | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
...edhat/devtools/intellij/qute/psi/internal/extensions/roq/RoqTemplateRootPathProvider.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,64 @@ | ||
/******************************************************************************* | ||
* 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.devtools.intellij.qute.psi.internal.extensions.roq; | ||
|
||
import java.util.List; | ||
|
||
|
||
import com.intellij.java.library.JavaLibraryUtil; | ||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.redhat.devtools.intellij.quarkus.QuarkusModuleUtil; | ||
import com.redhat.devtools.intellij.qute.psi.template.rootpath.ITemplateRootPathProvider; | ||
import com.redhat.devtools.intellij.qute.psi.utils.PsiQuteProjectUtils; | ||
import com.redhat.devtools.intellij.qute.psi.utils.PsiTypeUtils; | ||
import com.redhat.devtools.lsp4ij.LSPIJUtils; | ||
import com.redhat.qute.commons.TemplateRootPath; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Roq template root path provider for Roq project. | ||
*/ | ||
public class RoqTemplateRootPathProvider implements ITemplateRootPathProvider { | ||
|
||
private static final String ORIGIN = "roq"; | ||
|
||
private static final String[] TEMPLATES_BASE_DIRS = { "templates/", "content/", "src/main/resources/content/" }; | ||
|
||
@Override | ||
public boolean isApplicable(Module javaProject) { | ||
return RoqUtils.isRoqProject(javaProject); | ||
} | ||
|
||
@Override | ||
public void collectTemplateRootPaths(Module javaProject, List<TemplateRootPath> rootPaths) { | ||
VirtualFile moduleDir = QuarkusModuleUtil.getModuleDirPath(javaProject); | ||
if (moduleDir != null) { | ||
// templates | ||
String templateBaseDir = LSPIJUtils.toUri(moduleDir).resolve("templates").toASCIIString(); | ||
rootPaths.add(new TemplateRootPath(templateBaseDir, ORIGIN)); | ||
// content | ||
String contentBaseDir = LSPIJUtils.toUri(moduleDir).resolve("content").toASCIIString(); | ||
rootPaths.add(new TemplateRootPath(contentBaseDir, ORIGIN)); | ||
} | ||
// src/main/resources/content | ||
VirtualFile resourcesContentDir = PsiQuteProjectUtils.findBestResourcesDir(javaProject, "content"); | ||
if (resourcesContentDir != null) { | ||
String contentBaseDir = LSPIJUtils.toUri(resourcesContentDir).resolve("content").toASCIIString(); | ||
rootPaths.add(new TemplateRootPath(contentBaseDir, ORIGIN)); | ||
} | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/redhat/devtools/intellij/qute/psi/internal/extensions/roq/RoqUtils.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,44 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.qute.psi.internal.extensions.roq; | ||
|
||
import com.intellij.java.library.JavaLibraryUtil; | ||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.module.ModuleUtilCore; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Roq Utilities. | ||
*/ | ||
public class RoqUtils { | ||
|
||
/** | ||
* Returns true if the given module is a Roq project and false otherwise. | ||
* | ||
* @param module the module. | ||
* @return true if the given module is a Roq project and false otherwise. | ||
*/ | ||
public static boolean isRoqProject(@NotNull Module module) { | ||
if (JavaLibraryUtil.hasAnyLibraryJar(module, RoqJavaConstants.ROQ_MAVEN_COORS)) { | ||
return true; | ||
} | ||
|
||
Set<Module> projectDependencies = new HashSet<>(); | ||
ModuleUtilCore.getDependencies(module, projectDependencies); | ||
return projectDependencies | ||
.stream() | ||
.anyMatch(m -> RoqJavaConstants.ROQ_ARTIFACT_ID.equals(m.getName())); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...at/devtools/intellij/qute/psi/internal/extensions/webbundler/WebBundlerJavaConstants.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,32 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.qute.psi.internal.extensions.webbundler; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* Web Bundler Java constants. | ||
* | ||
* @author Angelo ZERR | ||
* | ||
*/ | ||
public class WebBundlerJavaConstants { | ||
|
||
private WebBundlerJavaConstants() { | ||
} | ||
|
||
public static final Collection<String> WEB_BUNDLER_MAVEN_COORS = List.of("io.quarkiverse.web-bundler:quarkus-roq-frontmatter"); | ||
|
||
public static final String BUNDLE_CLASS = "io.quarkiverse.web.bundler.runtime.Bundle"; | ||
|
||
} |
Oops, something went wrong.