use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration in project ceylon by eclipse.
the class ExpressionVisitor method refineMethod.
private void refineMethod(Tree.SpecifierStatement that) {
Function refinedMethod = (Function) that.getRefined();
Function method = (Function) that.getDeclaration();
ClassOrInterface ci = (ClassOrInterface) method.getContainer();
Declaration root = method.getRefinedDeclaration();
TypeDeclaration td = (TypeDeclaration) root.getContainer();
List<Declaration> interveningRefinements = getInterveningRefinements(method, root, ci, td);
if (interveningRefinements.isEmpty()) {
that.getBaseMemberExpression().addError("shortcut refinement does not exactly refine any overloaded inherited member");
} else {
Reference refinedProducedReference = accountForIntermediateRefinements(that, refinedMethod, method, ci, interveningRefinements);
List<Tree.ParameterList> parameterLists;
Tree.Term me = that.getBaseMemberExpression();
if (me instanceof Tree.ParameterizedExpression) {
Tree.ParameterizedExpression pe = (Tree.ParameterizedExpression) me;
parameterLists = pe.getParameterLists();
} else {
parameterLists = emptyList();
}
List<ParameterList> refinedParamLists = refinedMethod.getParameterLists();
List<ParameterList> methodParamLists = method.getParameterLists();
Map<TypeParameter, Type> subs = substitutions(refinedMethod, method);
for (int i = 0; i < refinedParamLists.size() && i < methodParamLists.size(); i++) {
ParameterList refinedParameters = refinedParamLists.get(i);
ParameterList parameters = methodParamLists.get(i);
Tree.ParameterList parameterList = parameterLists.size() <= i ? null : parameterLists.get(i);
List<Parameter> rps = refinedParameters.getParameters();
for (int j = 0; j < rps.size(); j++) {
Parameter refinedParameter = rps.get(j);
Type refinedParameterType = refinedProducedReference.getTypedParameter(refinedParameter).getFullType().substitute(subs, null);
Parameter parameter;
if (parameterList == null || parameterList.getParameters().size() <= j) {
parameter = parameters.getParameters().get(j);
parameter.getModel().setType(refinedParameterType);
parameter.setSequenced(refinedParameter.isSequenced());
} else {
Tree.Parameter param = parameterList.getParameters().get(j);
parameter = param.getParameterModel();
Type parameterType = parameter.getModel().getTypedReference().getFullType();
Node typeNode = param;
if (param instanceof Tree.ParameterDeclaration) {
Tree.ParameterDeclaration pd = (Tree.ParameterDeclaration) param;
Tree.Type type = pd.getTypedDeclaration().getType();
if (type != null) {
typeNode = type;
}
}
checkIsExactlyIgnoringNull(refinedParameters.isNamedParametersSupported(), parameterType, refinedParameterType, typeNode, "type of parameter '" + parameter.getName() + "' of '" + method.getName() + "' declared by '" + ci.getName() + "' is different to type of corresponding parameter " + message(refinedMethod, refinedParameter), 9200);
if (refinedParameter.isSequenced() && !parameter.isSequenced()) {
param.addError("parameter must be variadic: parameter " + message(refinedMethod, refinedParameter) + " is variadic");
}
if (!refinedParameter.isSequenced() && parameter.isSequenced()) {
param.addError("parameter may not be variadic: parameter " + message(refinedMethod, refinedParameter) + " is not variadic");
}
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.QualifiedType that) {
super.visit(that);
TypeDeclaration type = that.getDeclarationModel();
if (type != null) {
type = (TypeDeclaration) handleNativeHeader(type, that, true);
if (!type.isVisible(that.getScope())) {
if (type instanceof Constructor) {
that.addError("constructor is not visible: " + qualifiedDescription(that), 400);
} else {
that.addError("member type is not visible: " + qualifiedDescription(that), 400);
}
} else if (type.isPackageVisibility() && !declaredInPackage(type, unit)) {
that.addError("member type is not visible: " + qualifiedDescription(that) + " is package private");
} else // in fact this restriction is OK
if (type.isProtectedVisibility() && !declaredInPackage(type, unit)) {
that.addError("member type is not visible: " + qualifiedDescription(that) + " is protected");
}
// Note: we should remove this check if we ever
// make qualified member types like T.Member
// into a sort of virtual type
Tree.StaticType outerType = that.getOuterType();
if (outerType instanceof Tree.SimpleType) {
Tree.SimpleType st = (Tree.SimpleType) outerType;
TypeDeclaration std = st.getDeclarationModel();
if (std.isAlias()) {
Type et = std.getExtendedType();
if (et != null) {
std = et.resolveAliases().getDeclaration();
}
}
if (std instanceof TypeParameter) {
outerType.addError("type parameter should not occur as qualifying type: '" + std.getName(unit) + "' is a type parameter");
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration in project ceylon by eclipse.
the class AliasVisitor method typeList.
public static String typeList(List<TypeDeclaration> list) {
StringBuffer sb = new StringBuffer();
for (TypeDeclaration td : list) {
sb.append("'").append(td.getName()).append("', ");
}
sb.setLength(sb.length() - 2);
return sb.toString();
}
use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration in project ceylon by eclipse.
the class AnalyzerUtil method unwrapAliasedTypeConstructor.
static TypeDeclaration unwrapAliasedTypeConstructor(TypeDeclaration dec) {
TypeDeclaration d = dec;
while (!d.isParameterized() && d.isAlias()) {
Type et = d.getExtendedType();
if (et == null)
break;
et = et.resolveAliases();
d = et.getDeclaration();
if (et.isTypeConstructor() && d.isParameterized()) {
return d;
}
}
return dec;
}
use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration in project ceylon by eclipse.
the class AnnotationVisitor method isIllegalAnnotationParameterType.
private static boolean isIllegalAnnotationParameterType(Type pt) {
if (pt != null) {
if (pt.isIntersection() || pt.isUnion()) {
return true;
}
TypeDeclaration ptd = pt.getDeclaration();
Unit unit = ptd.getUnit();
if (!ptd.isAnnotation() && !isEnum(ptd) && !pt.isBoolean() && !pt.isString() && !pt.isInteger() && !pt.isFloat() && !pt.isCharacter() && !pt.isIterable() && !pt.isSequential() && !pt.isSequence() && !pt.isSubtypeOf(unit.getType(unit.getDeclarationDeclaration()))) {
return true;
}
if (pt.isIterable() || pt.isSequential() || pt.isSequence()) {
Type elementType = unit.getIteratedType(pt);
if (isIllegalAnnotationParameterType(elementType)) {
return true;
}
}
}
return false;
}
Aggregations