Search in sources :

Example 1 with QuteResolvedJavaTypeParams

use of com.redhat.qute.commons.QuteResolvedJavaTypeParams in project quarkus-ls by redhat-developer.

the class QuteProjectRegistry method resolveJavaType.

public CompletableFuture<ResolvedJavaTypeInfo> resolveJavaType(String javaTypeName, String projectUri) {
    CompletableFuture<ResolvedJavaTypeInfo> primitiveType = javaPrimitiveTypes.get(javaTypeName);
    if (primitiveType != null) {
        // It's a primitive type like boolean, double, float, etc
        return primitiveType;
    }
    if (StringUtils.isEmpty(javaTypeName) || StringUtils.isEmpty(projectUri)) {
        return RESOLVED_JAVA_CLASSINFO_NULL_FUTURE;
    }
    QuteProject project = getProject(projectUri);
    if (project == null) {
        return RESOLVED_JAVA_CLASSINFO_NULL_FUTURE;
    }
    CompletableFuture<ResolvedJavaTypeInfo> future = project.getResolvedJavaType(javaTypeName);
    if (future == null || future.isCancelled() || future.isCompletedExceptionally()) {
        QuteResolvedJavaTypeParams params = new QuteResolvedJavaTypeParams(javaTypeName, projectUri);
        future = // 
        getResolvedJavaType(params).thenCompose(c -> {
            if (c != null) {
                // Update members with the resolved class
                c.getFields().forEach(f -> {
                    f.setJavaType(c);
                });
                c.getMethods().forEach(m -> {
                    m.setJavaType(c);
                });
                // Load extended Java types
                if (c.getExtendedTypes() != null) {
                    List<CompletableFuture<ResolvedJavaTypeInfo>> resolvingExtendedFutures = new ArrayList<>();
                    for (String extendedType : c.getExtendedTypes()) {
                        CompletableFuture<ResolvedJavaTypeInfo> extendedFuture = resolveJavaType(extendedType, projectUri);
                        if (!extendedFuture.isDone()) {
                            resolvingExtendedFutures.add(extendedFuture);
                        }
                    }
                    if (!resolvingExtendedFutures.isEmpty()) {
                        CompletableFuture<Void> allFutures = CompletableFuture.allOf(resolvingExtendedFutures.toArray(new CompletableFuture[resolvingExtendedFutures.size()]));
                        return // 
                        allFutures.thenApply(a -> c);
                    }
                }
            }
            return CompletableFuture.completedFuture(c);
        });
        project.registerResolvedJavaType(javaTypeName, future);
    }
    return future;
}
Also used : Template(com.redhat.qute.parser.template.Template) QuteJavaTypesProvider(com.redhat.qute.ls.api.QuteJavaTypesProvider) RESOLVED_JAVA_CLASSINFO_NULL_FUTURE(com.redhat.qute.services.QuteCompletableFutures.RESOLVED_JAVA_CLASSINFO_NULL_FUTURE) MethodValueResolver(com.redhat.qute.project.datamodel.resolvers.MethodValueResolver) JavaFieldInfo(com.redhat.qute.commons.JavaFieldInfo) DataModelProject(com.redhat.qute.commons.datamodel.DataModelProject) StringUtils(com.redhat.qute.utils.StringUtils) ProjectInfo(com.redhat.qute.commons.ProjectInfo) QuteJavaTypesParams(com.redhat.qute.commons.QuteJavaTypesParams) QuteJavaDefinitionProvider(com.redhat.qute.ls.api.QuteJavaDefinitionProvider) ValueResolversRegistry(com.redhat.qute.project.datamodel.resolvers.ValueResolversRegistry) DataModelParameter(com.redhat.qute.commons.datamodel.DataModelParameter) LiteralSupport(com.redhat.qute.parser.template.LiteralSupport) Map(java.util.Map) Location(org.eclipse.lsp4j.Location) QuteUserTagProvider(com.redhat.qute.ls.api.QuteUserTagProvider) METHOD_VALUE_RESOLVERS_NULL_FUTURE(com.redhat.qute.services.QuteCompletableFutures.METHOD_VALUE_RESOLVERS_NULL_FUTURE) UserTagInfo(com.redhat.qute.commons.usertags.UserTagInfo) DataModelTemplate(com.redhat.qute.commons.datamodel.DataModelTemplate) LiteralSupport.getPrimitiveObjectType(com.redhat.qute.parser.template.LiteralSupport.getPrimitiveObjectType) ExtendedDataModelTemplate(com.redhat.qute.project.datamodel.ExtendedDataModelTemplate) JavaTypeInfo(com.redhat.qute.commons.JavaTypeInfo) Set(java.util.Set) QuteResolvedJavaTypeProvider(com.redhat.qute.ls.api.QuteResolvedJavaTypeProvider) List(java.util.List) NAMESPACE_RESOLVER_INFO_NULL_FUTURE(com.redhat.qute.services.QuteCompletableFutures.NAMESPACE_RESOLVER_INFO_NULL_FUTURE) JavaDataModelChangeEvent(com.redhat.qute.commons.datamodel.JavaDataModelChangeEvent) ResolvedJavaTypeInfo(com.redhat.qute.commons.ResolvedJavaTypeInfo) FieldValueResolver(com.redhat.qute.project.datamodel.resolvers.FieldValueResolver) JAVA_ELEMENT_INFO_NULL_FUTURE(com.redhat.qute.services.QuteCompletableFutures.JAVA_ELEMENT_INFO_NULL_FUTURE) JavaElementInfo(com.redhat.qute.commons.JavaElementInfo) ValueResolver(com.redhat.qute.project.datamodel.resolvers.ValueResolver) TypeValueResolver(com.redhat.qute.project.datamodel.resolvers.TypeValueResolver) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) QuteResolvedJavaTypeParams(com.redhat.qute.commons.QuteResolvedJavaTypeParams) QuteDataModelProjectParams(com.redhat.qute.commons.datamodel.QuteDataModelProjectParams) JavaMemberInfo(com.redhat.qute.commons.JavaMemberInfo) NamespaceResolverInfo(com.redhat.qute.commons.datamodel.resolvers.NamespaceResolverInfo) QuteUserTagParams(com.redhat.qute.commons.usertags.QuteUserTagParams) ExtendedDataModelProject(com.redhat.qute.project.datamodel.ExtendedDataModelProject) JavaParameterInfo(com.redhat.qute.commons.JavaParameterInfo) QuteDataModelProjectProvider(com.redhat.qute.ls.api.QuteDataModelProjectProvider) QuteProjectInfoProvider(com.redhat.qute.ls.api.QuteProjectInfoProvider) EXTENDED_TEMPLATE_DATAMODEL_NULL_FUTURE(com.redhat.qute.services.QuteCompletableFutures.EXTENDED_TEMPLATE_DATAMODEL_NULL_FUTURE) Collections(java.util.Collections) JavaMethodInfo(com.redhat.qute.commons.JavaMethodInfo) QuteJavaDefinitionParams(com.redhat.qute.commons.QuteJavaDefinitionParams) QuteResolvedJavaTypeParams(com.redhat.qute.commons.QuteResolvedJavaTypeParams) CompletableFuture(java.util.concurrent.CompletableFuture) ResolvedJavaTypeInfo(com.redhat.qute.commons.ResolvedJavaTypeInfo) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with QuteResolvedJavaTypeParams

