Search in sources :

Example 76 with Type

use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.

the class Types method makeFunctionalInterfaceClass.

/**
 * Create a symbol for a class that implements a given functional interface
 * and overrides its functional descriptor. This routine is used for two
 * main purposes: (i) checking well-formedness of a functional interface;
 * (ii) perform functional interface bridge calculation.
 */
public ClassSymbol makeFunctionalInterfaceClass(Env<AttrContext> env, Name name, List<Type> targets, long cflags) {
    if (targets.isEmpty()) {
        return null;
    }
    Symbol descSym = findDescriptorSymbol(targets.head.tsym);
    Type descType = findDescriptorType(targets.head);
    ClassSymbol csym = new ClassSymbol(cflags, name, env.enclClass.sym.outermostClass());
    csym.completer = null;
    csym.members_field = new Scope(csym);
    MethodSymbol instDescSym = new MethodSymbol(descSym.flags(), descSym.name, descType, csym);
    csym.members_field.enter(instDescSym);
    Type.ClassType ctype = new Type.ClassType(Type.noType, List.<Type>nil(), csym);
    ctype.supertype_field = syms.objectType;
    ctype.interfaces_field = targets;
    csym.type = ctype;
    csym.sourcefile = ((ClassSymbol) csym.owner).sourcefile;
    return csym;
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) Scope(org.eclipse.ceylon.langtools.tools.javac.code.Scope) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 77 with Type

use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.

the class Printer method printBrackets.

void printBrackets(Type t, StringBuilder sb, Locale locale) {
    Type arrel = t;
    while (arrel.hasTag(TypeTag.ARRAY)) {
        if (arrel.isAnnotated()) {
            sb.append(' ');
            sb.append(arrel.getAnnotationMirrors());
            sb.append(' ');
        }
        sb.append("[]");
        arrel = arrel.unannotatedType();
        arrel = ((ArrayType) arrel).elemtype;
    }
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 78 with Type

use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.

the class Printer method className.

/**
 * Converts a class name into a (possibly localized) string. Anonymous
 * inner classes get converted into a localized string.
 *
 * @param t the type of the class whose name is to be rendered
 * @param longform if set, the class' fullname is displayed - if unset the
 * short name is chosen (w/o package)
 * @param locale the locale in which the string is to be rendered
 * @return localized string representation
 */
protected String className(ClassType t, boolean longform, Locale locale) {
    Symbol sym = t.tsym;
    if (sym.name.length() == 0 && (sym.flags() & COMPOUND) != 0) {
        StringBuilder s = new StringBuilder(visit(t.supertype_field, locale));
        for (List<Type> is = t.interfaces_field; is.nonEmpty(); is = is.tail) {
            s.append('&');
            s.append(visit(is.head, locale));
        }
        return s.toString();
    } else if (sym.name.length() == 0) {
        String s;
        ClassType norm = (ClassType) t.tsym.type;
        if (norm == null) {
            s = localize(locale, "compiler.misc.anonymous.class", (Object) null);
        } else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
            s = localize(locale, "compiler.misc.anonymous.class", visit(norm.interfaces_field.head, locale));
        } else {
            s = localize(locale, "compiler.misc.anonymous.class", visit(norm.supertype_field, locale));
        }
        return s;
    } else if (longform) {
        return sym.getQualifiedName().toString();
    } else {
        return sym.name.toString();
    }
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 79 with Type

use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.

the class Printer method printBaseElementType.

void printBaseElementType(Type t, StringBuilder sb, Locale locale) {
    Type arrel = t;
    while (arrel.hasTag(TypeTag.ARRAY)) {
        arrel = arrel.unannotatedType();
        arrel = ((ArrayType) arrel).elemtype;
    }
    sb.append(visit(arrel, locale));
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 80 with Type

use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.

the class Symbol method getTypeParameters.

public List<TypeVariableSymbol> getTypeParameters() {
    ListBuffer<TypeVariableSymbol> l = new ListBuffer<>();
    for (Type t : type.getTypeArguments()) {
        Assert.check(t.tsym.getKind() == ElementKind.TYPE_PARAMETER);
        l.append((TypeVariableSymbol) t.tsym);
    }
    return l.toList();
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Aggregations

Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)164 Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)46 DeferredType (org.eclipse.ceylon.langtools.tools.javac.comp.DeferredAttr.DeferredType)13 DiagnosticType (org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticType)13 ArrayType (org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType)10 MethodType (org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType)10 ClassSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)9 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)9 MethodSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol)8 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)7 TypeSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol)7 DiagnosticPosition (org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticPosition)7 JavacType (org.eclipse.ceylon.compiler.java.loader.mirror.JavacType)5 PackageSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol)5 FunctionalInterfaceType (org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType)5 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)5 HashSet (java.util.HashSet)4 CompletionFailure (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure)4 VarSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol)4 FreeTypeListener (org.eclipse.ceylon.langtools.tools.javac.comp.Infer.FreeTypeListener)4