Search in sources :

Example 1 with QuteJavaTypesParams

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;
    });
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) QuteJavaTypesParams(com.redhat.qute.commons.QuteJavaTypesParams) JavaTypeInfo(com.redhat.qute.commons.JavaTypeInfo) CompletionItem(org.eclipse.lsp4j.CompletionItem) TextEdit(org.eclipse.lsp4j.TextEdit) Range(org.eclipse.lsp4j.Range) JavaParameterInfo(com.redhat.qute.commons.JavaParameterInfo)

Example 2 with QuteJavaTypesParams

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));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) QuteJavaTypesParams(com.redhat.qute.commons.QuteJavaTypesParams) JavaTypeInfo(com.redhat.qute.commons.JavaTypeInfo) Test(org.junit.Test)

Example 3 with QuteJavaTypesParams

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));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) QuteJavaTypesParams(com.redhat.qute.commons.QuteJavaTypesParams) JavaTypeInfo(com.redhat.qute.commons.JavaTypeInfo) Test(org.junit.Test)

Example 4 with QuteJavaTypesParams

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));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) QuteJavaTypesParams(com.redhat.qute.commons.QuteJavaTypesParams) JavaTypeInfo(com.redhat.qute.commons.JavaTypeInfo) Test(org.junit.Test)

Example 5 with QuteJavaTypesParams

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);
}
Also used : QuteJavaTypesParams(com.redhat.qute.commons.QuteJavaTypesParams) ArgumentUtils.getString(com.redhat.qute.jdt.internal.ls.ArgumentUtils.getString)

Aggregations

QuteJavaTypesParams (com.redhat.qute.commons.QuteJavaTypesParams)6 JavaTypeInfo (com.redhat.qute.commons.JavaTypeInfo)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 Test (org.junit.Test)4 JavaParameterInfo (com.redhat.qute.commons.JavaParameterInfo)1 ArgumentUtils.getString (com.redhat.qute.jdt.internal.ls.ArgumentUtils.getString)1 CompletionItem (org.eclipse.lsp4j.CompletionItem)1 CompletionList (org.eclipse.lsp4j.CompletionList)1 Range (org.eclipse.lsp4j.Range)1 TextEdit (org.eclipse.lsp4j.TextEdit)1