-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
403 additions
and
14 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
47 changes: 47 additions & 0 deletions
47
...at.qute.jdt/src/main/java/com/redhat/qute/commons/datamodel/DataModelTemplateMatcher.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,47 @@ | ||
/******************************************************************************* | ||
* 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.qute.commons.datamodel; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; | ||
|
||
/** | ||
* Data model template matcher used to inject data parameters with patterns. | ||
*/ | ||
public class DataModelTemplateMatcher { | ||
|
||
private List<String> includes; | ||
|
||
public DataModelTemplateMatcher() { | ||
|
||
} | ||
|
||
public DataModelTemplateMatcher(List<String> includes) { | ||
setIncludes(includes); | ||
} | ||
|
||
public List<String> getIncludes() { | ||
return includes; | ||
} | ||
|
||
public void setIncludes(List<String> includes) { | ||
this.includes = includes; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
ToStringBuilder b = new ToStringBuilder(this); | ||
b.add("includes", this.includes); | ||
return b.toString(); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...e.jdt/src/main/java/com/redhat/qute/jdt/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,73 @@ | ||
/******************************************************************************* | ||
* 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.qute.jdt.internal.extensions.roq; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.jdt.core.search.SearchMatch; | ||
import org.eclipse.jdt.core.search.SearchPattern; | ||
|
||
import com.redhat.qute.commons.datamodel.DataModelParameter; | ||
import com.redhat.qute.commons.datamodel.DataModelTemplate; | ||
import com.redhat.qute.commons.datamodel.DataModelTemplateMatcher; | ||
import com.redhat.qute.jdt.template.datamodel.AbstractDataModelProvider; | ||
import com.redhat.qute.jdt.template.datamodel.SearchContext; | ||
import com.redhat.qute.jdt.utils.JDTTypeUtils; | ||
|
||
/** | ||
* 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, IProgressMonitor monitor) { | ||
if (JDTTypeUtils.findType(context.getJavaProject(), RoqJavaConstants.SITE_CLASS) == null) { | ||
// 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(SearchMatch match, SearchContext context, IProgressMonitor monitor) { | ||
// Do nothing | ||
} | ||
|
||
@Override | ||
protected String[] getPatterns() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected SearchPattern createSearchPattern(String pattern) { | ||
return null; | ||
} | ||
|
||
} |
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
47 changes: 47 additions & 0 deletions
47
...hat.qute.ls/src/main/java/com/redhat/qute/commons/datamodel/DataModelTemplateMatcher.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,47 @@ | ||
/******************************************************************************* | ||
* 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.qute.commons.datamodel; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; | ||
|
||
/** | ||
* Data model template matcher used to inject data parameters with patterns. | ||
*/ | ||
public class DataModelTemplateMatcher { | ||
|
||
private List<String> includes; | ||
|
||
public DataModelTemplateMatcher() { | ||
|
||
} | ||
|
||
public DataModelTemplateMatcher(List<String> includes) { | ||
setIncludes(includes); | ||
} | ||
|
||
public List<String> getIncludes() { | ||
return includes; | ||
} | ||
|
||
public void setIncludes(List<String> includes) { | ||
this.includes = includes; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
ToStringBuilder b = new ToStringBuilder(this); | ||
b.add("includes", this.includes); | ||
return b.toString(); | ||
} | ||
} |
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
69 changes: 69 additions & 0 deletions
69
....ls/src/main/java/com/redhat/qute/project/datamodel/ExtendedDataModelTemplateMatcher.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,69 @@ | ||
/******************************************************************************* | ||
* 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.qute.project.datamodel; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import com.redhat.qute.commons.FileUtils; | ||
import com.redhat.qute.commons.datamodel.DataModelTemplateMatcher; | ||
import com.redhat.qute.settings.PathPatternMatcher; | ||
|
||
/** | ||
* Data model template matcher extension. | ||
*/ | ||
public class ExtendedDataModelTemplateMatcher extends DataModelTemplateMatcher { | ||
|
||
private Boolean anyMatches; | ||
|
||
private List<PathPatternMatcher> includes; | ||
|
||
public ExtendedDataModelTemplateMatcher(List<String> includes) { | ||
super(includes); | ||
} | ||
|
||
public boolean matches(String templateFileUri) { | ||
if (super.getIncludes() == null) { | ||
return false; | ||
} | ||
if (includes == null && anyMatches == null) { | ||
// Compute anyMatches flag or path pattern matcher. | ||
if (super.getIncludes().size() == 1 | ||
&& ("**".equals(super.getIncludes().get(0)) || "**/**".equals(super.getIncludes().get(0)))) { | ||
// To avoid computing path pattern matcher, if pattern is '**' or '**/**' | ||
// we consider that it is an any matches. | ||
anyMatches = true; | ||
} else { | ||
includes = super.getIncludes() // | ||
.stream() // | ||
.map(p -> new PathPatternMatcher(p)) // | ||
.collect(Collectors.toList()); | ||
} | ||
} | ||
|
||
if (anyMatches != null && anyMatches) { | ||
// Pattern is '**' or '**/**' | ||
return true; | ||
} | ||
|
||
// Checks if the template uri matches the includes which defines glob pattern | ||
URI uri = FileUtils.createUri(templateFileUri); | ||
for (PathPatternMatcher include : includes) { | ||
if (include.matches(uri)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
} |
Oops, something went wrong.