use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class AbstractTransformer method getTypedSignature.
private java.util.List<Type> getTypedSignature(Type currentType, TypedDeclaration found) {
// check that its signature is compatible
java.util.List<ParameterList> parameterLists = ((Function) found).getParameterLists();
if (parameterLists == null || parameterLists.isEmpty())
return null;
// only consider first param list
java.util.List<Parameter> parameters = parameterLists.get(0).getParameters();
if (parameters == null)
return null;
TypedReference typedMember = currentType.getTypedMember(found, Collections.<Type>emptyList());
if (typedMember == null)
return null;
java.util.List<Type> typedSignature = new ArrayList<Type>(parameters.size());
for (Parameter p : parameters) {
Type parameterType = typedMember.getTypedParameter(p).getFullType();
typedSignature.add(parameterType);
}
return typedSignature;
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class CallableBuilder method javaStaticMethodReference.
public static CallableBuilder javaStaticMethodReference(CeylonTransformer gen, Node node, Type typeModel, final Functional methodOrClass, Reference producedReference, Type expectedType) {
final ParameterList parameterList = methodOrClass.getFirstParameterList();
CallableBuilder inner = new CallableBuilder(gen, node, typeModel, parameterList);
ArrayList<Type> pt = new ArrayList<>();
for (Parameter p : methodOrClass.getFirstParameterList().getParameters()) {
pt.add(((Tree.MemberOrTypeExpression) node).getTarget().getTypedParameter(p).getType());
}
inner.parameterTypes = pt;
inner.defaultValueCall = inner.new MemberReferenceDefaultValueCall(methodOrClass);
JCExpression innerInvocation = gen.expressionGen().makeJavaStaticInvocation(gen, methodOrClass, producedReference, parameterList);
// Need to worry about boxing for Function and FunctionalParameter
if (methodOrClass instanceof TypedDeclaration) {
innerInvocation = gen.expressionGen().applyErasureAndBoxing(innerInvocation, methodOrClass.getType(), !CodegenUtil.isUnBoxed((TypedDeclaration) methodOrClass), BoxingStrategy.BOXED, methodOrClass.getType());
} else if (Strategy.isInstantiatorUntyped((Class) methodOrClass)) {
// $new method declared to return Object, so needs typecast
innerInvocation = gen.make().TypeCast(gen.makeJavaType(((Class) methodOrClass).getType()), innerInvocation);
}
List<JCStatement> innerBody = List.<JCStatement>of(gen.make().Return(innerInvocation));
inner.useDefaultTransformation(innerBody);
if (expectedType != null)
inner.checkForFunctionalInterface(expectedType);
return inner;
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class ClassOrPackageDoc method getParametersAssertions.
private Map<Parameter, Map<Tree.Assertion, List<Tree.Condition>>> getParametersAssertions(final Declaration decl) {
final Map<Parameter, Map<Tree.Assertion, List<Tree.Condition>>> parametersAssertions = new LinkedHashMap<Parameter, Map<Tree.Assertion, List<Tree.Condition>>>();
if (((Functional) decl).getParameterLists().isEmpty()) {
return parametersAssertions;
}
Node node = tool.getNode(decl);
PhasedUnit pu = tool.getUnit(decl);
if (node == null || pu == null) {
return parametersAssertions;
}
Tree.Body body = null;
if (node instanceof Tree.MethodDefinition) {
body = ((Tree.MethodDefinition) node).getBlock();
} else if (node instanceof Tree.ClassDefinition) {
body = ((Tree.ClassDefinition) node).getClassBody();
}
if (body == null) {
return parametersAssertions;
}
final Map<String, Parameter> parametersNames = new HashMap<String, Parameter>();
for (ParameterList parameterList : ((Functional) decl).getParameterLists()) {
for (Parameter parameter : parameterList.getParameters()) {
parametersNames.put(parameter.getName(), parameter);
}
}
body.visitChildren(new Visitor() {
private boolean stop = false;
private Tree.Assertion assertion = null;
private Set<Parameter> referencedParameters = new HashSet<Parameter>();
@Override
public void visit(Tree.Assertion that) {
assertion = that;
super.visit(that);
assertion = null;
}
@Override
public void visit(Tree.Condition that) {
referencedParameters.clear();
super.visit(that);
if (assertion != null && !referencedParameters.isEmpty()) {
for (Parameter referencedParameter : referencedParameters) {
Map<Tree.Assertion, List<Tree.Condition>> parameterAssertions = parametersAssertions.get(referencedParameter);
if (parameterAssertions == null) {
parameterAssertions = new LinkedHashMap<Tree.Assertion, List<Tree.Condition>>();
parametersAssertions.put(referencedParameter, parameterAssertions);
}
List<Tree.Condition> parameterConditions = parameterAssertions.get(assertion);
if (parameterConditions == null) {
parameterConditions = new ArrayList<Tree.Condition>();
parameterAssertions.put(assertion, parameterConditions);
}
parameterConditions.add(that);
}
}
}
@Override
public void visit(Tree.BaseMemberExpression that) {
if (assertion != null) {
Declaration d = that.getDeclaration();
Scope realScope = org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope(d.getScope());
if (parametersNames.containsKey(d.getName()) && realScope == decl) {
referencedParameters.add(parametersNames.get(d.getName()));
}
}
super.visit(that);
}
@Override
public void visit(Tree.Statement that) {
if (assertion == null) {
stop = true;
}
super.visit(that);
}
@Override
public void visitAny(Node that) {
if (!stop) {
super.visitAny(that);
}
}
});
return parametersAssertions;
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class ExpressionVisitor method inferParameterTypesDirectly.
/**
* Infer parameter types of anonymous function arguments
* in a direct invocation with named arguments.
*
* Also sets references from arguments back to parameters
* by side effect.
*/
private void inferParameterTypesDirectly(Tree.NamedArgumentList nal, Tree.MemberOrTypeExpression mte, Declaration dec) {
Reference reference = getInvokedProducedReference(dec, mte);
Functional fun = (Functional) dec;
List<ParameterList> pls = fun.getParameterLists();
if (!pls.isEmpty()) {
Set<Parameter> foundParameters = new HashSet<Parameter>();
ParameterList pl = pls.get(0);
List<Tree.NamedArgument> args = nal.getNamedArguments();
for (int i = 0; i < args.size(); i++) {
Tree.NamedArgument arg = args.get(i);
Parameter param = getMatchingParameter(pl, arg, foundParameters);
if (param != null) {
foundParameters.add(param);
arg.setParameter(param);
if (arg instanceof Tree.SpecifiedArgument) {
Tree.SpecifiedArgument sa = (Tree.SpecifiedArgument) arg;
Tree.SpecifierExpression se = sa.getSpecifierExpression();
if (se != null) {
setupTargetParameters(reference, param, se.getExpression());
inferParameterTypes(reference, param, se.getExpression(), false, true);
}
}
}
}
Tree.SequencedArgument sa = nal.getSequencedArgument();
if (sa != null) {
Parameter param = getUnspecifiedParameter(reference, pl, foundParameters);
if (param != null) {
sa.setParameter(param);
for (Tree.PositionalArgument pa : sa.getPositionalArguments()) {
if (pa instanceof Tree.ListedArgument) {
Tree.ListedArgument la = (Tree.ListedArgument) pa;
la.setParameter(param);
setupTargetParameters(reference, param, la.getExpression());
inferParameterTypes(reference, param, la.getExpression(), true, true);
}
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class ExpressionVisitor method createAnonymousFunctionParameters.
/**
* Iterate over the arguments of an invocation
* looking for anonymous functions with missing
* parameter lists, and create the parameter
* lists from the type of the parameters to
* which the arguments are assigned.
*/
private void createAnonymousFunctionParameters(Tree.InvocationExpression that) {
Tree.Primary primary = that.getPrimary();
Tree.PositionalArgumentList argList = that.getPositionalArgumentList();
if (argList != null && primary instanceof Tree.MemberOrTypeExpression) {
Tree.MemberOrTypeExpression mte = (Tree.MemberOrTypeExpression) primary;
List<Tree.PositionalArgument> args = argList.getPositionalArguments();
Declaration dec = mte.getDeclaration();
if (dec instanceof Functional) {
Functional fun = (Functional) dec;
ParameterList paramList = fun.getFirstParameterList();
if (paramList != null) {
List<Parameter> params = paramList.getParameters();
for (int i = 0, asz = args.size(), psz = params.size(); i < asz && i < psz; i++) {
Tree.PositionalArgument arg = args.get(i);
Parameter param = params.get(i);
if (arg instanceof Tree.ListedArgument && param != null) {
Tree.ListedArgument larg = (Tree.ListedArgument) arg;
List<Parameter> fpl = inferrableParameters(param);
Tree.Expression ex = larg.getExpression();
if (ex != null && fpl != null) {
Tree.Term term = ex.getTerm();
if (term instanceof Tree.FunctionArgument) {
Tree.FunctionArgument anon = (Tree.FunctionArgument) term;
createAnonymousFunctionParameters(fpl, term, anon);
}
}
}
}
}
}
}
}
Aggregations