Search in sources :

Example 16 with Symbol

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

the class Resolve method findType.

/**
 * Find an unqualified type symbol.
 *  @param env       The current environment.
 *  @param name      The type's name.
 */
Symbol findType(Env<AttrContext> env, Name name) {
    Symbol bestSoFar = typeNotFound;
    Symbol sym;
    boolean staticOnly = false;
    for (Env<AttrContext> env1 = env; env1.outer != null; env1 = env1.outer) {
        if (isStatic(env1))
            staticOnly = true;
        // First, look for a type variable and the first member type
        final Symbol tyvar = findTypeVar(env1, name, staticOnly);
        sym = findImmediateMemberType(env1, env1.enclClass.sym.type, name, env1.enclClass.sym);
        // immediate member, OR the type variable is for a method.
        if (tyvar != typeNotFound) {
            if (sym == typeNotFound || (tyvar.kind == TYP && tyvar.exists() && tyvar.owner.kind == MTH))
                return tyvar;
        }
        // otherwise, do the entire findMemberType
        if (sym == typeNotFound)
            sym = findInheritedMemberType(env1, env1.enclClass.sym.type, name, env1.enclClass.sym);
        if (staticOnly && sym.kind == TYP && sym.type.hasTag(CLASS) && sym.type.getEnclosingType().hasTag(CLASS) && env1.enclClass.sym.type.isParameterized() && sym.type.getEnclosingType().isParameterized())
            return new StaticError(sym);
        else if (sym.exists())
            return sym;
        else if (sym.kind < bestSoFar.kind)
            bestSoFar = sym;
        JCClassDecl encl = env1.baseClause ? (JCClassDecl) env1.tree : env1.enclClass;
        if ((encl.sym.flags() & STATIC) != 0)
            staticOnly = true;
    }
    if (!env.tree.hasTag(IMPORT)) {
        sym = findGlobalType(env, env.toplevel.namedImportScope, name);
        if (sym.exists())
            return sym;
        else if (sym.kind < bestSoFar.kind)
            bestSoFar = sym;
        sym = findGlobalType(env, env.toplevel.packge.members(), name);
        if (sym.exists())
            return sym;
        else if (sym.kind < bestSoFar.kind)
            bestSoFar = sym;
        sym = findGlobalType(env, env.toplevel.starImportScope, name);
        if (sym.exists())
            return sym;
        else if (sym.kind < bestSoFar.kind)
            bestSoFar = sym;
    }
    return bestSoFar;
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) DeferredAttrContext(org.eclipse.ceylon.langtools.tools.javac.comp.DeferredAttr.DeferredAttrContext)

Example 17 with Symbol

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

the class Resolve method findIdentInPackage.

/**
 * Find an identifier in a package which matches a specified kind set.
 *  @param env       The current environment.
 *  @param name      The identifier's name.
 *  @param kind      Indicates the possible symbol kinds
 *                   (a nonempty subset of TYP, PCK).
 */
