use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class RefinementVisitor method visit.
@Override
public void visit(Tree.Declaration that) {
super.visit(that);
Declaration dec = that.getDeclarationModel();
if (dec != null) {
boolean mayBeShared = dec.isToplevel() || dec.isClassOrInterfaceMember();
if (dec.isShared() && !mayBeShared) {
that.addError("shared declaration is not a member of a class, interface, or package: " + message(dec) + " may not be annotated 'shared'", 1200);
}
boolean mayBeRefined = dec instanceof Value || dec instanceof Function || dec instanceof Class;
if (!mayBeRefined) {
checkNonrefinableDeclaration(that, dec);
}
boolean member = dec.isClassOrInterfaceMember() && dec.isShared() && !isConstructor(dec) && // TODO: what about nested interfaces and abstract classes?!
!(dec instanceof TypeParameter);
if (member) {
checkMember(that, dec);
} else {
checkNonMember(that, dec);
}
if (dec.isNativeImplementation() || isNativeMember(dec)) {
checkNative(that, dec);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class RefinementVisitor method visit.
@Override
public void visit(Tree.SpecifierStatement that) {
super.visit(that);
List<Type> sig = new ArrayList<Type>();
Tree.Term term = that.getBaseMemberExpression();
while (term instanceof Tree.ParameterizedExpression) {
sig.clear();
Tree.ParameterizedExpression pe = (Tree.ParameterizedExpression) term;
Tree.TypeParameterList typeParameterList = pe.getTypeParameterList();
if (typeParameterList != null) {
// TODO: remove this for #1329
typeParameterList.addError("specification statements may not have type parameters");
}
Tree.ParameterList pl = pe.getParameterLists().get(0);
for (Tree.Parameter p : pl.getParameters()) {
if (p == null) {
sig.add(null);
} else {
Parameter model = p.getParameterModel();
if (model != null) {
sig.add(model.getType());
} else {
sig.add(null);
}
}
}
term = pe.getPrimary();
}
if (term instanceof Tree.BaseMemberExpression) {
Tree.BaseMemberExpression bme = (Tree.BaseMemberExpression) term;
Unit unit = that.getUnit();
TypedDeclaration td = getTypedDeclaration(bme.getScope(), name(bme.getIdentifier()), sig, false, unit);
if (td != null) {
that.setDeclaration(td);
Scope scope = that.getScope();
Scope container = scope.getContainer();
Scope realScope = getRealScope(container);
if (realScope instanceof ClassOrInterface) {
ClassOrInterface ci = (ClassOrInterface) realScope;
Scope tdcontainer = td.getContainer();
if (td.isClassOrInterfaceMember()) {
ClassOrInterface tdci = (ClassOrInterface) tdcontainer;
if (!tdcontainer.equals(realScope) && ci.inherits(tdci)) {
boolean lazy = that.getSpecifierExpression() instanceof Tree.LazySpecifierExpression;
if (!lazy && td.isVariable() && td.isJava()) {
// allow assignment to variable
// member of Java supertype
} else // refinement of an inherited member
if (tdcontainer == scope) {
that.addError("parameter declaration hides refining member: '" + td.getName(unit) + "' (rename parameter)");
} else if (td instanceof Value) {
refineAttribute((Value) td, bme, that, ci);
} else if (td instanceof Function) {
refineMethod((Function) td, bme, that, ci);
} else {
// TODO!
bme.addError("not a reference to a formal attribute: '" + td.getName(unit) + "'");
}
}
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class ExpressionVisitor method visitGenericBaseMemberReference.
private void visitGenericBaseMemberReference(Tree.StaticMemberOrTypeExpression that, TypedDeclaration member) {
if (member instanceof Function && member.isParameterized()) {
Function generic = (Function) member;
Scope scope = that.getScope();
Type outerType = scope.getDeclaringType(member);
TypedReference target = member.appliedTypedReference(outerType, NO_TYPE_ARGS);
that.setTarget(target);
Type functionType = genericFunctionType(generic, scope, member, target, unit);
that.setTypeModel(functionType);
checkNotJvm(that, "type functions are not supported on the JVM: '" + member.getName(unit) + "' is generic (specify explicit type arguments)");
}
}
use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class ExpressionVisitor method createAnonymousFunctionParameters.
/**
* Create the parameter list of the given
* anonymous function with a missing argument
* list, from the given parameter list of a
* functional parameter to which it is assigned.
*/
private void createAnonymousFunctionParameters(List<Parameter> parameters, Tree.Term term, Tree.FunctionArgument anon) {
Function model = anon.getDeclarationModel();
if (anon.getParameterLists().isEmpty()) {
Tree.ParameterList pl = new Tree.ParameterList(null);
ParameterList mpl = new ParameterList();
for (Parameter parameter : parameters) {
Tree.InitializerParameter ip = new Tree.InitializerParameter(null);
CommonToken token = new CommonToken(LIDENTIFIER, parameter.getName());
token.setStartIndex(term.getStartIndex());
Token tok = term.getToken();
token.setLine(tok.getLine());
token.setCharPositionInLine(tok.getCharPositionInLine());
Tree.Identifier id = new Tree.Identifier(token);
ip.setIdentifier(id);
pl.addParameter(ip);
ip.setUnit(unit);
ip.setScope(model);
id.setUnit(unit);
id.setScope(model);
Parameter mp = new Parameter();
mp.setDeclaration(model);
mp.setName(parameter.getName());
ip.setParameterModel(mp);
mpl.getParameters().add(mp);
pl.setModel(mpl);
}
pl.setUnit(unit);
pl.setScope(model);
model.addParameterList(mpl);
anon.addParameterList(pl);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class TreeUtil method hasUncheckedNulls.
private static boolean hasUncheckedNulls(Tree.Term term, boolean invoking) {
if (term instanceof Tree.MemberOrTypeExpression) {
Tree.MemberOrTypeExpression mte = (Tree.MemberOrTypeExpression) term;
Declaration d = mte.getDeclaration();
if (d instanceof TypedDeclaration) {
TypedDeclaration td = (TypedDeclaration) d;
return td.hasUncheckedNullType() && // because java method references can't be null
(!(d instanceof Function) || invoking);
} else {
return false;
}
} else if (term instanceof Tree.QualifiedMemberOrTypeExpression) {
Tree.QualifiedMemberOrTypeExpression qmte = (Tree.QualifiedMemberOrTypeExpression) term;
return hasUncheckedNulls(qmte.getPrimary(), invoking);
} else if (term instanceof Tree.InvocationExpression) {
Tree.InvocationExpression ite = (Tree.InvocationExpression) term;
return hasUncheckedNulls(ite.getPrimary(), true);
} else if (term instanceof Tree.DefaultOp) {
Tree.DefaultOp op = (Tree.DefaultOp) term;
return hasUncheckedNulls(op.getRightTerm(), invoking);
} else if (term instanceof Tree.Expression) {
Tree.Expression e = (Tree.Expression) term;
return hasUncheckedNulls(e.getTerm(), invoking);
} else if (term instanceof Tree.LetExpression) {
Tree.LetExpression e = (Tree.LetExpression) term;
return hasUncheckedNulls(e.getLetClause().getExpression(), invoking);
} else if (term instanceof Tree.IfExpression) {
Tree.IfExpression e = (Tree.IfExpression) term;
return hasUncheckedNulls(e.getIfClause().getExpression(), invoking) || hasUncheckedNulls(e.getElseClause().getExpression(), invoking);
} else if (term instanceof Tree.SwitchExpression) {
Tree.SwitchExpression e = (Tree.SwitchExpression) term;
for (CaseClause clause : e.getSwitchCaseList().getCaseClauses()) {
if (hasUncheckedNulls(clause.getExpression(), invoking)) {
return true;
}
}
if (e.getSwitchCaseList().getElseClause() != null) {
return hasUncheckedNulls(e.getSwitchCaseList().getElseClause().getExpression(), invoking);
}
return false;
} else {
return false;
}
}
Aggregations