use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.
the class Naming method appendTypeDeclaration.
private void appendTypeDeclaration(final TypeDeclaration decl, EnumSet<DeclNameFlag> flags, TypeDeclarationBuilder<?> typeDeclarationBuilder, Scope scope, final boolean last) {
if (scope instanceof Class || scope instanceof TypeAlias || (scope instanceof Constructor && (scope.equals(decl) || !ModelUtil.isLocalNotInitializerScope(scope)))) {
TypeDeclaration klass = (TypeDeclaration) scope;
if (klass.isAnonymous() && !klass.isNamed())
typeDeclarationBuilder.clear();
String className = "";
if (klass.getName() != null) {
if (ModelUtil.isCeylonDeclaration(klass))
className = escapeClassName(klass.getName());
else
className = getRealName(klass, NA_WRAPPER_UNQUOTED);
}
typeDeclarationBuilder.append(className);
if (ModelUtil.isCeylonDeclaration(klass)) {
if (flags.contains(DeclNameFlag.COMPANION) && ModelUtil.isLocalNotInitializer(klass) && last) {
typeDeclarationBuilder.append(IMPL_POSTFIX);
} else if (flags.contains(DeclNameFlag.ANNOTATION) && last) {
typeDeclarationBuilder.append(ANNO_POSTFIX);
} else if (flags.contains(DeclNameFlag.ANNOTATIONS) && last) {
typeDeclarationBuilder.append(ANNOS_POSTFIX);
} else if (flags.contains(DeclNameFlag.DELEGATION) && last) {
typeDeclarationBuilder.append(DELEGATION_POSTFIX);
}
}
} else if (scope instanceof Interface) {
Interface iface = (Interface) scope;
String className = "";
if (iface.getName() != null) {
if (ModelUtil.isCeylonDeclaration(iface))
className = iface.getName();
else
className = getRealName(iface, NA_WRAPPER_UNQUOTED);
}
typeDeclarationBuilder.append(className);
if (ModelUtil.isCeylonDeclaration(iface) && ((decl instanceof Class || decl instanceof Constructor || decl instanceof TypeAlias || scope instanceof Constructor) || flags.contains(DeclNameFlag.COMPANION))) {
typeDeclarationBuilder.append(IMPL_POSTFIX);
}
} else if (ModelUtil.isLocalNotInitializerScope(scope)) {
if (flags.contains(DeclNameFlag.COMPANION) || !(decl instanceof Interface)) {
typeDeclarationBuilder.clear();
} else if (flags.contains(DeclNameFlag.QUALIFIED) || (decl instanceof Interface)) {
Scope nonLocal = scope;
while (!(nonLocal instanceof Declaration)) {
nonLocal = nonLocal.getContainer();
}
typeDeclarationBuilder.append(((Declaration) nonLocal).getPrefixedName());
if (!Decl.equalScopes(scope, nonLocal)) {
typeDeclarationBuilder.append('$');
typeDeclarationBuilder.append(getLocalId(scope));
}
if (decl instanceof Interface) {
typeDeclarationBuilder.append('$');
} else {
if (flags.contains(DeclNameFlag.QUALIFIED)) {
typeDeclarationBuilder.selectAppended();
} else {
typeDeclarationBuilder.clear();
}
}
}
return;
} else if (scope instanceof TypedDeclaration && ((Declaration) scope).isToplevel()) {
// nothing? that's just weird
}
if (!last) {
if (decl instanceof Interface && ModelUtil.isCeylonDeclaration((TypeDeclaration) decl) && !flags.contains(DeclNameFlag.COMPANION)) {
typeDeclarationBuilder.append('$');
} else if (decl instanceof Constructor && ((Class) decl.getContainer()).isMember() && decl.getContainer().equals(scope)) {
typeDeclarationBuilder.append('$');
} else {
if (flags.contains(DeclNameFlag.QUALIFIED)) {
typeDeclarationBuilder.selectAppended();
} else {
typeDeclarationBuilder.clear();
}
}
} else {
typeDeclarationBuilder.selectAppended();
}
return;
}
use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.
the class NamedArgumentInvocation method getParameterTypeForValueType.
protected Type getParameterTypeForValueType(Reference producedReference, Parameter param) {
// we need to find the interface for this method
Type paramType = param.getModel().getReference().getFullType().getType();
Scope paramContainer = param.getModel().getContainer();
if (paramContainer instanceof TypedDeclaration) {
TypedDeclaration method = (TypedDeclaration) paramContainer;
if (method.getContainer() instanceof TypeDeclaration && !(method.getContainer() instanceof Constructor)) {
TypeDeclaration container = (TypeDeclaration) method.getContainer();
Type qualifyingType = producedReference.getQualifyingType();
if (qualifyingType != null) {
Type supertype = qualifyingType.getSupertype(container);
return paramType.substitute(supertype);
}
}
}
return paramType;
}
use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.
the class MetamodelVisitor method visit.
@Override
public void visit(Tree.SpecifierStatement st) {
TypedDeclaration d = ((Tree.SpecifierStatement) st).getDeclaration();
// Just add shared and actual annotations to this declaration
if (!isNativeHeader(d))
return;
if (d != null) {
Annotation ann = new Annotation();
ann.setName("shared");
d.getAnnotations().add(ann);
ann = new Annotation();
ann.setName("actual");
d.getAnnotations().add(ann);
if (d instanceof Function) {
gen.encodeMethod((Function) d);
} else if (d instanceof Value) {
gen.encodeAttributeOrGetter((Value) d);
} else {
throw new RuntimeException("JS compiler doesn't know how to encode " + d.getClass().getName() + " into model");
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.
the class TypeUtils method generateModelPath.
/**
* Returns the list of keys to get from the package to the declaration, in the model.
*/
public static List<String> generateModelPath(final Declaration d) {
final ArrayList<String> sb = new ArrayList<>();
final Package pkg = d.getUnit().getPackage();
sb.add(pkg.isLanguagePackage() ? "$" : pkg.getNameAsString());
if (d.isToplevel()) {
sb.add(d.getName());
if (d instanceof Setter) {
sb.add("$set");
}
} else {
Declaration p = d;
final int i = sb.size();
while (p instanceof Declaration) {
if (p instanceof Setter) {
sb.add(i, "$set");
}
final String mname = TypeUtils.modelName(p);
if (!(mname.startsWith("anon$") || mname.startsWith("anonymous#"))) {
sb.add(i, mname);
// Build the path in reverse
if (!p.isToplevel()) {
if (p instanceof Class) {
sb.add(i, p.isAnonymous() ? MetamodelGenerator.KEY_OBJECTS : MetamodelGenerator.KEY_CLASSES);
} else if (p instanceof org.eclipse.ceylon.model.typechecker.model.Interface) {
sb.add(i, MetamodelGenerator.KEY_INTERFACES);
} else if (p instanceof Function) {
if (!p.isAnonymous()) {
sb.add(i, MetamodelGenerator.KEY_METHODS);
}
} else if (p instanceof TypeAlias || p instanceof Setter) {
sb.add(i, MetamodelGenerator.KEY_ATTRIBUTES);
} else if (p instanceof Constructor || ModelUtil.isConstructor(p)) {
sb.add(i, MetamodelGenerator.KEY_CONSTRUCTORS);
} else {
// It's a value
TypeDeclaration td = ((TypedDeclaration) p).getTypeDeclaration();
sb.add(i, (td != null && td.isAnonymous()) ? MetamodelGenerator.KEY_OBJECTS : MetamodelGenerator.KEY_ATTRIBUTES);
}
}
}
p = ModelUtil.getContainingDeclaration(p);
while (p != null && p instanceof ClassOrInterface == false && !(p.isToplevel() || p.isAnonymous() || p.isClassOrInterfaceMember() || p.isJsCaptured())) {
p = ModelUtil.getContainingDeclaration(p);
}
}
}
return sb;
}
use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration 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