Search in sources :

Example 51 with Declaration

use of com.redhat.ceylon.model.typechecker.model.Declaration in project ceylon-compiler by ceylon.

the class IndexDoc method indexMembers.

private void indexMembers(Scope container, List<Declaration> members) throws IOException {
    for (Declaration decl : members) {
        if (!tool.shouldInclude(decl)) {
            continue;
        }
        if (decl instanceof ClassOrInterface) {
            ClassOrInterface classOrInterface = (ClassOrInterface) decl;
            indexMembers(classOrInterface, classOrInterface.getMembers());
        }
        if (indexDecl(container, decl)) {
            write(",\n");
        }
    }
}
Also used : ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) AttributeDeclaration(com.redhat.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration)

Example 52 with Declaration

use of com.redhat.ceylon.model.typechecker.model.Declaration in project ceylon-compiler by ceylon.

the class AbstractTransformer method makeReifiedTypeArguments.

public java.util.List<JCExpression> makeReifiedTypeArguments(Reference ref) {
    ref = resolveAliasesForReifiedTypeArguments(ref);
    Declaration declaration = ref.getDeclaration();
    if (!supportsReified(declaration))
        return Collections.emptyList();
    return makeReifiedTypeArguments(getTypeArguments(ref));
}
Also used : TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 53 with Declaration

use of com.redhat.ceylon.model.typechecker.model.Declaration in project ceylon-compiler by ceylon.

the class AbstractTransformer method canUseFastFailTypeTest.

private boolean canUseFastFailTypeTest(Type type) {
    if (type.getDeclaration() instanceof ClassOrInterface == false)
        return false;
    boolean isRaw = !type.getDeclaration().getTypeParameters().isEmpty();
    Type qualifyingType = type.getQualifyingType();
    if (qualifyingType == null && // ignore qualifying types of static java declarations
    (Decl.isCeylon(type.getDeclaration()) || !type.getDeclaration().isStaticallyImportable())) {
        Declaration declaration = type.getDeclaration();
        boolean local = false;
        do {
            // getDeclarationContainer will skip some containers we don't want to consider, so it's not good
            // for checking locality, rely on isLocal for that.
            local |= Decl.isLocal(declaration);
            // it may be contained in a function or value, and we want its type
            Declaration enclosingDeclaration = getDeclarationContainer(declaration);
            if (enclosingDeclaration instanceof TypedDeclaration) {
                local = true;
                // look up the containers
                declaration = enclosingDeclaration;
            } else if (enclosingDeclaration instanceof TypeDeclaration) {
                // we can't do instanceof on a local whose outer types contain type parameters, unless the local is raw
                if (enclosingDeclaration instanceof Generic && local && !isRaw && !((Generic) enclosingDeclaration).getTypeParameters().isEmpty())
                    return false;
                // look up the containers
                declaration = enclosingDeclaration;
            } else {
                // that's fucked up
                break;
            }
        // go up every containing typed declaration
        } while (declaration != null);
        // we can fast-fail!
        return true;
    } else if (qualifyingType != null) {
        // we can only fast-fail if the qualifying type can also be fast-failed
        return canUseFastFailTypeTest(qualifyingType);
    } else {
        // we can fast-fail!
        return true;
    }
}
Also used : ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Type(com.redhat.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType) Generic(com.redhat.ceylon.model.typechecker.model.Generic) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 54 with Declaration

use of com.redhat.ceylon.model.typechecker.model.Declaration in project ceylon-compiler by ceylon.

the class CeylonEnter method typeCheck.

