Search in sources :

Example 51 with TypedDeclaration

use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.

the class BmeGenerator method generateStaticReference.

static void generateStaticReference(Node n, Declaration d, GenerateJsVisitor gen) {
    Declaration orig = d instanceof TypedDeclaration ? ((TypedDeclaration) d).getOriginalDeclaration() : d;
    ClassOrInterface coi = (ClassOrInterface) (orig == null ? d : orig).getContainer();
    gen.qualify(n, coi);
    gen.out(gen.getNames().name(coi), ".$st$.", gen.getNames().name(d));
    if (d instanceof Value && ((Value) d).getType().getDeclaration().isAnonymous()) {
        gen.out("()");
    }
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) Value(org.eclipse.ceylon.model.typechecker.model.Value) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 52 with TypedDeclaration

use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.

the class CeylonEnter method typeCheck.

private void typeCheck() {
    final java.util.List<PhasedUnit> listOfUnits = phasedUnits.getPhasedUnits();
    Module jdk = modelLoader.getJDKBaseModule();
    Package javaLangPackage = jdk.getPackage("java.lang");
    for (PhasedUnit pu : listOfUnits) {
        pu.getUnit().setJavaLangPackage(javaLangPackage);
    }
    // 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));
            }
        }
    }
    EeVisitor eeVisitor = gen.getEeVisitor();
    UnsupportedVisitor uv = new UnsupportedVisitor(eeVisitor);
    JvmMissingNativeVisitor mnv = new JvmMissingNativeVisitor();
    BoxingDeclarationVisitor boxingDeclarationVisitor = new CompilerBoxingDeclarationVisitor(gen);
    BoxingVisitor boxingVisitor = new CompilerBoxingVisitor(gen);
    SmallDeclarationVisitor smallDeclarationVisitor = new SmallDeclarationVisitor();
    SmallVisitor smallVisitor = new SmallVisitor();
    DeferredVisitor deferredVisitor = new DeferredVisitor();
    AnnotationDeclarationVisitor adv = new AnnotationDeclarationVisitor(gen);
    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(eeVisitor);
        pu.getCompilationUnit().visit(uv);
        pu.getCompilationUnit().visit(adv);
    }
    i = 1;
    for (PhasedUnit pu : listOfUnits) {
        if (sp != null)
            progressPreparation(3, i++, size, pu);
        pu.getCompilationUnit().visit(boxingDeclarationVisitor);
        pu.getCompilationUnit().visit(smallDeclarationVisitor);
        pu.getCompilationUnit().visit(amv);
    }
    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(smallVisitor);
        compilationUnit.visit(deferredVisitor);
        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 : UsageWarning(org.eclipse.ceylon.compiler.typechecker.analyzer.UsageWarning) Warning(org.eclipse.ceylon.compiler.typechecker.analyzer.Warning) AnnotationModelVisitor(org.eclipse.ceylon.compiler.java.codegen.AnnotationModelVisitor) CompilerBoxingDeclarationVisitor(org.eclipse.ceylon.compiler.java.codegen.CompilerBoxingDeclarationVisitor) Unit(org.eclipse.ceylon.model.typechecker.model.Unit) CeylonCompilationUnit(org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit) CompilationUnit(org.eclipse.ceylon.compiler.typechecker.tree.Tree.CompilationUnit) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) JCCompilationUnit(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit) CeylonPhasedUnit(org.eclipse.ceylon.compiler.java.tools.CeylonPhasedUnit) DefiniteAssignmentVisitor(org.eclipse.ceylon.compiler.java.codegen.DefiniteAssignmentVisitor) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) CeylonPhasedUnit(org.eclipse.ceylon.compiler.java.tools.CeylonPhasedUnit) SmallDeclarationVisitor(org.eclipse.ceylon.compiler.java.codegen.SmallDeclarationVisitor) AnnotationDeclarationVisitor(org.eclipse.ceylon.compiler.java.codegen.AnnotationDeclarationVisitor) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) EeVisitor(org.eclipse.ceylon.compiler.java.codegen.EeVisitor) CompilerBoxingDeclarationVisitor(org.eclipse.ceylon.compiler.java.codegen.CompilerBoxingDeclarationVisitor) BoxingDeclarationVisitor(org.eclipse.ceylon.compiler.java.codegen.BoxingDeclarationVisitor) CeylonCompilationUnit(org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit) CompilationUnit(org.eclipse.ceylon.compiler.typechecker.tree.Tree.CompilationUnit) JCCompilationUnit(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeParameterCaptureVisitor(org.eclipse.ceylon.compiler.java.codegen.TypeParameterCaptureVisitor) UnsupportedVisitor(org.eclipse.ceylon.compiler.java.codegen.UnsupportedVisitor) InterfaceVisitor(org.eclipse.ceylon.compiler.java.codegen.InterfaceVisitor) JvmMissingNativeVisitor(org.eclipse.ceylon.compiler.java.codegen.JvmMissingNativeVisitor) DeferredVisitor(org.eclipse.ceylon.compiler.java.codegen.DeferredVisitor) CompilerBoxingVisitor(org.eclipse.ceylon.compiler.java.codegen.CompilerBoxingVisitor) SmallVisitor(org.eclipse.ceylon.compiler.java.codegen.SmallVisitor) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) CompilerBoxingVisitor(org.eclipse.ceylon.compiler.java.codegen.CompilerBoxingVisitor) BoxingVisitor(org.eclipse.ceylon.compiler.java.codegen.BoxingVisitor) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule)

