use of com.redhat.qute.parser.template.ParameterDeclaration in project quarkus-ls by redhat-developer.
the class QuteDefinition method findDefinitionFromPartWithNamespace.
private CompletableFuture<List<? extends LocationLink>> findDefinitionFromPartWithNamespace(String namespace, Part part, Template template) {
String projectUri = template.getProjectUri();
if (NamespacePart.DATA_NAMESPACE.equals(namespace)) {
// {data:it|em}
// check if it is defined in parameter declaration
ParameterDeclaration parameterDeclaration = template.findInParameterDeclarationByAlias(part.getPartName());
if (parameterDeclaration != null) {
String targetUri = template.getUri();
Range targetRange = QutePositionUtility.selectAlias(parameterDeclaration);
Range originSelectionRange = QutePositionUtility.createRange(part);
LocationLink locationLink = new LocationLink(targetUri, targetRange, targetRange, originSelectionRange);
return CompletableFuture.completedFuture(Arrays.asList(locationLink));
}
// check if it is defined with @CheckedTemplate
if (projectUri != null) {
return findDefinitionFromParameterDataModel(part, template, projectUri);
}
return NO_DEFINITION;
}
if (projectUri != null) {
// {config:booleanP|roperty(propertyName)}
return //
javaCache.findJavaElementWithNamespace(namespace, part.getPartName(), projectUri).thenCompose(member -> {
return findDefinitionFromJavaMember(member, part, projectUri);
});
}
return NO_DEFINITION;
}
use of com.redhat.qute.parser.template.ParameterDeclaration in project quarkus-ls by redhat-developer.
the class QuteDiagnostics method validateDataModel.
private void validateDataModel(Node parent, Template template, QuteValidationSettings validationSettings, ResolvingJavaTypeContext resolvingJavaTypeContext, ResolutionContext currentContext, List<Diagnostic> diagnostics) {
ResolutionContext previousContext = currentContext;
List<Node> children = parent.getChildren();
for (Node node : children) {
switch(node.getKind()) {
case ParameterDeclaration:
{
ParameterDeclaration parameter = (ParameterDeclaration) node;
String javaTypeToResolve = parameter.getJavaType();
if (!StringUtils.isEmpty(javaTypeToResolve)) {
String projectUri = template.getProjectUri();
if (projectUri != null) {
List<JavaTypeRangeOffset> classNameRanges = parameter.getJavaTypeNameRanges();
for (RangeOffset classNameRange : classNameRanges) {
String className = template.getText(classNameRange);
ResolvedJavaTypeInfo resolvedJavaType = resolveJavaType(className, projectUri, resolvingJavaTypeContext);
if (resolvedJavaType == null) {
// Java type doesn't exist
Range range = QutePositionUtility.createRange(classNameRange, template);
Diagnostic diagnostic = createDiagnostic(range, DiagnosticSeverity.Error, QuteErrorCode.UnknownType, className);
diagnostics.add(diagnostic);
} else if (!isResolvingJavaType(resolvedJavaType)) {
currentContext.put(javaTypeToResolve, resolvedJavaType);
}
}
}
}
break;
}
case Section:
{
Section section = (Section) node;
if (canChangeContext(section)) {
currentContext = new ResolutionContext(currentContext);
}
List<Parameter> parameters = section.getParameters();
// validate expression parameters
for (Parameter parameter : parameters) {
Expression expression = parameter.getJavaTypeExpression();
if (expression != null) {
ResolvedJavaTypeInfo result = validateExpression(expression, section, template, validationSettings, previousContext, resolvingJavaTypeContext, diagnostics);
switch(section.getSectionKind()) {
case FOR:
case EACH:
String alias = ((LoopSection) section).getAlias();
currentContext.put(alias, result);
break;
case WITH:
currentContext.setWithObject(result);
break;
case LET:
case SET:
currentContext.put(parameter.getName(), result);
break;
default:
}
}
}
switch(section.getSectionKind()) {
case INCLUDE:
validateIncludeSection((IncludeSection) section, diagnostics);
break;
default:
validateSectionTag(section, template, resolvingJavaTypeContext, diagnostics);
}
break;
}
case Expression:
{
validateExpression((Expression) node, null, template, validationSettings, previousContext, resolvingJavaTypeContext, diagnostics);
break;
}
default:
}
validateDataModel(node, template, validationSettings, resolvingJavaTypeContext, currentContext, diagnostics);
}
}
use of com.redhat.qute.parser.template.ParameterDeclaration in project quarkus-ls by redhat-developer.
the class QuteHover method doHoverForExpressionPartWithNamespace.
public CompletableFuture<Hover> doHoverForExpressionPartWithNamespace(String namespace, Part part, Template template, String projectUri, HoverRequest hoverRequest) {
if (NamespacePart.DATA_NAMESPACE.equals(namespace)) {
// {data:it|em}
// check if it is defined in parameter declaration
ParameterDeclaration parameterDeclaration = template.findInParameterDeclarationByAlias(part.getPartName());
if (parameterDeclaration != null) {
return doHoverForJavaType(part, parameterDeclaration.getJavaType(), projectUri, hoverRequest);
}
// check if it is defined with @CheckedTemplate
if (projectUri != null) {
return //
template.getParameterDataModel(part.getPartName()).thenCompose(parameter -> {
if (parameter != null) {
return doHoverForJavaType(part, parameter.getJavaType(), projectUri, hoverRequest);
}
return NO_HOVER;
});
}
return NO_HOVER;
}
if (projectUri != null) {
// {inject:be|an}
return //
javaCache.findJavaElementWithNamespace(namespace, part.getPartName(), projectUri).thenApply(javaElement -> {
if (javaElement == null) {
return null;
}
if (javaElement instanceof JavaTypeInfo) {
return doHoverForJavaType(part, (JavaTypeInfo) javaElement, hoverRequest);
}
JavaMemberInfo member = (JavaMemberInfo) javaElement;
boolean hasMarkdown = hoverRequest.canSupportMarkupKind(MarkupKind.MARKDOWN);
MarkupContent content = DocumentationUtils.getDocumentation(member, null, hasMarkdown);
Range range = QutePositionUtility.createRange(part);
return new Hover(content, range);
});
}
return NO_HOVER;
}
use of com.redhat.qute.parser.template.ParameterDeclaration in project quarkus-ls by redhat-developer.
the class QuteCompletionsForExpression method doCompleteExpressionForObjectPartWithParameterAlias.
private void doCompleteExpressionForObjectPartWithParameterAlias(Template template, Range range, CompletionList list) {
List<String> aliases = //
template.getChildren().stream().filter(//
n -> n.getKind() == NodeKind.ParameterDeclaration).map(//
n -> ((ParameterDeclaration) n).getAlias()).filter(//
alias -> alias != null).collect(Collectors.toList());
for (String alias : aliases) {
CompletionItem item = new CompletionItem();
item.setLabel(alias);
item.setKind(CompletionItemKind.Reference);
TextEdit textEdit = new TextEdit(range, alias);
item.setTextEdit(Either.forLeft(textEdit));
list.getItems().add(item);
}
}
use of com.redhat.qute.parser.template.ParameterDeclaration in project quarkus-ls by redhat-developer.
the class QuteSearchUtils method searchDeclaredObjectInParameterDeclaration.
private static void searchDeclaredObjectInParameterDeclaration(ObjectPart part, BiConsumer<Node, Range> collector) {
String partName = part.getPartName();
ParameterDeclaration parameterDeclaration = part.getOwnerTemplate().findInParameterDeclarationByAlias(partName);
if (parameterDeclaration != null) {
Range targetRange = QutePositionUtility.selectAlias(parameterDeclaration);
collector.accept(parameterDeclaration, targetRange);
}
}
Aggregations