use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class MetamodelGenerator method encodeAnnotations.
/**
* Encodes all annotations as a map which is then stored under the
* {@link #KEY_ANNOTATIONS} key in the specified map.
* If the map is null, only the bitset annotations are calculated and returned.
* @return The bitmask for the bitset annotations.
*/
public static int encodeAnnotations(List<Annotation> annotations, Object d, Map<String, Object> m) {
List<Map<String, List<String>>> anns = m == null ? null : new ArrayList<Map<String, List<String>>>(annotations.size());
int bits = 0;
for (Annotation a : annotations) {
String name = a.getName();
int idx = "native".equals(name) ? -1 : annotationBits.indexOf(name);
if (idx >= 0) {
bits |= (1 << idx);
} else if (anns != null) {
List<String> args = a.getPositionalArguments();
if (args == null) {
args = Collections.emptyList();
}
anns.add(Collections.singletonMap(name, args));
}
}
if (d instanceof Value && ((Value) d).isVariable()) {
// Sometimes the value is not annotated, it only has a defined Setter
bits |= (1 << annotationBits.indexOf("variable"));
} else if (d instanceof org.eclipse.ceylon.model.typechecker.model.Class && ((org.eclipse.ceylon.model.typechecker.model.Class) d).isAbstract()) {
bits |= (1 << annotationBits.indexOf("abstract"));
} else if (d instanceof Constructor && ((Constructor) d).isAbstract()) {
bits |= (1 << annotationBits.indexOf("abstract"));
}
if (bits > 0 && m != null) {
String key = d instanceof Module ? "$mod-pa" : d instanceof org.eclipse.ceylon.model.typechecker.model.Package ? "$pkg-pa" : KEY_PACKED_ANNS;
m.put(key, bits);
}
if (anns != null && m != null && !anns.isEmpty()) {
String key = d instanceof Module ? "$mod-anns" : d instanceof org.eclipse.ceylon.model.typechecker.model.Package ? "$pkg-anns" : KEY_ANNOTATIONS;
m.put(key, anns);
}
return bits;
}
use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class AbstractModelLoader method makeInteropAnnotationClass.
/**
* <pre>
* annotation class Annotation$Proxy(...) satisfies Annotation {
* // a `shared` class parameter for each method of Annotation
* }
* </pre>
* @param iface The model of the annotation @interface
* @return The annotation class for the given interface
*/
public AnnotationProxyClass makeInteropAnnotationClass(LazyInterface iface, Scope scope) {
AnnotationProxyClass klass = new AnnotationProxyClass(this, iface);
klass.setContainer(scope);
klass.setScope(scope);
if (!(scope instanceof Package)) {
klass.setStatic(true);
}
klass.setName(iface.getName() + "$Proxy");
klass.setShared(iface.isShared());
klass.setAnnotation(true);
Annotation annotationAnnotation = new Annotation();
annotationAnnotation.setName("annotation");
klass.getAnnotations().add(annotationAnnotation);
klass.getSatisfiedTypes().add(iface.getType());
klass.setUnit(iface.getUnit());
klass.setScope(scope);
return klass;
}
use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class AbstractModelLoader method setAnnotations.
private void setAnnotations(Annotated annotated, AnnotatedMirror classMirror, boolean isNativeHeader) {
if (classMirror.getAnnotation(CEYLON_ANNOTATIONS_ANNOTATION) != null) {
// If the class has @Annotations then use it (in >=1.2 only ceylon.language does)
Long mods = (Long) getAnnotationValue(classMirror, CEYLON_ANNOTATIONS_ANNOTATION, "modifiers");
if (mods != null) {
// If there is a modifiers value then use it to load the modifiers
for (LanguageAnnotation mod : LanguageAnnotation.values()) {
if (mod.isModifier()) {
if ((mod.mask & mods) != 0) {
annotated.getAnnotations().addAll(mod.makeFromCeylonAnnotation(null));
}
}
}
}
// Load anything else the long way, reading the @Annotation(name=...)
List<AnnotationMirror> annotations = getAnnotationArrayValue(classMirror, CEYLON_ANNOTATIONS_ANNOTATION);
if (annotations != null) {
for (AnnotationMirror annotation : annotations) {
annotated.getAnnotations().add(readModelAnnotation(annotation));
}
}
} else {
// according to the presence of @Shared$annotation etc
for (LanguageAnnotation mod : LanguageAnnotation.values()) {
if (classMirror.getAnnotation(mod.annotationType) != null) {
annotated.getAnnotations().addAll(mod.makeFromCeylonAnnotation(classMirror.getAnnotation(mod.annotationType)));
}
}
// but the typechecker wants them on the Class model.
if ((annotated instanceof Class) && ((Class) annotated).isAnonymous()) {
Class clazz = (Class) annotated;
Declaration objectValue = clazz.getContainer().getDirectMember(clazz.getName(), null, false);
if (objectValue != null) {
annotated.getAnnotations().addAll(objectValue.getAnnotations());
}
}
}
boolean hasCeylonDeprecated = false;
for (Annotation a : annotated.getAnnotations()) {
if (a.getName().equals("deprecated")) {
hasCeylonDeprecated = true;
break;
}
}
// and doesn't already have the ceylon annotation
if (classMirror.getAnnotation(JAVA_DEPRECATED_ANNOTATION) != null) {
if (!hasCeylonDeprecated) {
Annotation modelAnnotation = new Annotation();
modelAnnotation.setName("deprecated");
modelAnnotation.getPositionalArguments().add("");
annotated.getAnnotations().add(modelAnnotation);
hasCeylonDeprecated = true;
}
}
if (annotated instanceof Declaration && !((Declaration) annotated).getNativeBackends().none()) {
// Do nothing :
// it has already been managed when in the makeLazyXXX() function
} else {
manageNativeBackend(annotated, classMirror, isNativeHeader);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class ClassOrPackageDoc method writeAliases.
protected final void writeAliases(Declaration decl) throws IOException {
Annotation see = Util.getAnnotation(decl.getUnit(), decl.getAnnotations(), "aliased");
if (see == null)
return;
open("div class='aliased section'");
around("span class='title'", "Aliases: ");
open("span class='value'");
boolean first = true;
for (String target : see.getPositionalArguments()) {
if (!first) {
write(", ");
} else {
first = false;
}
open("code class='signature'");
String cssClass = decl instanceof TypeDeclaration ? "type-identifier" : "identifier";
open("span class='" + cssClass + "'");
write(target);
close("span");
close("code");
}
close("span");
close("div");
}
use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class ClassOrPackageDoc method writeParameterAssertions.
private void writeParameterAssertions(Declaration decl, Map<Tree.Assertion, List<Tree.Condition>> parameterAssertions) throws IOException {
if (parameterAssertions == null || parameterAssertions.isEmpty()) {
return;
}
PhasedUnit pu = tool.getUnit(decl);
open("div class='assertions' title='Parameter assertions'");
open("ul");
for (Tree.Assertion assertion : parameterAssertions.keySet()) {
List<Annotation> annotations = new ArrayList<Annotation>();
buildAnnotations(assertion.getAnnotationList(), annotations);
String doc = Util.getRawDoc(decl.getUnit(), annotations);
if (!Util.isEmpty(doc)) {
open("li");
write("<i class='icon-assertion'></i>");
write(Util.wikiToHTML(doc, linkRenderer()));
close("li");
} else {
for (Tree.Condition c : parameterAssertions.get(assertion)) {
String sourceCode = getSourceCode(pu, c);
open("li");
write("<i class='icon-assertion'></i>");
around("code", sourceCode);
close("li");
}
}
}
close("ul");
close("div");
}
Aggregations