use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.SequencedArgument in project ceylon by eclipse.
the class SequenceGenerator method tuple.
static void tuple(final Tree.Tuple that, final GenerateJsVisitor gen) {
SequencedArgument sarg = that.getSequencedArgument();
if (sarg == null) {
gen.out(gen.getClAlias(), "empty()");
} else {
final List<PositionalArgument> positionalArguments = sarg.getPositionalArguments();
final boolean spread = SequenceGenerator.isSpread(positionalArguments);
int lim = positionalArguments.size() - 1;
gen.out(gen.getClAlias(), "tpl$([");
int count = 0;
for (PositionalArgument expr : positionalArguments) {
if (!(count == lim && spread)) {
if (count > 0) {
gen.out(",");
}
expr.visit(gen);
}
count++;
}
gen.out("]");
if (spread) {
gen.out(",");
positionalArguments.get(lim).visit(gen);
}
gen.out(")");
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.SequencedArgument in project ceylon by eclipse.
the class ClassTransformer method transformAnnotationParameterDefault.
private JCExpression transformAnnotationParameterDefault(Tree.Parameter p) {
Tree.SpecifierOrInitializerExpression defaultArgument = Decl.getDefaultArgument(p);
Tree.Expression defaultExpression = defaultArgument.getExpression();
Tree.Term term = defaultExpression.getTerm();
JCExpression defaultLiteral = null;
if (term instanceof Tree.Literal && !(term instanceof Tree.QuotedLiteral)) {
defaultLiteral = expressionGen().transform((Tree.Literal) term);
} else if (term instanceof Tree.BaseMemberExpression) {
Tree.BaseMemberExpression bme = (Tree.BaseMemberExpression) term;
Declaration decl = bme.getDeclaration();
if (isBooleanTrue(decl)) {
defaultLiteral = makeBoolean(true);
} else if (isBooleanFalse(decl)) {
defaultLiteral = makeBoolean(false);
} else if (typeFact().isEmptyType(bme.getTypeModel())) {
defaultLiteral = make().NewArray(null, null, List.<JCExpression>nil());
} else if (Decl.isAnonCaseOfEnumeratedType(bme)) {
defaultLiteral = makeClassLiteral(bme.getTypeModel());
} else {
defaultLiteral = make().Literal(bme.getDeclaration().getQualifiedNameString());
}
} else if (term instanceof Tree.MemberOrTypeExpression) {
Tree.MemberOrTypeExpression mte = (Tree.MemberOrTypeExpression) term;
defaultLiteral = make().Literal(mte.getDeclaration().getQualifiedNameString());
} else if (term instanceof Tree.SequenceEnumeration) {
Tree.SequenceEnumeration seq = (Tree.SequenceEnumeration) term;
SequencedArgument sequencedArgument = seq.getSequencedArgument();
defaultLiteral = makeArrayInitializer(sequencedArgument);
} else if (term instanceof Tree.Tuple) {
Tree.Tuple seq = (Tree.Tuple) term;
SequencedArgument sequencedArgument = seq.getSequencedArgument();
defaultLiteral = makeArrayInitializer(sequencedArgument);
} else if (term instanceof Tree.InvocationExpression) {
// Allow invocations of annotation constructors, so long as they're
// themselves being invoked with permitted arguments
Tree.InvocationExpression invocation = (Tree.InvocationExpression) term;
try {
defaultLiteral = AnnotationInvocationVisitor.transform(expressionGen(), invocation);
} catch (BugException e) {
defaultLiteral = e.makeErroneous(this, invocation);
}
} else if (term instanceof Tree.MemberLiteral) {
defaultLiteral = expressionGen().makeMetaLiteralStringLiteralForAnnotation((Tree.MemberLiteral) term);
} else if (term instanceof Tree.TypeLiteral) {
defaultLiteral = expressionGen().makeMetaLiteralStringLiteralForAnnotation((Tree.TypeLiteral) term);
}
if (defaultLiteral == null) {
defaultLiteral = makeErroneous(p, "compiler bug: " + p.getParameterModel().getName() + " has an unsupported defaulted parameter expression");
}
return defaultLiteral;
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.SequencedArgument in project ceylon by eclipse.
the class NamedArgumentInvocation method buildVars.
/**
* Constructs the vars used in the Let expression
*/
private void buildVars() {
if (getPrimaryDeclaration() == null) {
return;
}
boolean prev = gen.expressionGen().withinInvocation(false);
java.util.List<Tree.NamedArgument> namedArguments = namedArgumentList.getNamedArguments();
SequencedArgument sequencedArgument = namedArgumentList.getSequencedArgument();
java.util.List<ParameterList> paramLists = ((Functional) getPrimaryDeclaration()).getParameterLists();
java.util.List<Parameter> declaredParams = paramLists.get(0).getParameters();
appendVarsForNamedArguments(namedArguments, declaredParams);
appendVarsForReifiedTypeArguments();
if (sequencedArgument != null)
appendVarsForSequencedArguments(sequencedArgument, declaredParams);
boolean hasDefaulted = appendVarsForDefaulted(declaredParams);
DefaultParameterMethodOwner owner = Strategy.defaultParameterMethodOwner(getPrimaryDeclaration());
if (hasDefaulted && owner != DefaultParameterMethodOwner.STATIC && owner != DefaultParameterMethodOwner.OUTER && owner != DefaultParameterMethodOwner.OUTER_COMPANION) {
vars.prepend(makeThis());
}
gen.expressionGen().withinInvocation(prev);
}
Aggregations