use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class MethodDefinitionBuilder method isParamTypeLocalToMethod.
private boolean isParamTypeLocalToMethod(Parameter parameter, Type nonWideningType) {
// error recovery
if (nonWideningType == null)
return false;
if (parameter.getModel().getTypeErased()) {
return false;
}
// make sure we resolve aliases
nonWideningType = nonWideningType.resolveAliases();
Declaration method = parameter.getDeclaration();
TypeDeclaration paramTypeDecl = nonWideningType.getDeclaration();
if (paramTypeDecl instanceof TypeParameter && Decl.equalScopeDecl(paramTypeDecl.getContainer(), method)) {
return false;
}
Scope scope = paramTypeDecl.getContainer();
while (scope != null && !(scope instanceof Package)) {
if (Decl.equalScopeDecl(scope, method)) {
return true;
}
scope = scope.getContainer();
}
return false;
}
use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class Naming method addNamesForWrapperClass.
private <R> void addNamesForWrapperClass(TypeDeclarationBuilder<R> builder, TypedDeclaration decl, int namingOptions) {
if ((namingOptions & NA_FQ) != 0) {
if ((namingOptions & NA_WRAPPER) == 0 && (namingOptions & NA_WRAPPER_UNQUOTED) == 0) {
throw new BugException("If you pass FQ you must pass WRAPPER or WRAPPER_UNQUOTED too, or there's no class name to qualify!");
}
List<String> outerNames = null;
Scope s = decl.getContainer();
boolean isInterop = false;
while (s != null) {
if (s instanceof Package) {
final List<String> packageName = isInterop ? ORG_ECLIPSE_CEYLON_LANGUAGE_PACKAGE : ((Package) s).getName();
for (int ii = 0; ii < packageName.size(); ii++) {
if (ii == 0 && packageName.get(ii).isEmpty()) {
continue;
}
builder.select(quoteIfJavaKeyword(packageName.get(ii)));
}
break;
} else if (s instanceof ClassOrInterface) {
ClassOrInterface c = (ClassOrInterface) s;
if (isJavaInterop(c))
isInterop = true;
if (outerNames == null) {
outerNames = new ArrayList<String>(2);
}
outerNames.add(getQuotedClassName(c, 0));
} else if (s instanceof TypedDeclaration) {
if (outerNames == null) {
outerNames = new ArrayList<String>(2);
}
outerNames.add(quoteIfJavaKeyword(getRealName((TypedDeclaration) s, 0)));
}
s = s.getContainer();
}
if (outerNames != null) {
for (int ii = outerNames.size() - 1; ii >= 0; ii--) {
String outerName = outerNames.get(ii);
builder.select(outerName);
}
}
}
if ((namingOptions & NA_WRAPPER) != 0) {
builder.select(getQuotedClassName(decl, namingOptions & (NA_GETTER | NA_SETTER)));
} else if ((namingOptions & NA_WRAPPER_UNQUOTED) != 0) {
builder.select(getRealName(decl, namingOptions & (NA_GETTER | NA_SETTER | NA_WRAPPER_UNQUOTED)));
} else if ((namingOptions & NA_Q_LOCAL_INSTANCE) != 0) {
if (Decl.isBoxedVariable(decl)) {
builder.select(getVariableBoxName(decl));
} else {
builder.select(getAttrClassName(decl, namingOptions & (NA_GETTER | NA_SETTER)));
}
}
if ((namingOptions & NA_WRAPPER_WITH_THIS) != 0) {
builder.select("this");
}
}
use of org.eclipse.ceylon.model.typechecker.model.Scope 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.Scope 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();
}
use of org.eclipse.ceylon.model.typechecker.model.Scope 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;
}
Aggregations