use of org.eclipse.ceylon.model.loader.mirror.TypeMirror in project ceylon by eclipse.
the class AnnotationLoader method setPrimaryFromAnnotationInvocationAnnotation.
private void setPrimaryFromAnnotationInvocationAnnotation(AnnotationMirror annotationInvocationAnnotation, AnnotationInvocation ai) {
TypeMirror annotationType = (TypeMirror) annotationInvocationAnnotation.getValue(AbstractModelLoader.CEYLON_ANNOTATION_INSTANTIATION_ANNOTATION_MEMBER);
ClassMirror annotationClassMirror = annotationType.getDeclaredClass();
Module module = modelLoader.findModuleForClassMirror(annotationClassMirror);
if (annotationClassMirror.getAnnotation(AbstractModelLoader.CEYLON_METHOD_ANNOTATION) != null) {
ai.setPrimary((Function) modelLoader.convertToDeclaration(module, annotationClassMirror, DeclarationType.VALUE));
} else {
ai.setPrimary((Class) modelLoader.convertToDeclaration(module, annotationClassMirror, DeclarationType.TYPE));
}
}
use of org.eclipse.ceylon.model.loader.mirror.TypeMirror in project ceylon by eclipse.
the class CeylonModelLoader method getFunctionalInterfaceType.
@Override
protected FunctionalInterfaceType getFunctionalInterfaceType(TypeMirror typeMirror) throws ModelResolutionException {
if (typeMirror.getKind() != TypeKind.DECLARED)
throw new ModelResolutionException("Failed to find functional interface type in " + typeMirror);
// FIXME: possibly apply other optimisations to lighten the lookup cost? see what javac does
Type type = ((JavacType) typeMirror).type;
try {
Type descriptorType = types.findDescriptorType(type);
// Let's be honest I've no idea what this means, but it happens and Javac seems to refuse it too
if (descriptorType.hasTag(TypeTag.FORALL))
throw new ModelResolutionException("Failed to find functional interface type in " + typeMirror);
MethodType methodDescriptorType = (MethodType) descriptorType;
MethodSymbol methodSymbol = (MethodSymbol) types.findDescriptorSymbol(type.tsym);
List<Type> parameterTypes = methodDescriptorType.getParameterTypes();
ListBuffer<TypeMirror> mirrorParameterTypes = new ListBuffer<>();
for (int i = 0; i < parameterTypes.size(); i++) {
Type parameterType = parameterTypes.get(i);
if (methodSymbol.isVarArgs() && i == parameterTypes.size() - 1)
parameterType = ((ArrayType) parameterType).getComponentType();
mirrorParameterTypes.add(new JavacType(parameterType));
}
return new FunctionalInterfaceType(new JavacMethod(new JavacClass(methodSymbol.enclClass()), methodSymbol), new JavacType(methodDescriptorType.getReturnType()), mirrorParameterTypes.toList(), methodSymbol.isVarArgs());
} catch (Symbol.CompletionFailure err) {
// bad luck
throw new ModelResolutionException("Failed to find functional interface type in " + typeMirror, err);
} catch (FunctionDescriptorLookupError err) {
throw new ModelResolutionException("Failed to find functional interface type in " + typeMirror, err);
}
}
use of org.eclipse.ceylon.model.loader.mirror.TypeMirror in project ceylon by eclipse.
the class JavacClass method getInterfaces.
@Override
public List<TypeMirror> getInterfaces() {
if (interfaces == null) {
List<TypeMirror> ret = new ArrayList<TypeMirror>(classSymbol.getInterfaces().size());
for (Type interfce : classSymbol.getInterfaces()) ret.add(new JavacType(interfce));
interfaces = Collections.unmodifiableList(ret);
}
return interfaces;
}
use of org.eclipse.ceylon.model.loader.mirror.TypeMirror in project ceylon by eclipse.
the class JavacType method getTypeArguments.
@Override
public List<TypeMirror> getTypeArguments() {
if (typeArguments == null) {
List<TypeMirror> args = new ArrayList<TypeMirror>(type.getTypeArguments().size());
for (Type typeArg : type.getTypeArguments()) {
args.add(new JavacType(typeArg));
}
typeArguments = Collections.unmodifiableList(args);
}
return typeArguments;
}
use of org.eclipse.ceylon.model.loader.mirror.TypeMirror in project ceylon by eclipse.
the class AbstractModelLoader method addInnerClassesFromAnnotation.
private void addInnerClassesFromAnnotation(ClassOrInterface klass, AnnotationMirror membersAnnotation) {
@SuppressWarnings("unchecked") List<AnnotationMirror> members = (List<AnnotationMirror>) membersAnnotation.getValue();
for (AnnotationMirror member : members) {
TypeMirror javaClassMirror = (TypeMirror) member.getValue("klass");
String javaClassName;
// void.class is the default value, I guess it's a primitive?
if (javaClassMirror != null && !javaClassMirror.isPrimitive()) {
javaClassName = javaClassMirror.getQualifiedName();
} else {
// we get the class name as a string
String name = (String) member.getValue("javaClassName");
ClassMirror container = null;
if (klass instanceof LazyClass) {
container = ((LazyClass) klass).classMirror;
} else if (klass instanceof LazyInterface) {
if (((LazyInterface) klass).isCeylon())
container = ((LazyInterface) klass).companionClass;
else
container = ((LazyInterface) klass).classMirror;
}
if (container == null)
throw new ModelResolutionException("Unknown container type: " + klass + " when trying to load inner class " + name);
javaClassName = container.getQualifiedName() + "$" + name;
}
Declaration innerDecl = convertToDeclaration(ModelUtil.getModuleContainer(klass), klass, javaClassName, DeclarationType.TYPE);
if (innerDecl == null)
throw new ModelResolutionException("Failed to load inner type " + javaClassName + " for outer type " + klass.getQualifiedNameString());
if (shouldLinkNatives(innerDecl)) {
initNativeHeaderMember(innerDecl);
}
}
}
Aggregations