Search in sources :

Example 6 with TypeSymbol

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

the class JavacTrees method getTree.

public JCTree getTree(Element element) {
    Symbol symbol = (Symbol) element;
    TypeSymbol enclosing = symbol.enclClass();
    Env<AttrContext> env = enter.getEnv(enclosing);
    if (env == null)
        return null;
    JCClassDecl classNode = env.enclClass;
    if (classNode != null) {
        if (TreeInfo.symbolFor(classNode) == element)
            return classNode;
        for (JCTree node : classNode.getMembers()) if (TreeInfo.symbolFor(node) == element)
            return node;
    }
    return null;
}
Also used : ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) JCTree(com.sun.tools.javac.tree.JCTree) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) AttrContext(com.sun.tools.javac.comp.AttrContext)

Example 7 with TypeSymbol

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

the class JavacUtil method getTypeParameters.

public static List<TypeParameterMirror> getTypeParameters(Symbol symbol) {
    try {
        com.sun.tools.javac.util.List<TypeSymbol> typeParameters = symbol.getTypeParameters();
        List<TypeParameterMirror> ret = new ArrayList<TypeParameterMirror>(typeParameters.size());
        for (TypeSymbol typeParameter : typeParameters) ret.add(new JavacTypeParameter(typeParameter));
        return ret;
    } catch (CompletionFailure x) {
        throw new ModelResolutionException("Failed to load type parameters", x);
    }
}
Also used : ModelResolutionException(com.redhat.ceylon.model.loader.ModelResolutionException) TypeParameterMirror(com.redhat.ceylon.model.loader.mirror.TypeParameterMirror) CompletionFailure(com.sun.tools.javac.code.Symbol.CompletionFailure) ArrayList(java.util.ArrayList) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol)

Example 8 with TypeSymbol

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

the class CeylonModelLoader method implemented.

/**
     * Copied from MethodSymbol.implemented and adapted for ignoring methods
     */
private Symbol implemented(MethodSymbol m, TypeSymbol c, Types types) {
    Symbol impl = null;
    for (List<Type> is = types.interfaces(c.type); impl == null && is.nonEmpty(); is = is.tail) {
        TypeSymbol i = is.head.tsym;
        impl = implementedIn(m, i, types);
        if (impl == null)
            impl = implemented(m, i, types);
    }
    return impl;
}
Also used : Type(com.sun.tools.javac.code.Type) UnknownType(com.redhat.ceylon.model.typechecker.model.UnknownType) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) PackageSymbol(com.sun.tools.javac.code.Symbol.PackageSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol)

Example 9 with TypeSymbol

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

the class CeylonModelLoader method isOverloadingMethod.

/**
     * Returns true if the given method is overloading an inherited method (from super class or interfaces).
     */
private boolean isOverloadingMethod(final MethodSymbol method) {
    /*
         * Copied from getOverriddenMethod and adapted for overloading
         */
    try {
        // interfaces have a different way to work
        if (method.owner.isInterface())
            return overloaded(method, method.owner.type.tsym, types);
        // so we stop there for it, especially since it does not have any overloading
        if (method.owner.type.tsym.getQualifiedName().toString().equals("ceylon.language.Exception"))
            return false;
        for (Type superType = types.supertype(method.owner.type); superType.tsym != null; superType = types.supertype(superType)) {
            TypeSymbol i = superType.tsym;
            String fqn = i.getQualifiedName().toString();
            // never go above this type since it has no supertype in Ceylon (does in Java though)
            if (fqn.equals("ceylon.language.Anything"))
                break;
            try {
                for (Entry e = i.members().lookup(method.name); e.scope != null; e = e.next()) {
                    // ignore some methods
                    if (isIgnored(e.sym))
                        continue;
                    if (!method.overrides(e.sym, (TypeSymbol) method.owner, types, false)) {
                        return true;
                    }
                }
                // try in the interfaces
                if (overloaded(method, i, types))
                    return true;
            } catch (Symbol.CompletionFailure x) {
            // just ignore unresolved interfaces, error will be logged when we try to add it
            }
            // so we stop there for it, especially since it does not have any overloading
            if (fqn.equals("ceylon.language.Exception"))
                break;
        }
        // try in the interfaces
        if (overloaded(method, method.owner.type.tsym, types))
            return true;
        return false;
    } catch (CompletionFailure x) {
        handleCompletionFailure(method, x);
        return false;
    }
}
Also used : Type(com.sun.tools.javac.code.Type) UnknownType(com.redhat.ceylon.model.typechecker.model.UnknownType) Entry(com.sun.tools.javac.code.Scope.Entry) CompletionFailure(com.sun.tools.javac.code.Symbol.CompletionFailure) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) PackageSymbol(com.sun.tools.javac.code.Symbol.PackageSymbol) CompletionFailure(com.sun.tools.javac.code.Symbol.CompletionFailure) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol)

Example 10 with TypeSymbol

use of com.sun.tools.javac.code.Symbol.TypeSymbol in project bazel by bazelbuild.

the class InternalUtils method substituteMethodReturnType.

/**
     * Returns the return type of a method, where the "raw" return type of that
     * method is given (i.e., the return type might still contain unsubstituted
     * type variables), given the receiver of the method call.
     */
public static TypeMirror substituteMethodReturnType(TypeMirror methodType, TypeMirror substitutedReceiverType) {
    if (methodType.getKind() != TypeKind.TYPEVAR) {
        return methodType;
    }
    // TODO: find a nicer way to substitute type variables
    String t = methodType.toString();
    Type finalReceiverType = (Type) substitutedReceiverType;
    int i = 0;
    for (TypeSymbol typeParam : finalReceiverType.tsym.getTypeParameters()) {
        if (t.equals(typeParam.toString())) {
            return finalReceiverType.getTypeArguments().get(i);
        }
        i++;
    }
    assert false;
    return null;
}
Also used : JCAnnotatedType(com.sun.tools.javac.tree.JCTree.JCAnnotatedType) WildcardType(javax.lang.model.type.WildcardType) Type(com.sun.tools.javac.code.Type) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol)

Aggregations

TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)21 Symbol (com.sun.tools.javac.code.Symbol)11 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)11 Type (com.sun.tools.javac.code.Type)11 MethodTree (com.sun.source.tree.MethodTree)6 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)6 PackageSymbol (com.sun.tools.javac.code.Symbol.PackageSymbol)4 JCTree (com.sun.tools.javac.tree.JCTree)4 VisitorState (com.google.errorprone.VisitorState)3 ClassTree (com.sun.source.tree.ClassTree)3 Tree (com.sun.source.tree.Tree)3 CompletionFailure (com.sun.tools.javac.code.Symbol.CompletionFailure)3 ArrayList (java.util.ArrayList)3 UnknownType (com.redhat.ceylon.model.typechecker.model.UnknownType)2 IdentifierTree (com.sun.source.tree.IdentifierTree)2 MemberSelectTree (com.sun.source.tree.MemberSelectTree)2 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)2 TreePath (com.sun.source.util.TreePath)2 Scope (com.sun.tools.javac.code.Scope)2 ClassType (com.sun.tools.javac.code.Type.ClassType)2