use of com.redhat.qute.commons.JavaTypeInfo 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.JavaTypeInfo 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.commons.JavaTypeInfo in project quarkus-ls by redhat-developer.
the class FieldValueResolver method getJavaTypeInfo.
@Override
public JavaTypeInfo getJavaTypeInfo() {
JavaTypeInfo javaType = super.getJavaTypeInfo();
if (javaType == null && sourceType != null) {
javaType = new JavaTypeInfo();
javaType.setSignature(sourceType);
super.setJavaType(javaType);
}
return javaType;
}
use of com.redhat.qute.commons.JavaTypeInfo in project quarkus-ls by redhat-developer.
the class QuteCompletionsForParameterDeclaration method collectJavaClassesSuggestions.
private CompletableFuture<CompletionList> collectJavaClassesSuggestions(String pattern, boolean hasAlias, boolean closed, JavaTypeRangeOffset rangeOffset, String projectUri, Template template, QuteCompletionSettings completionSettings) {
QuteJavaTypesParams params = new QuteJavaTypesParams(pattern, projectUri);
return //
javaCache.getJavaTypes(params).thenApply(result -> {
if (result == null) {
return null;
}
CompletionList list = new CompletionList();
list.setItems(new ArrayList<>());
Range range = QutePositionUtility.createRange(rangeOffset, template);
for (JavaTypeInfo typeInfo : result) {
String fullClassName = typeInfo.getName();
CompletionItem item = new CompletionItem();
item.setLabel(typeInfo.getSignature());
TextEdit textEdit = new TextEdit();
textEdit.setRange(range);
StringBuilder insertText = new StringBuilder(fullClassName);
if (typeInfo.getJavaTypeKind() == JavaTypeKind.Package) {
item.setKind(CompletionItemKind.Module);
if (rangeOffset.isInGeneric() && !rangeOffset.isGenericClosed()) {
insertText.append('>');
}
} else {
item.setKind(typeInfo.getJavaTypeKind() == JavaTypeKind.Interface ? CompletionItemKind.Interface : CompletionItemKind.Class);
int snippetIndex = 1;
// Generate class
int index = fullClassName.lastIndexOf('.');
String typeName = index != -1 ? fullClassName.substring(index + 1, fullClassName.length()) : fullClassName;
List<JavaParameterInfo> parameters = typeInfo.getTypeParameters();
if (!parameters.isEmpty()) {
insertText.append('<');
for (int i = 0; i < parameters.size(); i++) {
if (i > 0) {
insertText.append(',');
}
String parameterType = parameters.get(i).getType();
if (completionSettings.isCompletionSnippetsSupported()) {
SnippetsBuilder.placeholders(snippetIndex++, parameterType, insertText);
} else {
insertText.append(parameterType);
}
}
insertText.append('>');
} else if (rangeOffset.isInGeneric() && !rangeOffset.isGenericClosed()) {
insertText.append('>');
}
if (!hasAlias) {
insertText.append(' ');
}
// Generate alias
String alias = String.valueOf(typeName.charAt(0)).toLowerCase() + typeName.substring(1, typeName.length());
if (completionSettings.isCompletionSnippetsSupported()) {
item.setInsertTextFormat(InsertTextFormat.Snippet);
if (!hasAlias) {
SnippetsBuilder.placeholders(snippetIndex++, alias, insertText);
if (!closed) {
insertText.append("}");
}
}
// $0
SnippetsBuilder.tabstops(0, insertText);
} else {
item.setInsertTextFormat(InsertTextFormat.PlainText);
if (!hasAlias) {
insertText.append(alias);
if (!closed) {
insertText.append("}");
}
}
}
}
textEdit.setNewText(insertText.toString());
item.setTextEdit(Either.forLeft(textEdit));
list.getItems().add(item);
}
return list;
});
}
use of com.redhat.qute.commons.JavaTypeInfo in project quarkus-ls by redhat-developer.
the class JavaTypesSearch method collectClassesAndInterfaces.
private void collectClassesAndInterfaces(IProgressMonitor monitor, List<JavaTypeInfo> javaTypes) throws JavaModelException {
// Collect classes and interfaces according to the type name
SearchEngine engine = new SearchEngine();
//
engine.searchAllTypeNames(//
packageName == null ? null : packageName.toCharArray(), //
SearchPattern.R_EXACT_MATCH, //
typeName.toCharArray(), //
SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE, //
IJavaSearchConstants.CLASS_AND_INTERFACE, //
scope, new TypeNameMatchRequestor() {
@Override
public void acceptTypeNameMatch(TypeNameMatch match) {
IType type = (IType) match.getType();
String typeSignature = AbstractTypeResolver.resolveJavaTypeSignature(type);
JavaTypeInfo classInfo = new JavaTypeInfo();
classInfo.setSignature(typeSignature);
javaTypes.add(classInfo);
try {
classInfo.setKind(type.isInterface() ? JavaTypeKind.Interface : JavaTypeKind.Class);
} catch (JavaModelException e) {
LOGGER.log(Level.SEVERE, "Error while collecting Java Types for '" + packageName + " package and Java type '" + typeName + "'.", e);
}
}
}, //
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
}
Aggregations