Search in sources :

Example 1 with Package

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

the class ExpressionTransformer method appendDeclarationLiteralForAnnotation.

/**
 * Appends into the given builder a String representation of the given
 * declaration, suitable for parsing my the DeclarationParser.
 */
private static void appendDeclarationLiteralForAnnotation(Declaration decl, StringBuilder sb) {
    Scope container = decl.getContainer();
    while (true) {
        if (container instanceof Declaration) {
            appendDeclarationLiteralForAnnotation((Declaration) container, sb);
            sb.append(".");
            break;
        } else if (container instanceof Package) {
            appendDeclarationLiteralForAnnotation((Package) container, sb);
            sb.append(":");
            break;
        }
        container = container.getContainer();
    }
    if (decl instanceof Class) {
        sb.append("C").append(decl.getName());
    } else if (decl instanceof Interface) {
        sb.append("I").append(decl.getName());
    } else if (decl instanceof TypeAlias) {
        sb.append("A").append(decl.getName());
    } else if (decl instanceof Value) {
        sb.append("V").append(decl.getName());
    } else if (decl instanceof Function) {
        sb.append("F").append(decl.getName());
    } else if (decl instanceof TypeParameter) {
        sb.append("P").append(decl.getName());
    } else if (decl instanceof Constructor) {
        sb.append("c").append(decl.getName());
    } else {
        throw BugException.unhandledDeclarationCase(decl);
    }
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Scope(com.redhat.ceylon.model.typechecker.model.Scope) Constructor(com.redhat.ceylon.model.typechecker.model.Constructor) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) FieldValue(com.redhat.ceylon.model.loader.model.FieldValue) Value(com.redhat.ceylon.model.typechecker.model.Value) Class(com.redhat.ceylon.model.typechecker.model.Class) JCNewClass(com.sun.tools.javac.tree.JCTree.JCNewClass) TypeAlias(com.redhat.ceylon.model.typechecker.model.TypeAlias) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Package(com.redhat.ceylon.model.typechecker.model.Package) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface)

Example 2 with Package

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

the class Naming method addNamesForWrapperClass.

private <R> void addNamesForWrapperClass(TypeDeclarationBuilder<R> builder, TypedDeclaration decl, int namingOptions) {
    if ((namingOptions & NA_FQ) != 0) {
        if ((namingOptions & NA_WRAPPER) == 0 && (namingOptions & NA_WRAPPER_UNQUOTED) == 0) {
            throw new BugException("If you pass FQ you must pass WRAPPER or WRAPPER_UNQUOTED too, or there's no class name to qualify!");
        }
        List<String> outerNames = null;
        Scope s = decl.getContainer();
        while (s != null) {
            if (s instanceof Package) {
                final List<String> packageName = ((Package) s).getName();
                for (int ii = 0; ii < packageName.size(); ii++) {
                    if (ii == 0 && packageName.get(ii).isEmpty()) {
                        continue;
                    }
                    builder.select(quoteIfJavaKeyword(packageName.get(ii)));
                }
                break;
            } else if (s instanceof ClassOrInterface) {
                if (outerNames == null) {
                    outerNames = new ArrayList<String>(2);
                }
                outerNames.add(getQuotedClassName((ClassOrInterface) s, 0));
            } else if (s instanceof TypedDeclaration) {
                if (outerNames == null) {
                    outerNames = new ArrayList<String>(2);
                }
                outerNames.add(quoteIfJavaKeyword(((TypedDeclaration) s).getName()));
            }
            s = s.getContainer();
        }
        if (outerNames != null) {
            for (int ii = outerNames.size() - 1; ii >= 0; ii--) {
                String outerName = outerNames.get(ii);
                builder.select(outerName);
            }
        }
    }
    if ((namingOptions & NA_WRAPPER) != 0) {
        builder.select(getQuotedClassName(decl, namingOptions & (NA_GETTER | NA_SETTER)));
    } else if ((namingOptions & NA_WRAPPER_UNQUOTED) != 0) {
        builder.select(getRealName(decl, namingOptions & (NA_GETTER | NA_SETTER | NA_WRAPPER_UNQUOTED)));
    } else if ((namingOptions & NA_Q_LOCAL_INSTANCE) != 0) {
        if (Decl.isBoxedVariable(decl)) {
            builder.select(getVariableBoxName(decl));
        } else {
            builder.select(getAttrClassName(decl, namingOptions & (NA_GETTER | NA_SETTER)));
        }
    }
    if ((namingOptions & NA_WRAPPER_WITH_THIS) != 0) {
        builder.select("this");
    }
}
Also used : ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Scope(com.redhat.ceylon.model.typechecker.model.Scope) ArrayList(java.util.ArrayList) Package(com.redhat.ceylon.model.typechecker.model.Package)

