use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class AbstractModelLoader method makeInteropAnnotationClass.
/**
* <pre>
* annotation class Annotation$Proxy(...) satisfies Annotation {
* // a `shared` class parameter for each method of Annotation
* }
* </pre>
* @param iface The model of the annotation @interface
* @return The annotation class for the given interface
*/
public AnnotationProxyClass makeInteropAnnotationClass(LazyInterface iface, Scope scope) {
AnnotationProxyClass klass = new AnnotationProxyClass(this, iface);
klass.setContainer(scope);
klass.setScope(scope);
if (!(scope instanceof Package)) {
klass.setStatic(true);
}
klass.setName(iface.getName() + "$Proxy");
klass.setShared(iface.isShared());
klass.setAnnotation(true);
Annotation annotationAnnotation = new Annotation();
annotationAnnotation.setName("annotation");
klass.getAnnotations().add(annotationAnnotation);
klass.getSatisfiedTypes().add(iface.getType());
klass.setUnit(iface.getUnit());
klass.setScope(scope);
return klass;
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class AbstractModelLoader method getUnitForModule.
private Unit getUnitForModule(Module module) {
List<Package> packages = module.getPackages();
if (packages.isEmpty()) {
System.err.println("No package for module " + module.getNameAsString());
return null;
}
Package pkg = packages.get(0);
if (pkg instanceof LazyPackage == false) {
System.err.println("No lazy package for module " + module.getNameAsString());
return null;
}
Unit unit = getCompiledUnit((LazyPackage) pkg, null);
if (unit == null) {
System.err.println("No unit for module " + module.getNameAsString());
return null;
}
return unit;
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class AbstractModelLoader method loadLanguageModuleAndPackage.
protected Module loadLanguageModuleAndPackage() {
Module languageModule = findOrCreateModule(CEYLON_LANGUAGE, null);
addModuleToClassPath(languageModule, null);
Package languagePackage = findOrCreatePackage(languageModule, CEYLON_LANGUAGE);
typeFactory.setPackage(languagePackage);
// make sure the language module has its real dependencies added, because we need them in the classpath
// otherwise we will get errors on the Util and Metamodel calls we insert
// WARNING! Make sure this list is always the same as the one in /ceylon-runtime/dist/repo/ceylon/language/_version_/module.xml
// Note that we lie about the module exports: we pretend they're not imported at compile-time
// while they are at run-time (in the module.xml file), so that users don't get these imports
// visible in all their modules.
languageModule.addImport(new ModuleImport(null, findOrCreateModule("org.eclipse.ceylon.common", Versions.CEYLON_VERSION_NUMBER), false, false, Backend.Java));
languageModule.addImport(new ModuleImport(null, findOrCreateModule("org.eclipse.ceylon.model", Versions.CEYLON_VERSION_NUMBER), false, false, Backend.Java));
return languageModule;
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class AbstractModelLoader method setupWithNoStandardModules.
/**
* This is meant to be called if your subclass doesn't call loadStandardModules for whatever reason
*/
public void setupWithNoStandardModules() {
Module languageModule = modules.getLanguageModule();
if (languageModule == null)
throw new RuntimeException("Assertion failed: language module is null");
Package languagePackage = languageModule.getPackage(CEYLON_LANGUAGE);
if (languagePackage == null)
throw new RuntimeException("Assertion failed: language package is null");
typeFactory.setPackage(languagePackage);
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class TypeParser method loadType.
private Type loadType(String pkg, String fullName, Part part, Type qualifyingType) {
// try to find a qualified type
try {
Declaration newDeclaration;
if (qualifyingType == null) {
// FIXME: this only works for packages not contained in multiple modules
Package foundPackage = moduleScope.getPackage(pkg);
if (foundPackage != null)
newDeclaration = loader.getDeclaration(foundPackage.getModule(), pkg, fullName, scope);
else if (scope != null && !pkg.isEmpty() && loader.isDynamicMetamodel()) {
// try the default module, damnit
newDeclaration = loader.getDeclaration(loader.getLoadedModule(Module.DEFAULT_MODULE_NAME, null), pkg, fullName, scope);
} else if (scope != null) {
// if we did not find any package and the scope is null, chances are we're after a type variable
// or a relative type, so use the module scope
newDeclaration = loader.getDeclaration(moduleScope, pkg, fullName, scope);
} else
newDeclaration = null;
} else {
// look it up via its qualifying type or decl
Declaration qualifyingDeclaration = qualifyingType.getDeclaration();
if (qualifyingType.isUnion() || qualifyingType.isIntersection()) {
newDeclaration = qualifyingDeclaration.getMember(part.name, null, false);
} else {
if (qualifyingDeclaration instanceof FunctionOrValueInterface)
qualifyingDeclaration = ((FunctionOrValueInterface) qualifyingDeclaration).getUnderlyingDeclaration();
newDeclaration = AbstractModelLoader.getDirectMember((Scope) qualifyingDeclaration, part.name);
}
if (newDeclaration == null)
throw new ModelResolutionException("Failed to resolve inner type or declaration " + part.name + " in " + qualifyingDeclaration.getQualifiedNameString());
}
if (newDeclaration == null)
return null;
TypeDeclaration newTypeDeclaration;
if (newDeclaration instanceof TypeDeclaration)
newTypeDeclaration = (TypeDeclaration) newDeclaration;
else
newTypeDeclaration = new FunctionOrValueInterface((TypedDeclaration) newDeclaration);
Type ret = newTypeDeclaration.appliedType(qualifyingType, part.getParameters());
// set the use-site variance if required, now that we know the TypeParameter declarations
if (!part.getVariance().isEmpty()) {
List<TypeParameter> tps = newTypeDeclaration.getTypeParameters();
List<SiteVariance> variance = part.getVariance();
for (int i = 0, l1 = tps.size(), l2 = variance.size(); i < l1 && i < l2; i++) {
SiteVariance siteVariance = variance.get(i);
if (siteVariance != null) {
ret.setVariance(tps.get(i), siteVariance);
}
}
}
return ret;
} catch (ModelResolutionException x) {
// - if we have type parameters we must have a type
if (qualifyingType != null || (part.parameters != null && !part.parameters.isEmpty()))
throw x;
return null;
}
}
Aggregations