use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration in project ceylon by eclipse.
the class Naming method makeDefaultedParamMethod.
JCExpression makeDefaultedParamMethod(JCExpression qualifier, Parameter param) {
// TODO Can we merge this into makeName(..., NA_DPM) ?
if (!Strategy.hasDefaultParameterValueMethod(param)) {
throw new BugException();
}
Declaration decl = param.getDeclaration();
String methodName = getDefaultedParamMethodName(decl, param);
switch(Strategy.defaultParameterMethodOwner(param.getModel())) {
case SELF:
{
// method not within interface
Declaration container = param.getDeclaration().getRefinedDeclaration();
if (!container.isToplevel()) {
container = (Declaration) container.getContainer();
}
JCExpression className = makeTypeDeclarationExpression(qualifier, (TypeDeclaration) container, DeclNameFlag.COMPANION);
return makeSelect(className, methodName);
}
case OUTER:
case OUTER_COMPANION:
return makeQuotedQualIdent(qualifier, methodName);
case STATIC:
{
// top level method or class
// return makeSelect(gen().makeStaticQualifier(param.getDeclaration().getRefinedDeclaration()), methodName);
Declaration container = param.getDeclaration().getRefinedDeclaration();
if (!container.isToplevel() && !container.isStatic()) {
container = (Declaration) container.getContainer();
} else if (container.isStatic() && container instanceof TypedDeclaration) {
container = (Declaration) container.getContainer();
}
if (container instanceof TypedDeclaration) {
return makeSelect(makeName((TypedDeclaration) container, NA_FQ | NA_WRAPPER), methodName);
} else {
return makeSelect(gen().makeJavaType(((TypeDeclaration) container).getType(), AbstractTransformer.JT_RAW | AbstractTransformer.JT_NO_PRIMITIVES), methodName);
}
}
default:
// inner or local class or method, or method in an interface
return makeQuotedQualIdent(qualifier, methodName);
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration in project ceylon by eclipse.
the class Naming method makeNamedConstructorName.
public JCExpression makeNamedConstructorName(Constructor constructor, boolean delegation) {
DeclNameFlag[] flags = delegation ? new DeclNameFlag[] { DeclNameFlag.QUALIFIED, DeclNameFlag.DELEGATION } : new DeclNameFlag[] { DeclNameFlag.QUALIFIED };
Class cls = (Class) constructor.getContainer();
if (cls.isToplevel() || cls.isMember() && ((TypeDeclaration) cls.getContainer()).isToplevel()) {
return makeTypeDeclarationExpression(null, constructor, flags);
} else {
return maker.TypeCast(makeTypeDeclarationExpression(null, constructor, flags), // makeTypeDeclarationExpression(makeTypeDeclarationExpression(null, cls, DeclNameFlag.QUALIFIED), constructor, DeclNameFlag.QUALIFIED),
make().Literal(TypeTag.BOT, null));
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration 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.TypeDeclaration 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.TypeDeclaration in project ceylon by eclipse.
the class Decl method getOuterScopeOfMemberInvocation.
public static TypeDeclaration getOuterScopeOfMemberInvocation(Tree.StaticMemberOrTypeExpression expr, Declaration decl) {
// First check whether the expression is captured from an enclosing scope
TypeDeclaration outer = null;
// get the ClassOrInterface container of the declaration
Scope stop = ModelUtil.getClassOrInterfaceContainer(decl, false);
if (stop instanceof TypeDeclaration) {
// reified scope
Scope scope = expr.getScope();
while (!(scope instanceof Package)) {
if (scope.equals(stop)) {
outer = (TypeDeclaration) stop;
break;
}
scope = scope.getContainer();
}
}
// If not it might be inherited...
if (outer == null) {
outer = expr.getScope().getInheritingDeclaration(decl);
}
return outer;
}
Aggregations