Search in sources :

Example 46 with Class

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

the class DeclarationErrorVisitor method planAccordingToErrors.

/**
     * Update the plan according to the errors on the node
     */
private void planAccordingToErrors(Node that) {
    List<Message> errors = that.getErrors();
    for (Message message : errors) {
        if (isError(that, message)) {
            TransformationPlan plan;
            /*if (message.getCode() == MEMBER_HAS_WRONG_NUMBER_OF_PARAMETERS
                        && model.isActual()
                        && model.isClassMember()) {
                    plan = new ThrowerMethod(that, message);
                } else if (message.getCode() == TYPE_OF_PARAMETER_IS_DIFFERENT_TO_CORRESPONDING_PARAMETER
                        && model.isActual()
                        && model.isClassMember()) {
                    plan = new ThrowerMethod(that, message);
                } else if (message.getCode() == COULD_NOT_DETERMINE_PARAMETER_TYPE_SAME_AS_CORRESPONDING_PARAMETER
                        && model.isActual()
                        && model.isClassMember()) {
                    plan = new ThrowerMethod(that, message);
                } else if ((message.getCode() == REFINED_MEMBER_WRONG_NUM_PL
                                || message.getCode() == MISSING_PL_FUNCTION_DECL)
                        && model.isActual()
                        && model.isClassMember()) {
                    plan = new ThrowerMethod(that, message);
                } else*/
            if (message.getCode() == FORMAL_MEMBER_UNIMPLEMENTED_IN_CLASS_HIERARCHY && (model instanceof Class || (model instanceof Value && ((Value) model).getTypeDeclaration().isAnonymous()))) {
                plan = new ThrowerMethod(that, message);
            } else if (message.getCode() == PL_AND_CONSTRUCTORS && (model instanceof Class || (model instanceof Value && ((Value) model).getTypeDeclaration().isAnonymous()))) {
                plan = new ThrowerCatchallConstructor(that, message);
            } else {
                plan = new Drop(that, message);
            }
            newplan(plan);
        }
    }
}
Also used : Message(com.redhat.ceylon.compiler.typechecker.tree.Message) Value(com.redhat.ceylon.model.typechecker.model.Value) Class(com.redhat.ceylon.model.typechecker.model.Class) LazyClass(com.redhat.ceylon.model.loader.model.LazyClass)

Example 47 with Class

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

the class CeylonDocTool method collectSubclasses.

private void collectSubclasses() throws IOException {
    for (Module module : modules) {
        for (Package pkg : getPackages(module)) {
            for (Declaration decl : pkg.getMembers()) {
                if (!shouldInclude(decl)) {
                    continue;
                }
                if (decl instanceof ClassOrInterface) {
                    ClassOrInterface c = (ClassOrInterface) decl;
                    // subclasses map
                    if (c instanceof Class) {
                        Type superclass = c.getExtendedType();
                        if (superclass != null) {
                            TypeDeclaration superdec = superclass.getDeclaration();
                            if (subclasses.get(superdec) == null) {
                                subclasses.put(superdec, new ArrayList<Class>());
                            }
                            subclasses.get(superdec).add((Class) c);
                        }
                    }
                    List<Type> satisfiedTypes = new ArrayList<Type>(c.getSatisfiedTypes());
                    if (satisfiedTypes != null && satisfiedTypes.isEmpty() == false) {
                        // satisfying classes or interfaces map
                        for (Type satisfiedType : satisfiedTypes) {
                            TypeDeclaration superdec = satisfiedType.getDeclaration();
                            if (satisfyingClassesOrInterfaces.get(superdec) == null) {
                                satisfyingClassesOrInterfaces.put(superdec, new ArrayList<ClassOrInterface>());
                            }
                            satisfyingClassesOrInterfaces.get(superdec).add(c);
                        }
                    }
                }
            }
        }
    }
}
Also used : ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) NothingType(com.redhat.ceylon.model.typechecker.model.NothingType) Type(com.redhat.ceylon.model.typechecker.model.Type) ArrayList(java.util.ArrayList) Class(com.redhat.ceylon.model.typechecker.model.Class) Package(com.redhat.ceylon.model.typechecker.model.Package) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Module(com.redhat.ceylon.model.typechecker.model.Module) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 48 with Class

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

the class Naming method getMethodNameInternal.

