forked from redhat-developer/quarkus-ls
-
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.
Showing
13 changed files
with
287 additions
and
10 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
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(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...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,49 @@ | ||
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; | ||
|
||
public class RoqDataModelProvider extends AbstractDataModelProvider { | ||
|
||
@Override | ||
public void collectDataModel(SearchMatch match, SearchContext context, IProgressMonitor monitor) { | ||
|
||
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 | ||
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
64 changes: 64 additions & 0 deletions
64
....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,64 @@ | ||
/******************************************************************************* | ||
* 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) { | ||
if (super.getIncludes().size() == 1 | ||
&& ("**".equals(super.getIncludes().get(0)) || "**/**".equals(super.getIncludes().get(0)))) { | ||
anyMatches = true; | ||
} else { | ||
includes = super.getIncludes() // | ||
.stream() // | ||
.map(p -> new PathPatternMatcher(p)) // | ||
.collect(Collectors.toList()); | ||
} | ||
} | ||
|
||
if (anyMatches != null && anyMatches) { | ||
return true; | ||
} | ||
|
||
URI uri = FileUtils.createUri(templateFileUri); | ||
for (PathPatternMatcher include : includes) { | ||
if (include.matches(uri)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
} |
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
Oops, something went wrong.