Search in sources :

Example 1 with ClassOrInterface

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

the class CeylonDoc method getIcons.

protected final List<String> getIcons(Object obj) {
    List<String> icons = new ArrayList<String>();
    if (obj instanceof Declaration) {
        Declaration decl = (Declaration) obj;
        Annotation deprecated = Util.findAnnotation(decl, "deprecated");
        if (deprecated != null) {
            icons.add("icon-decoration-deprecated");
        }
        if (decl instanceof ClassOrInterface || decl instanceof Constructor) {
            if (decl instanceof Interface) {
                icons.add("icon-interface");
                if (Util.isEnumerated((ClassOrInterface) decl)) {
                    icons.add("icon-decoration-enumerated");
                }
            }
            if (decl instanceof Class) {
                Class klass = (Class) decl;
                if (klass.isAnonymous()) {
                    icons.add("icon-object");
                } else {
                    icons.add("icon-class");
                }
                if (klass.isAbstract()) {
                    icons.add("icon-decoration-abstract");
                }
                if (klass.isFinal() && !klass.isAnonymous() && !klass.isAnnotation()) {
                    icons.add("icon-decoration-final");
                }
                if (Util.isEnumerated(klass)) {
                    icons.add("icon-decoration-enumerated");
                }
            }
            if (decl instanceof Constructor) {
                icons.add("icon-class");
            }
            if (!decl.isShared()) {
                icons.add("icon-decoration-local");
            }
        }
        if (decl instanceof TypedDeclaration) {
            if (decl.isShared()) {
                icons.add("icon-shared-member");
            } else {
                icons.add("icon-local-member");
            }
            if (decl.isFormal()) {
                icons.add("icon-decoration-formal");
            }
            if (decl.isActual()) {
                Declaration refinedDeclaration = decl.getRefinedDeclaration();
                if (refinedDeclaration != null) {
                    if (refinedDeclaration.isFormal()) {
                        icons.add("icon-decoration-impl");
                    }
                    if (refinedDeclaration.isDefault()) {
                        icons.add("icon-decoration-over");
                    }
                }
            }
            if (((TypedDeclaration) decl).isVariable()) {
                icons.add("icon-decoration-variable");
            }
        }
        if (decl instanceof TypeAlias || decl instanceof NothingType) {
            icons.add("icon-type-alias");
        }
        if (decl.isAnnotation()) {
            icons.add("icon-decoration-annotation");
        }
    }
    if (obj instanceof Package) {
        Package pkg = (Package) obj;
        icons.add("icon-package");
        if (!pkg.isShared()) {
            icons.add("icon-decoration-local");
        }
    }
    if (obj instanceof ModuleImport) {
        ModuleImport moduleImport = (ModuleImport) obj;
        icons.add("icon-module");
        if (moduleImport.isExport()) {
            icons.add("icon-module-exported-decoration");
        }
        if (moduleImport.isOptional()) {
            icons.add("icon-module-optional-decoration");
        }
    }
    if (obj instanceof Module) {
        icons.add("icon-module");
    }
    return icons;
}
Also used : ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Constructor(com.redhat.ceylon.model.typechecker.model.Constructor) ArrayList(java.util.ArrayList) TypeAlias(com.redhat.ceylon.model.typechecker.model.TypeAlias) Annotation(com.redhat.ceylon.model.typechecker.model.Annotation) ModuleImport(com.redhat.ceylon.model.typechecker.model.ModuleImport) Class(com.redhat.ceylon.model.typechecker.model.Class) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) Package(com.redhat.ceylon.model.typechecker.model.Package) Module(com.redhat.ceylon.model.typechecker.model.Module) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) NothingType(com.redhat.ceylon.model.typechecker.model.NothingType)

Example 2 with ClassOrInterface

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

the class LinkRenderer method getExternalUrl.

private String getExternalUrl(Object to) {
    String url = null;
    if (to instanceof Module) {
        url = getExternalModuleUrl((Module) to);
        if (url != null) {
            url += "index.html";
        }
    } else if (to instanceof Package) {
        Package pkg = (Package) to;
        url = getExternalModuleUrl(pkg.getModule());
        if (url != null) {
            url += buildPackageUrlPath(pkg);
            url += "index.html";
        }
    } else if (to instanceof ClassOrInterface) {
        ClassOrInterface klass = (ClassOrInterface) to;
        Package pkg = getPackage(klass);
        url = getExternalModuleUrl(pkg.getModule());
        if (url != null) {
            url += buildPackageUrlPath(pkg);
            url += ceylonDocTool.getFileName(klass);
        }
    }
    return url;
}
Also used : ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) Package(com.redhat.ceylon.model.typechecker.model.Package) Module(com.redhat.ceylon.model.typechecker.model.Module)

Example 3 with ClassOrInterface

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

the class AbstractTransformer method canOptimiseReifiedTypeTest.

/**
     * Determine whether we can use a plain {@code instanceof} instead of 
     * a full {@code Util.isReified()} for a {@code is} test
     */