use of com.redhat.qute.commons.QuteResolvedJavaTypeParams in project quarkus-ls by redhat-developer.

the class TemplateGetResolvedJavaTypeTest method iterable.

@Test
public void iterable() throws Exception {
    loadMavenProject(QuteMavenProjectName.qute_quickstart);
    QuteResolvedJavaTypeParams params = new QuteResolvedJavaTypeParams("java.lang.Iterable", QuteMavenProjectName.qute_quickstart);
    ResolvedJavaTypeInfo result = QuteSupportForTemplate.getInstance().getResolvedJavaType(params, getJDTUtils(), new NullProgressMonitor());
    Assert.assertEquals("java.lang.Iterable<T>", result.getSignature());
    Assert.assertTrue(result.isIterable());
    Assert.assertEquals("java.lang.Iterable", result.getIterableType());
    Assert.assertEquals("java.lang.Object", result.getIterableOf());
    params = new QuteResolvedJavaTypeParams("Iterable", QuteMavenProjectName.qute_quickstart);
    result = QuteSupportForTemplate.getInstance().getResolvedJavaType(params, getJDTUtils(), new NullProgressMonitor());
    Assert.assertEquals("java.lang.Iterable<T>", result.getSignature());
    Assert.assertTrue(result.isIterable());
    Assert.assertEquals("java.lang.Iterable", result.getIterableType());
    Assert.assertEquals("java.lang.Object", result.getIterableOf());
    params = new QuteResolvedJavaTypeParams("Iterable<String>", QuteMavenProjectName.qute_quickstart);
    result = QuteSupportForTemplate.getInstance().getResolvedJavaType(params, getJDTUtils(), new NullProgressMonitor());
    Assert.assertEquals("java.lang.Iterable<java.lang.String>", result.getSignature());
    Assert.assertTrue(result.isIterable());
    Assert.assertEquals("java.lang.Iterable", result.getIterableType());
    Assert.assertEquals("java.lang.String", result.getIterableOf());
    params = new QuteResolvedJavaTypeParams("Iterable<java.lang.String>", QuteMavenProjectName.qute_quickstart);
    result = QuteSupportForTemplate.getInstance().getResolvedJavaType(params, getJDTUtils(), new NullProgressMonitor());
    Assert.assertEquals("java.lang.Iterable<java.lang.String>", result.getSignature());
    Assert.assertTrue(result.isIterable());
    Assert.assertEquals("java.lang.Iterable", result.getIterableType());
    Assert.assertEquals("java.lang.String", result.getIterableOf());
    params = new QuteResolvedJavaTypeParams("java.lang.Iterable<java.lang.String>", QuteMavenProjectName.qute_quickstart);
    result = QuteSupportForTemplate.getInstance().getResolvedJavaType(params, getJDTUtils(), new NullProgressMonitor());
    Assert.assertEquals("java.lang.Iterable<java.lang.String>", result.getSignature());
    Assert.assertTrue(result.isIterable());
    Assert.assertEquals("java.lang.Iterable", result.getIterableType());
    Assert.assertEquals("java.lang.String", result.getIterableOf());
}
Also used : QuteResolvedJavaTypeParams(com.redhat.qute.commons.QuteResolvedJavaTypeParams) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ResolvedJavaTypeInfo(com.redhat.qute.commons.ResolvedJavaTypeInfo) Test(org.junit.Test)

