-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
16 changed files
with
781 additions
and
183 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); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...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,71 @@ | ||
/******************************************************************************* | ||
* 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 (!JavaLibraryUtil.hasAnyLibraryJar(context.getJavaProject(), RoqJavaConstants.ROQ_MAVEN_COORS)) { | ||
// It is not a Roq application, don't inject site and page. | ||
return; | ||
} | ||
|
||
DataModelTemplate<DataModelParameter> roqTemplate = new DataModelTemplate<DataModelParameter>(); | ||
roqTemplate.setTemplateMatcher(new DataModelTemplateMatcher(Arrays.asList("**/**"))); | ||
|
||
// site | ||
DataModelParameter site = new DataModelParameter(); | ||
site.setKey("site"); | ||
site.setSourceType("io.quarkiverse.roq.frontmatter.runtime.model.Site"); | ||
roqTemplate.addParameter(site); | ||
|
||
// page | ||
DataModelParameter page = new DataModelParameter(); | ||
page.setKey("page"); | ||
page.setSourceType("io.quarkiverse.roq.frontmatter.runtime.model.Page"); | ||
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; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
.../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,34 @@ | ||
/******************************************************************************* | ||
* 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 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"; | ||
|
||
} |
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 JavaLibraryUtil.hasAnyLibraryJar(javaProject, RoqJavaConstants.ROQ_MAVEN_COORS); | ||
} | ||
|
||
@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)); | ||
} | ||
} | ||
|
||
} |
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.