use of org.eclipse.ceylon.model.typechecker.model.Reference in project ceylon by eclipse.
the class ExpressionVisitor method inferParameterTypesDirectly.
/**
* Infer parameter types of anonymous function arguments
* in a direct invocation with positional arguments.
*/
private boolean[] inferParameterTypesDirectly(Tree.PositionalArgumentList pal, Tree.MemberOrTypeExpression mte, Declaration dec, boolean error) {
List<Tree.PositionalArgument> args = pal.getPositionalArguments();
int argCount = args.size();
boolean[] delayed = new boolean[argCount];
Functional fun = (Functional) dec;
List<ParameterList> pls = fun.getParameterLists();
if (!pls.isEmpty()) {
List<Parameter> params = pls.get(0).getParameters();
Reference reference = getInvokedProducedReference(dec, mte);
int paramsSize = params.size();
for (int i = 0, j = 0; i < argCount && j < paramsSize; i++) {
Parameter param = params.get(j);
Tree.PositionalArgument arg = args.get(i);
arg.setParameter(param);
if (arg instanceof Tree.ListedArgument) {
Tree.ListedArgument la = (Tree.ListedArgument) arg;
delayed[i] = !inferParameterTypes(reference, param, la.getExpression(), param.isSequenced(), error);
}
if (!param.isSequenced()) {
j++;
}
}
}
return delayed;
}
use of org.eclipse.ceylon.model.typechecker.model.Reference in project ceylon by eclipse.
the class PrintVisitor method print.
private void print(Node node) {
print(node.getText());
print(" [" + node.getNodeType() + "]");
if (node.getToken() != null) {
print(" (" + node.getLocation() + ")");
}
if (node instanceof Tree.Term) {
Type type = ((Tree.Term) node).getTypeModel();
if (type != null) {
print(" : " + type.asString() + "");
}
}
if (node instanceof Tree.ComprehensionClause) {
Type type = ((Tree.ComprehensionClause) node).getTypeModel();
if (type != null) {
print(" : " + type.asString() + "");
}
}
if (node instanceof Tree.Type) {
Type type = ((Tree.Type) node).getTypeModel();
if (type != null) {
print(" : " + type.asString() + "");
}
}
if (node instanceof Tree.TypeArguments) {
List<Type> types = ((Tree.TypeArguments) node).getTypeModels();
if (types != null && !types.isEmpty()) {
print(" : <");
int i = 0;
for (Type pt : types) {
if (pt != null) {
print(pt.asString());
}
if (++i != types.size()) {
print(", ");
}
}
print(">");
}
}
if (node instanceof Tree.MemberOrTypeExpression) {
Reference t = ((Tree.MemberOrTypeExpression) node).getTarget();
Declaration d = ((Tree.MemberOrTypeExpression) node).getDeclaration();
if (t != null) {
print(" : " + t.asString() + "");
}
if (d != null) {
print(" : " + d);
}
}
if (node instanceof Tree.Outer) {
Declaration d = ((Tree.Outer) node).getDeclarationModel();
if (d != null) {
print(" : " + d);
}
}
if (node instanceof Tree.SelfExpression) {
Declaration d = ((Tree.SelfExpression) node).getDeclarationModel();
if (d != null) {
print(" : " + d);
}
}
if (node instanceof Tree.Declaration) {
Declaration d = ((Tree.Declaration) node).getDeclarationModel();
if (d != null) {
if (d.isCaptured() || d.isJsCaptured()) {
print("[captured]");
}
print(" : " + d);
Declaration rd = d.getRefinedDeclaration();
if (rd != null && !rd.equals(d)) {
Declaration container = (Declaration) rd.getContainer();
print(" (refines " + container.getName() + "." + rd.getName() + ")");
}
}
}
if (node instanceof Tree.SpecifierStatement) {
Declaration d = ((Tree.SpecifierStatement) node).getDeclaration();
if (d != null) {
print(" : " + d);
}
if (((Tree.SpecifierStatement) node).getRefinement()) {
Declaration rd = d.getRefinedDeclaration();
if (rd != null && !rd.equals(d)) {
Declaration container = (Declaration) rd.getContainer();
print(" (refines " + container.getName() + "." + rd.getName() + ")");
}
}
}
if (node instanceof Tree.SimpleType) {
Declaration d = ((Tree.SimpleType) node).getDeclarationModel();
if (d != null) {
print(" : " + d);
}
}
if (node instanceof Tree.ImportMemberOrType) {
Declaration d = ((Tree.ImportMemberOrType) node).getDeclarationModel();
if (d != null) {
print(" : " + d);
}
}
if (node instanceof Tree.Return) {
Declaration d = ((Tree.Return) node).getDeclaration();
if (d != null) {
print(" : " + d);
}
}
if (node instanceof Tree.PositionalArgument) {
Parameter p = ((Tree.PositionalArgument) node).getParameter();
if (p != null) {
print(" : " + p);
}
}
if (node instanceof Tree.NamedArgument) {
Parameter p = ((Tree.NamedArgument) node).getParameter();
if (p != null) {
print(" : " + p);
}
}
if (node instanceof Tree.SequencedArgument) {
Parameter p = ((Tree.SequencedArgument) node).getParameter();
if (p != null) {
print(" : " + p);
}
}
if (!node.getErrors().isEmpty()) {
String icon = " [!]";
for (Message e : node.getErrors()) {
if (!(e instanceof UsageWarning)) {
icon = " [X]";
}
}
print(icon + node.getErrors());
}
}
use of org.eclipse.ceylon.model.typechecker.model.Reference in project ceylon by eclipse.
the class ClassImpl method getDispatch.
ConstructorDispatch<Type, Arguments> getDispatch() {
if (!initialized) {
synchronized (this) {
if (!initialized) {
checkConstructor();
Reference reference;
if (!hasConstructors() && !hasEnumerated()) {
reference = producedType;
} else {
reference = ((org.eclipse.ceylon.model.typechecker.model.Class) declaration.declaration).getDefaultConstructor().appliedReference(producedType, null);
}
this.dispatch = new ConstructorDispatch<Type, Arguments>(reference, this, null, ((Class) producedType.getDeclaration()).getFirstParameterList().getParameters(), instance);
this.initialized = true;
}
}
}
return dispatch;
}
use of org.eclipse.ceylon.model.typechecker.model.Reference in project ceylon by eclipse.
the class ClassOrInterfaceImpl method addInterfaceIfCompatible.
@SuppressWarnings({ "hiding" })
private <Container, Type> void addInterfaceIfCompatible(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, ArrayList<ceylon.language.meta.model.MemberInterface<? super Container, ? extends Type>> members, InterfaceDeclarationImpl decl, org.eclipse.ceylon.model.typechecker.model.Type qualifyingType, ClassOrInterfaceImpl<Container> containerMetamodel, org.eclipse.ceylon.model.typechecker.model.Type reifiedType) {
// now the types
Reference producedReference = decl.declaration.appliedReference(qualifyingType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
org.eclipse.ceylon.model.typechecker.model.Type type = producedReference.getType();
if (!type.isSubtypeOf(reifiedType))
return;
// it's compatible!
members.add(decl.<Container, Type>memberInterfaceApply($reifiedContainer, $reifiedType, containerMetamodel));
}
use of org.eclipse.ceylon.model.typechecker.model.Reference in project ceylon by eclipse.
the class ClassOrInterfaceImpl method addAttributeIfCompatible.
private <Container, Get, Set> void addAttributeIfCompatible(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedGet, @Ignore TypeDescriptor $reifiedSet, ArrayList<ceylon.language.meta.model.Attribute<? super Container, ? extends Get, ? super Set>> members, ValueDeclarationImpl decl, org.eclipse.ceylon.model.typechecker.model.Type qualifyingType, ceylon.language.meta.model.Type<Container> qualifyingMetamodel, org.eclipse.ceylon.model.typechecker.model.Type reifiedGet, org.eclipse.ceylon.model.typechecker.model.Type reifiedSet) {
// now the types
Reference producedReference = decl.declaration.appliedReference(qualifyingType, NO_TYPE_ARGS);
org.eclipse.ceylon.model.typechecker.model.Type type = producedReference.getType();
if (!type.isSubtypeOf(reifiedGet))
return;
org.eclipse.ceylon.model.typechecker.model.Type setType = decl.getVariable() ? type : decl.declaration.getUnit().getNothingType();
if (!reifiedSet.isSubtypeOf(setType))
return;
// it's compatible!
members.add(decl.<Container, Get, Set>memberApply($reifiedContainer, $reifiedGet, $reifiedSet, qualifyingMetamodel));
}
Aggregations