Search in sources :

Example 6 with JavaMemberInfo

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

the class QuteProjectRegistry method findMember.

/**
 * Returns the Java member (field or method) from the given Java base type with
 * the given property and null otherwise.
 *
 * @param baseType   the Java base type.
 * @param property   the member property (field name or getter method name).
 * @param projectUri the project Uri used to search in the extended Java type.
 * @return the Java member (field or method) from the given Java base type with
 *         the given property and null otherwise.
 */
public JavaMemberInfo findMember(ResolvedJavaTypeInfo baseType, String property, String projectUri) {
    if (baseType == null) {
        return null;
    }
    if (baseType.isIterable() && !baseType.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 = baseType.getIterableType();
        baseType = resolveJavaType(iterableType, projectUri).getNow(null);
        if (baseType == null) {
            // The java type doesn't exists or it is resolving, stop the validation
            return null;
        }
    }
    // Search in the java root type
    JavaMemberInfo memberInfo = findMember(baseType, property);
    if (memberInfo != null) {
        return memberInfo;
    }
    if (baseType.getExtendedTypes() != null) {
        // Search in extended types
        for (String superType : baseType.getExtendedTypes()) {
            ResolvedJavaTypeInfo resolvedSuperType = resolveJavaType(superType, projectUri).getNow(null);
            if (resolvedSuperType != null) {
                JavaMemberInfo superMemberInfo = findMember(resolvedSuperType, property, projectUri);
                if (superMemberInfo != null) {
                    return superMemberInfo;
                }
            }
        }
    }
    // Search in value resolver
    String literalType = LiteralSupport.getLiteralJavaType(property);
    if (literalType != null) {
        // ex : @java.lang.Integer(base : T[]) : T (see qute-resolvers.jsonc)
        property = "@" + literalType;
    }
    return findValueResolver(property, baseType, projectUri);
}
Also used : JavaMemberInfo(com.redhat.qute.commons.JavaMemberInfo) ResolvedJavaTypeInfo(com.redhat.qute.commons.ResolvedJavaTypeInfo)

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