Example 3 with QuteResolvedJavaTypeParams

use of com.redhat.qute.commons.QuteResolvedJavaTypeParams in project quarkus-ls by redhat-developer.

the class QuteSupportForTemplateDelegateCommandHandler method createQuteResolvedJavaTyeParams.

private static QuteResolvedJavaTypeParams createQuteResolvedJavaTyeParams(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 QuteResolvedJavaTypeParams 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 QuteResolvedJavaTypeParams.projectUri!", commandId));
    }
    String className = getString(obj, CLASS_NAME_ATTR);
    if (className == null) {
        throw new UnsupportedOperationException(String.format("Command '%s' must be called with required QuteResolvedJavaTypeParams.className!", commandId));
    }
    return new QuteResolvedJavaTypeParams(className, projectUri);
}
Also used : QuteResolvedJavaTypeParams(com.redhat.qute.commons.QuteResolvedJavaTypeParams) ArgumentUtils.getString(com.redhat.qute.jdt.internal.ls.ArgumentUtils.getString)

Example 4 with QuteResolvedJavaTypeParams

use of com.redhat.qute.commons.QuteResolvedJavaTypeParams in project quarkus-ls by redhat-developer.

the class TemplateGetResolvedJavaTypeTest method someInterface.

@Test
public void someInterface() throws Exception {
    loadMavenProject(QuteMavenProjectName.qute_quickstart);
    QuteResolvedJavaTypeParams params = new QuteResolvedJavaTypeParams("org.acme.qute.SomeInterface", QuteMavenProjectName.qute_quickstart);
    ResolvedJavaTypeInfo result = QuteSupportForTemplate.getInstance().getResolvedJavaType(params, getJDTUtils(), new NullProgressMonitor());
    Assert.assertEquals("org.acme.qute.SomeInterface", result.getSignature());
    Assert.assertFalse(result.isIterable());
    Assert.assertNotNull(result.getMethods());
    Assert.assertEquals(1, result.getMethods().size());
    Assert.assertEquals("getName() : java.lang.String", result.getMethods().get(0).getSignature());
}
Also used : QuteResolvedJavaTypeParams(com.redhat.qute.commons.QuteResolvedJavaTypeParams) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ResolvedJavaTypeInfo(com.redhat.qute.commons.ResolvedJavaTypeInfo) Test(org.junit.Test)

Example 5 with QuteResolvedJavaTypeParams

use of com.redhat.qute.commons.QuteResolvedJavaTypeParams in project quarkus-ls by redhat-developer.

the class TemplateGetResolvedJavaTypeTest method list.