Example 53 with TypedDeclaration

use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.

the class AbstractModelLoader method findLocalContainerFromAnnotationAndSetCompanionClass.

private Scope findLocalContainerFromAnnotationAndSetCompanionClass(Package pkg, Interface declaration, AnnotationMirror localContainerAnnotation) {
    @SuppressWarnings("unchecked") List<String> path = (List<String>) localContainerAnnotation.getValue("path");
    // we start at the package
    Scope scope = pkg;
    for (String name : path) {
        scope = (Scope) getDirectMember(scope, name);
    }
    String companionClassName = (String) localContainerAnnotation.getValue("companionClassName");
    if (companionClassName == null || companionClassName.isEmpty()) {
        declaration.setCompanionClassNeeded(false);
        return scope;
    }
    ClassMirror container;
    Scope javaClassScope;
    if (scope instanceof TypedDeclaration && ((TypedDeclaration) scope).isMember())
        javaClassScope = scope.getContainer();
    else
        javaClassScope = scope;
    if (javaClassScope instanceof LazyInterface) {
        container = ((LazyInterface) javaClassScope).companionClass;
    } else if (javaClassScope instanceof LazyClass) {
        container = ((LazyClass) javaClassScope).classMirror;
    } else if (javaClassScope instanceof LazyValue) {
        container = ((LazyValue) javaClassScope).classMirror;
    } else if (javaClassScope instanceof LazyFunction) {
        container = ((LazyFunction) javaClassScope).classMirror;
    } else if (javaClassScope instanceof SetterWithLocalDeclarations) {
        container = ((SetterWithLocalDeclarations) javaClassScope).classMirror;
    } else {
        throw new ModelResolutionException("Unknown scope class: " + javaClassScope);
    }
    String qualifiedCompanionClassName = container.getQualifiedName() + "$" + companionClassName;
    ClassMirror companionClassMirror = lookupClassMirror(pkg.getModule(), qualifiedCompanionClassName);
    if (companionClassMirror == null)
        throw new ModelResolutionException("Could not find companion class mirror: " + qualifiedCompanionClassName);
    ((LazyInterface) declaration).companionClass = companionClassMirror;
    return scope;
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) LazyValue(org.eclipse.ceylon.model.loader.model.LazyValue) LazyFunction(org.eclipse.ceylon.model.loader.model.LazyFunction) ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface) SetterWithLocalDeclarations(org.eclipse.ceylon.model.loader.model.SetterWithLocalDeclarations) List(java.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass)

