use of com.redhat.qute.parser.template.SectionKind in project quarkus-ls by redhat-developer.
the class QuteTemplateIndex method collect.
private void collect(String template, List<QuteIndex> indexes) {
Scanner<TokenType, ScannerState> scanner = TemplateScanner.createScanner(template);
TokenType token = scanner.scan();
String lastTag = null;
int lastTokenOffset = -1;
SectionKind lastSectionKind = null;
while (token != TokenType.EOS) {
switch(token) {
case StartTag:
{
String tag = scanner.getTokenText();
if (SectionKind.INCLUDE.name().toLowerCase().equals(tag)) {
lastTag = tag;
lastTokenOffset = scanner.getTokenOffset();
lastSectionKind = SectionKind.INCLUDE;
} else if (SectionKind.INSERT.name().toLowerCase().equals(tag)) {
lastTag = tag;
lastTokenOffset = scanner.getTokenOffset();
lastSectionKind = SectionKind.INSERT;
} else if (isCustomTag(tag)) {
collectIndex(scanner.getTokenOffset(), SectionKind.CUSTOM, scanner.getTokenText(), null, template, indexes);
}
break;
}
case ParameterTag:
{
if (lastSectionKind != null) {
String parameter = scanner.getTokenText();
collectIndex(scanner.getTokenOffset(), lastSectionKind, lastTag, parameter, template, indexes);
lastTokenOffset = -1;
lastSectionKind = null;
lastTag = null;
}
break;
}
case Whitespace:
{
break;
}
default:
if (lastSectionKind != null) {
collectIndex(lastTokenOffset, lastSectionKind, lastTag, null, template, indexes);
lastTokenOffset = -1;
lastSectionKind = null;
lastTag = null;
}
}
token = scanner.scan();
}
}
use of com.redhat.qute.parser.template.SectionKind in project quarkus-ls by redhat-developer.
the class QuteDiagnostics method validateSectionTag.
private static void validateSectionTag(Section section, Template template, ResolvingJavaTypeContext resolvingJavaTypeContext, List<Diagnostic> diagnostics) {
String tagName = section.getTag();
if (StringUtils.isEmpty(tagName)) {
return;
}
SectionKind sectionKind = section.getSectionKind();
if (sectionKind == SectionKind.CUSTOM) {
if (!resolvingJavaTypeContext.isBinaryUserTagResolved()) {
// Don't validate custom tag, if the binary user tags are not loaded.
return;
}
QuteProject project = template.getProject();
if (project != null) {
// Check if section tag is an user tag
UserTag userTag = project.findUserTag(tagName);
if (userTag != null) {
return;
}
// Check if section tag is a parameter from an include section
Node parent = section.getParent();
while (parent != null) {
if (parent.getKind() == NodeKind.Section) {
Section parentSection = (Section) parent;
if (parentSection.getSectionKind() == SectionKind.INCLUDE) {
IncludeSection includeSection = (IncludeSection) parentSection;
List<QuteIndex> indexes = project.findInsertTagParameter(includeSection.getReferencedTemplateId(), tagName);
if (indexes != null) {
return;
}
}
}
parent = parent.getParent();
}
Range range = QutePositionUtility.selectStartTagName(section);
Diagnostic diagnostic = createDiagnostic(range, DiagnosticSeverity.Error, QuteErrorCode.UndefinedSectionTag, tagName);
// Create data information helpful for code action
diagnostic.setData(DiagnosticDataFactory.createUndefinedSectionTagData(tagName));
diagnostics.add(diagnostic);
}
}
}
Aggregations