Skip to content

Commit

Permalink
fix: Qute fragments doesn't work with non inner Templates Java file
Browse files Browse the repository at this point in the history
Fixes #1169

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr authored and fbricon committed Sep 18, 2023
1 parent 870e674 commit db1ab9b
Show file tree
Hide file tree
Showing 19 changed files with 359 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.acme.qute;

import io.quarkus.qute.CheckedTemplate;
import io.quarkus.qute.TemplateInstance;

import java.util.List;

@CheckedTemplate
public class ItemTemplates {

static native TemplateInstance items(List<Item> items);
static native TemplateInstance items$id1(List<Item> items);
static native TemplateInstance items3$id2(List<Item> items);
static native TemplateInstance items3$(List<Item> items);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.acme.qute;

import io.quarkus.qute.CheckedTemplate;
import io.quarkus.qute.TemplateInstance;

import java.util.List;

@CheckedTemplate(ignoreFragments = true)
public class ItemTemplatesIgnoreFragments {

static native TemplateInstance items2(List<Item> items);
static native TemplateInstance items2$id1(List<Item> items);
static native TemplateInstance items2$id2(List<Item> items);
}
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
Expand Down Expand Up @@ -46,6 +47,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -372,6 +374,8 @@ public String getJavadoc(QuteJavadocParams params, IPsiUtils utils, ProgressIndi
}
return getJavadoc(type, params.getDocumentFormat(), params.getMemberName(), params.getSignature(), refinedUtils,
monitor, new HashSet<>());
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
LOGGER.log(Level.WARNING,
"Error while collecting Javadoc for " + params.getSourceType() + "#" + params.getMemberName(), e);
Expand Down Expand Up @@ -431,6 +435,8 @@ private String getJavadoc(PsiClass type, DocumentFormat documentFormat, String m
return javadoc;
}
}
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Error while getting method signature of '" + method.getName() + "'.",
e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
package com.redhat.devtools.intellij.qute.psi.internal.java;

