Search in sources :

Example 21 with Parameter

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

the class UserTagUtils method collectUserTagParameters.

private static void collectUserTagParameters(Node parent, Template template, Set<String> extistingObjectParts, Consumer<ObjectPart> collector, CancelChecker cancelChecker) {
    cancelChecker.checkCanceled();
    if (parent.getKind() == NodeKind.Expression) {
        Expression expression = (Expression) parent;
        collectUserTagParameters(expression, extistingObjectParts, collector, cancelChecker);
        return;
    } else if (parent.getKind() == NodeKind.Section) {
        Section section = (Section) parent;
        List<Parameter> parameters = section.getParameters();
        for (Parameter parameter : parameters) {
            if (parameter.isCanHaveExpression()) {
                Expression expression = parameter.getJavaTypeExpression();
                collectUserTagParameters(expression, extistingObjectParts, collector, cancelChecker);
            }
        }
    }
    List<Node> children = parent.getChildren();
    for (Node node : children) {
        collectUserTagParameters(node, template, extistingObjectParts, collector, cancelChecker);
    }
}
Also used : Expression(com.redhat.qute.parser.template.Expression) Node(com.redhat.qute.parser.template.Node) Parameter(com.redhat.qute.parser.template.Parameter) List(java.util.List) Section(com.redhat.qute.parser.template.Section)

Example 22 with Parameter

use of com.redhat.qute.parser.template.Parameter 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;
}
Also used : LoopSection(com.redhat.qute.parser.template.sections.LoopSection) Node(com.redhat.qute.parser.template.Node) Parameter(com.redhat.qute.parser.template.Parameter) LoopSection(com.redhat.qute.parser.template.sections.LoopSection) BaseWhenSection(com.redhat.qute.parser.template.sections.BaseWhenSection) WithSection(com.redhat.qute.parser.template.sections.WithSection) Section(com.redhat.qute.parser.template.Section)

Example 23 with Parameter

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

the class QuteSearchUtils method searchReferencedObjects.

// ------------------- Search referenced objects
/**
 * Search referenced object of the given node.
 *
 * @param node          the origin node.
 * @param offset        the offset.
 * @param collector     the collector to collect node and range.
 * @param includeNode   true if the origin node must be collected and false
 *                      otherwise.
 * @param cancelChecker the cancel checker.
 */
public static void searchReferencedObjects(Node node, int offset, BiConsumer<Node, Range> collector, boolean includeNode, CancelChecker cancelChecker) {
    switch(node.getKind()) {
        case ParameterDeclaration:
            {
                ParameterDeclaration parameterDeclaration = (ParameterDeclaration) node;
                if (parameterDeclaration.isInJavaTypeName(offset)) {
                    // {@org.acme.It|em item}
                    RangeOffset rangeOffset = parameterDeclaration.getJavaTypeNameRange(offset);
                    if (rangeOffset != null) {
                        Range range = QutePositionUtility.createRange(rangeOffset, node.getOwnerTemplate());
                        collector.accept(parameterDeclaration, range);
                    }
                } else if (parameterDeclaration.isInAlias(offset)) {
                    // {@org.acme.Item it|em}
                    String alias = parameterDeclaration.getAlias();
                    if (includeNode) {
                        Range range = QutePositionUtility.selectAlias(parameterDeclaration);
                        collector.accept(parameterDeclaration, range);
                    }
                    searchReferencedObjects(alias, PartNameMatcher.BOTH, node, collector, cancelChecker);
                }
                break;
            }
        case Parameter:
            {
                Parameter parameter = (Parameter) node;
                if (includeNode) {
                    Range range = QutePositionUtility.selectParameterName(parameter);
                    collector.accept(parameter, range);
                }
                String alias = parameter.getName();
                searchReferencedObjects(alias, PartNameMatcher.ONLY_NAME, parameter.getParent(), collector, cancelChecker);
                break;
            }
        default:
            break;
    }
}
Also used : RangeOffset(com.redhat.qute.parser.template.RangeOffset) Parameter(com.redhat.qute.parser.template.Parameter) Range(org.eclipse.lsp4j.Range) ParameterDeclaration(com.redhat.qute.parser.template.ParameterDeclaration)

Example 24 with Parameter

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

the class QuteSearchUtils method searchDeclaredObject.

// ------------------- Search declared object
/**
 * Search the declared object of the given object part.
 *
 * @param part          the object part.
 * @param collector     the collector used to collect node and range.
 * @param includeNode   true if the origin part must be collected and false
 *                      otherwise.
 * @param cancelChecker the cancel checker.
 */
public static void searchDeclaredObject(ObjectPart part, BiConsumer<Node, Range> collector, boolean includeNode, CancelChecker cancelChecker) {
    if (includeNode) {
        Range range = QutePositionUtility.createRange(part);
        collector.accept(part, range);
    }
    String namespace = part.getNamespace();
    if (NamespacePart.DATA_NAMESPACE.equals(namespace)) {
        searchDeclaredObjectInParameterDeclaration(part, collector);
    } else {
        Parameter parameter = searchDeclaredObjectInParameter(part, cancelChecker);
        if (parameter != null) {
            Range targetRange = QutePositionUtility.selectParameterName(parameter);
            collector.accept(parameter, targetRange);
        } else {
            searchDeclaredObjectInParameterDeclaration(part, collector);
        }
    }
}
Also used : Parameter(com.redhat.qute.parser.template.Parameter) Range(org.eclipse.lsp4j.Range)

Example 25 with Parameter

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

the class WithSection 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