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;
}
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;
}
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;
}
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;
}
Aggregations