Search in sources :

Example 96 with Symbol

use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.

the class Resolve method findIdentInType.

/** Find an identifier among the members of a given type `site'.
     *  @param env       The current environment.
     *  @param site      The type containing the symbol to be found.
     *  @param name      The identifier's name.
     *  @param kind      Indicates the possible symbol kinds
     *                   (a subset of VAL, TYP).
     */
Symbol findIdentInType(Env<AttrContext> env, Type site, Name name, int kind) {
    Symbol bestSoFar = typeNotFound;
    Symbol sym;
    if ((kind & VAR) != 0) {
        sym = findField(env, site, name, site.tsym);
        if (sym.exists())
            return sym;
        else if (sym.kind < bestSoFar.kind)
            bestSoFar = sym;
    }
    if ((kind & TYP) != 0) {
        sym = findMemberType(env, site, name, site.tsym);
        if (sym.exists())
            return sym;
        else if (sym.kind < bestSoFar.kind)
            bestSoFar = sym;
    }
    return bestSoFar;
}
Also used : Symbol(com.sun.tools.javac.code.Symbol)

Example 97 with Symbol

use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.

the class Resolve method resolveConstructor.

/** Resolve constructor.
     *  @param pos       The position to use for error reporting.
     *  @param env       The environment current at the constructor invocation.
     *  @param site      The type of class for which a constructor is searched.
     *  @param argtypes  The types of the constructor invocation's value
     *                   arguments.
     *  @param typeargtypes  The types of the constructor invocation's type
     *                   arguments.
     */
Symbol resolveConstructor(DiagnosticPosition pos, Env<AttrContext> env, Type site, List<Type> argtypes, List<Type> typeargtypes) {
    Symbol sym = startResolution();
    List<MethodResolutionPhase> steps = methodResolutionSteps;
    while (steps.nonEmpty() && steps.head.isApplicable(boxingEnabled, varargsEnabled) && sym.kind >= ERRONEOUS) {
        currentStep = steps.head;
        sym = resolveConstructor(pos, env, site, argtypes, typeargtypes, steps.head.isBoxingRequired(), env.info.varArgs = steps.head.isVarargsRequired());
        methodResolutionCache.put(steps.head, sym);
        steps = steps.tail;
    }
    if (sym.kind >= AMBIGUOUS) {
        //if nothing is found return the 'first' error
        MethodResolutionPhase errPhase = firstErroneousResolutionPhase();
        sym = access(methodResolutionCache.get(errPhase), pos, site, names.init, true, argtypes, typeargtypes);
        env.info.varArgs = errPhase.isVarargsRequired();
    }
    return sym;
}
Also used : MethodResolutionPhase(com.sun.tools.javac.comp.Resolve.MethodResolutionPhase) Symbol(com.sun.tools.javac.code.Symbol)

Example 98 with Symbol

use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.

the class JavacElements method hides.

public boolean hides(Element hiderEl, Element hideeEl) {
    Symbol hider = cast(Symbol.class, hiderEl);
    Symbol hidee = cast(Symbol.class, hideeEl);
    // Names must match.  Nothing hides itself (just try it).
    if (hider == hidee || hider.kind != hidee.kind || hider.name != hidee.name) {
        return false;
    }
    // Methods only hide methods with matching signatures.
    if (hider.kind == Kinds.MTH) {
        if (!hider.isStatic() || !types.isSubSignature(hider.type, hidee.type)) {
            return false;
        }
    }
    // Hider must be in a subclass of hidee's class.
    // Note that if M1 hides M2, and M2 hides M3, and M3 is accessible
    // in M1's class, then M1 and M2 both hide M3.
    ClassSymbol hiderClass = hider.owner.enclClass();
    ClassSymbol hideeClass = hidee.owner.enclClass();
    if (hiderClass == null || hideeClass == null || !hiderClass.isSubClass(hideeClass, types)) {
        return false;
    }
    // The method isInheritedIn is poorly named:  it checks only access.
    return hidee.isInheritedIn(hiderClass, types);
}
Also used : Symbol(com.sun.tools.javac.code.Symbol)

Example 99 with Symbol

use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.

the class JavacElements method getAnnotation.

/**
     * An internal-use utility that creates a reified annotation.
     * This overloaded version take annotation inheritance into account.
     */
public static <A extends Annotation> A getAnnotation(ClassSymbol annotated, Class<A> annoType) {
    boolean inherited = annoType.isAnnotationPresent(Inherited.class);
    A result = null;
    while (annotated.name != annotated.name.table.names.java_lang_Object) {
        result = getAnnotation((Symbol) annotated, annoType);
        if (result != null || !inherited)
            break;
        Type sup = annotated.getSuperclass();
        if (sup.tag != TypeTags.CLASS || sup.isErroneous())
            break;
        annotated = (ClassSymbol) sup.tsym;
    }
    return result;
}
Also used : DeclaredType(javax.lang.model.type.DeclaredType) Symbol(com.sun.tools.javac.code.Symbol)

Example 100 with Symbol

use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.

the class JavacElements method matchAnnoToTree.

/**
     * Returns the tree for an annotation given the annotated element
     * and the element's own tree.  Returns null if the tree cannot be found.
     */
private JCTree matchAnnoToTree(AnnotationMirror findme, Element e, JCTree tree) {
    Symbol sym = cast(Symbol.class, e);
    class Vis extends JCTree.Visitor {

        List<JCAnnotation> result = null;

        public void visitTopLevel(JCCompilationUnit tree) {
            result = tree.packageAnnotations;
        }

        public void visitClassDef(JCClassDecl tree) {
            result = tree.mods.annotations;
        }

        public void visitMethodDef(JCMethodDecl tree) {
            result = tree.mods.annotations;
        }

        public void visitVarDef(JCVariableDecl tree) {
            result = tree.mods.annotations;
        }
    }
    Vis vis = new Vis();
    tree.accept(vis);
    if (vis.result == null)
        return null;
    return matchAnnoToTree(cast(Attribute.Compound.class, findme), sym.getAnnotationMirrors(), vis.result);
}
Also used : Symbol(com.sun.tools.javac.code.Symbol)

Aggregations

Symbol (com.sun.tools.javac.code.Symbol)195 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)56 Type (com.sun.tools.javac.code.Type)54 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)53 VarSymbol (com.sun.tools.javac.code.Symbol.VarSymbol)45 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)36 PackageSymbol (com.sun.tools.javac.code.Symbol.PackageSymbol)29 JCTree (com.sun.tools.javac.tree.JCTree)28 ClassType (com.sun.tools.javac.code.Type.ClassType)18 Tree (com.sun.source.tree.Tree)17 ExpressionTree (com.sun.source.tree.ExpressionTree)15 DynamicMethodSymbol (com.sun.tools.javac.code.Symbol.DynamicMethodSymbol)15 OperatorSymbol (com.sun.tools.javac.code.Symbol.OperatorSymbol)15 ClassTree (com.sun.source.tree.ClassTree)14 MethodTree (com.sun.source.tree.MethodTree)14 Name (com.sun.tools.javac.util.Name)14 IdentifierTree (com.sun.source.tree.IdentifierTree)13 ArrayType (com.sun.tools.javac.code.Type.ArrayType)12 MethodType (com.sun.tools.javac.code.Type.MethodType)12 UnionClassType (com.sun.tools.javac.code.Type.UnionClassType)12