use of com.redhat.qute.parser.template.Node in project quarkus-ls by redhat-developer.
the class QuteSymbolsProvider method findDocumentSymbols.
public List<DocumentSymbol> findDocumentSymbols(Template template, CancelChecker cancelChecker) {
List<DocumentSymbol> symbols = new ArrayList<>();
for (int i = 0; i < template.getChildCount(); i++) {
Node child = template.getChild(i);
findDocumentSymbols(child, symbols, template, cancelChecker);
}
return symbols;
}
use of com.redhat.qute.parser.template.Node in project quarkus-ls by redhat-developer.
the class QuteSymbolsProvider method findDocumentSymbols.
private void findDocumentSymbols(Node node, List<DocumentSymbol> symbols, Template template, CancelChecker cancelChecker) {
if (!isNodeSymbol(node)) {
return;
}
cancelChecker.checkCanceled();
String name = nodeToName(node);
Range selectionRange = getSymbolRange(node);
Range range = selectionRange;
List<DocumentSymbol> children = new ArrayList<>();
DocumentSymbol symbol = new DocumentSymbol(name, getSymbolKind(node), range, selectionRange, null, children);
symbols.add(symbol);
if (node.getChildCount() > 0) {
for (int i = 0; i < node.getChildCount(); i++) {
Node child = node.getChild(i);
findDocumentSymbols(child, children, template, cancelChecker);
}
}
}
use of com.redhat.qute.parser.template.Node in project quarkus-ls by redhat-developer.
the class QuteSearchUtils method searchDeclaredObjectInParameter.
private static Parameter searchDeclaredObjectInParameter(ObjectPart part, CancelChecker cancelChecker) {
String partName = part.getPartName();
Node parent = part.getParentSection();
while (parent != null) {
if (parent.getKind() == NodeKind.Section) {
Section section = (Section) parent;
switch(section.getSectionKind()) {
case EACH:
case FOR:
LoopSection iterableSection = (LoopSection) section;
if (!iterableSection.isInElseBlock(part.getStart())) {
String alias = iterableSection.getAlias();
if (partName.equals(alias) || section.isMetadata(partName)) {
// - or the metadata of the section (ex : item_count)
return iterableSection.getAliasParameter();
}
}
break;
case LET:
case SET:
List<Parameter> parameters = section.getParameters();
for (Parameter parameter : parameters) {
if (partName.equals(parameter.getName())) {
return parameter;
}
}
break;
default:
}
}
parent = parent.getParent();
}
return null;
}
use of com.redhat.qute.parser.template.Node in project quarkus-ls by redhat-developer.
the class QuteProject method collectInsert.
private void collectInsert(String insertParamater, Node parent, Template template, List<QuteIndex> indexes) {
if (parent.getKind() == NodeKind.Section) {
Section section = (Section) parent;
if (section.getSectionKind() == SectionKind.INSERT) {
Parameter parameter = section.getParameterAtIndex(0);
if (parameter != null) {
try {
if (insertParamater == null || insertParamater.equals(parameter.getValue())) {
Position position = template.positionAt(parameter.getStart());
Path path = createPath(template.getUri());
QuteTemplateIndex templateIndex = new QuteTemplateIndex(path, template.getTemplateId());
QuteIndex index = new QuteIndex("insert", parameter.getValue(), position, SectionKind.INSERT, templateIndex);
indexes.add(index);
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
}
List<Node> children = parent.getChildren();
for (Node node : children) {
collectInsert(insertParamater, node, template, indexes);
}
}
use of com.redhat.qute.parser.template.Node in project quarkus-ls by redhat-developer.
the class ExpressionParser method parse.
/**
* Returns the parsing result of the given expression content.
*
* @param expression the content to parse.
* @param cancelChecker the cancel checker.
*
* @return the parsing result of the given expression content.
*/
public static List<Node> parse(Expression expression, CancelChecker cancelChecker) {
if (cancelChecker == null) {
cancelChecker = DEFAULT_CANCEL_CHECKER;
}
Template template = expression.getOwnerTemplate();
String text = template.getText();
int start = expression.getStartContentOffset();
int end = expression.getEndContentOffset();
ExpressionScanner scanner = ExpressionScanner.createScanner(text, start, end);
TokenType token = scanner.scan();
List<Node> expressionContent = new ArrayList<>();
Parts currentParts = null;
while (token != TokenType.EOS) {
cancelChecker.checkCanceled();
int tokenOffset = scanner.getTokenOffset();
int tokenEnd = scanner.getTokenEnd();
switch(token) {
case Whitespace:
currentParts = null;
break;
case NamespacePart:
currentParts = new Parts(tokenOffset, tokenEnd);
currentParts.setExpressionParent(expression);
expressionContent.add(currentParts);
NamespacePart namespacePart = new NamespacePart(tokenOffset, tokenEnd);
currentParts.addPart(namespacePart);
break;
case ObjectPart:
if (!(currentParts != null && currentParts.getChildCount() == 1 && currentParts.getChild(0).getPartKind() == PartKind.Namespace)) {
currentParts = new Parts(tokenOffset, tokenEnd);
currentParts.setExpressionParent(expression);
expressionContent.add(currentParts);
}
if (currentParts != null) {
ObjectPart objectPart = new ObjectPart(tokenOffset, tokenEnd);
currentParts.addPart(objectPart);
}
break;
case PropertyPart:
if (currentParts != null) {
PropertyPart propertyPart = new PropertyPart(tokenOffset, tokenEnd);
currentParts.addPart(propertyPart);
}
break;
case MethodPart:
if (currentParts != null) {
MethodPart methodPart = new MethodPart(tokenOffset, tokenEnd);
currentParts.addPart(methodPart);
}
break;
case Dot:
if (currentParts != null) {
currentParts.addDot(tokenOffset);
}
break;
case ColonSpace:
if (currentParts != null) {
currentParts.addColonSpace(tokenOffset);
}
break;
case OpenBracket:
if (currentParts != null) {
Node last = currentParts.getLastChild();
if (last instanceof MethodPart) {
((MethodPart) last).setOpenBracket(tokenOffset);
}
}
break;
case CloseBracket:
if (currentParts != null) {
Node last = currentParts.getLastChild();
if (last instanceof MethodPart) {
((MethodPart) last).setCloseBracket(tokenOffset);
}
}
break;
case StartString:
case String:
case EndString:
// ignore string tokens
break;
default:
currentParts = null;
break;
}
token = scanner.scan();
}
// adjust end offset for the current parts
if (currentParts != null) {
currentParts.setEnd(end);
Node last = currentParts.getLastChild();
if (last instanceof MethodPart) {
if (!last.isClosed()) {
// the current method is not closed with ')', adjust end method with the end
// offset.
((MethodPart) last).setEnd(end);
}
}
}
return expressionContent;
}
Aggregations