use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.
the class AbstractModelLoader method addMethod.
private Function addMethod(ClassOrInterface klass, MethodMirror methodMirror, ClassMirror classMirror, boolean isCeylon, boolean isOverloaded, boolean isNativeHeader, boolean isCoercedMethod) {
JavaMethod method = new JavaMethod(methodMirror);
String methodName = methodMirror.getName();
method.setCoercionPoint(isCoercedMethod);
method.setContainer(klass);
method.setScope(klass);
method.setRealName(methodName);
method.setUnit(klass.getUnit());
method.setOverloaded(isOverloaded);
method.setVariadic(methodMirror.isVariadic());
Type type = null;
try {
setMethodOrValueFlags(klass, methodMirror, method, isCeylon);
} catch (ModelResolutionException x) {
// collect an error in its type
type = logModelResolutionException(x, klass, "method '" + methodMirror.getName() + "' (checking if it is an overriding method)");
}
if (methodName.equals("hash") || methodName.equals("string"))
method.setName(methodName + "_method");
else {
String ceylonName = JvmBackendUtil.strip(methodName, isCeylon, method.isShared());
if (!isCeylon && !JvmBackendUtil.isInitialLowerCase(ceylonName))
ceylonName = NamingBase.getJavaBeanName(ceylonName);
method.setName(ceylonName);
}
method.setDefaultedAnnotation(methodMirror.isDefault());
// type params first
try {
setTypeParameters(method, methodMirror, isCeylon);
} catch (ModelResolutionException x) {
if (type == null) {
type = logModelResolutionException(x, klass, "method '" + methodMirror.getName() + "' (loading type parameters)");
}
}
Module module = ModelUtil.getModuleContainer(method);
// do not log an additional error if we had one from checking if it was overriding
if (type == null)
type = obtainType(methodMirror.getReturnType(), methodMirror, method, module, "method '" + methodMirror.getName() + "'", klass);
NullStatus nullPolicy = getUncheckedNullPolicy(isCeylon, methodMirror.getReturnType(), methodMirror);
switch(nullPolicy) {
case Optional:
if (!isCeylon) {
type = makeOptionalTypePreserveUnderlyingType(type, module);
}
break;
case UncheckedNull:
method.setUncheckedNullType(true);
break;
}
if (type.isCached()) {
type = type.clone();
}
method.setType(type);
// now its parameters
if (isEqualsMethod(methodMirror))
setEqualsParameters(method, methodMirror);
else
setParameters(method, classMirror, methodMirror, isCeylon, klass, isCoercedMethod);
type.setRaw(isRaw(module, methodMirror.getReturnType()));
markDeclaredVoid(method, methodMirror);
markUnboxed(method, methodMirror, methodMirror.getReturnType());
markSmall(method, methodMirror.getReturnType());
markTypeErased(method, methodMirror, methodMirror.getReturnType());
markUntrustedType(method, methodMirror, methodMirror.getReturnType());
method.setDeprecated(isDeprecated(methodMirror));
setAnnotations(method, methodMirror, isNativeHeader);
klass.addMember(method);
ModelUtil.setVisibleScope(method);
addLocalDeclarations(method, classMirror, methodMirror);
return method;
}
use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.
the class AbstractModelLoader method setTypeParametersFromAnnotations.
// from our annotation
private void setTypeParametersFromAnnotations(Scope scope, List<TypeParameter> params, AnnotatedMirror mirror, List<AnnotationMirror> typeParameterAnnotations, List<TypeParameterMirror> typeParameterMirrors) {
// We must first add every type param, before we resolve the bounds, which can
// refer to type params.
String selfTypeName = getSelfTypeFromAnnotations(mirror);
int i = 0;
for (AnnotationMirror typeParamAnnotation : typeParameterAnnotations) {
TypeParameter param = new TypeParameter();
param.setUnit(scope.getUnit());
param.setContainer(scope);
param.setScope(scope);
ModelUtil.setVisibleScope(param);
param.setDeclaration((Declaration) scope);
// let's not trigger the lazy-loading if we're completing a LazyClass/LazyInterface
if (scope instanceof LazyContainer)
((LazyContainer) scope).addMember(param);
else
// must be a method
scope.addMember(param);
param.setName((String) typeParamAnnotation.getValue("value"));
param.setExtendedType(typeFactory.getAnythingType());
if (i < typeParameterMirrors.size()) {
TypeParameterMirror typeParameterMirror = typeParameterMirrors.get(i);
param.setNonErasedBounds(hasNonErasedBounds(typeParameterMirror));
}
String varianceName = (String) typeParamAnnotation.getValue("variance");
if (varianceName != null) {
if (varianceName.equals("IN")) {
param.setContravariant(true);
} else if (varianceName.equals("OUT"))
param.setCovariant(true);
}
// If this is a self type param then link it to its type's declaration
if (param.getName().equals(selfTypeName)) {
param.setSelfTypedDeclaration((TypeDeclaration) scope);
}
params.add(param);
i++;
}
Module moduleScope = ModelUtil.getModuleContainer(scope);
// Now all type params have been set, we can resolve the references parts
Iterator<TypeParameter> paramsIterator = params.iterator();
for (AnnotationMirror typeParamAnnotation : typeParameterAnnotations) {
TypeParameter param = paramsIterator.next();
@SuppressWarnings("unchecked") List<String> satisfiesAttribute = (List<String>) typeParamAnnotation.getValue("satisfies");
setListOfTypes(param.getSatisfiedTypes(), satisfiesAttribute, scope, moduleScope, "type parameter '" + param.getName() + "' satisfied types");
@SuppressWarnings("unchecked") List<String> caseTypesAttribute = (List<String>) typeParamAnnotation.getValue("caseTypes");
if (caseTypesAttribute != null && !caseTypesAttribute.isEmpty())
param.setCaseTypes(new LinkedList<Type>());
setListOfTypes(param.getCaseTypes(), caseTypesAttribute, scope, moduleScope, "type parameter '" + param.getName() + "' case types");
String defaultValueAttribute = (String) typeParamAnnotation.getValue("defaultValue");
if (defaultValueAttribute != null && !defaultValueAttribute.isEmpty()) {
Type decodedType = decodeType(defaultValueAttribute, scope, moduleScope, "type parameter '" + param.getName() + "' defaultValue");
param.setDefaultTypeArgument(decodedType);
param.setDefaulted(true);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.
the class RuntimeModelLoader method findModuleForClass.
public Module findModuleForClass(Class<?> klass) {
ClassLoader cl = klass.getClassLoader();
if (cl instanceof CeylonModuleClassLoader) {
CeylonModuleClassLoader classLoader = (CeylonModuleClassLoader) cl;
String name = classLoader.getModuleName();
String version = classLoader.getModuleVersion();
String cacheKey = cacheKeyByModule(name, version);
Module ret = moduleCache.get(cacheKey);
if (ret == null) {
// there's a good chance we didn't get the module loaded in time, wait until that classloader is
// registered then, but give it a nudge:
// this can complete in another thread or this thread
classLoader.registerInMetaModel();
Object lock = getLock();
synchronized (lock) {
int tries = MAX_JBOSS_MODULES_WAITS;
while (!classLoaders.containsValue(cl)) {
try {
lock.wait(JBOSS_MODULES_TIMEOUT);
} catch (InterruptedException e) {
throw new ModelResolutionException(e);
}
if (tries-- < 0)
throw new ModelResolutionException("Failed to find registered classloader for " + klass);
}
ret = moduleCache.get(cacheKey);
}
}
return ret;
} else {
// revert to a single classloader version?
// FIXME: perhaps we can have other one-classloader-to-one-module setups than jboss modules?
String pkgName = ReflectionUtils.getPackageName(klass);
// even on jboss modules, the jdk has no class loader, so jdk classes will have to be resolved
// to the jdk modules by package
String jdkModuleName = JDKUtils.getJDKModuleNameForPackage(pkgName);
if (jdkModuleName != null)
return findModule(jdkModuleName, JDKUtils.jdk.version);
if (isDynamicMetamodel())
return lazyLoadModuleForPackage(pkgName);
return lookupModuleByPackageName(pkgName);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Module 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.typechecker.model.Module in project ceylon by eclipse.
the class RuntimeModelLoader method loadStandardModules.
@Override
public void loadStandardModules() {
// set up the type factory and that's it: do not try to load the language module package before it's set up
// by Metamodel.loadModule
jdkProvider = new JdkProvider();
Module languageModule = findOrCreateModule(CEYLON_LANGUAGE, null);
addModuleToClassPath(languageModule, (ArtifactResult) null);
Package languagePackage = findOrCreatePackage(languageModule, CEYLON_LANGUAGE);
typeFactory.setPackage(languagePackage);
// make sure the jdk modules are loaded because those are not initialised by jboss modules nor the IDE Launcher
for (String jdkModule : JDKUtils.getJDKModuleNames()) findOrCreateModule(jdkModule, JDKUtils.jdk.version);
for (String jdkOracleModule : JDKUtils.getOracleJDKModuleNames()) findOrCreateModule(jdkOracleModule, JDKUtils.jdk.version);
}
Aggregations