Example 54 with TypedDeclaration

use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.

the class JvmBackendUtil method getTopmostRefinedDeclaration.

public static Declaration getTopmostRefinedDeclaration(Declaration decl, Map<Function, Function> methodOverrides) {
    if (decl instanceof FunctionOrValue && ((FunctionOrValue) decl).isParameter() && decl.getContainer() instanceof Class) {
        // Parameters in a refined class are not considered refinements themselves
        // We have in find the refined attribute
        Class c = (Class) decl.getContainer();
        boolean isAlias = c.isAlias();
        boolean isActual = c.isActual();
        // boxing and stuff
        if (isAlias || isActual) {
            Functional ctor = null;
            int index = c.getParameterList().getParameters().indexOf(findParamForDecl(((TypedDeclaration) decl)));
            // Note(Stef): not entirely sure about that one, what about aliases of actual classes?
            while ((isAlias && c.isAlias()) || (isActual && c.isActual())) {
                ctor = (isAlias && c.isAlias()) ? (Functional) ((ClassAlias) c).getConstructor() : c;
                Type et = c.getExtendedType();
                c = et != null && et.isClass() ? (Class) et.getDeclaration() : null;
                // handle compile errors
                if (c == null)
                    return null;
            }
            if (isActual) {
                ctor = c;
            }
            // be safe
            if (ctor == null || ctor.getParameterLists() == null || ctor.getParameterLists().isEmpty() || ctor.getFirstParameterList() == null || ctor.getFirstParameterList().getParameters() == null || ctor.getFirstParameterList().getParameters().size() <= index)
                return null;
            decl = ctor.getFirstParameterList().getParameters().get(index).getModel();
        }
        if (decl.isShared()) {
            Declaration refinedDecl = c.getRefinedMember(decl.getName(), getSignature(decl), isVariadic(decl));
            if (refinedDecl != null && !ModelUtil.equal(refinedDecl, decl)) {
                return getTopmostRefinedDeclaration(refinedDecl, methodOverrides);
            }
        }
        return decl;
    } else if (decl instanceof FunctionOrValue && // a parameter
    ((FunctionOrValue) decl).isParameter() && (// that's not parameter of a functional parameter
    (decl.getContainer() instanceof Function && !(((Function) decl.getContainer()).isParameter())) || // or is a parameter in a specification
    decl.getContainer() instanceof Specification || (decl.getContainer() instanceof Function && ((Function) decl.getContainer()).isParameter() && createMethod((Function) decl.getContainer())))) {
        // or is a class functional parameter
        // Parameters in a refined method are not considered refinements themselves
        // so we have to look up the corresponding parameter in the container's refined declaration
        Functional func = (Functional) getParameterized((FunctionOrValue) decl);
        if (func == null)
            return decl;
        Declaration kk = getTopmostRefinedDeclaration((Declaration) func, methodOverrides);
        // error recovery
        if (kk instanceof Functional == false)
            return decl;
        Functional refinedFunc = (Functional) kk;
        // shortcut if the functional doesn't override anything
        if (ModelUtil.equal((Declaration) refinedFunc, (Declaration) func)) {
            return decl;
        }
        if (func.getParameterLists().size() != refinedFunc.getParameterLists().size()) {
            // invalid input
            return decl;
        }
        for (int ii = 0; ii < func.getParameterLists().size(); ii++) {
            if (func.getParameterLists().get(ii).getParameters().size() != refinedFunc.getParameterLists().get(ii).getParameters().size()) {
                // invalid input
                return decl;
            }
            // find the index of the parameter in the declaration
            int index = 0;
            for (Parameter px : func.getParameterLists().get(ii).getParameters()) {
                if (px.getModel() == null || px.getModel().equals(decl)) {
                    // And return the corresponding parameter from the refined declaration
                    return refinedFunc.getParameterLists().get(ii).getParameters().get(index).getModel();
                }
                index++;
            }
            continue;
        }
    } else if (methodOverrides != null && decl instanceof Function && ModelUtil.equal(decl.getRefinedDeclaration(), decl) && decl.getContainer() instanceof Specification && ((Specification) decl.getContainer()).getDeclaration() instanceof Function && ((Function) ((Specification) decl.getContainer()).getDeclaration()).isShortcutRefinement() && // hash lookup we do next to make sure it is really one of those cases
    methodOverrides.containsKey(decl)) {
        // special case for class X() extends T(){ m = function() => e; } which we inline
        decl = methodOverrides.get(decl);
    }
    Declaration refinedDecl = decl.getRefinedDeclaration();
    if (refinedDecl != null && !ModelUtil.equal(refinedDecl, decl))
        return getTopmostRefinedDeclaration(refinedDecl);
    return decl;
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) Function(org.eclipse.ceylon.model.typechecker.model.Function) VisibilityType(org.eclipse.ceylon.model.cmr.VisibilityType) ArtifactResultType(org.eclipse.ceylon.model.cmr.ArtifactResultType) Type(org.eclipse.ceylon.model.typechecker.model.Type) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) Class(org.eclipse.ceylon.model.typechecker.model.Class) Specification(org.eclipse.ceylon.model.typechecker.model.Specification) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 55 with TypedDeclaration