private void typeCheck() {
    final java.util.List<PhasedUnit> listOfUnits = phasedUnits.getPhasedUnits();
    // Delegate to an external typechecker (e.g. the IDE build)
    compilerDelegate.typeCheck(listOfUnits);
    if (sp != null) {
        sp.clearLine();
        sp.log("Preparation phase");
    }
    int size = listOfUnits.size();
    int i = 1;
    // This phase is proper to the Java backend 
    ForcedCaptureVisitor fcv = new ForcedCaptureVisitor();
    for (PhasedUnit pu : listOfUnits) {
        if (sp != null)
            progressPreparation(1, i++, size, pu);
        Unit unit = pu.getUnit();
        final CompilationUnit compilationUnit = pu.getCompilationUnit();
        compilationUnit.visit(fcv);
        for (Declaration d : unit.getDeclarations()) {
            if (d instanceof TypedDeclaration && !(d instanceof Setter) && // skip already captured members
            !d.isCaptured()) {
                compilationUnit.visit(new MethodOrValueReferenceVisitor((TypedDeclaration) d));
            }
        }
    }
    UnsupportedVisitor uv = new UnsupportedVisitor();
    JvmMissingNativeVisitor mnv = new JvmMissingNativeVisitor(modelLoader);
    BoxingDeclarationVisitor boxingDeclarationVisitor = new CompilerBoxingDeclarationVisitor(gen);
    BoxingVisitor boxingVisitor = new CompilerBoxingVisitor(gen);
    DeferredVisitor deferredVisitor = new DeferredVisitor();
    AnnotationModelVisitor amv = new AnnotationModelVisitor(gen);
    DefiniteAssignmentVisitor dav = new DefiniteAssignmentVisitor();
    TypeParameterCaptureVisitor tpCaptureVisitor = new TypeParameterCaptureVisitor();
    InterfaceVisitor localInterfaceVisitor = new InterfaceVisitor();
    // Extra phases for the compiler
    // boxing visitor depends on boxing decl
    i = 1;
    for (PhasedUnit pu : listOfUnits) {
        if (sp != null)
            progressPreparation(2, i++, size, pu);
        pu.getCompilationUnit().visit(uv);
    }
    i = 1;
    for (PhasedUnit pu : listOfUnits) {
        if (sp != null)
            progressPreparation(3, i++, size, pu);
        pu.getCompilationUnit().visit(boxingDeclarationVisitor);
    }
    i = 1;
    // the others can run at the same time
    for (PhasedUnit pu : listOfUnits) {
        if (sp != null)
            progressPreparation(4, i++, size, pu);
        CompilationUnit compilationUnit = pu.getCompilationUnit();
        compilationUnit.visit(mnv);
        compilationUnit.visit(boxingVisitor);
        compilationUnit.visit(deferredVisitor);
        compilationUnit.visit(amv);
        compilationUnit.visit(dav);
        compilationUnit.visit(tpCaptureVisitor);
        compilationUnit.visit(localInterfaceVisitor);
    }
    i = 1;
    for (PhasedUnit pu : listOfUnits) {
        if (sp != null)
            progressPreparation(5, i++, size, pu);
        CompilationUnit compilationUnit = pu.getCompilationUnit();
        compilationUnit.visit(new WarningSuppressionVisitor<Warning>(Warning.class, pu.getSuppressedWarnings()));
    }
    collectTreeErrors(true, true);
}
Also used : CeylonCompilationUnit(com.redhat.ceylon.compiler.java.codegen.CeylonCompilationUnit) CompilationUnit(com.redhat.ceylon.compiler.typechecker.tree.Tree.CompilationUnit) JCCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) TypeParameterCaptureVisitor(com.redhat.ceylon.compiler.java.codegen.TypeParameterCaptureVisitor) Warning(com.redhat.ceylon.compiler.typechecker.analyzer.Warning) UsageWarning(com.redhat.ceylon.compiler.typechecker.analyzer.UsageWarning) AnnotationModelVisitor(com.redhat.ceylon.compiler.java.codegen.AnnotationModelVisitor) UnsupportedVisitor(com.redhat.ceylon.compiler.java.codegen.UnsupportedVisitor) CompilerBoxingDeclarationVisitor(com.redhat.ceylon.compiler.java.codegen.CompilerBoxingDeclarationVisitor) CeylonCompilationUnit(com.redhat.ceylon.compiler.java.codegen.CeylonCompilationUnit) CompilationUnit(com.redhat.ceylon.compiler.typechecker.tree.Tree.CompilationUnit) Unit(com.redhat.ceylon.model.typechecker.model.Unit) JCCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit) CeylonPhasedUnit(com.redhat.ceylon.compiler.java.tools.CeylonPhasedUnit) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit) DefiniteAssignmentVisitor(com.redhat.ceylon.compiler.java.codegen.DefiniteAssignmentVisitor) InterfaceVisitor(com.redhat.ceylon.compiler.java.codegen.InterfaceVisitor) CeylonPhasedUnit(com.redhat.ceylon.compiler.java.tools.CeylonPhasedUnit) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit) JvmMissingNativeVisitor(com.redhat.ceylon.compiler.java.codegen.JvmMissingNativeVisitor) DeferredVisitor(com.redhat.ceylon.compiler.java.codegen.DeferredVisitor) CompilerBoxingVisitor(com.redhat.ceylon.compiler.java.codegen.CompilerBoxingVisitor) Setter(com.redhat.ceylon.model.typechecker.model.Setter) CompilerBoxingVisitor(com.redhat.ceylon.compiler.java.codegen.CompilerBoxingVisitor) BoxingVisitor(com.redhat.ceylon.compiler.java.codegen.BoxingVisitor) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) BoxingDeclarationVisitor(com.redhat.ceylon.compiler.java.codegen.BoxingDeclarationVisitor) CompilerBoxingDeclarationVisitor(com.redhat.ceylon.compiler.java.codegen.CompilerBoxingDeclarationVisitor)

Example 55 with Declaration

use of com.redhat.ceylon.model.typechecker.model.Declaration in project ceylon-compiler by ceylon.

the class DeclarationErrorVisitor method visit.

public void visit(Tree.ExtendedType that) {
    that.getType().visit(this);
    // error if we tried to generate a ctor for this class.
    if (that.getType().getDeclarationModel() instanceof LazyClass && !((LazyClass) that.getType().getDeclarationModel()).isCeylon()) {
        boolean hasPrivateCtor = false;
        List<Declaration> overloads = ((LazyClass) that.getType().getDeclarationModel()).getOverloads();
        if (overloads != null) {
            for (Declaration ctor : overloads) {
                if (!ctor.isShared()) {
                    hasPrivateCtor = true;
                    break;
                }
            }
        }
        if (hasPrivateCtor) {
            that.getInvocationExpression().visit(this);
        }
    }
}
Also used : Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) LazyClass(com.redhat.ceylon.model.loader.model.LazyClass)

Aggregations

Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)107 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)95 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)80 Type (com.redhat.ceylon.model.typechecker.model.Type)34 Function (com.redhat.ceylon.model.typechecker.model.Function)33 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)30 Class (com.redhat.ceylon.model.typechecker.model.Class)28 Value (com.redhat.ceylon.model.typechecker.model.Value)28 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)27 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)27 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)24 AttributeDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration)22 JCTree (com.sun.tools.javac.tree.JCTree)22 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)21 MethodDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration)20 Interface (com.redhat.ceylon.model.typechecker.model.Interface)20 Scope (com.redhat.ceylon.model.typechecker.model.Scope)20 Package (com.redhat.ceylon.model.typechecker.model.Package)17 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)17 ArrayList (java.util.ArrayList)16