use of com.redhat.qute.commons.QuteJavaTypesParams 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.QuteJavaTypesParams in project quarkus-ls by redhat-developer.
the class TemplateGetJavaTypeTest method item.
@Test
public void item() throws Exception {
loadMavenProject(QuteMavenProjectName.qute_quickstart);
QuteJavaTypesParams params = new QuteJavaTypesParams("Item", QuteMavenProjectName.qute_quickstart);
List<JavaTypeInfo> actual = QuteSupportForTemplate.getInstance().getJavaTypes(params, getJDTUtils(), new NullProgressMonitor());
assertJavaTypes(//
actual, //
t("org.acme.qute.Item", JavaTypeKind.Class), t("org.acme.qute.ItemResource", JavaTypeKind.Class));
}
use of com.redhat.qute.commons.QuteJavaTypesParams in project quarkus-ls by redhat-developer.
the class TemplateGetJavaTypeTest method packages.
@Test
public void packages() throws Exception {
loadMavenProject(QuteMavenProjectName.qute_quickstart);
QuteJavaTypesParams params = new QuteJavaTypesParams("java.", QuteMavenProjectName.qute_quickstart);
List<JavaTypeInfo> actual = QuteSupportForTemplate.getInstance().getJavaTypes(params, getJDTUtils(), new NullProgressMonitor());
assertJavaTypes(//
actual, //
t("java.util", JavaTypeKind.Package), t("java.lang", JavaTypeKind.Package));
}
use of com.redhat.qute.commons.QuteJavaTypesParams in project quarkus-ls by redhat-developer.
the class TemplateGetJavaTypeTest method list.
@Test
public void list() throws Exception {
loadMavenProject(QuteMavenProjectName.qute_quickstart);
QuteJavaTypesParams params = new QuteJavaTypesParams("List", QuteMavenProjectName.qute_quickstart);
List<JavaTypeInfo> actual = QuteSupportForTemplate.getInstance().getJavaTypes(params, getJDTUtils(), new NullProgressMonitor());
assertJavaTypes(//
actual, t("java.util.List<E>", JavaTypeKind.Interface));
}
use of com.redhat.qute.commons.QuteJavaTypesParams in project quarkus-ls by redhat-developer.
the class QuteSupportForTemplateDelegateCommandHandler method createQuteJavaTypesParams.
private static QuteJavaTypesParams createQuteJavaTypesParams(List<Object> arguments, String commandId) {
Map<String, Object> obj = getFirst(arguments);
if (obj == null) {
throw new UnsupportedOperationException(String.format("Command '%s' must be called with one QuteJavaTypesParams argument!", commandId));
}
// Get project name from the java file URI
String projectUri = getString(obj, PROJECT_URI_ATTR);
if (projectUri == null) {
throw new UnsupportedOperationException(String.format("Command '%s' must be called with required QuteJavaTypesParams.projectUri!", commandId));
}
String pattern = getString(obj, PATTERN_ATTR);
if (pattern == null) {
throw new UnsupportedOperationException(String.format("Command '%s' must be called with required QuteJavaTypesParams.pattern!", commandId));
}
return new QuteJavaTypesParams(pattern, projectUri);
}
Aggregations