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;
}
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());
}
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);
}
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());
}
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());
}
Aggregations