use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.ParameterList that) {
ParameterList pl = parameterList;
parameterList = new ParameterList();
that.setModel(parameterList);
super.visit(that);
parameterList = pl;
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.Constructor that) {
Constructor c = new Constructor();
that.setConstructor(c);
if (scope instanceof Class) {
Class clazz = (Class) scope;
if (that.getIdentifier() == null && clazz.getDefaultConstructor() != null) {
// found an overloaded default constructor
// we'll set up the class overloads later
// when exiting visit(Tree.ClassDefinition)
clazz.setOverloaded(true);
clazz.setAbstraction(true);
}
}
visitDeclaration(that, c, false);
Type at;
Scope realScope = getRealScope(scope);
if (realScope instanceof Class) {
Class clazz = (Class) realScope;
Type ot = clazz.getType();
c.setExtendedType(ot);
at = c.appliedType(ot, NO_TYPE_ARGS);
clazz.setConstructors(true);
if (clazz.isAnonymous()) {
that.addError("anonymous class may not have constructor: '" + clazz.getName() + "' is an anonymous class");
}
} else {
at = null;
that.addError("constructor declaration must occur directly in the body of a class");
}
Function f = new Function();
f.setType(at);
that.setDeclarationModel(f);
visitDeclaration(that, f);
Scope o = enterScope(c);
super.visit(that);
exitScope(o);
f.setImplemented(that.getBlock() != null);
if (that.getParameterList() == null) {
that.addError("missing parameter list in constructor declaration: '" + name(that.getIdentifier()) + "' must have a parameter list", 1000);
} else {
ParameterList model = that.getParameterList().getModel();
model.setFirst(true);
if (model != null) {
c.addParameterList(model);
// TODO: fix this
f.addParameterList(model);
}
}
if (c.isAbstract()) {
if (that.getIdentifier() == null) {
that.addError("default constructor may not be annotated 'abstract'", 1601);
} else if (c.isShared()) {
that.addError("abstract constructor may not be annotated 'shared'", 1610);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class TypeHierarchyVisitor method checkForFormalsNotImplemented.
private void checkForFormalsNotImplemented(Node that, List<Type> orderedTypes, Class clazz) {
Type aggregation = buildAggregatedType(orderedTypes);
for (Type.Members members : aggregation.membersByName.values()) {
if (!members.formals.isEmpty()) {
if (members.actualsNonFormals.isEmpty()) {
Declaration example = members.formals.iterator().next();
Declaration declaringType = (Declaration) example.getContainer();
if (!clazz.equals(declaringType)) {
String name = example.getName();
if (isJavaSetter(example) && aggregation.membersByName.containsKey(setterToProperty(name))) {
// (i.e. a setter with no getter)
continue;
}
addUnimplementedFormal(clazz, example);
that.addError("formal member '" + name + "' of '" + declaringType.getName() + "' not implemented for concrete class '" + clazz.getName() + "': '" + clazz.getName() + "' neither directly implements nor inherits a concrete implementation of '" + name + "'", 300);
continue;
}
}
for (Declaration f : members.formals) {
if (isOverloadedVersion(f) && !f.isCoercionPoint()) {
boolean found = false;
// boolean variadic = f.isVariadic();
for (Declaration a : members.actualsNonFormals) {
if (f.getRefinedDeclaration().equals(a.getRefinedDeclaration())) {
found = true;
break;
}
}
if (!found) {
StringBuilder paramTypes = new StringBuilder();
List<ParameterList> parameterLists = ((Functional) f).getParameterLists();
if (!parameterLists.isEmpty()) {
for (Parameter p : parameterLists.get(0).getParameters()) {
if (paramTypes.length() > 0) {
paramTypes.append(", ");
}
if (!isTypeUnknown(p.getType())) {
paramTypes.append(p.getType().asString());
}
}
}
Declaration declaringType = (Declaration) f.getContainer();
addUnimplementedFormal(clazz, f);
that.addError("overloaded formal member '" + f.getName() + "(" + paramTypes + ")' of '" + declaringType.getName() + "' not implemented in class hierarchy");
}
}
}
}
/*if (!members.concretesOnInterfaces.isEmpty() && members.actualsNonFormals.isEmpty()) {
Declaration declaringType = (Declaration) members.concretesOnInterfaces.iterator().next().getContainer();
that.addWarning("interface member " + members.name +
" of " + declaringType.getName() +
" not implemented in class hierarchy (concrete interface members not yet supported)");
}*/
}
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class ExpressionVisitor method checkJavaAnnotationElements.
private void checkJavaAnnotationElements(List<Tree.PositionalArgument> args, List<Parameter> params, Declaration target) {
if (target instanceof Function && target.isAnnotation()) {
Function method = (Function) target;
ParameterList parameterList = method.getFirstParameterList();
if (!parameterList.isPositionalParametersSupported()) {
for (int i = 0; i < params.size() && i < args.size(); i++) {
Parameter parameter = parameterList.getParameters().get(i);
Tree.PositionalArgument arg = args.get(i);
boolean isJavaAnnotationValueParameter = "value".equals(parameter.getName());
if (arg != null && !isJavaAnnotationValueParameter) {
arg.addUsageWarning(Warning.javaAnnotationElement, "positional argument to Java annotation element: '" + parameter.getName() + "' (use named arguments)");
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.ParameterList in project ceylon by eclipse.
the class InvocationGenerator method applyNamedArguments.
void applyNamedArguments(Tree.NamedArgumentList argList, Functional func, Map<String, String> argVarNames, boolean superAccess, Map<TypeParameter, Type> targs) {
final ParameterList plist = func.getFirstParameterList();
boolean first = true;
if (superAccess) {
gen.out(".call(this");
if (!plist.getParameters().isEmpty()) {
gen.out(",");
}
} else {
gen.out("(");
}
for (Parameter p : plist.getParameters()) {
if (!first)
gen.out(",");
final String vname = argVarNames.get(p.getName());
if (vname == null) {
if (p.isDefaulted()) {
gen.out("undefined");
} else {
gen.out(gen.getClAlias(), "empty()");
}
} else {
gen.out(vname);
}
first = false;
}
if (targs != null && !targs.isEmpty()) {
if (!first) {
gen.out(",");
}
TypeUtils.printTypeArguments(argList, targs, gen, false, null);
}
gen.out(")");
}
Aggregations