Search in sources :

Example 61 with Symbol

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

the class Gen method setTypeAnnotationPositions.

private void setTypeAnnotationPositions(int treePos) {
    MethodSymbol meth = code.meth;
    boolean initOrClinit = code.meth.getKind() == org.eclipse.ceylon.javax.lang.model.element.ElementKind.CONSTRUCTOR || code.meth.getKind() == org.eclipse.ceylon.javax.lang.model.element.ElementKind.STATIC_INIT;
    for (Attribute.TypeCompound ta : meth.getRawTypeAttributes()) {
        if (ta.hasUnknownPosition())
            ta.tryFixPosition();
        if (ta.position.matchesPos(treePos))
            ta.position.updatePosOffset(code.cp);
    }
    if (!initOrClinit)
        return;
    for (Attribute.TypeCompound ta : meth.owner.getRawTypeAttributes()) {
        if (ta.hasUnknownPosition())
            ta.tryFixPosition();
        if (ta.position.matchesPos(treePos))
            ta.position.updatePosOffset(code.cp);
    }
    ClassSymbol clazz = meth.enclClass();
    for (Symbol s : new org.eclipse.ceylon.langtools.tools.javac.model.FilteredMemberList(clazz.members())) {
        if (!s.getKind().isField())
            continue;
        for (Attribute.TypeCompound ta : s.getRawTypeAttributes()) {
            if (ta.hasUnknownPosition())
                ta.tryFixPosition();
            if (ta.position.matchesPos(treePos))
                ta.position.updatePosOffset(code.cp);
        }
    }
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) TypeCompound(org.eclipse.ceylon.langtools.tools.javac.code.Attribute.TypeCompound)

Example 62 with Symbol

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

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

Example 63 with Symbol

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

the class JavacElements method getTreeAndTopLevel.

/**
 * Returns the tree node and compilation unit corresponding to this
 * element, or null if they can't be found.
 */
private Pair<JCTree, JCCompilationUnit> getTreeAndTopLevel(Element e) {
    Symbol sym = cast(Symbol.class, e);
    Env<AttrContext> enterEnv = getEnterEnv(sym);
    if (enterEnv == null)
        return null;
    JCTree tree = TreeInfo.declarationFor(sym, enterEnv.tree);
    if (tree == null || enterEnv.toplevel == null)
        return null;
    return new Pair<JCTree, JCCompilationUnit>(tree, enterEnv.toplevel);
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) AttrContext(org.eclipse.ceylon.langtools.tools.javac.comp.AttrContext)

Example 64 with Symbol

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

the class JavacElements method getAllMembers.

/**
 * {@inheritDoc}
 */
public FilteredMemberList getAllMembers(TypeElement element) {
    Symbol sym = cast(Symbol.class, element);
    Scope scope = sym.members().dupUnshared();
    List<Type> closure = types.closure(sym.asType());
    for (Type t : closure) addMembers(scope, t);
    return new FilteredMemberList(scope);
}
Also used : DeclaredType(org.eclipse.ceylon.javax.lang.model.type.DeclaredType) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 65 with Symbol

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

the class JavacTypes method asMemberOf.

/**
 * Returns the type of an element when that element is viewed as
 * a member of, or otherwise directly contained by, a given type.
 * For example,
 * when viewed as a member of the parameterized type {@code Set<String>},
 * the {@code Set.add} method is an {@code ExecutableType}
 * whose parameter is of type {@code String}.
 *
 * @param containing  the containing type
 * @param element     the element
 * @return the type of the element as viewed from the containing type
 * @throws IllegalArgumentException if the element is not a valid one
 *          for the given type
 */
public TypeMirror asMemberOf(DeclaredType containing, Element element) {
    Type site = (Type) containing;
    Symbol sym = (Symbol) element;
    if (types.asSuper(site, sym.getEnclosingElement()) == null)
        throw new IllegalArgumentException(sym + "@" + site);
    return types.memberType(site, sym);
}
Also used : 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