use of org.eclipse.ceylon.model.loader.mirror.TypeMirror in project ceylon by eclipse.
the class AnnotationLoader method readObjectValuesAnnotation.
private LiteralAnnotationTerm readObjectValuesAnnotation(Module moduleScope, AnnotationMirror valueAnnotation, boolean singleValue) {
if (singleValue) {
TypeMirror klass = getAnnotationClassValues(valueAnnotation, "value").get(0);
Type type = modelLoader.obtainType(moduleScope, klass, null, null);
ObjectLiteralAnnotationTerm term = new ObjectLiteralAnnotationTerm(type);
return term;
} else {
CollectionLiteralAnnotationTerm result = new CollectionLiteralAnnotationTerm(ObjectLiteralAnnotationTerm.FACTORY);
for (TypeMirror klass : getAnnotationClassValues(valueAnnotation, "value")) {
Type type = modelLoader.obtainType(moduleScope, klass, null, null);
result.addElement(new ObjectLiteralAnnotationTerm(type));
}
return result;
}
}
use of org.eclipse.ceylon.model.loader.mirror.TypeMirror in project ceylon by eclipse.
the class JavacTypeParameter method getBounds.
@Override
public List<TypeMirror> getBounds() {
if (bounds == null) {
org.eclipse.ceylon.langtools.tools.javac.util.List<Type> bnds = typeSymbol.getBounds();
List<TypeMirror> ret = new ArrayList<TypeMirror>(bnds.size());
for (Type type : bnds) ret.add(new JavacType(type));
bounds = Collections.unmodifiableList(ret);
}
return bounds;
}
use of org.eclipse.ceylon.model.loader.mirror.TypeMirror in project ceylon by eclipse.
the class AbstractModelLoader method getLocalContainer.
private Scope getLocalContainer(Package pkg, ClassMirror classMirror, Declaration declaration) {
AnnotationMirror localContainerAnnotation = classMirror.getAnnotation(CEYLON_LOCAL_CONTAINER_ANNOTATION);
String qualifier = getAnnotationStringValue(classMirror, CEYLON_LOCAL_DECLARATION_ANNOTATION, "qualifier");
// deal with types local to functions in the body of toplevel non-lazy attributes, whose container is ultimately the package
Boolean isPackageLocal = getAnnotationBooleanValue(classMirror, CEYLON_LOCAL_DECLARATION_ANNOTATION, "isPackageLocal");
if (BooleanUtil.isTrue(isPackageLocal)) {
// make sure it still knows it's a local
declaration.setQualifier(qualifier);
return null;
}
LocalDeclarationContainer methodDecl = null;
// we get a @LocalContainer annotation for local interfaces
if (localContainerAnnotation != null) {
methodDecl = (LocalDeclarationContainer) findLocalContainerFromAnnotationAndSetCompanionClass(pkg, (Interface) declaration, localContainerAnnotation);
} else {
// all the other cases stay where they belong
MethodMirror method = classMirror.getEnclosingMethod();
if (method == null)
return null;
// see where that method belongs
ClassMirror enclosingClass = method.getEnclosingClass();
while (enclosingClass.isAnonymous()) {
// this gives us the method in which the anonymous class is, which should be the one we're looking for
method = enclosingClass.getEnclosingMethod();
if (method == null)
return null;
// and the method's containing class
enclosingClass = method.getEnclosingClass();
}
// if we are in a setter class, the attribute is declared in the getter class, so look for its declaration there
TypeMirror getterClass = (TypeMirror) getAnnotationValue(enclosingClass, CEYLON_SETTER_ANNOTATION, "getterClass");
boolean isSetter = false;
// we use void.class as default value
if (getterClass != null && !getterClass.isPrimitive()) {
enclosingClass = getterClass.getDeclaredClass();
isSetter = true;
}
String javaClassName = enclosingClass.getQualifiedName();
// make sure we don't go looking in companion classes
if (javaClassName.endsWith(NamingBase.Suffix.$impl.name()))
javaClassName = javaClassName.substring(0, javaClassName.length() - 5);
// find the enclosing declaration
Declaration enclosingClassDeclaration = convertToDeclaration(pkg.getModule(), javaClassName, DeclarationType.TYPE);
if (enclosingClassDeclaration instanceof ClassOrInterface) {
ClassOrInterface containerDecl = (ClassOrInterface) enclosingClassDeclaration;
// now find the method's declaration
// FIXME: find the proper overload if any
String name = method.getName();
if (method.isConstructor() || name.startsWith(NamingBase.Prefix.$default$.toString())) {
methodDecl = (LocalDeclarationContainer) containerDecl;
} else {
// this is only for error messages
String type;
// lots of special cases
if (isStringAttribute(method)) {
name = "string";
type = "attribute";
} else if (isHashAttribute(method)) {
name = "hash";
type = "attribute";
} else if (isGetter(method)) {
// simple attribute
name = getJavaAttributeName(method);
type = "attribute";
} else if (isSetter(method)) {
// simple attribute
name = getJavaAttributeName(method);
type = "attribute setter";
isSetter = true;
} else {
type = "method";
}
// it can be foo$priv$canonical so get rid of that one first
if (name.endsWith(NamingBase.Suffix.$canonical$.toString())) {
name = name.substring(0, name.length() - 11);
}
name = JvmBackendUtil.strip(name, true, method.isPublic() || method.isProtected() || method.isDefaultAccess());
if (name.indexOf('$') > 0) {
// may be a default parameter expression? get the method name which is first
name = name.substring(0, name.indexOf('$'));
}
methodDecl = (LocalDeclarationContainer) containerDecl.getDirectMember(name, null, false);
if (methodDecl == null)
throw new ModelResolutionException("Failed to load outer " + type + " " + name + " for local type " + classMirror.getQualifiedName().toString());
// if it's a setter we wanted, let's get it
if (isSetter) {
LocalDeclarationContainer setter = (LocalDeclarationContainer) ((Value) methodDecl).getSetter();
if (setter == null)
throw new ModelResolutionException("Failed to load outer " + type + " " + name + " for local type " + classMirror.getQualifiedName().toString());
methodDecl = setter;
}
}
} else if (enclosingClassDeclaration instanceof LazyFunction) {
// local and toplevel methods
methodDecl = (LazyFunction) enclosingClassDeclaration;
} else if (enclosingClassDeclaration instanceof LazyValue) {
// local and toplevel attributes
if (enclosingClassDeclaration.isToplevel() && method.getName().equals(NamingBase.Unfix.set_.name()))
isSetter = true;
if (isSetter) {
LocalDeclarationContainer setter = (LocalDeclarationContainer) ((LazyValue) enclosingClassDeclaration).getSetter();
if (setter == null)
throw new ModelResolutionException("Failed to toplevel attribute setter " + enclosingClassDeclaration.getName() + " for local type " + classMirror.getQualifiedName().toString());
methodDecl = setter;
} else
methodDecl = (LazyValue) enclosingClassDeclaration;
} else {
throw new ModelResolutionException("Unknown container type " + enclosingClassDeclaration + " for local type " + classMirror.getQualifiedName().toString());
}
}
// we have the method, now find the proper local qualifier if any
if (qualifier == null)
return null;
declaration.setQualifier(qualifier);
methodDecl.addLocalDeclaration(declaration);
return methodDecl;
}
use of org.eclipse.ceylon.model.loader.mirror.TypeMirror 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.loader.mirror.TypeMirror in project ceylon by eclipse.
the class AbstractModelLoader method getFunctionalInterfaceAsCallable.
private Type getFunctionalInterfaceAsCallable(Module moduleScope, Scope scope, TypeMirror typeMirror) {
try {
FunctionalInterfaceType functionalInterfaceType = getFunctionalInterfaceType(typeMirror);
Type returnType = obtainType(moduleScope, functionalInterfaceType.getReturnType(), scope, TypeLocation.TOPLEVEL);
java.util.List<Type> modelParameterTypes = new ArrayList<Type>(functionalInterfaceType.getParameterTypes().size());
for (TypeMirror parameterType : functionalInterfaceType.getParameterTypes()) {
Type modelParameterType = obtainType(moduleScope, parameterType, scope, TypeLocation.TOPLEVEL);
modelParameterTypes.add(modelParameterType);
}
org.eclipse.ceylon.model.typechecker.model.Type parameterTuple = typeFactory.getTupleType(modelParameterTypes, functionalInterfaceType.isVariadic(), false, -1);
org.eclipse.ceylon.model.typechecker.model.Type callableType = typeFactory.getCallableDeclaration().appliedType(null, Arrays.asList(returnType, parameterTuple));
return callableType;
} catch (ModelResolutionException x) {
return logModelResolutionException(x, scope, "Failure to turn functional interface to Callable type");
}
}
Aggregations