import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VfsUtilCore;
Expand All @@ -31,6 +33,7 @@

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.CancellationException;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -164,6 +167,8 @@ private static boolean isIgnoreFragments(PsiAnnotation checkedTemplateAnnotation
ignoreFragment = AnnotationUtils.getValueAsBoolean(pair);
}
}
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
// Do nothing
}
Expand Down Expand Up @@ -205,6 +210,8 @@ private void collectTemplateLink(PsiElement fieldOrMethod, PsiLiteralValue locat
}
collectTemplateLink(fieldOrMethod, locationAnnotation, type, className, fieldOrMethodName, location,
templateFile, templatePathInfo);
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (RuntimeException e) {
LOGGER.log(Level.WARNING, "Error while creating Qute CodeLens for Java file.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
Expand Down Expand Up @@ -44,6 +46,7 @@
import org.jetbrains.jps.model.java.JavaSourceRootType;

import java.util.Arrays;
import java.util.concurrent.CancellationException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -98,6 +101,8 @@ private static WorkspaceEdit handleMissingField(GenerateMissingJavaMemberParams
PsiClass javaType;
try {
javaType = utils.findClass(project, params.getJavaType());
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
return null;
}
Expand Down Expand Up @@ -130,6 +135,8 @@ private static WorkspaceEdit handleCreateMissingField(GenerateMissingJavaMemberP
Document jdtTextEdit;
try {
jdtTextEdit = cu.getViewProvider().getDocument();
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
return null;
}
Expand Down Expand Up @@ -167,6 +174,8 @@ private static WorkspaceEdit handleUpdatePermissionsOfExistingField(GenerateMiss
Document jdtTextEdit;
try {
jdtTextEdit = cu.getViewProvider().getDocument();
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
return null;
}
Expand All @@ -181,6 +190,8 @@ private static WorkspaceEdit handleCreateMissingGetterCodeAction(GenerateMissing
PsiClass javaType;
try {
javaType = utils.findClass(project, params.getJavaType());
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
return null;
}
Expand Down Expand Up @@ -213,6 +224,8 @@ private static WorkspaceEdit handleCreateMissingGetterCodeAction(GenerateMissing
Document jdtTextEdit;
try {
jdtTextEdit = cu.getViewProvider().getDocument();
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
return null;
}
Expand All @@ -229,6 +242,8 @@ private static WorkspaceEdit handleCreateMissingTemplateExtension(GenerateMissin
PsiClass type = null;
try {
type = utils.findClass(project, params.getTemplateClass());
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
LOGGER.log(Level.WARNING,
String.format("JavaModelException while trying to locate template extension class {0}",
Expand Down Expand Up @@ -275,6 +290,8 @@ private static WorkspaceEdit addTemplateExtensionToFile(GenerateMissingJavaMembe
Document jdtTextEdit;
try {
jdtTextEdit = cu.getViewProvider().getDocument();
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
return null;
}
Expand Down Expand Up @@ -308,6 +325,8 @@ private static WorkspaceEdit createNewTemplateExtensionFile(GenerateMissingJavaM
try {
addContentEdit = createNewTemplateExtensionsContent(cu, name, params.getMissingProperty(),
params.getJavaType(), fixBrokenUri(destPackage.getUrl() + "/" + name + ".java"), utils);
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Failure while constructing new Java file content", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*******************************************************************************/
package com.redhat.devtools.intellij.qute.psi.internal.template;

import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.psi.PsiLiteral;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils;
import org.eclipse.lsp4j.Location;
Expand All @@ -19,6 +21,8 @@
import com.redhat.qute.commons.datamodel.DataModelParameter;
import com.redhat.qute.commons.datamodel.DataModelTemplate;

import java.util.concurrent.CancellationException;

/**
* AST visitor used to collect {@link DataModelParameter} parameter for a given
* {@link DataModelTemplate} template.
Expand Down Expand Up @@ -69,6 +73,8 @@ protected boolean visitParameter(Object paramName, Object paramType) {
literal.getTextLength());
String uri = utils.toUri(getMethod().getContainingFile());
this.location = new Location(uri, range);
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (RuntimeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CancellationException;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.psi.*;
import com.intellij.psi.util.ClassUtil;
import com.redhat.devtools.intellij.qute.psi.internal.resolver.ITypeResolver;
Expand Down Expand Up @@ -101,6 +104,8 @@ private static boolean isIgnoreFragments(PsiAnnotation checkedTemplateAnnotation
ignoreFragment = AnnotationUtils.getValueAsBoolean(pair);
}
}
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
// Do nothing
}
Expand Down Expand Up @@ -198,6 +203,8 @@ public static void collectParameters(PsiMethod method, ITypeResolver typeResolve
}
}

} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
LOGGER.log(Level.WARNING,
"Error while getting method template parameter of '" + method.getName() + "'.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
*******************************************************************************/
package com.redhat.devtools.intellij.qute.psi.internal.template.datamodel;

import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
Expand All @@ -30,6 +32,7 @@
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -136,6 +139,8 @@ private void collectResolversForTemplateData(PsiMember member, String namespace,
resolvers.add(resolver);
}
}
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
LOGGER.log(Level.WARNING,
"Error while getting annotation member value of '" + member.getName() + "'.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CancellationException;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiFile;
Expand Down Expand Up @@ -136,6 +139,8 @@ private static String getLocation(PsiField field) {
if (annotation != null) {
return AnnotationUtils.getAnnotationMemberValue(annotation, "value");
}
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Error while getting @Location of '" + field.getName() + "'.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@


import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.psi.*;
import com.redhat.devtools.intellij.qute.psi.QuteSupportForTemplate;
import com.redhat.devtools.intellij.qute.psi.internal.resolver.ITypeResolver;
Expand Down Expand Up @@ -99,6 +102,8 @@ private void collectResolversForMessage(PsiMethod method, PsiAnnotation messageA
private static PsiAnnotation getMessageBundleAnnotation(PsiClass type) {
try {
return AnnotationUtils.getAnnotation(type, MESSAGE_BUNDLE_ANNOTATION);
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Error while getting @MessageBundle annotation value.", e);
return null;
Expand All @@ -111,6 +116,8 @@ private static String getNamespaceMessage(PsiAnnotation messageBundleAnnotation)
if (messageBundleAnnotation != null) {
namespace = AnnotationUtils.getAnnotationMemberValue(messageBundleAnnotation, VALUE_ANNOTATION_NAME);
}
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Error while getting @MessageBundle#value annotation value.", e);
return null;
Expand All @@ -124,6 +131,8 @@ private static String getLocaleMessage(PsiAnnotation messageBundleAnnotation) {
return AnnotationUtils.getAnnotationMemberValue(messageBundleAnnotation,
MESSAGE_BUNDLE_ANNOTATION_LOCALE);
}
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Error while getting @MessageBundle#locale annotation value.", e);
return null;
Expand All @@ -134,6 +143,8 @@ private static String getLocaleMessage(PsiAnnotation messageBundleAnnotation) {
private static String getMessageContent(PsiAnnotation messageAnnotation) {
try {
return AnnotationUtils.getAnnotationMemberValue(messageAnnotation, VALUE_ANNOTATION_NAME);
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Error while getting @Message#value annotation value.", e);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
*******************************************************************************/
package com.redhat.devtools.intellij.qute.psi.internal.template.resolvedtype;

import java.util.concurrent.CancellationException;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.psi.*;
import com.redhat.qute.commons.InvalidMethodReason;
import com.redhat.qute.commons.ResolvedJavaTypeInfo;
Expand Down Expand Up @@ -74,6 +77,8 @@ protected InvalidMethodReason getValidMethodForQute(PsiMethod method, String typ
if (method.getModifierList().hasExplicitModifier(PsiModifier.STATIC)) {
return InvalidMethodReason.Static;
}
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (RuntimeException e) {
LOGGER.log(Level.WARNING, "Error while checking if '" + method.getName() + "' is valid.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
*******************************************************************************/
package com.redhat.devtools.intellij.qute.psi.template.datamodel;

import java.util.concurrent.CancellationException;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.intellij.lang.ASTNode;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiReference;
Expand Down Expand Up @@ -68,6 +71,8 @@ public void collectDataModel(Object match, SearchContext context, ProgressIndica
try {
// Collect properties from the class name and stop the loop.
processField(field, context, monitor);
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) {
throw e;
} catch (Exception e) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.log(
Expand Down
Loading

0 comments on commit db1ab9b

Please sign in to comment.