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.
Fragment support between Java / Template file
See redhat-developer/vscode-quarkus#563 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
906a34f
commit 6df6159
Showing
22 changed files
with
654 additions
and
272 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...om.redhat.qute.jdt/src/main/java/com/redhat/qute/commons/datamodel/DataModelFragment.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,35 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 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 org.eclipse.xtext.xbase.lib.util.ToStringBuilder; | ||
|
||
public class DataModelFragment<T extends DataModelParameter> extends DataModelParameters<T> { | ||
|
||
private String id; | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
ToStringBuilder b = new ToStringBuilder(this); | ||
b.add("id", this.id); | ||
b.add("parameters", this.getParameters()); | ||
return b.toString(); | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
....redhat.qute.jdt/src/main/java/com/redhat/qute/commons/datamodel/DataModelParameters.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,119 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 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.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
public class DataModelParameters<T extends DataModelParameter> { | ||
|
||
private String sourceType; | ||
|
||
private String sourceMethod; | ||
|
||
private List<T> parameters; | ||
|
||
private transient Map<String, T> parametersMap; | ||
|
||
/** | ||
* Returns the Java source type where this data model template is defined. | ||
* | ||
* @return the Java source type where this data model template is defined. | ||
*/ | ||
public String getSourceType() { | ||
return sourceType; | ||
} | ||
|
||
/** | ||
* Set the Java source type where this data model template is defined. | ||
* | ||
* @param sourceType the Java source type where this data model template is | ||
* defined. | ||
*/ | ||
public void setSourceType(String sourceType) { | ||
this.sourceType = sourceType; | ||
} | ||
|
||
/** | ||
* Returns the Java source method where this data model template is defined and | ||
* null otherwise. | ||
* | ||
* @return the Java source method where this data model template is defined and | ||
* null otherwise. | ||
*/ | ||
public String getSourceMethod() { | ||
return sourceMethod; | ||
} | ||
|
||
/** | ||
* Set the Java source method where this data model template is defined and null | ||
* otherwise. | ||
* | ||
* @param sourceMethod the Java source method where this data model template is | ||
* defined and null otherwise. | ||
*/ | ||
public void setSourceMethod(String sourceMethod) { | ||
this.sourceMethod = sourceMethod; | ||
} | ||
|
||
/** | ||
* Returns the list of data model parameters. | ||
* | ||
* @return the list of data model parameters. | ||
*/ | ||
public List<T> getParameters() { | ||
return parameters; | ||
} | ||
|
||
/** | ||
* Set the list of data model parameters. | ||
* | ||
* @param parameters the list of data model parameters. | ||
*/ | ||
public void setParameters(List<T> parameters) { | ||
this.parameters = parameters; | ||
} | ||
|
||
/** | ||
* Returns the parameter from the given key and null otherwise. | ||
* | ||
* @param key the parameter key. | ||
* | ||
* @return the parameter from the given key and null otherwise. | ||
*/ | ||
public T getParameter(String key) { | ||
List<T> parameters = getParameters(); | ||
if (parameters == null) { | ||
return null; | ||
} | ||
return getParametersMap().get(key); | ||
} | ||
|
||
public void addParameter(T parameter) { | ||
if (parameters == null) { | ||
parameters = new ArrayList<>(); | ||
} | ||
parameters.add(parameter); | ||
getParametersMap().put(parameter.getKey(), parameter); | ||
} | ||
|
||
private Map<String, T> getParametersMap() { | ||
if (parametersMap == null) { | ||
parametersMap = parameters.stream() | ||
.collect(Collectors.toMap(DataModelParameter::getKey, Function.identity())); | ||
} | ||
return parametersMap; | ||
} | ||
} |
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.