use of com.redhat.qute.parser.template.ParameterDeclaration.JavaTypeRangeOffset 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.JavaTypeRangeOffset in project quarkus-ls by redhat-developer.
the class QuteCompletionsForParameterDeclaration method doCollectJavaClassesSuggestions.
public CompletableFuture<CompletionList> doCollectJavaClassesSuggestions(ParameterDeclaration parameterDeclaration, Template template, int offset, QuteCompletionSettings completionSettings) {
String projectUri = template.getProjectUri();
if (projectUri != null) {
if (parameterDeclaration.isInJavaTypeName(offset)) {
// Completion for java types
JavaTypeRangeOffset rangeOffset = parameterDeclaration.getJavaTypeNameRange(offset);
if (rangeOffset != null) {
boolean hasAlias = parameterDeclaration.hasAlias();
boolean closed = parameterDeclaration.isClosed();
String patternTypeName = template.getText(rangeOffset.getStart(), offset);
return collectJavaClassesSuggestions(patternTypeName, hasAlias, closed, rangeOffset, projectUri, template, completionSettings);
}
}
}
return QuteCompletions.EMPTY_FUTURE_COMPLETION;
}
Aggregations