use of org.eclipse.ceylon.model.typechecker.model.Parameter 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.Parameter 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.Parameter in project ceylon by eclipse.
the class AnnotationInvocation method makeAnnotation.
public JCExpression makeAnnotation(ExpressionTransformer exprGen, AnnotationInvocation ai, org.eclipse.ceylon.langtools.tools.javac.util.List<AnnotationFieldName> parameterPath) {
ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
for (AnnotationArgument aa : getAnnotationArguments()) {
Parameter name = aa.getParameter();
if (!isInstantiation()) {
AnnotationInvocation annotationInvocation = (AnnotationInvocation) getConstructorDeclaration().getAnnotationConstructor();
for (AnnotationArgument a2 : annotationInvocation.getAnnotationArguments()) {
if (a2.getTerm() instanceof ParameterAnnotationTerm) {
if (((ParameterAnnotationTerm) a2.getTerm()).getSourceParameter().equals(aa.getParameter())) {
name = a2.getParameter();
break;
}
}
}
}
args.append(makeAnnotationArgument(exprGen, ai, name, parameterPath.append(aa), aa.getTerm()));
}
return exprGen.make().Annotation(makeAnnotationType(exprGen), args.toList());
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.
the class AnnotationInvocationVisitor method transformConstructor.
private static JCAnnotation transformConstructor(ExpressionTransformer exprGen, Tree.InvocationExpression invocation, AnnotationInvocation ai, org.eclipse.ceylon.langtools.tools.javac.util.List<AnnotationFieldName> fieldPath) {
Map<Parameter, ListBuffer<JCExpression>> args = new LinkedHashMap<Parameter, ListBuffer<JCExpression>>();
List<Parameter> classParameters = ai.getClassParameters();
// The class parameter's we've not yet figured out the value for
ArrayList<Parameter> unbound = new ArrayList<Parameter>(classParameters);
for (Parameter classParameter : classParameters) {
for (AnnotationArgument argument : ai.findAnnotationArgumentForClassParameter(invocation, new HashSet<Function>(), classParameter)) {
JCExpression expr = transformConstructorArgument(exprGen, invocation, classParameter, argument, fieldPath);
appendArgument(args, classParameter, expr);
unbound.remove(classParameter);
}
}
outer: for (Parameter classParameter : new ArrayList<>(unbound)) {
// Defaulted argument
if (ai.isInstantiation()) {
if (classParameter.isDefaulted()) {
// That's OK, we'll pick up the default argument from
// the Java Annotation type
unbound.remove(classParameter);
continue outer;
}
} else {
Function ac2 = (Function) ai.getPrimary();
AnnotationInvocation i = (AnnotationInvocation) ac2.getAnnotationConstructor();
for (AnnotationArgument aa : i.getAnnotationArguments()) {
if (aa.getParameter().equals(classParameter)) {
appendArgument(args, classParameter, aa.getTerm().makeAnnotationArgumentValue(exprGen, i, org.eclipse.ceylon.langtools.tools.javac.util.List.<AnnotationFieldName>of(aa)));
unbound.remove(classParameter);
continue outer;
}
}
}
if (Strategy.hasEmptyDefaultArgument(classParameter)) {
appendArgument(args, classParameter, exprGen.make().NewArray(null, null, org.eclipse.ceylon.langtools.tools.javac.util.List.<JCExpression>nil()));
unbound.remove(classParameter);
continue outer;
}
}
for (Parameter classParameter : unbound) {
appendArgument(args, classParameter, exprGen.makeErroneous(invocation, "compiler bug: unbound annotation class parameter " + classParameter.getName()));
}
ListBuffer<JCExpression> assignments = new ListBuffer<JCExpression>();
for (Map.Entry<Parameter, ListBuffer<JCExpression>> entry : args.entrySet()) {
ListBuffer<JCExpression> exprs = entry.getValue();
if (exprs.size() == 1) {
assignments.append(makeArgument(exprGen, invocation, entry.getKey(), exprs.first()));
} else {
assignments.append(makeArgument(exprGen, invocation, entry.getKey(), exprGen.make().NewArray(null, null, exprs.toList())));
}
}
JCAnnotation annotation = exprGen.at(invocation).Annotation(ai.makeAnnotationType(exprGen), assignments.toList());
return annotation;
}
use of org.eclipse.ceylon.model.typechecker.model.Parameter 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);
}
}
}
}
}
}
Aggregations