use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class ClassTransformer method addAtContainer.
private void addAtContainer(ClassDefinitionBuilder classBuilder, TypeDeclaration model) {
Scope scope = Decl.getNonSkippedContainer((Scope) model);
Scope declarationScope = Decl.getFirstDeclarationContainer((Scope) model);
boolean inlineObjectInToplevelAttr = Decl.isTopLevelObjectExpressionType(model);
if (scope == null || (scope instanceof Package && !inlineObjectInToplevelAttr) && scope == declarationScope)
return;
if (scope instanceof ClassOrInterface && scope == declarationScope && !inlineObjectInToplevelAttr && // we do not check for types inside initialiser section which are private and not captured because we treat them as members
!(model instanceof Interface && Decl.hasLocalNotInitializerAncestor(model))) {
ClassOrInterface container = (ClassOrInterface) scope;
List<JCAnnotation> atContainer = makeAtContainer(container.getType(), model.isStatic());
classBuilder.annotations(atContainer);
} else {
if (model instanceof Interface)
classBuilder.annotations(makeLocalContainerPath((Interface) model));
Declaration declarationContainer = getDeclarationContainer(model);
classBuilder.annotations(makeAtLocalDeclaration(model.getQualifier(), declarationContainer == null));
}
}
use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class ClassTransformer method makeLocalContainerPath.
private List<JCAnnotation> makeLocalContainerPath(Interface model) {
List<String> path = List.nil();
Scope container = model.getContainer();
while (container != null && container instanceof Package == false) {
if (container instanceof Declaration)
path = path.prepend(((Declaration) container).getPrefixedName());
container = container.getContainer();
}
return makeAtLocalContainer(path, model.isCompanionClassNeeded() ? model.getJavaCompanionClassName() : null);
}
use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class ExpressionTransformer method appendDeclarationLiteralForAnnotation.
/**
* Appends into the given builder a String representation of the given
* declaration, suitable for parsing my the DeclarationParser.
*/
private static void appendDeclarationLiteralForAnnotation(Declaration decl, StringBuilder sb) {
Scope container = decl.getContainer();
while (true) {
if (container instanceof Declaration) {
appendDeclarationLiteralForAnnotation((Declaration) container, sb);
sb.append(".");
break;
} else if (container instanceof Package) {
appendDeclarationLiteralForAnnotation((Package) container, sb);
sb.append(":");
break;
}
container = container.getContainer();
}
if (decl instanceof Class) {
sb.append("C").append(decl.getName());
} else if (decl instanceof Interface) {
sb.append("I").append(decl.getName());
} else if (decl instanceof TypeAlias) {
sb.append("A").append(decl.getName());
} else if (decl instanceof Value) {
sb.append("V").append(decl.getName());
} else if (decl instanceof Function) {
sb.append("F").append(decl.getName());
} else if (decl instanceof TypeParameter) {
sb.append("P").append(decl.getName());
} else if (decl instanceof Constructor) {
sb.append("c").append(decl.getName());
} else {
throw BugException.unhandledDeclarationCase(decl);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class ExpressionTransformer method makeQualifiedDollarThis.
private JCExpression makeQualifiedDollarThis(Tree.BaseMemberExpression expr) {
Declaration decl = expr.getDeclaration();
Interface interf = (Interface) ModelUtil.getClassOrInterfaceContainer(decl);
// find the target container interface that is or satisfies the given interface
Scope scope = expr.getScope();
boolean needsQualified = false;
while (scope != null) {
if (scope instanceof Interface) {
if (Decl.equalScopeDecl(scope, interf) || ((Interface) scope).inherits(interf)) {
break;
}
// we only need to qualify it if we're aiming for a $this of an outer interface than the interface we are caught in
needsQualified = true;
}
scope = scope.getContainer();
}
if (!needsQualified)
return naming.makeQuotedThis();
interf = (Interface) scope;
return makeQualifiedDollarThis(interf.getType());
}
use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class ExpressionTransformer method functionalParameterRequiresCallable.
/**
* Determines whether we need to generate an AbstractCallable when taking
* a method reference to a method that's declared as a FunctionalParameter
*/
private boolean functionalParameterRequiresCallable(Function functionalParameter, Tree.StaticMemberOrTypeExpression expr) {
if (!functionalParameter.isParameter()) {
throw new BugException();
}
boolean hasMethod = JvmBackendUtil.createMethod(functionalParameter);
if (!hasMethod) {
// A functional parameter that's not method wrapped will already be Callable-wrapped
return false;
}
// Optimization: If we're in a scope where the Callable field is visible
// we don't need to create a method ref
Scope scope = expr.getScope();
while (true) {
if (scope instanceof Package) {
break;
}
if (scope.equals(functionalParameter.getContainer())) {
return false;
}
scope = scope.getContainer();
}
// Otherwise we do require an AbstractCallable.
return true;
}
Aggregations