Search in sources :

Example 1 with Token

use of org.apache.velocity.runtime.parser.Token in project intellij-community by JetBrains.

the class FileTemplateUtil method collectAttributes.

private static void collectAttributes(Set<String> referenced, Set<String> defined, Node apacheNode, final Set<String> propertiesNames, final boolean includeDummies, Set<String> visitedIncludes, Project project) throws ParseException {
    int childCount = apacheNode.jjtGetNumChildren();
    for (int i = 0; i < childCount; i++) {
        Node apacheChild = apacheNode.jjtGetChild(i);
        collectAttributes(referenced, defined, apacheChild, propertiesNames, includeDummies, visitedIncludes, project);
        if (apacheChild instanceof ASTReference) {
            ASTReference apacheReference = (ASTReference) apacheChild;
            String s = apacheReference.literal();
            s = referenceToAttribute(s, includeDummies);
            if (s != null && s.length() > 0 && !propertiesNames.contains(s)) {
                referenced.add(s);
            }
        } else if (apacheChild instanceof ASTSetDirective) {
            ASTReference lhs = (ASTReference) apacheChild.jjtGetChild(0);
            String attr = referenceToAttribute(lhs.literal(), false);
            if (attr != null) {
                defined.add(attr);
            }
        } else if (apacheChild instanceof ASTDirective && "parse".equals(((ASTDirective) apacheChild).getDirectiveName()) && apacheChild.jjtGetNumChildren() == 1) {
            Node literal = apacheChild.jjtGetChild(0);
            if (literal instanceof ASTStringLiteral && literal.jjtGetNumChildren() == 0) {
                Token firstToken = literal.getFirstToken();
                if (firstToken != null) {
                    String s = StringUtil.unquoteString(firstToken.toString());
                    final FileTemplate includedTemplate = FileTemplateManager.getInstance(project).getTemplate(s);
                    if (includedTemplate != null && visitedIncludes.add(s)) {
                        SimpleNode template = VelocityWrapper.parse(new StringReader(includedTemplate.getText()), "MyTemplate");
                        collectAttributes(referenced, defined, template, propertiesNames, includeDummies, visitedIncludes, project);
                    }
                }
            }
        }
    }
}
Also used : CustomFileTemplate(com.intellij.ide.fileTemplates.impl.CustomFileTemplate) StringReader(java.io.StringReader) Token(org.apache.velocity.runtime.parser.Token)

Aggregations

CustomFileTemplate (com.intellij.ide.fileTemplates.impl.CustomFileTemplate)1 StringReader (java.io.StringReader)1 Token (org.apache.velocity.runtime.parser.Token)1