use of org.eclipse.ceylon.model.loader.mirror.ClassMirror in project ceylon by eclipse.
the class AbstractModelLoader method findModuleClass.
protected ClassMirror findModuleClass(Module module, String pkgName) {
String moduleClassName = pkgName + "." + NamingBase.MODULE_DESCRIPTOR_CLASS_NAME;
logVerbose("[Trying to look up module from " + moduleClassName + "]");
ClassMirror moduleClass = loadClass(module, pkgName, moduleClassName);
if (moduleClass == null) {
// perhaps we have an old module?
String oldModuleClassName = pkgName + "." + NamingBase.OLD_MODULE_DESCRIPTOR_CLASS_NAME;
logVerbose("[Trying to look up older module descriptor from " + oldModuleClassName + "]");
ClassMirror oldModuleClass = loadClass(module, pkgName, oldModuleClassName);
// keep it only if it has a module annotation, otherwise it could be a normal value
if (oldModuleClass != null && oldModuleClass.getAnnotation(CEYLON_MODULE_ANNOTATION) != null)
moduleClass = oldModuleClass;
}
return moduleClass;
}
use of org.eclipse.ceylon.model.loader.mirror.ClassMirror 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.loader.mirror.ClassMirror in project ceylon by eclipse.
the class AbstractModelLoader method setInterfaceCompanionClass.
protected void setInterfaceCompanionClass(Declaration d, ClassOrInterface container, LazyPackage pkg) {
// find its companion class in its real container
ClassMirror containerMirror = null;
if (container instanceof LazyClass) {
containerMirror = ((LazyClass) container).classMirror;
} else if (container instanceof LazyInterface) {
// container must be a LazyInterface, as TypeAlias doesn't contain anything
containerMirror = ((LazyInterface) container).companionClass;
if (containerMirror == null) {
throw new ModelResolutionException("Interface companion class for " + container.getQualifiedNameString() + " not set up");
}
}
String companionName;
if (containerMirror != null)
companionName = containerMirror.getFlatName() + "$" + NamingBase.suffixName(NamingBase.Suffix.$impl, d.getName());
else {
// toplevel
String p = pkg.getNameAsString();
companionName = "";
if (!p.isEmpty())
companionName = p + ".";
companionName += NamingBase.suffixName(NamingBase.Suffix.$impl, d.getName());
}
ClassMirror companionClass = lookupClassMirror(pkg.getModule(), companionName);
if (companionClass == null) {
((Interface) d).setCompanionClassNeeded(false);
}
((LazyInterface) d).companionClass = companionClass;
}
use of org.eclipse.ceylon.model.loader.mirror.ClassMirror in project ceylon by eclipse.
the class RuntimeModelLoader method lazyLoadModuleForPackage.
private Module lazyLoadModuleForPackage(String pkgName) {
if (lazyLoadedModulesByPackage.containsKey(pkgName)) {
return lazyLoadedModulesByPackage.get(pkgName);
}
Module module;
if (pkgName.isEmpty()) {
module = modules.getDefaultModule();
} else {
// pretend it's the default module trying to load a new module? not sure what
// to do here
Module loadByModule = modules.getDefaultModule();
ClassMirror moduleClass = findModuleClass(loadByModule, pkgName);
if (moduleClass != null) {
String name = getAnnotationStringValue(moduleClass, CEYLON_MODULE_ANNOTATION, "name");
String version = getAnnotationStringValue(moduleClass, CEYLON_MODULE_ANNOTATION, "version");
module = findOrCreateModule(name, version);
loadCompiledModule(module);
// damnit, make it import the default module, otherwise it won't be able to see non-ceylon modules
module.addImport(new ModuleImport(null, modules.getDefaultModule(), false, false));
// FIXME: do other things like what RuntimeModuleManager does?
} else {
// try parent package
int lastDot = pkgName.lastIndexOf('.');
String parentPackage;
if (lastDot == -1)
parentPackage = "";
else
parentPackage = pkgName.substring(0, lastDot);
module = lazyLoadModuleForPackage(parentPackage);
}
}
// cache module and return
lazyLoadedModulesByPackage.put(pkgName, module);
return module;
}
use of org.eclipse.ceylon.model.loader.mirror.ClassMirror in project ceylon by eclipse.
the class JvmBackendUtil method getMirrorName.
public static String getMirrorName(AnnotatedMirror mirror) {
String name;
AnnotationMirror annot = mirror.getAnnotation(CEYLON_NAME_ANNOTATION);
if (annot != null) {
name = (String) annot.getValue();
} else {
name = mirror.getName();
name = name.isEmpty() ? name : stripLeadingDollar(name);
if (mirror instanceof ClassMirror && isInitialLowerCase(name) && name.endsWith("_") && mirror.getAnnotation(CEYLON_CEYLON_ANNOTATION) != null) {
name = name.substring(0, name.length() - 1);
}
}
return name;
}
Aggregations