use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.

the class NamingBase method getSetterName.

public static String getSetterName(Declaration decl) {
    // use the refined decl except when the current declaration is variable and the refined isn't
    Declaration refinedDecl = decl.getRefinedDeclaration();
    if (isValue(decl) && isValue(refinedDecl)) {
        Value v = (Value) decl;
        Value rv = (Value) refinedDecl;
        if (!v.isVariable() || rv.isVariable()) {
            decl = refinedDecl;
        }
    } else {
        decl = refinedDecl;
    }
    if (decl instanceof FieldValue) {
        return ((FieldValue) decl).getRealName();
    }
    if (decl instanceof JavaBeanValue && // one it will not. This is also used for late setters...
    ((JavaBeanValue) decl).getSetterName() != null) {
        return ((JavaBeanValue) decl).getSetterName();
    } else if (decl.isClassOrInterfaceMember() && !isLocalToInitializer(decl) || decl.isStatic()) {
        String setterName = getSetterName(decl.getName());
        if (decl.isMember() && !decl.isShared()) {
            setterName = suffixName(Suffix.$priv$, setterName);
        }
        return setterName;
    } else if (decl instanceof TypedDeclaration && isBoxedVariable((TypedDeclaration) decl)) {
        return name(Unfix.ref);
    } else {
        return name(Unfix.set_);
    }
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Value(org.eclipse.ceylon.model.typechecker.model.Value) JavaBeanValue(org.eclipse.ceylon.model.loader.model.JavaBeanValue) FieldValue(org.eclipse.ceylon.model.loader.model.FieldValue) JvmBackendUtil.isValue(org.eclipse.ceylon.model.loader.JvmBackendUtil.isValue) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) FieldValue(org.eclipse.ceylon.model.loader.model.FieldValue) JavaBeanValue(org.eclipse.ceylon.model.loader.model.JavaBeanValue)

Aggregations

TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)110 Type (org.eclipse.ceylon.model.typechecker.model.Type)58 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)51 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)50 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)47 Function (org.eclipse.ceylon.model.typechecker.model.Function)34 Value (org.eclipse.ceylon.model.typechecker.model.Value)28 Class (org.eclipse.ceylon.model.typechecker.model.Class)26 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)26 AnalyzerUtil.getTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration)25 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)22 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)21 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)21 AnalyzerUtil.getPackageTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration)20 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)19 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)18 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)17 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)17 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)16 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)15