Search in sources :

Example 1 with NamespacePart

use of com.redhat.qute.parser.expression.NamespacePart in project quarkus-ls by redhat-developer.

the class QuteDiagnostics method validateExpressionParts.

private ResolvedJavaTypeInfo validateExpressionParts(Parts parts, Section ownerSection, Template template, String projectUri, QuteValidationSettings validationSettings, ResolutionContext resolutionContext, ResolvingJavaTypeContext resolvingJavaTypeContext, List<Diagnostic> diagnostics) {
    ResolvedJavaTypeInfo resolvedJavaType = null;
    String namespace = null;
    for (int i = 0; i < parts.getChildCount(); i++) {
        Part current = parts.getChild(i);
        if (current.isLast()) {
            // It's the last part, check if it is not ended with '.'
            int end = current.getEnd();
            String text = template.getText();
            if (end < text.length()) {
                char c = text.charAt(end);
                if (c == '.') {
                    Range range = QutePositionUtility.createRange(end, end + 1, template);
                    Diagnostic diagnostic = createDiagnostic(range, DiagnosticSeverity.Error, QuteErrorCode.SyntaxError, "Unexpected '.' token.");
                    diagnostics.add(diagnostic);
                }
            }
        }
        switch(current.getPartKind()) {
            case Namespace:
                {
                    NamespacePart namespacePart = (NamespacePart) current;
                    namespace = validateNamespace(namespacePart, projectUri, validationSettings, resolvingJavaTypeContext, diagnostics);
                    if (namespace == null) {
                        // Invalid namespace
                        return null;
                    }
                    break;
                }
            case Object:
                {
                    ObjectPart objectPart = (ObjectPart) current;
                    resolvedJavaType = validateObjectPart(namespace, objectPart, ownerSection, template, projectUri, validationSettings, resolutionContext, diagnostics, resolvingJavaTypeContext);
                    if (resolvedJavaType == null) {
                        // property, method.
                        return null;
                    }
                    break;
                }
            case Method:
            case Property:
                {
                    // java.util.List<org.acme.Item>
                    ResolvedJavaTypeInfo iter = resolvedJavaType;
                    if (resolvedJavaType != null && resolvedJavaType.isIterable() && !resolvedJavaType.isArray()) {
                        // Expression uses iterable type
                        // {@java.util.List<org.acme.Item items>
                        // {items.size()}
                        // Property, method to validate must be done for iterable type (ex :
                        // java.util.List
                        String iterableType = resolvedJavaType.getIterableType();
                        resolvedJavaType = resolveJavaType(iterableType, projectUri, resolvingJavaTypeContext);
                        if (resolvedJavaType == null || isResolvingJavaType(resolvedJavaType)) {
                            // The java type doesn't exists or it is resolving, stop the validation
                            return null;
                        }
                    }
                    resolvedJavaType = validateMemberPart(current, ownerSection, template, projectUri, validationSettings, resolutionContext, resolvedJavaType, iter, diagnostics, resolvingJavaTypeContext);
                    if (resolvedJavaType == null) {
                        // followings property, method.
                        return null;
                    }
                    break;
                }
        }
    }
    return resolvedJavaType;
}
Also used : ObjectPart(com.redhat.qute.parser.expression.ObjectPart) MethodPart(com.redhat.qute.parser.expression.MethodPart) Part(com.redhat.qute.parser.expression.Part) PropertyPart(com.redhat.qute.parser.expression.PropertyPart) ObjectPart(com.redhat.qute.parser.expression.ObjectPart) NamespacePart(com.redhat.qute.parser.expression.NamespacePart) NamespacePart(com.redhat.qute.parser.expression.NamespacePart) ResolvedJavaTypeInfo(com.redhat.qute.commons.ResolvedJavaTypeInfo) DiagnosticDataFactory.createDiagnostic(com.redhat.qute.services.diagnostics.DiagnosticDataFactory.createDiagnostic) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range)

Aggregations

ResolvedJavaTypeInfo (com.redhat.qute.commons.ResolvedJavaTypeInfo)1 MethodPart (com.redhat.qute.parser.expression.MethodPart)1 NamespacePart (com.redhat.qute.parser.expression.NamespacePart)1 ObjectPart (com.redhat.qute.parser.expression.ObjectPart)1 Part (com.redhat.qute.parser.expression.Part)1 PropertyPart (com.redhat.qute.parser.expression.PropertyPart)1 DiagnosticDataFactory.createDiagnostic (com.redhat.qute.services.diagnostics.DiagnosticDataFactory.createDiagnostic)1 Diagnostic (org.eclipse.lsp4j.Diagnostic)1 Range (org.eclipse.lsp4j.Range)1