use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class LocalTypeVisitor method visit.
@Override
public void visit(Tree.BaseMemberOrTypeExpression that) {
Declaration model = that.getDeclaration();
if (model != null && (model instanceof Function || model instanceof Class) && !that.getAssigned() && // if it's a parameter we don't need to wrap it in a class
!model.isParameter() && (model instanceof Class == false || !that.getStaticMethodReferencePrimary()) && !that.getDirectlyInvoked()) {
String prefix = this.prefix;
enterAnonymousClass();
super.visit(that);
exitAnonymousClass();
this.prefix = prefix;
} else {
super.visit(that);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class LocalTypeVisitor method visit.
@Override
public void visit(Tree.QualifiedMemberOrTypeExpression that) {
Declaration model = that.getDeclaration();
if (model != null && (model instanceof Function || model instanceof Class) && !that.getAssigned() && // if it's a parameter we don't need to wrap it in a class
!model.isParameter() && (model instanceof Class == false || !that.getStaticMethodReferencePrimary()) && !that.getDirectlyInvoked()) {
String prefix = this.prefix;
enterAnonymousClass();
super.visit(that);
exitAnonymousClass();
this.prefix = prefix;
} else {
super.visit(that);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Class 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.Class 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.Class in project ceylon by eclipse.
the class Naming method makeTypeDeclaration.
private <R> R makeTypeDeclaration(TypeDeclarationBuilder<R> declarationBuilder, final TypeDeclaration decl, DeclNameFlag... options) {
EnumSet<DeclNameFlag> flags = EnumSet.noneOf(DeclNameFlag.class);
flags.addAll(Arrays.asList(options));
if (flags.contains(DeclNameFlag.ANNOTATION) && !Decl.isAnnotationClass(decl)) {
throw new BugException(decl.getName());
}
if (flags.contains(DeclNameFlag.ANNOTATIONS) && !(Decl.isAnnotationClass(decl) || decl instanceof Class || gen().isSequencedAnnotation((Class) decl))) {
throw new BugException(decl.getName());
}
java.util.List<Scope> l = new java.util.ArrayList<Scope>();
Scope s = decl;
do {
l.add(s);
s = s.getContainer();
} while (!(s instanceof Package));
Collections.reverse(l);
if (flags.contains(DeclNameFlag.QUALIFIED) && (!decl.isAnonymous() || decl.isNamed())) {
final List<String> packageName = Decl.isJavaArray(decl) || AbstractTransformer.isJavaInterop(decl) ? ORG_ECLIPSE_CEYLON_LANGUAGE_PACKAGE : ((Package) s).getName();
if (packageName.isEmpty() || !packageName.get(0).isEmpty()) {
declarationBuilder.select("");
}
for (int ii = 0; ii < packageName.size(); ii++) {
declarationBuilder.select(quoteIfJavaKeyword(packageName.get(ii)));
}
}
for (int ii = 0; ii < l.size(); ii++) {
Scope scope = l.get(ii);
final boolean last = ii == l.size() - 1;
appendTypeDeclaration(decl, flags, declarationBuilder, scope, last);
}
return declarationBuilder.result();
}
Aggregations