Search in sources :

Example 46 with Symbol

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

the class LambdaToMethod method deserGetter.

private JCExpression deserGetter(String func, Type type, List<Type> argTypes, List<JCExpression> args) {
    MethodType getmt = new MethodType(argTypes, type, List.<Type>nil(), syms.methodClass);
    Symbol getsym = rs.resolveQualifiedMethod(null, attrEnv, syms.serializedLambdaType, names.fromString(func), argTypes, List.<Type>nil());
    return make.Apply(List.<JCExpression>nil(), make.Select(make.Ident(kInfo.deserParamSym).setType(syms.serializedLambdaType), getsym).setType(getmt), args).setType(type);
}
Also used : MethodType(org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType) VarSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol) MethodSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) TypeSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol) DynamicMethodSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.DynamicMethodSymbol) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)

Example 47 with Symbol

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

the class Check method firstIncompatibility.

/**
 * Return the first method which is defined with same args
 *  but different return types in two given interfaces, or null if none
 *  exists.
 *  @param t1     The first type.
 *  @param t2     The second type.
 *  @param site   The most derived type.
 *  @returns symbol from t2 that conflicts with one in t1.
 */
private Symbol firstIncompatibility(DiagnosticPosition pos, Type t1, Type t2, Type site) {
    Map<TypeSymbol, Type> interfaces1 = new HashMap<TypeSymbol, Type>();
    closure(t1, interfaces1);
    Map<TypeSymbol, Type> interfaces2;
    if (t1 == t2)
        interfaces2 = interfaces1;
    else
        closure(t2, interfaces1, interfaces2 = new HashMap<TypeSymbol, Type>());
    for (Type t3 : interfaces1.values()) {
        for (Type t4 : interfaces2.values()) {
            Symbol s = firstDirectIncompatibility(pos, t3, t4, site);
            if (s != null)
                return s;
        }
    }
    return null;
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 48 with Symbol

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

the class Check method checkDefaultMethodClashes.

void checkDefaultMethodClashes(DiagnosticPosition pos, Type site) {
    DefaultMethodClashFilter dcf = new DefaultMethodClashFilter(site);
    for (Symbol m : types.membersClosure(site, false).getElements(dcf)) {
        Assert.check(m.kind == MTH);
        List<MethodSymbol> prov = types.interfaceCandidates(site, (MethodSymbol) m);
        if (prov.size() > 1) {
            ListBuffer<Symbol> abstracts = new ListBuffer<>();
            ListBuffer<Symbol> defaults = new ListBuffer<>();
            for (MethodSymbol provSym : prov) {
                if ((provSym.flags() & DEFAULT) != 0) {
                    defaults = defaults.append(provSym);
                } else if ((provSym.flags() & ABSTRACT) != 0) {
                    abstracts = abstracts.append(provSym);
                }
                if (defaults.nonEmpty() && defaults.size() + abstracts.size() >= 2) {
                    // strong semantics - issue an error if two sibling interfaces
                    // have two override-equivalent defaults - or if one is abstract
                    // and the other is default
                    String errKey;
                    Symbol s1 = defaults.first();
                    Symbol s2;
                    if (defaults.size() > 1) {
                        errKey = "types.incompatible.unrelated.defaults";
                        s2 = defaults.toList().tail.head;
                    } else {
                        errKey = "types.incompatible.abstract.default";
                        s2 = abstracts.first();
                    }
                    log.error(pos, errKey, Kinds.kindName(site.tsym), site, m.name, types.memberType(site, m).getParameterTypes(), s1.location(), s2.location());
                    break;
                }
            }
        }
    }
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 49 with Symbol

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

the class Check method validateAnnotation.

private boolean validateAnnotation(JCAnnotation a) {
    boolean isValid = true;
    // collect an inventory of the annotation elements
    Set<MethodSymbol> members = new LinkedHashSet<MethodSymbol>();
    for (Scope.Entry e = a.annotationType.type.tsym.members().elems; e != null; e = e.sibling) if (e.sym.kind == MTH && e.sym.name != names.clinit && (e.sym.flags() & SYNTHETIC) == 0)
        members.add((MethodSymbol) e.sym);
    // remove the ones that are assigned values
    for (JCTree arg : a.args) {
        // recovery
        if (!arg.hasTag(ASSIGN))
            continue;
        JCAssign assign = (JCAssign) arg;
        Symbol m = TreeInfo.symbol(assign.lhs);
        if (m == null || m.type.isErroneous())
            continue;
        if (!members.remove(m)) {
            isValid = false;
            log.error(assign.lhs.pos(), "duplicate.annotation.member.value", m.name, a.type);
        }
    }
    // all the remaining ones better have default values
    List<Name> missingDefaults = List.nil();
    for (MethodSymbol m : members) {
        if (m.defaultValue == null && !m.type.isErroneous()) {
            missingDefaults = missingDefaults.append(m.name);
        }
    }
    missingDefaults = missingDefaults.reverse();
    if (missingDefaults.nonEmpty()) {
        isValid = false;
        String key = (missingDefaults.size() > 1) ? "annotation.missing.default.value.1" : "annotation.missing.default.value";
        log.error(a.pos(), key, a.type, missingDefaults);
    }
    // repeated values in its value member
    if (a.annotationType.type.tsym != syms.annotationTargetType.tsym || a.args.tail == null)
        return isValid;
    // error recovery
    if (!a.args.head.hasTag(ASSIGN))
        return false;
    JCAssign assign = (JCAssign) a.args.head;
    Symbol m = TreeInfo.symbol(assign.lhs);
    if (m.name != names.value)
        return false;
    JCTree rhs = assign.rhs;
    if (!rhs.hasTag(NEWARRAY))
        return false;
    JCNewArray na = (JCNewArray) rhs;
    Set<Symbol> targets = new HashSet<Symbol>();
    for (JCTree elem : na.elems) {
        if (!targets.add(TreeInfo.symbol(elem))) {
            isValid = false;
            log.error(elem.pos(), "repeated.annotation.target");
        }
    }
    return isValid;
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)

Example 50 with Symbol

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

the class Check method checkCommonOverriderIn.

// WHERE
boolean checkCommonOverriderIn(Symbol s1, Symbol s2, Type site) {
    Map<TypeSymbol, Type> supertypes = new HashMap<TypeSymbol, Type>();
    Type st1 = types.memberType(site, s1);
    Type st2 = types.memberType(site, s2);
    closure(site, supertypes);
    for (Type t : supertypes.values()) {
        for (Scope.Entry e = t.tsym.members().lookup(s1.name); e.scope != null; e = e.next()) {
            Symbol s3 = e.sym;
            if (s3 == s1 || s3 == s2 || s3.kind != MTH || (s3.flags() & (BRIDGE | SYNTHETIC)) != 0)
                continue;
            Type st3 = types.memberType(site, s3);
            if (types.overrideEquivalent(st3, st1) && types.overrideEquivalent(st3, st2) && types.returnTypeSubstitutable(st3, st1) && types.returnTypeSubstitutable(st3, st2)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Aggregations

Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)115 Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)42 ClassSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)16 MethodSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol)15 VarSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol)12 TypeSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol)11 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)11 DeferredAttrContext (org.eclipse.ceylon.langtools.tools.javac.comp.DeferredAttr.DeferredAttrContext)8 DeferredType (org.eclipse.ceylon.langtools.tools.javac.comp.DeferredAttr.DeferredType)8 DiagnosticType (org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticType)8 DynamicMethodSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.DynamicMethodSymbol)6 MethodType (org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType)6 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)5 DiagnosticPosition (org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticPosition)4 ErrorType (org.eclipse.ceylon.javax.lang.model.type.ErrorType)3 Scope (org.eclipse.ceylon.langtools.tools.javac.code.Scope)3 PackageSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol)3 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 DeclaredType (org.eclipse.ceylon.javax.lang.model.type.DeclaredType)2