use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class GenerateJsVisitor method getSuperMemberScope.
/**
* Checks if the given node is a MemberOrTypeExpression or QualifiedType which
* represents an access to a supertype member and returns the scope of that
* member or null.
*/
Scope getSuperMemberScope(Node node) {
Scope scope = null;
if (node instanceof Tree.QualifiedMemberOrTypeExpression) {
// Check for "super.member"
Tree.QualifiedMemberOrTypeExpression qmte = (Tree.QualifiedMemberOrTypeExpression) node;
final Term primary = eliminateParensAndWidening(qmte.getPrimary());
if (primary instanceof Tree.Super) {
scope = qmte.getDeclaration().getContainer();
}
} else if (node instanceof Tree.QualifiedType) {
// Check for super.Membertype
Tree.QualifiedType qtype = (Tree.QualifiedType) node;
if (qtype.getOuterType() instanceof Tree.SuperType) {
scope = qtype.getDeclarationModel().getContainer();
}
}
return scope;
}
use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class MethodOrValueReferenceVisitor method isSelfCaptured.
/**
* Returns true if <code>that</code> is within the scope of the type of <code>d</code>,
* which must be a value declaration for an object declaration.
*/
private boolean isSelfCaptured(Primary that, TypedDeclaration d) {
TypeDeclaration type = d.getTypeDeclaration();
Scope scope = that.getScope();
while (scope != null && !(scope instanceof Package) && !Decl.equalScopeDecl(scope, type)) {
scope = scope.getScope();
}
return Decl.equalScopeDecl(scope, type);
}
use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class AbstractModelLoader method findLocalContainerFromAnnotationAndSetCompanionClass.
private Scope findLocalContainerFromAnnotationAndSetCompanionClass(Package pkg, Interface declaration, AnnotationMirror localContainerAnnotation) {
@SuppressWarnings("unchecked") List<String> path = (List<String>) localContainerAnnotation.getValue("path");
// we start at the package
Scope scope = pkg;
for (String name : path) {
scope = (Scope) getDirectMember(scope, name);
}
String companionClassName = (String) localContainerAnnotation.getValue("companionClassName");
if (companionClassName == null || companionClassName.isEmpty()) {
declaration.setCompanionClassNeeded(false);
return scope;
}
ClassMirror container;
Scope javaClassScope;
if (scope instanceof TypedDeclaration && ((TypedDeclaration) scope).isMember())
javaClassScope = scope.getContainer();
else
javaClassScope = scope;
if (javaClassScope instanceof LazyInterface) {
container = ((LazyInterface) javaClassScope).companionClass;
} else if (javaClassScope instanceof LazyClass) {
container = ((LazyClass) javaClassScope).classMirror;
} else if (javaClassScope instanceof LazyValue) {
container = ((LazyValue) javaClassScope).classMirror;
} else if (javaClassScope instanceof LazyFunction) {
container = ((LazyFunction) javaClassScope).classMirror;
} else if (javaClassScope instanceof SetterWithLocalDeclarations) {
container = ((SetterWithLocalDeclarations) javaClassScope).classMirror;
} else {
throw new ModelResolutionException("Unknown scope class: " + javaClassScope);
}
String qualifiedCompanionClassName = container.getQualifiedName() + "$" + companionClassName;
ClassMirror companionClassMirror = lookupClassMirror(pkg.getModule(), qualifiedCompanionClassName);
if (companionClassMirror == null)
throw new ModelResolutionException("Could not find companion class mirror: " + qualifiedCompanionClassName);
((LazyInterface) declaration).companionClass = companionClassMirror;
return scope;
}
use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class AbstractModelLoader method isRaw.
private boolean isRaw(Module module, TypeMirror type) {
// See https://github.com/ceylon/ceylon-compiler/issues/1085
switch(type.getKind()) {
// arrays are never raw
case ARRAY:
case BOOLEAN:
case BYTE:
case CHAR:
case DOUBLE:
case ERROR:
case FLOAT:
case INT:
case LONG:
case NULL:
case SHORT:
case TYPEVAR:
case VOID:
case WILDCARD:
return false;
case DECLARED:
ClassMirror klass = type.getDeclaredClass();
if (klass.isJavaSource()) {
// I suppose this should work
return type.isRaw();
}
List<String> path = new LinkedList<String>();
String pkgName = klass.getPackage().getQualifiedName();
String unquotedPkgName = unquotePackageName(klass.getPackage());
String qualifiedName = klass.getQualifiedName();
String relativeName = pkgName.isEmpty() ? qualifiedName : qualifiedName.substring(pkgName.length() + 1);
for (String name : relativeName.split("[\\$\\.]")) {
if (!name.isEmpty()) {
path.add(name);
}
}
if (path.size() > 1) {
// find the proper class mirror for the container
klass = loadClass(module, pkgName, new StringBuilder(pkgName).append('.').append(path.get(0)).toString());
if (klass == null)
return false;
}
if (!path.isEmpty() && klass.isLoadedFromSource()) {
// we need to find its model
Scope scope = packagesByName.get(cacheKeyByModule(module, unquotedPkgName));
if (scope == null)
return false;
for (String name : path) {
Declaration decl = scope.getDirectMember(name, null, false);
if (decl == null)
return false;
// if we get a value, we want its type
if (JvmBackendUtil.isValue(decl) && ((Value) decl).getTypeDeclaration().getName().equals(name))
decl = ((Value) decl).getTypeDeclaration();
if (decl instanceof TypeDeclaration == false)
return false;
scope = (TypeDeclaration) decl;
}
TypeDeclaration typeDecl = (TypeDeclaration) scope;
return typeDecl.isParameterized() && type.getTypeArguments().isEmpty();
}
try {
return type.isRaw();
} catch (Exception x) {
// it will be logged somewhere else
return false;
}
default:
return false;
}
}
use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class AbstractModelLoader method makeSetter.
private SetterWithLocalDeclarations makeSetter(Value value, ClassMirror classMirror) {
SetterWithLocalDeclarations setter = new SetterWithLocalDeclarations(classMirror);
Scope scope = value.getContainer();
setter.setContainer(scope);
setter.setScope(scope);
setter.setType(value.getType());
setter.setName(value.getName());
Parameter p = new Parameter();
p.setHidden(true);
Value v = new Value();
v.setType(value.getType());
v.setUnboxed(value.getUnboxed());
v.setInitializerParameter(p);
v.setContainer(setter);
v.setScope(setter);
p.setModel(v);
v.setName(setter.getName());
p.setName(setter.getName());
p.setDeclaration(setter);
setter.setParameter(p);
value.setSetter(setter);
setter.setGetter(value);
return setter;
}
Aggregations