Search in sources :

Example 51 with Symbol

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

the class Check method checkNonCyclicElementsInternal.

void checkNonCyclicElementsInternal(DiagnosticPosition pos, TypeSymbol tsym) {
    if ((tsym.flags_field & ACYCLIC_ANN) != 0)
        return;
    if ((tsym.flags_field & LOCKED) != 0) {
        log.error(pos, "cyclic.annotation.element");
        return;
    }
    try {
        tsym.flags_field |= LOCKED;
        for (Scope.Entry e = tsym.members().elems; e != null; e = e.sibling) {
            Symbol s = e.sym;
            if (s.kind != Kinds.MTH)
                continue;
            checkAnnotationResType(pos, ((MethodSymbol) s).type.getReturnType());
        }
    } finally {
        tsym.flags_field &= ~LOCKED;
        tsym.flags_field |= ACYCLIC_ANN;
    }
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 52 with Symbol

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

the class Enter method visitClassDef.

@Override
public void visitClassDef(JCClassDecl tree) {
    Symbol owner = env.info.scope.owner;
    Scope enclScope = enterScope(env);
    ClassSymbol c;
    if (owner.kind == PCK) {
        // We are seeing a toplevel class.
        PackageSymbol packge = (PackageSymbol) owner;
        for (Symbol q = packge; q != null && q.kind == PCK; q = q.owner) q.flags_field |= EXISTS;
        c = reader.enterClass(tree.name, packge);
        packge.members().enterIfAbsent(c);
        if ((tree.mods.flags & PUBLIC) != 0 && !classNameMatchesFileName(c, env) && !sourceLanguage.isCeylon()) {
            log.error(tree.pos(), "class.public.should.be.in.file", tree.name);
        }
    } else {
        if (!tree.name.isEmpty() && !chk.checkUniqueClassName(tree.pos(), tree.name, enclScope)) {
            result = null;
            return;
        }
        if (owner.kind == TYP) {
            // We are seeing a member class.
            c = reader.enterClass(tree.name, (TypeSymbol) owner);
            if ((owner.flags_field & INTERFACE) != 0) {
                tree.mods.flags |= PUBLIC | STATIC;
            }
        } else {
            // We are seeing a local class.
            c = reader.defineClass(tree.name, owner);
            c.flatname = chk.localClassName(c);
            if (!c.name.isEmpty())
                chk.checkTransparentClass(tree.pos(), c, env.info.scope);
        }
    }
    tree.sym = c;
    // Enter class into `compiled' table and enclosing scope.
    if (chk.compiled.get(c.flatname) != null) {
        duplicateClass(tree.pos(), c);
        result = types.createErrorType(tree.name, (TypeSymbol) owner, Type.noType);
        tree.sym = (ClassSymbol) result.tsym;
        return;
    }
    chk.compiled.put(c.flatname, c);
    // CEYLON(stef): don't add anonymous classes to the environment
    if (tree.name.length() != 0)
        enclScope.enter(c);
    // Set up an environment for class block and store in `typeEnvs'
    // table, to be retrieved later in memberEnter and attribution.
    Env<AttrContext> localEnv = classEnv(tree, env);
    typeEnvs.put(c, localEnv);
    // Fill out class fields.
    c.completer = memberEnter;
    c.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, c, tree);
    c.sourcefile = env.toplevel.sourcefile;
    c.members_field = new Scope(c);
    // determine the enclosing type
    if (sourceLanguage.isCeylon()) {
        // (This would be an illegal access to "this before super").
        if (env.info.isSelfCall && (isNewAnonymousClass(env.tree) || isNewLetClass(env.tree))) {
            c.flags_field |= CEYLON_NOOUTERTHIS;
        }
    }
    ClassType ct = (ClassType) c.type;
    // Ceylon: make sure everything is reset if we Enter twice for bootstrap
    ct.interfaces_field = null;
    ct.allparams_field = null;
    ct.supertype_field = null;
    ct.all_interfaces_field = null;
    // End Ceylon
    if (owner.kind != PCK && (c.flags_field & STATIC) == 0) {
        // We are seeing a local or inner class.
        // Set outer_field of this class to closest enclosing class
        // which contains this class in a non-static context
        // (its "enclosing instance class"), provided such a class exists.
        Symbol owner1 = owner;
        // Ceylon: make sure we skip outer classes if required
        boolean skip = c.skipOuterClass();
        while (skip || ((owner1.kind & (VAR | MTH)) != 0 && (owner1.flags_field & STATIC) == 0)) {
            // Ceylon: we only take new outer class skip orders from types, never from methods/vars
            if (owner1.kind == TYP)
                skip = owner1.skipOuterClass();
            owner1 = owner1.owner;
        }
        if (owner1.kind == TYP) {
            ct.setEnclosingType(owner1.type);
        }
    }
    // Enter type parameters.
    ct.typarams_field = classEnter(tree.typarams, localEnv);
    // completed later.
    if (!c.isLocal() && uncompleted != null)
        uncompleted.append(c);
    // System.err.println("entering " + c.fullname + " in " + c.owner);//DEBUG
    // Recursively enter all member classes.
    classEnter(tree.defs, localEnv);
    result = c.type;
}
Also used : Scope(org.eclipse.ceylon.langtools.tools.javac.code.Scope) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 53 with Symbol

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

the class TransTypes method visitApply.

public void visitApply(JCMethodInvocation tree) {
    tree.meth = translate(tree.meth, null);
    Symbol meth = TreeInfo.symbol(tree.meth);
    Type mt = meth.erasure(types);
    List<Type> argtypes = mt.getParameterTypes();
    if (allowEnums && meth.name == names.init && meth.owner == syms.enumSym)
        argtypes = argtypes.tail.tail;
    if (tree.varargsElement != null)
        tree.varargsElement = types.erasure(tree.varargsElement);
    else if (tree.args.length() != argtypes.length()) {
        log.error(tree.pos(), "method.invoked.with.incorrect.number.arguments", tree.args.length(), argtypes.length());
    }
    tree.args = translateArgs(tree.args, argtypes, tree.varargsElement);
    tree.type = types.erasure(tree.type);
    // Insert casts of method invocation results as needed.
    result = retype(tree, mt.getReturnType(), pt);
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 54 with Symbol

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

the class Types method functionalInterfaceBridges.

/**
 * Find the minimal set of methods that are overridden by the functional
 * descriptor in 'origin'. All returned methods are assumed to have different
 * erased signatures.
 */
public List<Symbol> functionalInterfaceBridges(TypeSymbol origin) {
    Assert.check(isFunctionalInterface(origin));
    Symbol descSym = findDescriptorSymbol(origin);
    CompoundScope members = membersClosure(origin.type, false);
    ListBuffer<Symbol> overridden = new ListBuffer<>();
    outer: for (Symbol m2 : members.getElementsByName(descSym.name, bridgeFilter)) {
        if (m2 == descSym)
            continue;
        else if (descSym.overrides(m2, origin, Types.this, false)) {
            for (Symbol m3 : overridden) {
                if (isSameType(m3.erasure(Types.this), m2.erasure(Types.this)) || (m3.overrides(m2, origin, Types.this, false) && (pendingBridges((ClassSymbol) origin, m3.enclClass()) || (((MethodSymbol) m2).binaryImplementation((ClassSymbol) m3.owner, Types.this) != null)))) {
                    continue outer;
                }
            }
            overridden.add(m2);
        }
    }
    return overridden.toList();
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 55 with Symbol

use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol 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)

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