use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class TreeUtil method buildAnnotations.
public static void buildAnnotations(Tree.AnnotationList al, List<Annotation> annotations) {
if (al != null) {
Tree.AnonymousAnnotation aa = al.getAnonymousAnnotation();
if (aa != null) {
Annotation ann = new Annotation();
ann.setName("doc");
Tree.StringLiteral lit = aa.getStringLiteral();
if (lit != null) {
String text = lit.getText();
ann.addPositionalArgument(text);
annotations.add(ann);
}
}
for (Tree.Annotation a : al.getAnnotations()) {
Annotation ann = new Annotation();
Tree.BaseMemberExpression bma = (Tree.BaseMemberExpression) a.getPrimary();
String name = bma.getIdentifier().getText();
ann.setName(name);
Tree.NamedArgumentList nal = a.getNamedArgumentList();
if (nal != null) {
for (Tree.NamedArgument na : nal.getNamedArguments()) {
if (na instanceof Tree.SpecifiedArgument) {
Tree.SpecifiedArgument sa = (Tree.SpecifiedArgument) na;
Tree.SpecifierExpression sie = sa.getSpecifierExpression();
Tree.Expression e = sie.getExpression();
if (e != null) {
Tree.Term t = e.getTerm();
Parameter p = sa.getParameter();
if (p != null) {
String text = toString(t);
if (text != null) {
ann.addNamedArgument(p.getName(), text);
}
}
}
}
}
}
Tree.PositionalArgumentList pal = a.getPositionalArgumentList();
if (pal != null) {
for (Tree.PositionalArgument pa : pal.getPositionalArguments()) {
if (pa instanceof Tree.ListedArgument) {
Tree.ListedArgument la = (Tree.ListedArgument) pa;
Tree.Term t = la.getExpression().getTerm();
String text = toString(t);
if (text != null) {
ann.addPositionalArgument(text);
}
}
}
}
annotations.add(ann);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class AbstractModelLoader method readModelAnnotation.
private Annotation readModelAnnotation(AnnotationMirror annotation) {
Annotation modelAnnotation = new Annotation();
modelAnnotation.setName((String) annotation.getValue());
@SuppressWarnings("unchecked") List<String> arguments = (List<String>) annotation.getValue("arguments");
if (arguments != null) {
modelAnnotation.getPositionalArguments().addAll(arguments);
} else {
@SuppressWarnings("unchecked") List<AnnotationMirror> namedArguments = (List<AnnotationMirror>) annotation.getValue("namedArguments");
if (namedArguments != null) {
for (AnnotationMirror namedArgument : namedArguments) {
String argName = (String) namedArgument.getValue("name");
String argValue = (String) namedArgument.getValue("value");
modelAnnotation.getNamedArguments().put(argName, argValue);
}
}
}
return modelAnnotation;
}
use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class AbstractModelLoader method makeInteropAnnotationConstructor.
public AnnotationProxyMethod makeInteropAnnotationConstructor(LazyInterface iface, AnnotationProxyClass klass, OutputElement oe, Scope scope) {
String ctorName = oe == null ? NamingBase.getJavaBeanName(iface.getName()) : NamingBase.getDisambigAnnoCtorName(iface, oe);
AnnotationProxyMethod ctor = new AnnotationProxyMethod(this, klass, oe);
ctor.setAnnotationTarget(oe);
ctor.setContainer(scope);
ctor.setScope(scope);
if (!(scope instanceof Package)) {
ctor.setStatic(true);
}
ctor.setAnnotation(true);
ctor.setName(ctorName);
ctor.setShared(iface.isShared());
Annotation annotationAnnotation2 = new Annotation();
annotationAnnotation2.setName("annotation");
ctor.getAnnotations().add(annotationAnnotation2);
ctor.setType(((TypeDeclaration) iface).getType());
ctor.setUnit(iface.getUnit());
return ctor;
}
use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class RefinementVisitor method refineAttribute.
private void refineAttribute(Value assignedAttribute, Tree.BaseMemberExpression bme, Tree.SpecifierStatement that, ClassOrInterface c) {
if (!assignedAttribute.isFormal() && !assignedAttribute.isDefault() && !assignedAttribute.isShortcutRefinement()) {
// this condition is here to squash a dupe message
that.addError("inherited attribute may not be assigned in initializer and may not be refined: " + message(assignedAttribute) + " is declared neither 'formal' nor 'default'", 510);
// return;
} else if (assignedAttribute.isVariable()) {
that.addError("inherited attribute may not be assigned in initializer and may not be refined by non-variable: " + message(assignedAttribute) + " is declared 'variable'");
// return;
}
ClassOrInterface ci = (ClassOrInterface) assignedAttribute.getContainer();
String name = assignedAttribute.getName();
Declaration refined = ci.getRefinedMember(name, null, false);
Value root = refined instanceof Value ? (Value) refined : assignedAttribute;
Reference rv = getRefinedMemberReference(assignedAttribute, c);
boolean lazy = that.getSpecifierExpression() instanceof Tree.LazySpecifierExpression;
Value attribute = new Value();
attribute.setName(name);
attribute.setShared(true);
attribute.setActual(true);
attribute.getAnnotations().add(new Annotation("shared"));
attribute.getAnnotations().add(new Annotation("actual"));
attribute.setRefinedDeclaration(root);
Unit unit = that.getUnit();
attribute.setUnit(unit);
attribute.setContainer(c);
attribute.setScope(c);
attribute.setShortcutRefinement(true);
attribute.setTransient(lazy);
Declaration rvd = rv.getDeclaration();
if (rvd instanceof TypedDeclaration) {
TypedDeclaration rvtd = (TypedDeclaration) rvd;
attribute.setUncheckedNullType(rvtd.hasUncheckedNullType());
}
ModelUtil.setVisibleScope(attribute);
c.addMember(attribute);
that.setRefinement(true);
that.setDeclaration(attribute);
that.setRefined(assignedAttribute);
unit.addDeclaration(attribute);
setRefiningType(c, ci, name, null, false, root, attribute, unit, NO_SUBSTITUTIONS);
}
use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class RefinementVisitor method refineMethod.
private void refineMethod(Function assignedMethod, Tree.BaseMemberExpression bme, Tree.SpecifierStatement that, ClassOrInterface c) {
if (!assignedMethod.isFormal() && !assignedMethod.isDefault() && !assignedMethod.isShortcutRefinement()) {
// this condition is here to squash a dupe message
bme.addError("inherited method may not be refined: " + message(assignedMethod) + " is declared neither 'formal' nor 'default'", 510);
// return;
}
ClassOrInterface ci = (ClassOrInterface) assignedMethod.getContainer();
String name = assignedMethod.getName();
List<Type> signature = getSignature(assignedMethod);
boolean variadic = isVariadic(assignedMethod);
Declaration refined = ci.getRefinedMember(name, signature, variadic);
Function root = refined instanceof Function ? (Function) refined : assignedMethod;
Reference rm = getRefinedMemberReference(assignedMethod, c);
Function method = new Function();
method.setName(name);
List<Tree.ParameterList> paramLists;
List<TypeParameter> typeParams;
Tree.Term me = that.getBaseMemberExpression();
if (me instanceof Tree.ParameterizedExpression) {
Tree.ParameterizedExpression pe = (Tree.ParameterizedExpression) me;
paramLists = pe.getParameterLists();
Tree.TypeParameterList typeParameterList = pe.getTypeParameterList();
if (typeParameterList != null) {
typeParams = new ArrayList<TypeParameter>();
for (Tree.TypeParameterDeclaration tpd : typeParameterList.getTypeParameterDeclarations()) {
typeParams.add(tpd.getDeclarationModel());
}
} else {
typeParams = null;
}
} else {
paramLists = emptyList();
typeParams = null;
}
Unit unit = that.getUnit();
final Map<TypeParameter, Type> subs;
if (typeParams != null) {
// the type parameters are written
// down in the shortcut refinement
method.setTypeParameters(typeParams);
// TODO: check 'em!!
// no need to check them because
// this case is actually disallowed
// elsewhere (specification statements
// may not have type parameters)
subs = NO_SUBSTITUTIONS;
} else if (assignedMethod.isParameterized()) {
if (me instanceof Tree.ParameterizedExpression) {
// we have parameters, but no type parameters
bme.addError("refined method is generic: '" + assignedMethod.getName(unit) + "' declares type parameters");
subs = NO_SUBSTITUTIONS;
} else {
// we're assigning a method reference
// so we need to magic up some "fake"
// type parameters
subs = copyTypeParametersFromRefined(assignedMethod, method, unit);
}
} else {
subs = NO_SUBSTITUTIONS;
}
int i = 0;
for (ParameterList pl : assignedMethod.getParameterLists()) {
Tree.ParameterList params = paramLists.size() <= i ? null : paramLists.get(i++);
createRefiningParameterList(rm, method, params, unit, subs, pl);
}
method.setShared(true);
method.setActual(true);
method.getAnnotations().add(new Annotation("shared"));
method.getAnnotations().add(new Annotation("actual"));
method.setRefinedDeclaration(root);
method.setUnit(unit);
method.setContainer(c);
method.setScope(c);
method.setShortcutRefinement(true);
method.setDeclaredVoid(assignedMethod.isDeclaredVoid());
Declaration rmd = rm.getDeclaration();
if (rmd instanceof TypedDeclaration) {
TypedDeclaration rmtd = (TypedDeclaration) rmd;
method.setUncheckedNullType(rmtd.hasUncheckedNullType());
}
ModelUtil.setVisibleScope(method);
c.addMember(method);
that.setRefinement(true);
that.setDeclaration(method);
that.setRefined(root);
unit.addDeclaration(method);
Scope scope = that.getScope();
if (scope instanceof Specification) {
Specification spec = (Specification) scope;
spec.setDeclaration(method);
}
setRefiningType(c, ci, name, signature, variadic, root, method, unit, subs);
inheritDefaultedArguments(method);
}
Aggregations