use of com.redhat.qute.parser.template.JavaTypeInfoProvider 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.parser.template.JavaTypeInfoProvider in project quarkus-ls by redhat-developer.
the class JavaDataModelCache method resolveJavaType.
private CompletableFuture<ResolvedJavaTypeInfo> resolveJavaType(ObjectPart objectPart, String projectUri, boolean nullIfDontMatchWithIterable) {
CompletableFuture<ResolvedJavaTypeInfo> future = null;
JavaTypeInfoProvider javaTypeInfo = objectPart.resolveJavaType();
if (javaTypeInfo == null) {
return RESOLVED_JAVA_TYPE_INFO_NULL_FUTURE;
}
String javaType = javaTypeInfo.getJavaType();
if (StringUtils.isEmpty(javaType)) {
Expression expression = javaTypeInfo.getJavaTypeExpression();
if (expression != null) {
String literalJavaType = expression.getLiteralJavaType();
if (literalJavaType != null) {
future = resolveJavaType(literalJavaType, projectUri);
} else {
Part lastPart = expression.getLastPart();
if (lastPart == null) {
return RESOLVED_JAVA_TYPE_INFO_NULL_FUTURE;
}
future = resolveJavaType(lastPart, projectUri);
}
}
}
if (future == null) {
future = resolveJavaType(javaType, projectUri);
}
Node node = javaTypeInfo.getJavaTypeOwnerNode();
Section section = getOwnerSection(node);
if (section != null) {
if (section.isIterable()) {
future = //
future.thenCompose(resolvedType -> {
if (resolvedType == null) {
return RESOLVED_JAVA_TYPE_INFO_NULL_FUTURE;
}
if (!resolvedType.isIterable()) {
if (resolvedType.isInteger()) {
// {/for}
return resolveJavaType(resolvedType.getName(), projectUri);
}
if (nullIfDontMatchWithIterable) {
// {item.|}
return RESOLVED_JAVA_TYPE_INFO_NULL_FUTURE;
}
}
// valid case
// Ex:
// {@java.util.List<org.acme.Item> items}
// {#for item in items}
// {item.|}
// Here
// - resolvedType = java.util.List<org.acme.Item>
// - iterTypeName = org.acme.Item
// Resolve org.acme.Item
String iterTypeName = resolvedType.getIterableOf();
return resolveJavaType(iterTypeName, projectUri);
});
}
}
return future;
}
use of com.redhat.qute.parser.template.JavaTypeInfoProvider in project quarkus-ls by redhat-developer.
the class ObjectPart method resolveJavaType.
public JavaTypeInfoProvider resolveJavaType() {
Template template = super.getOwnerTemplate();
String partName = getPartName();
boolean hasNamespace = getNamespace() != null;
if (hasNamespace) {
// ex : {data:item}
return template.findWithNamespace(this);
}
// ex : {item}
// Loop for parent section to discover the class name
Section section = super.getParentSection();
while (section != null) {
switch(section.getSectionKind()) {
case EACH:
case FOR:
LoopSection iterableSection = (LoopSection) section;
if (!iterableSection.isInElseBlock(getStart())) {
String alias = iterableSection.getAlias();
if (partName.equals(alias)) {
return iterableSection.getIterableParameter();
}
}
break;
case LET:
case SET:
List<Parameter> parameters = section.getParameters();
for (Parameter parameter : parameters) {
if (partName.equals(parameter.getName())) {
return parameter;
}
}
break;
default:
}
// ex : count for #each
JavaTypeInfoProvider metadata = section.getMetadata(partName);
if (metadata != null) {
return metadata;
}
section = section.getParentSection();
}
// - from @CheckedTemplate
return template.findInInitialDataModel(this);
}
use of com.redhat.qute.parser.template.JavaTypeInfoProvider in project quarkus-ls by redhat-developer.
the class QuteSearchUtils method tryToCollectObjectPartOrParameter.
public static void tryToCollectObjectPartOrParameter(String partName, PartNameMatcher matcher, Expression expression, Node ownerNode, BiConsumer<Node, Range> collector) {
// object part)
if (!tryToCollectObjectParts(partName, matcher, expression, collector)) {
if (ownerNode.getKind() == NodeKind.Section) {
Section onwerSection = (Section) ownerNode;
// Check the current expression references a metadata of the section
ObjectPart objectPart = expression.getObjectPart();
if (objectPart != null) {
JavaTypeInfoProvider metadata = onwerSection.getMetadata(objectPart.getPartName());
if (metadata != null) {
// Adjust the object part range with the given part name
// Example if expression is like {item_count}
// Range should be {|item|_count}
Range range = QutePositionUtility.createRange(objectPart.getStart(), objectPart.getStart() + partName.length(), objectPart.getOwnerTemplate());
collector.accept(objectPart, range);
}
}
}
}
}
Aggregations