Example 3 with Package

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

the class AbstractTransformer method isJavaEnumType.

boolean isJavaEnumType(Type type) {
    Module jdkBaseModule = loader().getJDKBaseModule();
    Package javaLang = jdkBaseModule.getPackage("java.lang");
    TypeDeclaration enumDecl = (TypeDeclaration) javaLang.getDirectMember("Enum", null, false);
    if (type.isClass() && type.getDeclaration().isAnonymous()) {
        type = type.getExtendedType();
    }
    return type.isSubtypeOf(enumDecl.appliedType(null, Collections.singletonList(type)));
}
Also used : Package(com.redhat.ceylon.model.typechecker.model.Package) Module(com.redhat.ceylon.model.typechecker.model.Module) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 4 with Package

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

the class IndexApiDoc method collectDeclarations.

private List<Declaration> collectDeclarations() {
    List<Declaration> declarations = new ArrayList<Declaration>();
    for (Package pkg : tool.getPackages(module)) {
        if (tool.shouldInclude(pkg)) {
            List<Declaration> members = pkg.getMembers();
            for (Declaration member : members) {
                if (tool.shouldInclude(member)) {
                    if (member instanceof Value && ((Value) member).getTypeDeclaration().isAnonymous()) {
                        continue;
                    }
                    declarations.add(member);
                }
            }
        }
    }
    Collections.sort(declarations, ReferenceableComparatorByName.INSTANCE);
    return declarations;
}
Also used : ArrayList(java.util.ArrayList) Value(com.redhat.ceylon.model.typechecker.model.Value) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) Package(com.redhat.ceylon.model.typechecker.model.Package)

Example 5 with Package

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

the class LinkRenderer method isLinkable.

private boolean isLinkable(Declaration decl) {
    if (decl == null) {
        return false;
    }
    if (decl.isParameter()) {
        return true;
    }
    if (!ceylonDocTool.isIncludeNonShared()) {
        if (!decl.isShared()) {
            return false;
        }
        Scope c = decl.getContainer();
        while (c != null) {
            boolean isShared = true;
            if (c instanceof Declaration) {
                isShared = ((Declaration) c).isShared();
            }
            if (c instanceof Package) {
                isShared = ((Package) c).isShared();
            }
            if (!isShared) {
                return false;
            }
            c = c.getContainer();
        }
    }
    return true;
}
Also used : Scope(com.redhat.ceylon.model.typechecker.model.Scope) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Package(com.redhat.ceylon.model.typechecker.model.Package)

Aggregations

Package (com.redhat.ceylon.model.typechecker.model.Package)47 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)18 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)17 Module (com.redhat.ceylon.model.typechecker.model.Module)16 Scope (com.redhat.ceylon.model.typechecker.model.Scope)16 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)14 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)11 ArrayList (java.util.ArrayList)10 Class (com.redhat.ceylon.model.typechecker.model.Class)8 Interface (com.redhat.ceylon.model.typechecker.model.Interface)7 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)6 Value (com.redhat.ceylon.model.typechecker.model.Value)6 PhasedUnit (com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)5 Function (com.redhat.ceylon.model.typechecker.model.Function)5 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)5 Type (com.redhat.ceylon.model.typechecker.model.Type)4 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)4 CeylonCompilationUnit (com.redhat.ceylon.compiler.java.codegen.CeylonCompilationUnit)3 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)3 File (java.io.File)3