private static String getMethodNameInternal(TypedDeclaration decl) {
    String name;
    if (decl.isClassOrInterfaceMember() && decl instanceof Function) {
        Declaration refined = decl.getRefinedDeclaration();
        if (refined instanceof JavaMethod) {
            return ((JavaMethod) refined).getRealName();
        }
        name = quoteMethodNameIfProperty((Function) decl);
    } else {
        name = decl.getName();
    }
    if (decl.isClassMember() && "readResolve".equals(name) && Strategy.addReadResolve((Class) decl.getContainer())) {
        return quote(name);
    }
    if (decl.isClassMember() && "writeReplace".equals(name) && Strategy.useSerializationProxy((Class) decl.getContainer())) {
        return quote(name);
    }
    // ERASURE
    if (QUOTABLE_METHOD_NAMES.contains(name)) {
        return quote(name);
    } else {
        return quoteIfJavaKeyword(name);
    }
}
Also used : LazyFunction(com.redhat.ceylon.model.loader.model.LazyFunction) Function(com.redhat.ceylon.model.typechecker.model.Function) JavaMethod(com.redhat.ceylon.model.loader.model.JavaMethod) Class(com.redhat.ceylon.model.typechecker.model.Class) LazyClass(com.redhat.ceylon.model.loader.model.LazyClass) 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 49 with Class

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

the class Naming method makeNamedConstructorName.

public JCExpression makeNamedConstructorName(Constructor constructor, boolean delegation) {
    DeclNameFlag[] flags = delegation ? new DeclNameFlag[] { DeclNameFlag.QUALIFIED, DeclNameFlag.DELEGATION } : new DeclNameFlag[] { DeclNameFlag.QUALIFIED };
    Class cls = (Class) constructor.getContainer();
    if (cls.isToplevel() || (cls.isMember() && ((TypeDeclaration) cls.getContainer()).isToplevel())) {
        return makeTypeDeclarationExpression(null, constructor, flags);
    } else {
        return maker.TypeCast(makeTypeDeclarationExpression(null, constructor, flags), //makeTypeDeclarationExpression(makeTypeDeclarationExpression(null, cls, DeclNameFlag.QUALIFIED), constructor, DeclNameFlag.QUALIFIED),
        make().Literal(TypeTags.BOT, null));
    }
}
Also used : Class(com.redhat.ceylon.model.typechecker.model.Class) LazyClass(com.redhat.ceylon.model.loader.model.LazyClass)

Example 50 with Class

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

the class Naming method makeTypeDeclaration.

private <R> R makeTypeDeclaration(TypeDeclarationBuilder<R> declarationBuilder, final TypeDeclaration decl, DeclNameFlag... options) {
    EnumSet<DeclNameFlag> flags = EnumSet.noneOf(DeclNameFlag.class);
    flags.addAll(Arrays.asList(options));
    if (flags.contains(DeclNameFlag.ANNOTATION) && !Decl.isAnnotationClass(decl)) {
        throw new BugException(decl.getName());
    }
    if (flags.contains(DeclNameFlag.ANNOTATIONS) && !(Decl.isAnnotationClass(decl) || decl instanceof Class || gen().isSequencedAnnotation((Class) decl))) {
        throw new BugException(decl.getName());
    }
    java.util.List<Scope> l = new java.util.ArrayList<Scope>();
    Scope s = decl;
    do {
        l.add(s);
        s = s.getContainer();
    } while (!(s instanceof Package));
    Collections.reverse(l);
    if (flags.contains(DeclNameFlag.QUALIFIED) && (!decl.isAnonymous() || decl.isNamed())) {
        final List<String> packageName;
        if (!AbstractTransformer.isJavaArray(decl))
            packageName = ((Package) s).getName();
        else
            packageName = COM_REDHAT_CEYLON_LANGUAGE_PACKAGE;
        if (packageName.isEmpty() || !packageName.get(0).isEmpty()) {
            declarationBuilder.select("");
        }
        for (int ii = 0; ii < packageName.size(); ii++) {
            declarationBuilder.select(quoteIfJavaKeyword(packageName.get(ii)));
        }
    }
    for (int ii = 0; ii < l.size(); ii++) {
        Scope scope = l.get(ii);
        final boolean last = ii == l.size() - 1;
        appendTypeDeclaration(decl, flags, declarationBuilder, scope, last);
    }
    return declarationBuilder.result();
}
Also used : ArrayList(java.util.ArrayList) Scope(com.redhat.ceylon.model.typechecker.model.Scope) Class(com.redhat.ceylon.model.typechecker.model.Class) LazyClass(com.redhat.ceylon.model.loader.model.LazyClass) Package(com.redhat.ceylon.model.typechecker.model.Package)

Aggregations

Class (com.redhat.ceylon.model.typechecker.model.Class)81 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)52 Type (com.redhat.ceylon.model.typechecker.model.Type)45 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)37 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)28 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)26 Function (com.redhat.ceylon.model.typechecker.model.Function)23 IntersectionType (com.redhat.ceylon.model.typechecker.model.IntersectionType)22 UnionType (com.redhat.ceylon.model.typechecker.model.UnionType)22 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)22 TypeParser (com.redhat.ceylon.model.loader.TypeParser)21 Test (org.junit.Test)21 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)20 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)19 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)19 Value (com.redhat.ceylon.model.typechecker.model.Value)19 JCTree (com.sun.tools.javac.tree.JCTree)19 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)17 Interface (com.redhat.ceylon.model.typechecker.model.Interface)17 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)14