Search in sources :

Example 1 with JavaMemberInfo

use of com.redhat.qute.commons.JavaMemberInfo in project quarkus-ls by redhat-developer.

the class QuteDiagnostics method validatePropertyPart.

/**
 * Validate the given property part.
 *
 * @param part                     the property part to validate.
 * @param ownerSection             the owner section and null otherwise.
 * @param template                 the template.
 * @param projectUri               the project Uri.
 * @param resolutionContext        the resolution context.
 * @param baseType                 the base object type.
 * @param iterableOfType           the iterable of type.
 * @param diagnostics              the diagnostic list to fill.
 * @param resolvingJavaTypeContext the resolving Java type context.
 *
 * @return the Java type returned by the member part and null otherwise.
 */
private ResolvedJavaTypeInfo validatePropertyPart(PropertyPart part, Section ownerSection, Template template, String projectUri, ResolutionContext resolutionContext, ResolvedJavaTypeInfo resolvedJavaType, ResolvedJavaTypeInfo iterableOfType, List<Diagnostic> diagnostics, ResolvingJavaTypeContext resolvingJavaTypeContext) {
    JavaMemberInfo javaMember = javaCache.findMember(part, resolvedJavaType, projectUri);
    if (javaMember == null) {
        // ex : {@org.acme.Item item}
        // "{item.XXXX}
        Range range = QutePositionUtility.createRange(part);
        Diagnostic diagnostic = createDiagnostic(range, DiagnosticSeverity.Error, QuteErrorCode.UnknownProperty, part.getPartName(), resolvedJavaType.getSignature());
        diagnostics.add(diagnostic);
        return null;
    }
    String memberType = javaMember.resolveJavaElementType(iterableOfType);
    return validateJavaTypePart(part, ownerSection, projectUri, diagnostics, resolvingJavaTypeContext, memberType);
}
Also used : JavaMemberInfo(com.redhat.qute.commons.JavaMemberInfo) DiagnosticDataFactory.createDiagnostic(com.redhat.qute.services.diagnostics.DiagnosticDataFactory.createDiagnostic) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range)

Example 2 with JavaMemberInfo

use of com.redhat.qute.commons.JavaMemberInfo in project quarkus-ls by redhat-developer.

the class QuteDiagnostics method validateObjectPart.

private ResolvedJavaTypeInfo validateObjectPart(String namespace, ObjectPart objectPart, Section ownerSection, Template template, String projectUri, QuteValidationSettings validationSettings, ResolutionContext resolutionContext, List<Diagnostic> diagnostics, ResolvingJavaTypeContext resolvingJavaTypeContext) {
    JavaMemberInfo javaMember = resolutionContext.findMemberWithObject(objectPart.getPartName(), projectUri);
    if (javaMember != null) {
        ResolvedJavaTypeInfo resolvedJavaType = resolveJavaType(javaMember.getJavaElementType(), projectUri, resolvingJavaTypeContext);
        if (isResolvingJavaType(resolvedJavaType)) {
            return null;
        }
        return resolvedJavaType;
    }
    JavaTypeInfoProvider javaTypeInfo = objectPart.resolveJavaType();
    if (javaTypeInfo == null) {
        if (!resolvingJavaTypeContext.isDataModelTemplateResolved()) {
            // The data model is not loaded, ignore the error of undefined object
            return null;
        }
        if (UserTagUtils.isUserTag(template)) {
            // Ignore undefined object diagnostic for user tag
            return null;
        }
        // ex : {item} --> undefined object
        DiagnosticSeverity severity = validationSettings.getUndefinedObject().getDiagnosticSeverity();
        if (severity == null) {
            return null;
        }
        Range range = QutePositionUtility.createRange(objectPart);
        Diagnostic diagnostic = createDiagnostic(range, severity, QuteErrorCode.UndefinedObject, objectPart.getPartName());
        // Create data information helpful for code action
        diagnostic.setData(DiagnosticDataFactory.createUndefinedObjectData(objectPart.getPartName(), ownerSection != null && ownerSection.isIterable()));
        diagnostics.add(diagnostic);
        return null;
    }
    String javaTypeToResolve = javaTypeInfo.getJavaType();
    if (javaTypeToResolve == null) {
        // case of (#for item as data.items) where data.items expression must be
        // evaluated
        Expression expression = javaTypeInfo.getJavaTypeExpression();
        if (expression != null) {
            String literalJavaType = expression.getLiteralJavaType();
            if (literalJavaType != null) {
                javaTypeToResolve = literalJavaType;
            } else {
                Part lastPart = expression.getLastPart();
                if (lastPart != null) {
                    ResolvedJavaTypeInfo alias = javaCache.resolveJavaType(lastPart, projectUri).getNow(RESOLVING_JAVA_TYPE);
                    if (isResolvingJavaType(alias)) {
                        return null;
                    }
                    if (alias == null) {
                        if (!resolvingJavaTypeContext.isDataModelTemplateResolved()) {
                            // The data model is not loaded, don't validate the item of items.
                            return null;
                        }
                    } else {
                        javaTypeToResolve = alias.getSignature();
                    }
                }
            }
        }
    }
    return validateJavaTypePart(objectPart, ownerSection, projectUri, diagnostics, resolvingJavaTypeContext, javaTypeToResolve);
}
Also used : JavaMemberInfo(com.redhat.qute.commons.JavaMemberInfo) JavaTypeInfoProvider(com.redhat.qute.parser.template.JavaTypeInfoProvider) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) Expression(com.redhat.qute.parser.template.Expression) 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) 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)

