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 2, 2022
1 parent f7ef2e8 commit 8bfdfd3
Show file tree
Hide file tree
Showing 20 changed files with 800 additions and 176 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 List<TemplateDataAnnotation> templateDataAnnotations;

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

/**
* Set the list of '@io.quarkus.qute.TemplateData' annotations for the Java
* type.
*
* @param templateDataAnnotations the list of '@io.quarkus.qute.TemplateData'
* annotations for the Java type.
*/
public void setTemplateDataAnnotations(List<TemplateDataAnnotation> templateDataAnnotations) {
this.templateDataAnnotations = templateDataAnnotations;
}

/**
* Returns the list of '@io.quarkus.qute.TemplateData' annotations for the Java
* type.
*
* @return the list of '@io.quarkus.qute.TemplateData' annotations for the Java
* type.
*/
public List<TemplateDataAnnotation> getTemplateDataAnnotations() {
return templateDataAnnotations;
}

@Override
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
b.add("name", this.getName());
b.add("signature", this.getSignature());
b.add("iterableOf", this.getIterableOf());
b.add("iterableType", this.getIterableType());
b.add("templateDataAnnotations", this.getTemplateDataAnnotations());
return b.toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*******************************************************************************
* Copyright (c) 2021 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.qute.commons;

import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;

/**
* '@io.quarkus.qute.TemplateData' annotation.
*
* @author Angelo ZERR
*
*/
public class TemplateDataAnnotation {

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

public boolean isIgnoreSuperclasses() {
return ignoreSuperclasses != null && ignoreSuperclasses.booleanValue();
}

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

@Override
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
b.add("ignoreSuperclasses", this.isIgnoreSuperclasses());
return b.toString();
}
}
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.TemplateDataAnnotation;
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 @@ -352,7 +356,11 @@ public ResolvedJavaTypeInfo getResolvedJavaType(QuteResolvedJavaTypeParams param

ITypeResolver typeResolver = createTypeResolver(type);

// 1) Collect fields
// 1) Collect annotations
// - @TemplateData
List<TemplateDataAnnotation> templateDataAnnotations = collectTemplateDataAnnotations(type);

// 2) Collect fields
List<JavaFieldInfo> fieldsInfo = new ArrayList<>();

// Standard fields
Expand All @@ -376,7 +384,7 @@ public ResolvedJavaTypeInfo getResolvedJavaType(QuteResolvedJavaTypeParams param
}
}