@Test
public void list() throws Exception {
    loadMavenProject(QuteMavenProjectName.qute_quickstart);
    QuteResolvedJavaTypeParams params = new QuteResolvedJavaTypeParams("java.util.List", QuteMavenProjectName.qute_quickstart);
    ResolvedJavaTypeInfo result = QuteSupportForTemplate.getInstance().getResolvedJavaType(params, getJDTUtils(), new NullProgressMonitor());
    Assert.assertEquals("java.util.List<E>", result.getSignature());
    Assert.assertTrue(result.isIterable());
    Assert.assertEquals("java.util.List", result.getIterableType());
    Assert.assertEquals("java.lang.Object", result.getIterableOf());
    // Invalid method void clear();
    JavaMethodInfo clearMethod = findMethod(result, "clear");
    Assert.assertNull(clearMethod);
    InvalidMethodReason reason = result.getInvalidMethodReason("clear");
    Assert.assertEquals(InvalidMethodReason.VoidReturn, reason);
    params = new QuteResolvedJavaTypeParams("List", QuteMavenProjectName.qute_quickstart);
    result = QuteSupportForTemplate.getInstance().getResolvedJavaType(params, getJDTUtils(), new NullProgressMonitor());
    Assert.assertNull(result);
    params = new QuteResolvedJavaTypeParams("List<String>", QuteMavenProjectName.qute_quickstart);
    Assert.assertNull(result);
    params = new QuteResolvedJavaTypeParams("List<java.lang.String>", QuteMavenProjectName.qute_quickstart);
    result = QuteSupportForTemplate.getInstance().getResolvedJavaType(params, getJDTUtils(), new NullProgressMonitor());
    Assert.assertNull(result);
    params = new QuteResolvedJavaTypeParams("java.util.List<java.lang.String>", QuteMavenProjectName.qute_quickstart);
    result = QuteSupportForTemplate.getInstance().getResolvedJavaType(params, getJDTUtils(), new NullProgressMonitor());
    Assert.assertEquals("java.util.List<java.lang.String>", result.getSignature());
    Assert.assertTrue(result.isIterable());
    Assert.assertEquals("java.util.List", result.getIterableType());
    Assert.assertEquals("java.lang.String", result.getIterableOf());
}
Also used : QuteResolvedJavaTypeParams(com.redhat.qute.commons.QuteResolvedJavaTypeParams) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JavaMethodInfo(com.redhat.qute.commons.JavaMethodInfo) ResolvedJavaTypeInfo(com.redhat.qute.commons.ResolvedJavaTypeInfo) InvalidMethodReason(com.redhat.qute.commons.InvalidMethodReason) Test(org.junit.Test)

Aggregations

QuteResolvedJavaTypeParams (com.redhat.qute.commons.QuteResolvedJavaTypeParams)11 ResolvedJavaTypeInfo (com.redhat.qute.commons.ResolvedJavaTypeInfo)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 Test (org.junit.Test)8 JavaMethodInfo (com.redhat.qute.commons.JavaMethodInfo)5 InvalidMethodReason (com.redhat.qute.commons.InvalidMethodReason)4 JavaElementInfo (com.redhat.qute.commons.JavaElementInfo)1 JavaFieldInfo (com.redhat.qute.commons.JavaFieldInfo)1 JavaMemberInfo (com.redhat.qute.commons.JavaMemberInfo)1 JavaParameterInfo (com.redhat.qute.commons.JavaParameterInfo)1 JavaTypeInfo (com.redhat.qute.commons.JavaTypeInfo)1 ProjectInfo (com.redhat.qute.commons.ProjectInfo)1 QuteJavaDefinitionParams (com.redhat.qute.commons.QuteJavaDefinitionParams)1 QuteJavaTypesParams (com.redhat.qute.commons.QuteJavaTypesParams)1 DataModelParameter (com.redhat.qute.commons.datamodel.DataModelParameter)1 DataModelProject (com.redhat.qute.commons.datamodel.DataModelProject)1 DataModelTemplate (com.redhat.qute.commons.datamodel.DataModelTemplate)1 JavaDataModelChangeEvent (com.redhat.qute.commons.datamodel.JavaDataModelChangeEvent)1 QuteDataModelProjectParams (com.redhat.qute.commons.datamodel.QuteDataModelProjectParams)1 NamespaceResolverInfo (com.redhat.qute.commons.datamodel.resolvers.NamespaceResolverInfo)1