private boolean canOptimiseReifiedTypeTest(Type type) {
    if (isJavaArray(type)) {
        if (isJavaObjectArray(type)) {
            MultidimensionalArray multiArray = getMultiDimensionalArrayInfo(type);
            // we can test, even if not fully reified in Java
            return multiArray.type.getDeclaration() instanceof ClassOrInterface;
        } else {
            // primitive array we can test
            return true;
        }
    }
    // we can optimise it if we've got a ClassOrInterface with only Anything type parameters
    if (type.getDeclaration() instanceof ClassOrInterface == false)
        return false;
    for (Entry<TypeParameter, Type> entry : type.getTypeArguments().entrySet()) {
        TypeParameter tp = entry.getKey();
        if (!type.isCovariant(tp)) {
            return false;
        }
        java.util.List<Type> bounds = tp.getSatisfiedTypes();
        Type ta = entry.getValue();
        if ((bounds == null || bounds.isEmpty()) && !isAnything(ta)) {
            return false;
        }
        for (Type bound : bounds) {
            if (!ta.isSupertypeOf(bound)) {
                return false;
            }
        }
    }
    // they're all Anything (or supertypes of their upper bound) we can optimise, unless we have a container with type arguments
    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();
        do {
            // it may be contained in a function or value, and we want its type
            Declaration enclosingDeclaration = getDeclarationContainer(declaration);
            if (enclosingDeclaration instanceof TypedDeclaration) {
                // must be in scope
                if (enclosingDeclaration instanceof Generic && !((Generic) enclosingDeclaration).getTypeParameters().isEmpty())
                    return false;
                // look up the containers
                declaration = enclosingDeclaration;
            } else if (enclosingDeclaration instanceof TypeDeclaration) {
                // we can't optimise if that container has type arguments as they are not provided
                if (enclosingDeclaration instanceof Generic && !((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 optimise!
        return true;
    } else if (qualifyingType != null) {
        // we can only optimise if the qualifying type can also be optimised
        return canOptimiseReifiedTypeTest(qualifyingType);
    } else {
        // we can optimise!
        return true;
    }
}
Also used : ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) JCTypeParameter(com.sun.tools.javac.tree.JCTree.JCTypeParameter) 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 4 with ClassOrInterface

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

the class AbstractTransformer method getSimpleNumParametersOfCallable.

private int getSimpleNumParametersOfCallable(Type args) {
    // can be a defaulted tuple of Empty|Tuple
    if (args.isUnion()) {
        java.util.List<Type> caseTypes = args.getCaseTypes();
        if (caseTypes == null || caseTypes.size() != 2)
            return -1;
        Type caseA = caseTypes.get(0);
        TypeDeclaration caseADecl = caseA.getDeclaration();
        Type caseB = caseTypes.get(1);
        TypeDeclaration caseBDecl = caseB.getDeclaration();
        if (caseADecl instanceof ClassOrInterface == false || caseBDecl instanceof ClassOrInterface == false)
            return -1;
        if (caseADecl.getQualifiedNameString().equals("ceylon.language::Empty") && caseBDecl.getQualifiedNameString().equals("ceylon.language::Tuple"))
            return getSimpleNumParametersOfCallable(caseB);
        if (caseBDecl.getQualifiedNameString().equals("ceylon.language::Empty") && caseADecl.getQualifiedNameString().equals("ceylon.language::Tuple"))
            return getSimpleNumParametersOfCallable(caseA);
        return -1;
    }
    // can be Tuple, Empty, Sequence or Sequential
    if (!args.isClassOrInterface())
        return -1;
    TypeDeclaration declaration = args.getDeclaration();
    String name = declaration.getQualifiedNameString();
    if (name.equals("ceylon.language::Tuple")) {
        Type rest = args.getTypeArgumentList().get(2);
        int ret = getSimpleNumParametersOfCallable(rest);
        if (ret == -1)
            return -1;
        return ret + 1;
    }
    if (name.equals("ceylon.language::Empty")) {
        return 0;
    }
    if (name.equals("ceylon.language::Sequential") || name.equals("ceylon.language::Sequence")) {
        return 1;
    }
    return -1;
}
Also used : ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) Type(com.redhat.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 5 with ClassOrInterface

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

the class InterfaceVisitor method visit.

@Override
public void visit(Tree.ClassOrInterface that) {
    ClassOrInterface model = that.getDeclarationModel();
    // and they are useless at runtime
    if (!model.isAlias()) {
        // we never need to collect other local declaration names since only interfaces compete in the $impl name range
        if (model instanceof Interface)
            collect(that, (Interface) model);
        Set<String> old = localCompanionClasses;
        localCompanionClasses = new HashSet<String>();
        super.visit(that);
        localCompanionClasses = old;
    }
    if (model instanceof Interface) {
        ((Interface) model).setCompanionClassNeeded(isInterfaceWithCode(model));
    }
}
Also used : ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface)

Aggregations

ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)37 Type (com.redhat.ceylon.model.typechecker.model.Type)21 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)20 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)16 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)15 Interface (com.redhat.ceylon.model.typechecker.model.Interface)13 ModelUtil.appliedType (com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType)11 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)11 Class (com.redhat.ceylon.model.typechecker.model.Class)9 Package (com.redhat.ceylon.model.typechecker.model.Package)7 Scope (com.redhat.ceylon.model.typechecker.model.Scope)7 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)7 Function (com.redhat.ceylon.model.typechecker.model.Function)6 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)6 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)5 Constructor (com.redhat.ceylon.model.typechecker.model.Constructor)5 TypeAlias (com.redhat.ceylon.model.typechecker.model.TypeAlias)5 JCTree (com.sun.tools.javac.tree.JCTree)5 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)5 ArrayList (java.util.ArrayList)5