Symbol findIdentInPackage(Env<AttrContext> env, TypeSymbol pck, Name name, int kind) {
    Name fullname = TypeSymbol.formFullName(name, pck);
    Symbol bestSoFar = typeNotFound;
    PackageSymbol pack = null;
    if ((kind & PCK) != 0) {
        pack = reader.enterPackage(fullname);
        if (pack.exists())
            return pack;
    }
    if ((kind & TYP) != 0) {
        Symbol sym = loadClass(env, fullname);
        if (sym.exists()) {
            // don't allow programs to use flatnames
            if (name == sym.name)
                return sym;
        } else if (sym.kind < bestSoFar.kind)
            bestSoFar = sym;
    }
    return (pack != null) ? pack : bestSoFar;
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 18 with Symbol

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

the class Resolve method resolveInternalConstructor.

/**
 * Resolve a constructor, throw a fatal error if not found.
 *  @param pos       The position to use for error reporting.
 *  @param env       The environment current at the method invocation.
 *  @param site      The type to be constructed.
 *  @param argtypes  The types of the invocation's value arguments.
 *  @param typeargtypes  The types of the invocation's type arguments.
 */
public MethodSymbol resolveInternalConstructor(DiagnosticPosition pos, Env<AttrContext> env, Type site, List<Type> argtypes, List<Type> typeargtypes) {
    MethodResolutionContext resolveContext = new MethodResolutionContext();
    resolveContext.internalResolution = true;
    Symbol sym = resolveConstructor(resolveContext, pos, env, site, argtypes, typeargtypes);
    if (sym.kind == MTH)
        return (MethodSymbol) sym;
    else
        throw new FatalError(diags.fragment("fatal.err.cant.locate.ctor", site));
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 19 with Symbol

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

the class Resolve method findFun.

/**
 * Find unqualified method matching given name, type and value arguments.
 *  @param env       The current environment.
 *  @param name      The method's name.
 *  @param argtypes  The method's value arguments.
 *  @param typeargtypes  The method's type arguments.
 *  @param allowBoxing Allow boxing conversions of arguments.
 *  @param useVarargs Box trailing arguments into an array for varargs.
 */
Symbol findFun(Env<AttrContext> env, Name name, List<Type> argtypes, List<Type> typeargtypes, boolean allowBoxing, boolean useVarargs) {
    Symbol bestSoFar = methodNotFound;
    Symbol sym;
    Env<AttrContext> env1 = env;
    boolean staticOnly = false;
    while (env1.outer != null) {
        if (isStatic(env1))
            staticOnly = true;
        Assert.check(env1.info.preferredTreeForDiagnostics == null);
        env1.info.preferredTreeForDiagnostics = env.tree;
        try {
            sym = findMethod(env1, env1.enclClass.sym.type, name, argtypes, typeargtypes, allowBoxing, useVarargs, false);
            if (sym.exists()) {
                if (staticOnly && sym.kind == MTH && sym.owner.kind == TYP && (sym.flags() & STATIC) == 0)
                    return new StaticError(sym);
                else
                    return sym;
            } else if (sym.kind < bestSoFar.kind) {
                bestSoFar = sym;
            }
        } finally {
            env1.info.preferredTreeForDiagnostics = null;
        }
        if ((env1.enclClass.sym.flags() & STATIC) != 0)
            staticOnly = true;
        env1 = env1.outer;
    }
    sym = findMethod(env, syms.predefClass.type, name, argtypes, typeargtypes, allowBoxing, useVarargs, false);
    if (sym.exists())
        return sym;
    Scope.Entry e = env.toplevel.namedImportScope.lookup(name);
    for (; e.scope != null; e = e.next()) {
        sym = e.sym;
        Type origin = e.getOrigin().owner.type;
        if (sym.kind == MTH) {
            if (e.sym.owner.type != origin)
                sym = sym.clone(e.getOrigin().owner);
            if (!isAccessible(env, origin, sym))
                sym = new AccessError(env, origin, sym);
            bestSoFar = selectBest(env, origin, argtypes, typeargtypes, sym, bestSoFar, allowBoxing, useVarargs, false);
        }
    }
    if (bestSoFar.exists())
        return bestSoFar;
    e = env.toplevel.starImportScope.lookup(name);
    for (; e.scope != null; e = e.next()) {
        sym = e.sym;
        Type origin = e.getOrigin().owner.type;
        if (sym.kind == MTH) {
            if (e.sym.owner.type != origin)
                sym = sym.clone(e.getOrigin().owner);
            if (!isAccessible(env, origin, sym))
                sym = new AccessError(env, origin, sym);
            bestSoFar = selectBest(env, origin, argtypes, typeargtypes, sym, bestSoFar, allowBoxing, useVarargs, false);
        }
    }
    return bestSoFar;
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) DeferredType(org.eclipse.ceylon.langtools.tools.javac.comp.DeferredAttr.DeferredType) DiagnosticType(org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticType) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) DeferredAttrContext(org.eclipse.ceylon.langtools.tools.javac.comp.DeferredAttr.DeferredAttrContext)

Example 20 with Symbol

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

the class Resolve method findVar.

/**
 * Find unqualified variable or field with given name.
 *  Synthetic fields always skipped.
 *  @param env     The current environment.
 *  @param name    The name of the variable or field.
 */
Symbol findVar(Env<AttrContext> env, Name name) {
    Symbol bestSoFar = varNotFound;
    Symbol sym;
    Env<AttrContext> env1 = env;
    boolean staticOnly = false;
    while (env1.outer != null) {
        if (isStatic(env1))
            staticOnly = true;
        Scope.Entry e = env1.info.scope.lookup(name);
        while (e.scope != null && (e.sym.kind != VAR || (e.sym.flags_field & SYNTHETIC) != 0)) e = e.next();
        sym = (e.scope != null) ? e.sym : findField(env1, env1.enclClass.sym.type, name, env1.enclClass.sym);
        if (sym.exists()) {
            if (staticOnly && sym.kind == VAR && sym.owner.kind == TYP && (sym.flags() & STATIC) == 0)
                return new StaticError(sym);
            else
                return sym;
        } else if (sym.kind < bestSoFar.kind) {
            bestSoFar = sym;
        }
        if ((env1.enclClass.sym.flags() & STATIC) != 0)
            staticOnly = true;
        env1 = env1.outer;
    }
    sym = findField(env, syms.predefClass.type, name, syms.predefClass);
    if (sym.exists())
        return sym;
    if (bestSoFar.exists())
        return bestSoFar;
    Symbol origin = null;
    for (Scope sc : new Scope[] { env.toplevel.namedImportScope, env.toplevel.starImportScope }) {
        Scope.Entry e = sc.lookup(name);
        for (; e.scope != null; e = e.next()) {
            sym = e.sym;
            if (sym.kind != VAR)
                continue;
            // invariant: sym.kind == VAR
            if (bestSoFar.kind < AMBIGUOUS && sym.owner != bestSoFar.owner)
                return new AmbiguityError(bestSoFar, sym);
            else if (bestSoFar.kind >= VAR) {
                origin = e.getOrigin().owner;
                bestSoFar = isAccessible(env, origin.type, sym) ? sym : new AccessError(env, origin.type, sym);
            }
        }
        if (bestSoFar.exists())
            break;
    }
    if (bestSoFar.kind == VAR && bestSoFar.owner.type != origin.type)
        return bestSoFar.clone(origin);
    else
        return bestSoFar;
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) DeferredAttrContext(org.eclipse.ceylon.langtools.tools.javac.comp.DeferredAttr.DeferredAttrContext)

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