Skip to content

Commit

Permalink
Provide qute.nativeImages.enabled setting
Browse files Browse the repository at this point in the history
Fixes redhat-developer#629

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed May 1, 2022
1 parent f7ef2e8 commit e482850
Show file tree
Hide file tree
Showing 20 changed files with 440 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class ResolvedJavaTypeInfo extends JavaTypeInfo {

private Boolean isIterable;

private TemplateDataInfo templateData;

/**
* Returns list of extended types.
*
Expand Down Expand Up @@ -178,6 +180,18 @@ private synchronized boolean computeIsIterable() {
return iterable;
}

public TemplateDataInfo getTemplateData() {
return templateData;
}

public void setTemplateData(TemplateDataInfo templateData) {
this.templateData = templateData;
}

public boolean canSupportNativeImages() {
return templateData != null;
}

@Override
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.redhat.qute.commons;

public class TemplateDataInfo {

/**
* If set to true do not automatically analyze superclasses.
*/
private boolean ignoreSuperclasses;

public boolean isIgnoreSuperclasses() {
return ignoreSuperclasses;
}

public void setIgnoreSuperclasses(boolean ignoreSuperclasses) {
this.ignoreSuperclasses = ignoreSuperclasses;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
Expand Down Expand Up @@ -54,19 +55,22 @@
import com.redhat.qute.commons.QuteProjectParams;
import com.redhat.qute.commons.QuteResolvedJavaTypeParams;
import com.redhat.qute.commons.ResolvedJavaTypeInfo;
import com.redhat.qute.commons.TemplateDataInfo;
import com.redhat.qute.commons.datamodel.DataModelParameter;
import com.redhat.qute.commons.datamodel.DataModelProject;
import com.redhat.qute.commons.datamodel.DataModelTemplate;
import com.redhat.qute.commons.datamodel.QuteDataModelProjectParams;
import com.redhat.qute.commons.usertags.QuteUserTagParams;
import com.redhat.qute.commons.usertags.UserTagInfo;
import com.redhat.qute.jdt.internal.QuteJavaConstants;
import com.redhat.qute.jdt.internal.resolver.AbstractTypeResolver;
import com.redhat.qute.jdt.internal.resolver.ClassFileTypeResolver;
import com.redhat.qute.jdt.internal.resolver.CompilationUnitTypeResolver;
import com.redhat.qute.jdt.internal.resolver.ITypeResolver;
import com.redhat.qute.jdt.internal.template.JavaTypesSearch;
import com.redhat.qute.jdt.internal.template.QuarkusIntegrationForQute;
import com.redhat.qute.jdt.internal.template.TemplateDataSupport;
import com.redhat.qute.jdt.utils.AnnotationUtils;
import com.redhat.qute.jdt.utils.IJDTUtils;
import com.redhat.qute.jdt.utils.JDTQuteProjectUtils;

Expand Down Expand Up @@ -420,13 +424,21 @@ public ResolvedJavaTypeInfo getResolvedJavaType(QuteResolvedJavaTypeParams param
extendedTypes.remove(typeName);
}

// Get information about @TemplateData
TemplateDataInfo templateData = null;
IAnnotation templateDataAnnotation = AnnotationUtils.getAnnotation(type, QuteJavaConstants.TEMPLATE_DATA_ANNOTATION);
if (templateDataAnnotation != null) {
templateData = new TemplateDataInfo();
}

ResolvedJavaTypeInfo resolvedType = new ResolvedJavaTypeInfo();
String typeSignature = AbstractTypeResolver.resolveJavaTypeSignature(type);
resolvedType.setSignature(typeSignature);
resolvedType.setFields(fieldsInfo);
resolvedType.setMethods(methodsInfo);
resolvedType.setInvalidMethods(invalidMethods);
resolvedType.setExtendedTypes(extendedTypes);
resolvedType.setTemplateData(templateData);
return resolvedType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class QuteJavaConstants {

public static final String TEMPLATE_EXTENSION_ANNOTATION_MATCH_NAME = "matchName";

public static final String TEMPLATE_DATA_ANNOTATION = "io.quarkus.qute.TemplateData";

public static final String LOCATION_ANNOTATION = "io.quarkus.qute.Location";

public static final String TEMPLATE_CLASS = "io.quarkus.qute.Template";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class ResolvedJavaTypeInfo extends JavaTypeInfo {

private Boolean isIterable;

private TemplateDataInfo templateData;

/**
* Returns list of extended types.
*
Expand Down Expand Up @@ -178,6 +180,18 @@ private synchronized boolean computeIsIterable() {
return iterable;
}

public TemplateDataInfo getTemplateData() {
return templateData;
}

public void setTemplateData(TemplateDataInfo templateData) {
this.templateData = templateData;
}

public boolean canSupportNativeImages() {
return templateData != null;
}

@Override
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.redhat.qute.commons;

public class TemplateDataInfo {

/**
* If set to true do not automatically analyze superclasses.
*/
private boolean ignoreSuperclasses;

public boolean isIgnoreSuperclasses() {
return ignoreSuperclasses;
}

public void setIgnoreSuperclasses(boolean ignoreSuperclasses) {
this.ignoreSuperclasses = ignoreSuperclasses;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public synchronized void updateSettings(Object initializationOptionsSettings) {
// Some inlay hint settings changed, ask the client to refresh all inlay hints.
getLanguageClient().refreshInlayHints();
}
if (result.isValidationSettingsChanged()) {
if (result.isValidationSettingsChanged() || result.isNativeImagesSettingsChanged()) {
// Some validation settings changed
textDocumentService.validationSettingsChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completio
(cancelChecker, template) -> {
return getQuteLanguageService()
.doComplete(template, params.getPosition(), sharedSettings.getCompletionSettings(),
sharedSettings.getFormattingSettings(), cancelChecker) //
sharedSettings.getFormattingSettings(), sharedSettings.getNativeImagesSettings(),
cancelChecker) //
.thenApply(list -> {
return Either.forRight(list);
});
Expand Down Expand Up @@ -283,7 +284,8 @@ private void triggerValidationFor(QuteTextDocument document) {
ResolvingJavaTypeContext resolvingJavaTypeContext = new ResolvingJavaTypeContext(template,
quteLanguageServer.getDataModelCache());
List<Diagnostic> diagnostics = getQuteLanguageService().doDiagnostics(template,
getSharedSettings().getValidationSettings(template.getUri()), resolvingJavaTypeContext,
getSharedSettings().getValidationSettings(template.getUri()),
getSharedSettings().getNativeImagesSettings(), resolvingJavaTypeContext,
() -> template.checkCanceled());

// Diagnostics has been collected, before diagnostics publishing, check if the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class JavaMemberResult {
private JavaMemberInfo member;
private boolean matchParameters;
private boolean matchVirtualMethod;
private boolean supportNativeImages;

/**
* Returns the Java member which matches the part name and null otherwise.
Expand Down Expand Up @@ -87,4 +88,11 @@ public void setMatchVirtualMethod(boolean matchVirtualMethod) {
this.matchVirtualMethod = matchVirtualMethod;
}

public boolean isSupportNativeImages() {
return supportNativeImages;
}

public void setSupportNativeImages(boolean supportNativeImages) {
this.supportNativeImages = supportNativeImages;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,14 @@ private CompletableFuture<List<MethodValueResolver>> getMethodValueResolvers(Str
public CompletableFuture<ExtendedDataModelTemplate> getDataModelTemplate(Template template) {
String projectUri = template.getProjectUri();
if (StringUtils.isEmpty(projectUri)) {
// The project uri is not already get (it occurs when Qute template is opened and the project information takes some times).
// The project uri is not already get (it occurs when Qute template is opened
// and the project information takes some times).
// Load the project information and call the data model.
return template.getProjectFuture() //
.thenCompose(project -> {
if (project == null) {
return null;
}
return getDataModelTemplate(template, project.getUri());
});
}
Expand Down Expand Up @@ -350,6 +354,32 @@ public JavaMemberInfo findMember(ResolvedJavaTypeInfo baseType, String property,
if (baseType == null) {
return null;
}
JavaMemberInfo member = findWithJavaReflection(baseType, property, projectUri);
if (member != null) {
return member;
}
return findValueResolver(baseType, property, projectUri);
}

public JavaMemberResult findProperty(ResolvedJavaTypeInfo baseType, String property,
String projectUri) {
JavaMemberResult result = new JavaMemberResult();

JavaMemberInfo member = findValueResolver(baseType, property, projectUri);
if (member != null) {
result.setMember(member);
return result;
}
member = findWithJavaReflection(baseType, property, projectUri);
if (member != null) {
result.setSupportNativeImages(baseType.canSupportNativeImages());
result.setMember(member);
return result;
}
return result;
}

public JavaMemberInfo findWithJavaReflection(ResolvedJavaTypeInfo baseType, String property, String projectUri) {
if (baseType.isIterable() && !baseType.isArray()) {
// Expression uses iterable type
// {@java.util.List<org.acme.Item items>
Expand Down Expand Up @@ -382,13 +412,7 @@ public JavaMemberInfo findMember(ResolvedJavaTypeInfo baseType, String property,
}
}
}
// Search in value resolver
String literalType = LiteralSupport.getLiteralJavaType(property);
if (literalType != null) {
// ex : @java.lang.Integer(base : T[]) : T (see qute-resolvers.jsonc)
property = "@" + literalType;
}
return findValueResolver(property, baseType, projectUri);
return null;
}

/**
Expand Down Expand Up @@ -623,9 +647,14 @@ private static boolean isEmpty(String value) {
return value == null || value.isEmpty();
}

public MethodValueResolver findValueResolver(String property, ResolvedJavaTypeInfo resolvedType,
String projectUri) {
List<MethodValueResolver> resolvers = getResolversFor(resolvedType, projectUri);
public MethodValueResolver findValueResolver(ResolvedJavaTypeInfo baseType, String property, String projectUri) {
// Search in value resolver
String literalType = LiteralSupport.getLiteralJavaType(property);
if (literalType != null) {
// ex : @java.lang.Integer(base : T[]) : T (see qute-resolvers.jsonc)
property = "@" + literalType;
}
List<MethodValueResolver> resolvers = getResolversFor(baseType, projectUri);
for (MethodValueResolver resolver : resolvers) {
if (isMatchMethod(resolver, property)) {
return resolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ public JavaMemberInfo findMember(ResolvedJavaTypeInfo baseType, String property,
return projectRegistry.findMember(baseType, property, projectUri);
}

public JavaMemberResult findProperty(Part part, ResolvedJavaTypeInfo baseType, String projectUri) {
return projectRegistry.findProperty(baseType, part.getPartName(), projectUri);
}

public boolean hasNamespace(String namespace, String projectUri) {
return projectRegistry.hasNamespace(namespace, projectUri);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.redhat.qute.services.completions.QuteCompletionsForSnippets;
import com.redhat.qute.settings.QuteCompletionSettings;
import com.redhat.qute.settings.QuteFormattingSettings;
import com.redhat.qute.settings.QuteNativeImagesSettings;

/**
* The Qute completions
Expand Down Expand Up @@ -74,16 +75,17 @@ public QuteCompletions(JavaDataModelCache javaCache, SnippetRegistryProvider<Sni
/**
* Returns completion list for the given position
*
* @param template the Qute template
* @param position the position where completion was triggered
* @param completionSettings the completion settings.
* @param formattingSettings the formatting settings.
* @param cancelChecker the cancel checker
* @param template the Qute template
* @param position the position where completion was triggered
* @param completionSettings the completion settings.
* @param formattingSettings the formatting settings.
* @param nativeImagesSettings the native image settings.
* @param cancelChecker the cancel checker
* @return completion list for the given position
*/
public CompletableFuture<CompletionList> doComplete(Template template, Position position,
QuteCompletionSettings completionSettings, QuteFormattingSettings formattingSettings,
CancelChecker cancelChecker) {
QuteNativeImagesSettings nativeImagesSettings, CancelChecker cancelChecker) {
CompletionRequest completionRequest = null;
try {
completionRequest = new CompletionRequest(template, position, completionSettings, formattingSettings);
Expand Down Expand Up @@ -112,7 +114,7 @@ public CompletableFuture<CompletionList> doComplete(Template template, Position
expression = ((Part) node).getParent().getParent();
}
return completionForExpression.doCompleteExpression(completionRequest, expression, nodeExpression, template,
offset, completionSettings, formattingSettings, cancelChecker);
offset, completionSettings, formattingSettings, nativeImagesSettings, cancelChecker);
} else if (node.getKind() == NodeKind.Text) {
// The completion is triggered in text node (before node)
Section parent = node.getParentSection();
Expand Down Expand Up @@ -149,7 +151,7 @@ public CompletableFuture<CompletionList> doComplete(Template template, Position
if (nbBrackets % 2 != 0) {
// The completion is triggered in text node after bracket '{' character
return completionForExpression.doCompleteExpression(completionRequest, null, node, template, offset,
completionSettings, formattingSettings, cancelChecker);
completionSettings, formattingSettings, nativeImagesSettings, cancelChecker);
}
return EMPTY_FUTURE_COMPLETION;
}
Expand All @@ -165,7 +167,7 @@ public CompletableFuture<CompletionList> doComplete(Template template, Position
if (parameter.isAfterAssign(offset)) {
// {# let name=|
return completionForExpression.doCompleteExpression(completionRequest, null, null, template, offset,
completionSettings, formattingSettings, cancelChecker);
completionSettings, formattingSettings, nativeImagesSettings, cancelChecker);
}
}
return collectSnippetSuggestions(completionRequest);
Expand Down
Loading

0 comments on commit e482850

Please sign in to comment.