use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class AbstractTransformer method makeReifiedTypeArgumentResolved.
private JCExpression makeReifiedTypeArgumentResolved(Type pt, boolean qualified, TypeArgumentAccessor typeArgumentAccessor, boolean wantsRaw) {
if (pt.isUnion()) {
// FIXME: refactor this shite
List<JCExpression> typeTestArguments = List.nil();
java.util.List<Type> typeParameters = pt.getCaseTypes();
if (typeParameters.size() == 2) {
Type alternative = null;
if (typeParameters.get(0).isEmpty())
alternative = typeParameters.get(1);
else if (typeParameters.get(1).isEmpty())
alternative = typeParameters.get(0);
if (alternative != null && alternative.isTuple()) {
JCExpression tupleType = makeTupleTypeDescriptor(alternative, true);
if (tupleType != null)
return tupleType;
}
}
for (int i = typeParameters.size() - 1; i >= 0; i--) {
typeTestArguments = typeTestArguments.prepend(makeReifiedTypeArgument(typeParameters.get(i)));
}
return make().Apply(null, makeSelect(makeTypeDescriptorType(), "union"), typeTestArguments);
} else if (pt.isIntersection()) {
List<JCExpression> typeTestArguments = List.nil();
java.util.List<Type> typeParameters = pt.getSatisfiedTypes();
for (int i = typeParameters.size() - 1; i >= 0; i--) {
typeTestArguments = typeTestArguments.prepend(makeReifiedTypeArgument(typeParameters.get(i)));
}
return make().Apply(null, makeSelect(makeTypeDescriptorType(), "intersection"), typeTestArguments);
} else if (pt.isNothing()) {
return makeNothingTypeDescriptor();
}
TypeDeclaration declaration = pt.getDeclaration();
if (declaration instanceof Constructor) {
pt = pt.getExtendedType();
declaration = pt.getDeclaration();
}
if (pt.isClassOrInterface()) {
// see if we have an alias for it
if (supportsReifiedAlias((ClassOrInterface) declaration)) {
JCExpression qualifier = naming.makeDeclarationName(declaration, DeclNameFlag.QUALIFIED);
return makeSelect(qualifier, naming.getTypeDescriptorAliasName());
}
if (pt.isTuple()) {
JCExpression tupleType = makeTupleTypeDescriptor(pt, false);
if (tupleType != null)
return tupleType;
}
// no alias, must build it
List<JCExpression> typeTestArguments;
JCExpression thisType = makeUnerasedClassLiteral(declaration);
if (!wantsRaw) {
typeTestArguments = makeReifiedTypeArgumentsResolved(pt.getTypeArgumentList(), qualified, typeArgumentAccessor);
// do we have variance overrides?
Map<TypeParameter, SiteVariance> varianceOverrides = pt.getVarianceOverrides();
if (!varianceOverrides.isEmpty()) {
// we need to pass them as second argument then, in an array
ListBuffer<JCExpression> varianceElements = new ListBuffer<JCExpression>();
for (TypeParameter typeParameter : declaration.getTypeParameters()) {
SiteVariance useSiteVariance = varianceOverrides.get(typeParameter);
String selector;
if (useSiteVariance != null) {
switch(useSiteVariance) {
case IN:
selector = "IN";
break;
case OUT:
selector = "OUT";
break;
default:
selector = "NONE";
break;
}
} else {
selector = "NONE";
}
JCExpression varianceElement = make().Select(makeIdent(syms().ceylonVarianceType), names().fromString(selector));
varianceElements.append(varianceElement);
}
JCNewArray varianceArray = make().NewArray(makeIdent(syms().ceylonVarianceType), List.<JCExpression>nil(), varianceElements.toList());
typeTestArguments = typeTestArguments.prepend(varianceArray);
}
} else {
typeTestArguments = List.nil();
}
typeTestArguments = typeTestArguments.prepend(thisType);
JCExpression classDescriptor = make().Apply(null, makeSelect(makeTypeDescriptorType(), "klass"), typeTestArguments);
Type qualifyingType = pt.getQualifyingType();
JCExpression containerType = null;
if (qualifyingType == null) {
// it may be contained in a function or value, and we want its type
// or static class members may have no qualifying type but we want the TDs to treat
// them as members anyway
Declaration enclosingDeclaration = getDeclarationContainer(declaration);
if (enclosingDeclaration instanceof TypedDeclaration)
containerType = makeTypedDeclarationTypeDescriptorResolved((TypedDeclaration) enclosingDeclaration, typeArgumentAccessor);
else if (enclosingDeclaration instanceof TypeDeclaration) {
qualifyingType = ((TypeDeclaration) enclosingDeclaration).getType();
}
}
if (qualifyingType != null && qualifyingType.isConstructor()) {
qualifyingType = qualifyingType.getQualifyingType();
}
if (qualifyingType != null) {
if (declaration.isStatic() && supportsReified(declaration)) {
// There is no outer instance with a $reified$T field
final Type t = pt;
containerType = makeReifiedTypeArgumentResolved(qualifyingType, true, new TypeArgumentAccessor() {
public JCExpression getTypeDescriptor(TypeParameter tp, boolean qualified) {
return makeSelect(naming.makeQualifiedThis(makeJavaType(t, JT_RAW)), naming.getTypeArgumentDescriptorName(tp));
}
}, false);
} else {
containerType = makeReifiedTypeArgumentResolved(qualifyingType, true, typeArgumentAccessor, // we want raw containers, since we can't capture their TPs
declaration.isStatic());
}
}
if (containerType == null) {
return classDescriptor;
} else {
return make().Apply(null, makeSelect(makeTypeDescriptorType(), "member"), List.of(containerType, classDescriptor));
}
} else if (pt.isTypeParameter()) {
return typeArgumentAccessor.getTypeDescriptor((TypeParameter) declaration, qualified);
} else {
throw BugException.unhandledDeclarationCase(declaration);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class CeylonDoc method getIcons.
protected final List<String> getIcons(Object obj) {
List<String> icons = new ArrayList<String>();
if (obj instanceof Declaration) {
Declaration decl = (Declaration) obj;
Annotation deprecated = Util.findAnnotation(decl, "deprecated");
if (deprecated != null) {
icons.add("icon-decoration-deprecated");
}
if (decl instanceof ClassOrInterface || decl instanceof Constructor) {
if (decl instanceof Interface) {
icons.add("icon-interface");
if (Util.isEnumerated((ClassOrInterface) decl)) {
icons.add("icon-decoration-enumerated");
}
}
if (decl instanceof Class) {
Class klass = (Class) decl;
if (klass.isAnonymous()) {
icons.add("icon-object");
} else {
icons.add("icon-class");
}
if (klass.isAbstract()) {
icons.add("icon-decoration-abstract");
}
if (klass.isFinal() && !klass.isAnonymous() && !klass.isAnnotation()) {
icons.add("icon-decoration-final");
}
if (Util.isEnumerated(klass)) {
icons.add("icon-decoration-enumerated");
}
}
if (decl instanceof Constructor) {
icons.add("icon-class");
}
if (!decl.isShared()) {
icons.add("icon-decoration-local");
}
}
if (decl instanceof TypedDeclaration) {
if (decl.isShared()) {
icons.add("icon-shared-member");
} else {
icons.add("icon-local-member");
}
if (decl.isFormal()) {
icons.add("icon-decoration-formal");
}
if (decl.isActual()) {
Declaration refinedDeclaration = decl.getRefinedDeclaration();
if (refinedDeclaration != null) {
if (refinedDeclaration.isFormal()) {
icons.add("icon-decoration-impl");
}
if (refinedDeclaration.isDefault()) {
icons.add("icon-decoration-over");
}
}
}
if (((TypedDeclaration) decl).isVariable()) {
icons.add("icon-decoration-variable");
}
}
if (decl instanceof TypeAlias || decl instanceof NothingType) {
icons.add("icon-type-alias");
}
if (decl.isAnnotation()) {
icons.add("icon-decoration-annotation");
}
}
if (obj instanceof Package) {
Package pkg = (Package) obj;
icons.add("icon-package");
if (!pkg.isShared()) {
icons.add("icon-decoration-local");
}
}
if (obj instanceof ModuleImport) {
ModuleImport moduleImport = (ModuleImport) obj;
icons.add("icon-module");
if (moduleImport.isExport()) {
icons.add("icon-module-exported-decoration");
}
if (moduleImport.isOptional()) {
icons.add("icon-module-optional-decoration");
}
}
if (obj instanceof Module) {
icons.add("icon-module");
}
return icons;
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class ClassOrPackageDoc method doc.
protected final void doc(String id, String name, Declaration d) throws IOException {
String declarationName = Util.getDeclarationName(d);
id = (id != null ? id : name);
boolean alias = Util.nullSafeCompare(name, declarationName) != 0;
// put the id on the td because IE8 doesn't support id attributes on tr (yeah right)
open("tr");
open("td id='" + id + "' nowrap");
writeIcon(d);
if (!(d instanceof Constructor)) {
around("code class='decl-label'", name);
close("td");
open("td");
}
writeLinkOneSelf(id);
if (alias) {
writeTagged(d);
writeAlias(d);
} else {
writeLinkSource(d);
writeTagged(d);
if (d instanceof Functional) {
writeParameterLinksIfRequired((Functional) d);
}
open("code class='signature'");
around("span class='modifiers'", getModifiers(d));
write(" ");
if (!ModelUtil.isConstructor(d)) {
if (!Decl.isDynamic(d)) {
if (d instanceof Functional && ((Functional) d).isDeclaredVoid()) {
around("span class='void'", "void");
} else if (d instanceof TypedDeclaration) {
linkRenderer().to(((TypedDeclaration) d).getType()).useScope(d).write();
} else {
linkRenderer().to(d).useScope(d).write();
}
} else {
around("span class='dynamic'", "dynamic");
}
}
write(" ");
open("span class='identifier'");
write(name);
close("span");
if (isConstantValue(d)) {
writeConstantValue((Value) d);
}
if (d instanceof Generic) {
writeTypeParameters(d.getTypeParameters(), d);
}
if (d instanceof Functional) {
writeParameterList((Functional) d, d);
}
if (d instanceof Generic) {
writeTypeParametersConstraints(d.getTypeParameters(), d);
}
if (d instanceof Value) {
Setter setter = ((Value) d).getSetter();
if (setter != null && Util.getAnnotation(setter.getUnit(), setter.getAnnotations(), "doc") != null) {
tool.warningSetterDoc(d.getQualifiedNameString(), d);
}
}
close("code");
writeDescription(d);
}
close("td");
close("tr");
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class AnnotationUtil method isNaturalTarget.
/**
* Whether an annotation (with the given {@code annotationCtorDecl}
* annotation constructor) used on the given declaration ({@code useSite})
* should be added to the Java annotations of the given generated program
* elements ({@code target})
* @param annotationCtorDecl
* @param useSite
* @param target
* @return
*/
public static boolean isNaturalTarget(// use site is either a Declaration, or a Package, or a Module,
Function annotationCtorDecl, // module imports
Object useSite, OutputElement target) {
EnumSet<AnnotationTarget> interopTargets;
if (annotationCtorDecl instanceof AnnotationProxyMethod) {
AnnotationProxyMethod annotationProxyMethod = (AnnotationProxyMethod) annotationCtorDecl;
if (annotationProxyMethod.getAnnotationTarget() == target) {
// Foo__WHATEVER, so honour the WHATEVER
return true;
}
interopTargets = annotationProxyMethod.getAnnotationTargets();
} else {
interopTargets = null;
}
if (useSite instanceof Declaration) {
if (ModelUtil.isConstructor((Declaration) useSite)) {
if (useSite instanceof Functional) {
return target == OutputElement.CONSTRUCTOR;
} else if (useSite instanceof Value) {
// If the constructor has a getter we can't annotate, let's
// put the annotations on the constructor
Class constructedClass = ModelUtil.getConstructedClass((Declaration) useSite);
// See CeylonVisitor.transformSingletonConstructor for those tests
if (constructedClass.isToplevel() || constructedClass.isClassMember())
return target == OutputElement.GETTER;
return target == OutputElement.CONSTRUCTOR;
}
} else if (useSite instanceof Class) {
if (((Class) useSite).getParameterList() != null && interopTargets != null && interopTargets.contains(AnnotationTarget.CONSTRUCTOR) && !interopTargets.contains(AnnotationTarget.TYPE)) {
return target == OutputElement.CONSTRUCTOR;
}
return target == OutputElement.TYPE;
} else if (useSite instanceof Interface) {
return target == OutputElement.TYPE;
} else if (useSite instanceof Value) {
Value value = (Value) useSite;
boolean p = value.isParameter() && target == OutputElement.PARAMETER;
if (annotationCtorDecl instanceof AnnotationProxyMethod) {
if (!value.isTransient() && (interopTargets == null || interopTargets.contains(AnnotationTarget.FIELD))) {
return target == OutputElement.FIELD;
} else {
return target == OutputElement.GETTER;
}
} else {
return p || target == OutputElement.GETTER;
}
} else if (useSite instanceof Setter) {
return target == OutputElement.SETTER;
} else if (useSite instanceof Function) {
return target == OutputElement.METHOD;
} else if (useSite instanceof Constructor) {
return target == OutputElement.CONSTRUCTOR;
} else if (useSite instanceof TypeAlias) {
return target == OutputElement.TYPE;
}
} else if (useSite instanceof Package) {
return (annotationCtorDecl instanceof AnnotationProxyMethod) ? target == OutputElement.PACKAGE : target == OutputElement.TYPE;
} else if (useSite instanceof Module) {
return target == OutputElement.TYPE;
} else if (useSite instanceof Tree.ImportModule) {
return target == OutputElement.FIELD;
}
throw new RuntimeException("" + useSite);
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class ExpressionVisitor method resolveQualifiedTypeExpression.
private TypeDeclaration resolveQualifiedTypeExpression(Tree.QualifiedTypeExpression that, boolean error) {
if (checkMember(that)) {
Tree.Primary primary = that.getPrimary();
Tree.Identifier id = that.getIdentifier();
List<Type> signature = that.getSignature();
boolean spread = that.getEllipsis();
String name = name(id);
String container;
boolean ambiguous;
TypeDeclaration type;
Type pt;
if (primary instanceof Tree.Package) {
Package pack = unit.getPackage();
container = "package '" + pack.getNameAsString() + "'";
type = getPackageTypeDeclaration(name, signature, spread, unit);
ambiguous = false;
pt = null;
} else {
pt = primary.getTypeModel().resolveAliases();
TypeDeclaration d = getDeclaration(that, pt);
if (d instanceof Constructor) {
d = d.getExtendedType().getDeclaration();
}
container = "type '" + d.getName(unit) + "'";
Scope scope = that.getScope();
type = getTypeMember(d, name, signature, spread, unit, scope);
ambiguous = type == null && d.isMemberAmbiguous(name, unit, signature, spread);
if (type == null) {
container += memberCorrectionMessage(name, d, scope, unit, cancellable);
}
}
if (type == null) {
if (error) {
if (ambiguous) {
that.addError("member type is ambiguous: '" + name + "' for " + container);
} else {
that.addError("member type is not defined: '" + name + "' in " + container, 100);
unit.setUnresolvedReferences();
}
}
} else {
type = (TypeDeclaration) handleAbstractionOrHeader(type, that, error);
if (error) {
checkStaticPrimary(that, primary, type, pt);
}
that.setDeclaration(type);
resetSuperReference(that);
if (!isSelfReference(primary) && !type.isShared()) {
type.setOtherInstanceAccess(true);
}
if (error) {
if (checkConcreteClass(type, that)) {
if (checkVisibleConstructor(that, type)) {
checkQualifiedTypeAndConstructorVisibility(that, type, name, container);
}
}
if (!inExtendsClause) {
checkSuperMember(that, signature, spread);
}
}
}
return type;
} else {
return null;
}
}
Aggregations