use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.
the class AbstractModelLoader method getRepeatableContainer.
public Interface getRepeatableContainer(Class c) {
if (c instanceof AnnotationProxyClass) {
AnnotationMirror mirror = ((AnnotationProxyClass) c).iface.classMirror.getAnnotation("java.lang.annotation.Repeatable");
if (mirror != null) {
TypeMirror m = (TypeMirror) mirror.getValue();
Module module = findModuleForClassMirror(m.getDeclaredClass());
return (Interface) convertDeclaredTypeToDeclaration(module, m, DeclarationType.TYPE);
}
}
return null;
}
use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.
the class AbstractModelLoader method addInnerClassesFromMirror.
private void addInnerClassesFromMirror(ClassOrInterface klass, ClassMirror classMirror) {
boolean isJDK = isFromJDK(classMirror);
Module module = ModelUtil.getModule(klass);
for (ClassMirror innerClass : classMirror.getDirectInnerClasses()) {
// We skip members marked with @Ignore
if (innerClass.getAnnotation(CEYLON_IGNORE_ANNOTATION) != null)
continue;
// We skip anonymous inner classes
if (innerClass.isAnonymous())
continue;
// We skip private classes, otherwise the JDK has a ton of unresolved things
if (isJDK && !innerClass.isPublic())
continue;
// convert it
convertToDeclaration(module, klass, innerClass, DeclarationType.TYPE);
// no need to set its container as that's now handled by convertToDeclaration
}
}
use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.
the class AbstractModelLoader method getJavaAnnotationExtendedType.
private Type getJavaAnnotationExtendedType(ClassOrInterface klass, ClassMirror classMirror) {
TypeDeclaration constrainedAnnotation = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_CONSTRAINED_ANNOTATION_TYPE, klass, DeclarationType.TYPE);
AnnotationMirror target = classMirror.getAnnotation("java.lang.annotation.Target");
Set<Type> types = new HashSet<Type>();
if (target != null) {
@SuppressWarnings("unchecked") List<String> values = (List<String>) target.getValue();
for (String value : values) {
switch(value) {
case "TYPE":
TypeDeclaration decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_CLASS_OR_INTERFACE_DECLARATION_TYPE, klass, DeclarationType.TYPE);
types.add(decl.getType());
decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_ALIAS_DECLARATION_TYPE, klass, DeclarationType.TYPE);
types.add(decl.getType());
break;
case "ANNOTATION_TYPE":
decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_CLASS_OR_INTERFACE_DECLARATION_TYPE, klass, DeclarationType.TYPE);
types.add(decl.getType());
break;
case "CONSTRUCTOR":
decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_CONSTRUCTOR_DECLARATION_TYPE, klass, DeclarationType.TYPE);
types.add(decl.getType());
if (!values.contains("TYPE")) {
decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_CLASS_WITH_INIT_DECLARATION_TYPE, klass, DeclarationType.TYPE);
types.add(decl.getType());
}
break;
case "METHOD":
// method annotations may be applied to shared members which are turned into getter methods
case "PARAMETER":
decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_FUNCTION_OR_VALUE_DECLARATION_TYPE, klass, DeclarationType.TYPE);
types.add(decl.getType());
break;
case "FIELD":
case "LOCAL_VARIABLE":
decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_VALUE_DECLARATION_TYPE, klass, DeclarationType.TYPE);
types.add(decl.getType());
break;
case "PACKAGE":
decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_PACKAGE_DECLARATION_TYPE, klass, DeclarationType.TYPE);
types.add(decl.getType());
break;
default:
}
}
}
Module module = ModelUtil.getModuleContainer(klass);
Type annotatedType;
if (types.size() == 1)
annotatedType = types.iterator().next();
else if (types.isEmpty()) {
TypeDeclaration decl;
if (target == null) {
// default is anything
decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_ANNOTATED_TYPE, klass, DeclarationType.TYPE);
} else {
// we either had an empty set which means cannot be used as annotation in Java (only as annotation member)
// or that we only had unmappable targets
decl = typeFactory.getNothingDeclaration();
}
annotatedType = decl.getType();
} else {
List<Type> list = new ArrayList<Type>(types.size());
list.addAll(types);
annotatedType = union(list, getUnitForModule(module));
}
Type constrainedType = constrainedAnnotation.appliedType(null, Arrays.asList(klass.getType(), getOptionalType(klass.getType(), module), annotatedType));
return constrainedType;
}
use of org.eclipse.ceylon.model.typechecker.model.Module 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.Module in project ceylon by eclipse.
the class AbstractModelLoader method propertiesMatch.
private boolean propertiesMatch(ClassOrInterface klass, MethodMirror getter, MethodMirror setter) {
// only add the setter if it has the same visibility as the getter
if (setter.isPublic() && getter.isPublic() || setter.isProtected() && getter.isProtected() || setter.isDefaultAccess() && getter.isDefaultAccess() || (!setter.isPublic() && !getter.isPublic() && !setter.isProtected() && !getter.isProtected() && !setter.isDefaultAccess() && !getter.isDefaultAccess())) {
Module module = ModelUtil.getModuleContainer(klass);
VariableMirror setterParam = setter.getParameters().get(0);
Type paramType = obtainType(setterParam.getType(), setterParam, klass, module, "setter '" + setter.getName() + "'", klass);
Type returnType = obtainType(getter.getReturnType(), getter, klass, module, "getter '" + getter.getName() + "'", klass);
// only add the setter if it has exactly the same type as the getter
if (paramType.isExactly(returnType)) {
return true;
}
}
return false;
}
Aggregations