use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class TypeUtils method convertTupleToParameters.
/**
* Turns a Tuple type into a parameter list.
*/
public static List<Parameter> convertTupleToParameters(Type _tuple) {
final ArrayList<Parameter> rval = new ArrayList<>();
int pos = 0;
final Unit unit = getUnit(_tuple);
final Type empty = unit.getEmptyType();
while (_tuple != null && !(_tuple.isSubtypeOf(empty) || _tuple.isTypeParameter())) {
Parameter _p = null;
if (isTuple(_tuple)) {
_p = new Parameter();
_p.setModel(new Value());
if (_tuple.isUnion()) {
// Handle union types for defaulted parameters
for (Type mt : _tuple.getCaseTypes()) {
if (mt.isTuple()) {
_p.getModel().setType(mt.getTypeArgumentList().get(1));
_tuple = mt.getTypeArgumentList().get(2);
break;
}
}
_p.setDefaulted(true);
} else {
_p.getModel().setType(_tuple.getTypeArgumentList().get(1));
_tuple = _tuple.getTypeArgumentList().get(2);
}
} else if (unit.isSequentialType(_tuple)) {
// Handle Sequence, for nonempty variadic parameters
_p = new Parameter();
_p.setModel(new Value());
_p.getModel().setType(_tuple.getTypeArgumentList().get(0));
_p.setSequenced(true);
_tuple = null;
} else {
if (pos > 100) {
return rval;
}
}
if (_p != null) {
_p.setName("arg" + pos);
rval.add(_p);
}
pos++;
}
return rval;
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class JsOutput method publishUnsharedDeclarations.
public void publishUnsharedDeclarations(JsIdentifierNames names) {
// #489 lists with unshared toplevel members of each package
for (org.eclipse.ceylon.model.typechecker.model.Package pkg : module.getPackages()) {
ArrayList<Declaration> unsharedDecls = new ArrayList<>(pkg.getMembers().size());
for (Declaration d : pkg.getMembers()) {
if (!d.isShared() && !(d.isAnonymous() && d.getName() != null && d.getName().startsWith("anonymous#")) && (!d.isNative() || d.getNativeBackends().supports(Backend.JavaScript))) {
unsharedDecls.add(d);
}
}
if (!unsharedDecls.isEmpty()) {
out("ex$.$pkgunsh$", pkg.getNameAsString().replace('.', '$'), "={");
boolean first = true;
for (Declaration d : unsharedDecls) {
if (d.getName() == null)
continue;
// TODO only use quotes when absolutely necessary
if (d.isAnonymous()) {
// Don't generate anything for anonymous types
} else if (d instanceof Setter) {
// ignore
if (((Setter) d).getGetter() == null) {
if (first)
first = false;
else
out(",");
out("'", d.getName(), "':", names.setter(d));
}
} else if (d instanceof Value) {
if (first)
first = false;
else
out(",");
out("'", d.getName(), "':", names.getter(d, true));
} else {
if (first)
first = false;
else
out(",");
out("'", d.getName(), "':", names.name(d));
}
}
out("};\n");
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class TestBitAnnotations method testEncode.
@Test
public void testEncode() {
final Value v = new Value();
int b = MetamodelGenerator.encodeAnnotations(v.getAnnotations(), v, null);
Assert.assertEquals(0, b);
v.getAnnotations().add(new Annotation("shared"));
b = MetamodelGenerator.encodeAnnotations(v.getAnnotations(), v, null);
Assert.assertEquals(1, b);
v.getAnnotations().add(new Annotation("actual"));
b = MetamodelGenerator.encodeAnnotations(v.getAnnotations(), v, null);
Assert.assertEquals(3, b);
v.getAnnotations().add(new Annotation("default"));
b = MetamodelGenerator.encodeAnnotations(v.getAnnotations(), v, null);
Assert.assertEquals(11, b);
}
use of org.eclipse.ceylon.model.typechecker.model.Value 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.Value 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) + "'");
}
}
}
}
}
}
}
Aggregations