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);
}
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);
}
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;
}
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);
}
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);
}
Aggregations