Example 3 with JavaMemberInfo

use of com.redhat.qute.commons.JavaMemberInfo 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;
}
Also used : JavaMemberInfo(com.redhat.qute.commons.JavaMemberInfo) JavaTypeInfo(com.redhat.qute.commons.JavaTypeInfo) ResolvedJavaTypeInfo(com.redhat.qute.commons.ResolvedJavaTypeInfo) Hover(org.eclipse.lsp4j.Hover) Range(org.eclipse.lsp4j.Range) MarkupContent(org.eclipse.lsp4j.MarkupContent) ParameterDeclaration(com.redhat.qute.parser.template.ParameterDeclaration)

Example 4 with JavaMemberInfo

use of com.redhat.qute.commons.JavaMemberInfo in project quarkus-ls by redhat-developer.

the class QuteHover method doHoverForPropertyPart.

private Hover doHoverForPropertyPart(Part part, String projectUri, ResolvedJavaTypeInfo resolvedType, ResolvedJavaTypeInfo iterableOfResolvedType, HoverRequest hoverRequest) {
    // The Java class type from the previous part had been resolved, resolve the
    // property
    JavaMemberInfo member = javaCache.findMember(part, resolvedType, projectUri);
    if (member == null) {
        return null;
    }
    boolean hasMarkdown = hoverRequest.canSupportMarkupKind(MarkupKind.MARKDOWN);
    MarkupContent content = DocumentationUtils.getDocumentation(member, iterableOfResolvedType, hasMarkdown);
    Range range = QutePositionUtility.createRange(part);
    return new Hover(content, range);
}
Also used : JavaMemberInfo(com.redhat.qute.commons.JavaMemberInfo) Hover(org.eclipse.lsp4j.Hover) Range(org.eclipse.lsp4j.Range) MarkupContent(org.eclipse.lsp4j.MarkupContent)

Example 5 with JavaMemberInfo

use of com.redhat.qute.commons.JavaMemberInfo in project quarkus-ls by redhat-developer.

the class JavaDataModelCache method resolveJavaType.

private CompletionStage<ResolvedJavaTypeInfo> resolveJavaType(Part part, String projectUri, ResolvedJavaTypeInfo resolvedType) {
    JavaMemberInfo member = findMember(part, resolvedType, projectUri);
    if (member == null) {
        return RESOLVED_JAVA_TYPE_INFO_NULL_FUTURE;
    }
    String memberType = member.resolveJavaElementType(resolvedType);
    return resolveJavaType(memberType, projectUri);
}
Also used : JavaMemberInfo(com.redhat.qute.commons.JavaMemberInfo)

Aggregations

JavaMemberInfo (com.redhat.qute.commons.JavaMemberInfo)6 Range (org.eclipse.lsp4j.Range)4 ResolvedJavaTypeInfo (com.redhat.qute.commons.ResolvedJavaTypeInfo)3 DiagnosticDataFactory.createDiagnostic (com.redhat.qute.services.diagnostics.DiagnosticDataFactory.createDiagnostic)2 Diagnostic (org.eclipse.lsp4j.Diagnostic)2 Hover (org.eclipse.lsp4j.Hover)2 MarkupContent (org.eclipse.lsp4j.MarkupContent)2 JavaTypeInfo (com.redhat.qute.commons.JavaTypeInfo)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 Expression (com.redhat.qute.parser.template.Expression)1 JavaTypeInfoProvider (com.redhat.qute.parser.template.JavaTypeInfoProvider)1 ParameterDeclaration (com.redhat.qute.parser.template.ParameterDeclaration)1 DiagnosticSeverity (org.eclipse.lsp4j.DiagnosticSeverity)1