Search in sources :

Example 1 with VarSymbol

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

the class LambdaToMethod method makeLambdaStatementBody.

private JCBlock makeLambdaStatementBody(JCBlock block, final JCMethodDecl lambdaMethodDecl, boolean completeNormally) {
    final Type restype = lambdaMethodDecl.type.getReturnType();
    final boolean isTarget_void = restype.hasTag(VOID);
    boolean isTarget_Void = types.isSameType(restype, types.boxedClass(syms.voidType).type);
    class LambdaBodyTranslator extends TreeTranslator {

        @Override
        public void visitClassDef(JCClassDecl tree) {
            // do NOT recurse on any inner classes
            result = tree;
        }

        @Override
        public void visitLambda(JCLambda tree) {
            // do NOT recurse on any nested lambdas
            result = tree;
        }

        @Override
        public void visitReturn(JCReturn tree) {
            boolean isLambda_void = tree.expr == null;
            if (isTarget_void && !isLambda_void) {
                // Void to void conversion:
                // { TYPE $loc = RET-EXPR; return; }
                VarSymbol loc = makeSyntheticVar(0, names.fromString("$loc"), tree.expr.type, lambdaMethodDecl.sym);
                JCVariableDecl varDef = make.VarDef(loc, tree.expr);
                result = make.Block(0, List.<JCStatement>of(varDef, make.Return(null)));
            } else if (!isTarget_void || !isLambda_void) {
                // non-void to non-void conversion:
                // return (TYPE)RET-EXPR;
                tree.expr = transTypes.coerce(attrEnv, tree.expr, restype);
                result = tree;
            } else {
                result = tree;
            }
        }
    }
    JCBlock trans_block = new LambdaBodyTranslator().translate(block);
    if (completeNormally && isTarget_Void) {
        // there's no return statement and the lambda (possibly inferred)
        // return type is java.lang.Void; emit a synthetic return statement
        trans_block.stats = trans_block.stats.append(make.Return(make.Literal(BOT, null).setType(syms.botType)));
    }
    return trans_block;
}
Also used : MethodType(org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType) Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) TreeTranslator(org.eclipse.ceylon.langtools.tools.javac.tree.TreeTranslator) VarSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol)

Example 2 with VarSymbol

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

the class JavacClass method getDirectFields.

@Override
public List<FieldMirror> getDirectFields() {
    if (fields == null) {
        List<FieldMirror> ret = new LinkedList<FieldMirror>();
        for (Symbol sym : classSymbol.getEnclosedElements()) {
            if (sym instanceof VarSymbol && (sym.flags() & Flags.PRIVATE) == 0) {
                ret.add(new JavacField((VarSymbol) sym));
            }
        }
        fields = Collections.unmodifiableList(ret);
    }
    return fields;
}
Also used : FieldMirror(org.eclipse.ceylon.model.loader.mirror.FieldMirror) VarSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol) MethodSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) VarSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol) LinkedList(java.util.LinkedList)

Example 3 with VarSymbol

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

the class JavacMethod method getParameters.

@Override
public List<VariableMirror> getParameters() {
    if (parameters == null) {
        org.eclipse.ceylon.langtools.tools.javac.util.List<VarSymbol> params = methodSymbol.getParameters();
        List<VariableMirror> ret = new ArrayList<VariableMirror>(params.size());
        for (VarSymbol parameter : params) ret.add(new JavacVariable(parameter));
        parameters = Collections.unmodifiableList(ret);
    }
    return parameters;
}
Also used : VariableMirror(org.eclipse.ceylon.model.loader.mirror.VariableMirror) ArrayList(java.util.ArrayList) VarSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol)

Example 4 with VarSymbol

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

the class JavacTrees method searchField.

/**
 * @see com.sun.tools.javadoc.ClassDocImpl#searchField
 */
private VarSymbol searchField(ClassSymbol tsym, Name fieldName, Set<ClassSymbol> searched) {
    if (searched.contains(tsym)) {
        return null;
    }
    searched.add(tsym);
    for (org.eclipse.ceylon.langtools.tools.javac.code.Scope.Entry e = tsym.members().lookup(fieldName); e.scope != null; e = e.next()) {
        if (e.sym.kind == Kinds.VAR) {
            return (VarSymbol) e.sym;
        }
    }
    // ### If we found a VarSymbol above, but which did not pass
    // ### the modifier filter, we should return failure here!
    ClassSymbol encl = tsym.owner.enclClass();
    if (encl != null) {
        VarSymbol vsym = searchField(encl, fieldName, searched);
        if (vsym != null) {
            return vsym;
        }
    }
    // search superclass
    Type superclass = tsym.getSuperclass();
    if (superclass.tsym != null) {
        VarSymbol vsym = searchField((ClassSymbol) superclass.tsym, fieldName, searched);
        if (vsym != null) {
            return vsym;
        }
    }
    // search interfaces
    List<Type> intfs = tsym.getInterfaces();
    for (List<Type> l = intfs; l.nonEmpty(); l = l.tail) {
        Type intf = l.head;
        if (intf.isErroneous())
            continue;
        VarSymbol vsym = searchField((ClassSymbol) intf.tsym, fieldName, searched);
        if (vsym != null) {
            return vsym;
        }
    }
    return null;
}
Also used : UnionClassType(org.eclipse.ceylon.langtools.tools.javac.code.Type.UnionClassType) DeclaredType(org.eclipse.ceylon.javax.lang.model.type.DeclaredType) Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) ErrorType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ErrorType) ArrayType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType) ClassType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ClassType) Scope(org.eclipse.ceylon.langtools.source.tree.Scope) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) VarSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol)

Aggregations

VarSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol)4 ClassSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)2 Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 DeclaredType (org.eclipse.ceylon.javax.lang.model.type.DeclaredType)1 Scope (org.eclipse.ceylon.langtools.source.tree.Scope)1 Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)1 MethodSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol)1 ArrayType (org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType)1 ClassType (org.eclipse.ceylon.langtools.tools.javac.code.Type.ClassType)1 ErrorType (org.eclipse.ceylon.langtools.tools.javac.code.Type.ErrorType)1 MethodType (org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType)1 UnionClassType (org.eclipse.ceylon.langtools.tools.javac.code.Type.UnionClassType)1 TreeTranslator (org.eclipse.ceylon.langtools.tools.javac.tree.TreeTranslator)1 FieldMirror (org.eclipse.ceylon.model.loader.mirror.FieldMirror)1 VariableMirror (org.eclipse.ceylon.model.loader.mirror.VariableMirror)1