Search in sources :

Example 1 with AliasDeclaration

use of com.google.template.soy.soytree.AliasDeclaration in project closure-templates by google.

the class ValidateAliasesPass method run.

@Override
public void run(SoyFileNode file, IdGenerator nodeIdGen) {
    if (file.getSoyFileKind() != SoyFileKind.SRC) {
        return;
    }
    for (AliasDeclaration alias : file.getAliasDeclarations()) {
        if (options.getCompileTimeGlobals().containsKey(alias.alias().identifier())) {
            errorReporter.report(alias.alias().location(), ALIAS_CONFLICTS_WITH_GLOBAL, alias.alias());
        }
        SoyType type = registry.getType(alias.alias().identifier());
        // When running with a dummy type provider that parses all types as unknown, ignore that.
        if (type != null && type.getKind() != SoyType.Kind.UNKNOWN) {
            errorReporter.report(alias.alias().location(), ALIAS_CONFLICTS_WITH_TYPE_NAME, alias.alias());
        }
        String conflictingNamespacedType = registry.findTypeWithMatchingNamespace(alias.alias().identifier());
        if (conflictingNamespacedType != null) {
            errorReporter.report(alias.alias().location(), ALIAS_CONFLICTS_WITH_TYPE_PREFIX, alias.alias(), conflictingNamespacedType);
        }
        String prefix = alias.alias().identifier() + ".";
        for (String global : options.getCompileTimeGlobals().keySet()) {
            if (global.startsWith(prefix)) {
                errorReporter.report(alias.alias().location(), ALIAS_CONFLICTS_WITH_GLOBAL_PREFIX, alias.alias(), global);
            }
        }
    }
}
Also used : SoyType(com.google.template.soy.types.SoyType) AliasDeclaration(com.google.template.soy.soytree.AliasDeclaration)

Aggregations

AliasDeclaration (com.google.template.soy.soytree.AliasDeclaration)1 SoyType (com.google.template.soy.types.SoyType)1