Search in sources :

Example 26 with PhasedUnit

use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon by eclipse.

the class CeylonDocTool method warningMissingThrows.

protected void warningMissingThrows(Declaration d) {
    if (ignoreMissingThrows) {
        return;
    }
    final Scope scope = d.getScope();
    final PhasedUnit unit = getUnit(d);
    final Node node = getNode(d);
    if (scope == null || unit == null || unit.getUnit() == null || node == null || !(d instanceof FunctionOrValue)) {
        return;
    }
    List<Type> documentedExceptions = new ArrayList<Type>();
    for (Annotation annotation : d.getAnnotations()) {
        if (annotation.getName().equals("throws")) {
            String exceptionName = annotation.getPositionalArguments().get(0);
            Declaration exceptionDecl = scope.getMemberOrParameter(unit.getUnit(), exceptionName, null, false);
            if (exceptionDecl instanceof TypeDeclaration) {
                documentedExceptions.add(((TypeDeclaration) exceptionDecl).getType());
            }
        }
    }
    final List<Type> thrownExceptions = new ArrayList<Type>();
    node.visitChildren(new Visitor() {

        @Override
        public void visit(Tree.Throw that) {
            Expression expression = that.getExpression();
            if (expression != null) {
                thrownExceptions.add(expression.getTypeModel());
            } else {
                thrownExceptions.add(unit.getUnit().getExceptionType());
            }
        }

        @Override
        public void visit(Tree.Declaration that) {
        // the end of searching
        }
    });
    for (Type thrownException : thrownExceptions) {
        boolean isDocumented = false;
        for (Type documentedException : documentedExceptions) {
            if (thrownException.isSubtypeOf(documentedException)) {
                isDocumented = true;
                break;
            }
        }
        if (!isDocumented) {
            richLog.warning(CeylondMessages.msg("warn.missingThrows", thrownException.asString(), getWhere(d), getPosition(getNode(d))));
        }
    }
}
Also used : Visitor(org.eclipse.ceylon.compiler.typechecker.tree.Visitor) AssertionVisitor(org.eclipse.ceylon.compiler.typechecker.util.AssertionVisitor) Node(org.eclipse.ceylon.compiler.typechecker.tree.Node) ArrayList(java.util.ArrayList) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) Type(org.eclipse.ceylon.model.typechecker.model.Type) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Expression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Expression) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 27 with PhasedUnit

use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon by eclipse.

the class CeylonDocTool method buildNodesMaps.

private void buildNodesMaps() {
    for (final PhasedUnit pu : phasedUnits) {
        CompilationUnit cu = pu.getCompilationUnit();
        Walker.walkCompilationUnit(new Visitor() {

            public void visit(Tree.Declaration that) {
                modelUnitMap.put(that.getDeclarationModel(), pu);
                modelNodeMap.put(that.getDeclarationModel(), that);
                super.visit(that);
            }

            public void visit(Tree.ObjectDefinition that) {
                if (that.getDeclarationModel() != null && that.getDeclarationModel().getTypeDeclaration() != null) {
                    TypeDeclaration typeDecl = that.getDeclarationModel().getTypeDeclaration();
                    modelUnitMap.put(typeDecl, pu);
                    modelNodeMap.put(typeDecl, that);
                }
                super.visit(that);
            }

            public void visit(Tree.PackageDescriptor that) {
                if (that.getImportPath() != null && that.getImportPath().getModel() != null) {
                    Referenceable model = that.getImportPath().getModel();
                    modelUnitMap.put(model, pu);
                    modelNodeMap.put(model, that);
                }
                super.visit(that);
            }

            public void visit(Tree.ModuleDescriptor that) {
                if (that.getImportPath() != null && that.getImportPath().getModel() != null) {
                    Referenceable model = that.getImportPath().getModel();
                    modelUnitMap.put(model, pu);
                    modelNodeMap.put(model, that);
                }
                super.visit(that);
            }

            public void visit(Tree.SpecifierStatement that) {
                modelUnitMap.put(that.getDeclaration(), pu);
                modelNodeMap.put(that.getDeclaration(), that);
                super.visit(that);
            }

            public void visit(Tree.Parameter param) {
                parameterUnitMap.put(param.getParameterModel(), pu);
                parameterNodeMap.put(param.getParameterModel(), param);
                super.visit(param);
            }
        }, cu);
    }
}
Also used : CompilationUnit(org.eclipse.ceylon.compiler.typechecker.tree.Tree.CompilationUnit) Visitor(org.eclipse.ceylon.compiler.typechecker.tree.Visitor) AssertionVisitor(org.eclipse.ceylon.compiler.typechecker.util.AssertionVisitor) Referenceable(org.eclipse.ceylon.model.typechecker.model.Referenceable) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Example 28 with PhasedUnit

use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon by eclipse.

the class PhasedUnitsModuleManager method initTypeCheckedUnits.

private void initTypeCheckedUnits() {
    for (PhasedUnit unit : getPhasedUnits().getPhasedUnits()) {
        // obtain the unit container path
        final String pkgName = Util.getUnitPackageName(unit);
        unit.getCompilationUnit().visit(new SourceDeclarationVisitor() {

            @Override
            public void loadFromSource(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Declaration decl) {
                compiledClasses.add(Util.getQuotedFQN(pkgName, decl));
            }

            @Override
            public void loadFromSource(ModuleDescriptor that) {
            // don't think we care about these
            }

            @Override
            public void loadFromSource(PackageDescriptor that) {
            // don't think we care about these
            }
        });
    }
}
Also used : ModuleDescriptor(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ModuleDescriptor) SourceDeclarationVisitor(org.eclipse.ceylon.compiler.java.loader.SourceDeclarationVisitor) PackageDescriptor(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PackageDescriptor) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Aggregations

PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)28 File (java.io.File)9 Package (org.eclipse.ceylon.model.typechecker.model.Package)7 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)6 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 TypeCheckerBuilder (org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder)5 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)5 HashMap (java.util.HashMap)4 CeylonCompilationUnit (org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit)4 MetamodelVisitor (org.eclipse.ceylon.compiler.js.loader.MetamodelVisitor)4 PhasedUnits (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits)4 Node (org.eclipse.ceylon.compiler.typechecker.tree.Node)4 Visitor (org.eclipse.ceylon.compiler.typechecker.tree.Visitor)4 JCCompilationUnit (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit)4 Module (org.eclipse.ceylon.model.typechecker.model.Module)4 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)4 Map (java.util.Map)3 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)3