// 2) Collect methods
// 3) Collect methods
List<JavaMethodInfo> methodsInfo = new ArrayList<>();
Map<String, InvalidMethodReason> invalidMethods = new HashMap<>();
IMethod[] methods = type.getMethods();
Expand Down Expand Up @@ -409,7 +417,7 @@ public ResolvedJavaTypeInfo getResolvedJavaType(QuteResolvedJavaTypeParams param
}
} else {
// ex : String implements CharSequence, ....
ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(monitor);
ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(monitor);
IType[] allSuperTypes = typeHierarchy.getSupertypes(type);
extendedTypes = Stream.of(allSuperTypes) //
.map(superType -> superType.getFullyQualifiedName()) //
Expand All @@ -427,9 +435,35 @@ public ResolvedJavaTypeInfo getResolvedJavaType(QuteResolvedJavaTypeParams param
resolvedType.setMethods(methodsInfo);
resolvedType.setInvalidMethods(invalidMethods);
resolvedType.setExtendedTypes(extendedTypes);
resolvedType.setTemplateDataAnnotations(templateDataAnnotations);
return resolvedType;
}

private static List<TemplateDataAnnotation> collectTemplateDataAnnotations(IType type) throws JavaModelException {
List<TemplateDataAnnotation> templateDataAnnotations = null;
IAnnotation[] annotations = type.getAnnotations();
for (IAnnotation annotation : annotations) {
if (AnnotationUtils.isMatchAnnotation(annotation, QuteJavaConstants.TEMPLATE_DATA_ANNOTATION)) {
if (templateDataAnnotations == null) {
templateDataAnnotations = new ArrayList<>();
}
templateDataAnnotations.add(createTemplateData(annotation));
}
}
return templateDataAnnotations;
}

private static TemplateDataAnnotation createTemplateData(IAnnotation templateDataAnnotation)
throws JavaModelException {
TemplateDataAnnotation templateData = new TemplateDataAnnotation();
String ignoreSuperclasses = AnnotationUtils.getAnnotationMemberValue(templateDataAnnotation,
QuteJavaConstants.TEMPLATE_DATA_ANNOTATION_IGNORE_SUPER_CLASSES);
if ("true".equals(ignoreSuperclasses)) {
templateData.setIgnoreSuperclasses(Boolean.TRUE);
}
return templateData;
}

private String getFullQualifiedName(IProgressMonitor monitor, IJavaProject javaProject, String name)
throws JavaModelException {
if (name.indexOf('.') != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,32 @@ public class QuteJavaConstants {

public static final String JAVAX_INJECT_NAMED_ANNOTATION = "javax.inject.Named";

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

public static final String TEMPLATE_CLASS = "io.quarkus.qute.Template";

public static final String ENGINE_BUILDER_CLASS = "io.quarkus.qute.EngineBuilder";

public static final String VALUE_ANNOTATION_NAME = "value";

// @CheckedTemplate

public static final String CHECKED_TEMPLATE_ANNOTATION = "io.quarkus.qute.CheckedTemplate";

public static final String OLD_CHECKED_TEMPLATE_ANNOTATION = "io.quarkus.qute.api.CheckedTemplate";

// @TemplateExtension

public static final String TEMPLATE_EXTENSION_ANNOTATION = "io.quarkus.qute.TemplateExtension";

public static final String TEMPLATE_EXTENSION_ANNOTATION_NAMESPACE = "namespace";

public static final String TEMPLATE_EXTENSION_ANNOTATION_MATCH_NAME = "matchName";

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

public static final String TEMPLATE_CLASS = "io.quarkus.qute.Template";
// @TemplateData

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

public static final String TEMPLATE_DATA_ANNOTATION_IGNORE_SUPER_CLASSES = "ignoreSuperclasses";

public static final String VALUE_ANNOTATION_NAME = "value";
}
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 List<TemplateDataAnnotation> templateDataAnnotations;

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

/**
* Set the list of '@io.quarkus.qute.TemplateData' annotations for the Java
* type.
*
* @param templateDataAnnotations the list of '@io.quarkus.qute.TemplateData'
* annotations for the Java type.
*/
public void setTemplateDataAnnotations(List<TemplateDataAnnotation> templateDataAnnotations) {
this.templateDataAnnotations = templateDataAnnotations;
}

/**
* Returns the list of '@io.quarkus.qute.TemplateData' annotations for the Java
* type.
*
* @return the list of '@io.quarkus.qute.TemplateData' annotations for the Java
* type.
*/
public List<TemplateDataAnnotation> getTemplateDataAnnotations() {
return templateDataAnnotations;
}

@Override
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
b.add("name", this.getName());
b.add("signature", this.getSignature());
b.add("iterableOf", this.getIterableOf());
b.add("iterableType", this.getIterableType());
b.add("templateDataAnnotations", this.getTemplateDataAnnotations());
return b.toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*******************************************************************************
* Copyright (c) 2021 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.qute.commons;

import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;

/**
* '@io.quarkus.qute.TemplateData' annotation.
*
* @author Angelo ZERR
*
*/
public class TemplateDataAnnotation {

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

public boolean isIgnoreSuperclasses() {
return ignoreSuperclasses != null && ignoreSuperclasses.booleanValue();
}

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

@Override
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
b.add("ignoreSuperclasses", this.isIgnoreSuperclasses());
return b.toString();
}
}
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
Loading

0 comments on commit 8bfdfd3

Please sign in to comment.