Search in sources :

Example 1 with Validator

use of org.eclipse.ceylon.compiler.typechecker.tree.Validator in project ceylon by eclipse.

the class PhasedUnit method validateTree.

public void validateTree() {
    // System.out.println("Validating tree for " + fileName);
    if (!treeValidated) {
        String fn = unit.getRelativePath();
        for (int i = 0; i < fn.length(); i = fn.offsetByCodePoints(i, 1)) {
            int cp = fn.codePointAt(i);
            if (cp > 127) {
                rootNode.addUsageWarning(Warning.filenameNonAscii, "source file name has non-ASCII characters: " + fn);
            }
        }
        String ufn = unit.getFilename();
        for (Unit u : unit.getPackage().getUnits()) {
            if (!u.equals(unit) && u.getFilename().equalsIgnoreCase(ufn)) {
                if (u.getFilename().equals(ufn)) {
                    String errorMessage = "identical source files: " + unit.getFullPath() + " and " + u.getFullPath();
                    if (u.getFilename().equals(MODULE_FILE) || u.getFilename().equals(PACKAGE_FILE)) {
                        errorMessage += " (a module/package descriptor should be defined only once, even in case of multiple source directories)";
                    }
                    rootNode.addError(errorMessage);
                } else {
                    rootNode.addUsageWarning(Warning.filenameCaselessCollision, "source file names differ only by case: " + unit.getFullPath() + " and " + u.getFullPath());
                }
            }
        }
        rootNode.visit(new Validator().setExceptionHandler(this));
        rootNode.visit(new Visitor() {

            @Override
            public void visit(ModuleDescriptor that) {
                super.visit(that);
                ImportPath importPath = that.getImportPath();
                if (importPath != null) {
                    String moduleName = formatPath(importPath.getIdentifiers());
                    ModuleSourceMapper moduleManagerUtil = moduleSourceMapperRef.get();
                    if (moduleManagerUtil != null) {
                        for (Module otherModule : moduleManagerUtil.getCompiledModules()) {
                            String otherModuleName = otherModule.getNameAsString();
                            if (moduleName.startsWith(otherModuleName + ".") || otherModuleName.startsWith(moduleName + ".")) {
                                StringBuilder error = new StringBuilder().append("Found two modules within the same hierarchy: '").append(otherModule.getNameAsString()).append("' and '").append(moduleName).append("'");
                                that.addError(error.toString());
                            }
                        }
                    }
                }
            }
        }.setExceptionHandler(this));
        treeValidated = true;
    }
}
Also used : ModuleDescriptor(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ModuleDescriptor) DeprecationVisitor(org.eclipse.ceylon.compiler.typechecker.util.DeprecationVisitor) ImportVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.ImportVisitor) TypeHierarchyVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.TypeHierarchyVisitor) LocalDeclarationVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.LocalDeclarationVisitor) StatisticsVisitor(org.eclipse.ceylon.compiler.typechecker.util.StatisticsVisitor) InheritanceVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.InheritanceVisitor) ExpressionVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.ExpressionVisitor) SpecificationVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.SpecificationVisitor) RefinementVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.RefinementVisitor) PrintVisitor(org.eclipse.ceylon.compiler.typechecker.util.PrintVisitor) SelfReferenceVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.SelfReferenceVisitor) TypeArgumentVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.TypeArgumentVisitor) VisibilityVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.VisibilityVisitor) DeclarationVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.DeclarationVisitor) SupertypeVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.SupertypeVisitor) ModuleVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.ModuleVisitor) UsageVisitor(org.eclipse.ceylon.compiler.typechecker.util.UsageVisitor) LiteralVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.LiteralVisitor) Visitor(org.eclipse.ceylon.compiler.typechecker.tree.Visitor) ControlFlowVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.ControlFlowVisitor) TypeVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.TypeVisitor) AnnotationVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.AnnotationVisitor) DefaultTypeArgVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.DefaultTypeArgVisitor) AssertionVisitor(org.eclipse.ceylon.compiler.typechecker.util.AssertionVisitor) AliasVisitor(org.eclipse.ceylon.compiler.typechecker.analyzer.AliasVisitor) ImportPath(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ImportPath) ModuleSourceMapper(org.eclipse.ceylon.compiler.typechecker.analyzer.ModuleSourceMapper) Unit(org.eclipse.ceylon.model.typechecker.model.Unit) Module(org.eclipse.ceylon.model.typechecker.model.Module) Validator(org.eclipse.ceylon.compiler.typechecker.tree.Validator)

Aggregations

AliasVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.AliasVisitor)1 AnnotationVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.AnnotationVisitor)1 ControlFlowVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.ControlFlowVisitor)1 DeclarationVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.DeclarationVisitor)1 DefaultTypeArgVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.DefaultTypeArgVisitor)1 ExpressionVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.ExpressionVisitor)1 ImportVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.ImportVisitor)1 InheritanceVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.InheritanceVisitor)1 LiteralVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.LiteralVisitor)1 LocalDeclarationVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.LocalDeclarationVisitor)1 ModuleSourceMapper (org.eclipse.ceylon.compiler.typechecker.analyzer.ModuleSourceMapper)1 ModuleVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.ModuleVisitor)1 RefinementVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.RefinementVisitor)1 SelfReferenceVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.SelfReferenceVisitor)1 SpecificationVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.SpecificationVisitor)1 SupertypeVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.SupertypeVisitor)1 TypeArgumentVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.TypeArgumentVisitor)1 TypeHierarchyVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.TypeHierarchyVisitor)1 TypeVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.TypeVisitor)1 VisibilityVisitor (org.eclipse.ceylon.compiler.typechecker.analyzer.VisibilityVisitor)1