Search in sources :

Example 26 with Parameter

use of com.redhat.qute.parser.template.Parameter 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);
    }
}
Also used : Path(java.nio.file.Path) FileUtils.createPath(com.redhat.qute.utils.FileUtils.createPath) QuteTemplateIndex(com.redhat.qute.project.indexing.QuteTemplateIndex) Position(org.eclipse.lsp4j.Position) Node(com.redhat.qute.parser.template.Node) QuteIndex(com.redhat.qute.project.indexing.QuteIndex) Parameter(com.redhat.qute.parser.template.Parameter) DataModelParameter(com.redhat.qute.commons.datamodel.DataModelParameter) Section(com.redhat.qute.parser.template.Section) BadLocationException(com.redhat.qute.ls.commons.BadLocationException)

Example 27 with Parameter

use of com.redhat.qute.parser.template.Parameter in project quarkus-ls by redhat-developer.

the class IfSection method accept0.

@Override
protected void accept0(ASTVisitor visitor) {
    boolean visitChildren = visitor.visit(this);
    if (visitChildren) {
        List<Parameter> parameters = getParameters();
        for (Parameter parameter : parameters) {
            acceptChild(visitor, parameter);
        }
        acceptChildren(visitor, getChildren());
    }
    visitor.endVisit(this);
}
Also used : Parameter(com.redhat.qute.parser.template.Parameter)

Example 28 with Parameter

use of com.redhat.qute.parser.template.Parameter in project quarkus-ls by redhat-developer.

the class IncludeSection method accept0.

@Override
protected void accept0(ASTVisitor visitor) {
    boolean visitChildren = visitor.visit(this);
    if (visitChildren) {
        List<Parameter> parameters = getParameters();
        for (Parameter parameter : parameters) {
            acceptChild(visitor, parameter);
        }
        acceptChildren(visitor, getChildren());
    }
    visitor.endVisit(this);
}
Also used : Parameter(com.redhat.qute.parser.template.Parameter)

Example 29 with Parameter

use of com.redhat.qute.parser.template.Parameter in project quarkus-ls by redhat-developer.

the class ParameterParser method parse.

public static List<Parameter> parse(ParametersContainer expression, boolean methodParameters, CancelChecker cancelChecker) {
    if (cancelChecker == null) {
        cancelChecker = DEFAULT_CANCEL_CHECKER;
    }
    Template template = expression.getOwnerTemplate();
    String text = template.getText();
    int start = expression.getStartParametersOffset();
    int end = expression.getEndParametersOffset();
    ParameterScanner scanner = ParameterScanner.createScanner(text, start, end, methodParameters);
    TokenType token = scanner.scan();
    List<Parameter> parameters = new ArrayList<>();
    Parameter currentParameter = null;
    while (token != TokenType.EOS) {
        cancelChecker.checkCanceled();
        int tokenOffset = scanner.getTokenOffset();
        int tokenEnd = scanner.getTokenEnd();
        switch(token) {
            case Whitespace:
                currentParameter = null;
                break;
            case ParameterName:
                currentParameter = new Parameter(tokenOffset, tokenEnd);
                currentParameter.setParameterParent(expression);
                parameters.add(currentParameter);
                break;
            case ParameterValue:
                if (currentParameter != null) {
                    // current parameter can be null when parameter name is not defined
                    // ex : {#let =123} (instead of {#let name=123})
                    currentParameter.setStartValue(tokenOffset);
                    currentParameter.setEndValue(tokenEnd);
                }
                break;
            default:
        }
        token = scanner.scan();
    }
    return parameters;
}
Also used : TokenType(com.redhat.qute.parser.parameter.scanner.TokenType) ArrayList(java.util.ArrayList) ParameterScanner(com.redhat.qute.parser.parameter.scanner.ParameterScanner) Parameter(com.redhat.qute.parser.template.Parameter) Template(com.redhat.qute.parser.template.Template)

Example 30 with Parameter

use of com.redhat.qute.parser.template.Parameter in project quarkus-ls by redhat-developer.

the class CustomSection method accept0.

@Override
protected void accept0(ASTVisitor visitor) {
    boolean visitChildren = visitor.visit(this);
    if (visitChildren) {
        List<Parameter> parameters = getParameters();
        for (Parameter parameter : parameters) {
            acceptChild(visitor, parameter);
        }
        acceptChildren(visitor, getChildren());
    }
    visitor.endVisit(this);
}
Also used : Parameter(com.redhat.qute.parser.template.Parameter)

Aggregations

Parameter (com.redhat.qute.parser.template.Parameter)30 Node (com.redhat.qute.parser.template.Node)9 Section (com.redhat.qute.parser.template.Section)9 Range (org.eclipse.lsp4j.Range)9 Expression (com.redhat.qute.parser.template.Expression)6 LoopSection (com.redhat.qute.parser.template.sections.LoopSection)6 ResolvedJavaTypeInfo (com.redhat.qute.commons.ResolvedJavaTypeInfo)3 NamespacePart (com.redhat.qute.parser.expression.NamespacePart)3 Part (com.redhat.qute.parser.expression.Part)3 ParameterDeclaration (com.redhat.qute.parser.template.ParameterDeclaration)3 DiagnosticDataFactory.createDiagnostic (com.redhat.qute.services.diagnostics.DiagnosticDataFactory.createDiagnostic)3 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Diagnostic (org.eclipse.lsp4j.Diagnostic)3 BadLocationException (com.redhat.qute.ls.commons.BadLocationException)2 MethodPart (com.redhat.qute.parser.expression.MethodPart)2 RangeOffset (com.redhat.qute.parser.template.RangeOffset)2 Template (com.redhat.qute.parser.template.Template)2 IncludeSection (com.redhat.qute.parser.template.sections.IncludeSection)2