use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class ModuleDoc method writeLicense.
private void writeLicense(Module module) throws IOException {
Annotation annotation = Util.getAnnotation(module.getUnit(), module.getAnnotations(), "license");
if (annotation == null)
return;
String license = annotation.getPositionalArguments().get(0);
if (license == null || license.isEmpty())
return;
open("div class='license section'");
around("span class='title'", "License: ");
around("span class='value'", license);
close("div");
}
use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class CeylonDoc method writeSee.
protected final <T extends Annotated & Referenceable> void writeSee(T decl) throws IOException {
Annotation see = Util.getAnnotation(decl.getUnit(), decl.getAnnotations(), "see");
if (see == null)
return;
open("div class='see section'");
around("span class='title'", "See also ");
open("span class='value'");
boolean first = true;
for (String target : see.getPositionalArguments()) {
if (!first) {
write(", ");
} else {
first = false;
}
// TODO: add 'identifier' or 'type-identitier' CSS class
linkRenderer().to(target).withinText(true).useScope(decl).printAbbreviated(false).printTypeParameters(false).write();
}
close("span");
close("div");
}
use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class CeylonDoc method writeBy.
protected final void writeBy(Object obj) throws IOException {
List<Annotation> annotations;
if (obj instanceof Declaration) {
annotations = ((Declaration) obj).getAnnotations();
} else if (obj instanceof Module) {
annotations = ((Module) obj).getAnnotations();
} else if (obj instanceof Package) {
annotations = ((Package) obj).getAnnotations();
} else {
throw new IllegalArgumentException();
}
List<String> authors = new ArrayList<>();
for (Annotation annotation : annotations) {
if (annotation.getName().equals("by")) {
for (String author : annotation.getPositionalArguments()) {
authors.add(author);
}
}
}
if (!authors.isEmpty()) {
open("div class='by section'");
around("span class='title'", "By: ");
around("span class='value'", Util.join(", ", authors));
close("div");
}
}
use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class CeylonDocTool method warningMissingThrows.
protected void warningMissingThrows(Declaration d) {
if (ignoreMissingThrows) {
return;
}
final Scope scope = d.getScope();
final PhasedUnit unit = getUnit(d);
final Node node = getNode(d);
if (scope == null || unit == null || unit.getUnit() == null || node == null || !(d instanceof FunctionOrValue)) {
return;
}
List<Type> documentedExceptions = new ArrayList<Type>();
for (Annotation annotation : d.getAnnotations()) {
if (annotation.getName().equals("throws")) {
String exceptionName = annotation.getPositionalArguments().get(0);
Declaration exceptionDecl = scope.getMemberOrParameter(unit.getUnit(), exceptionName, null, false);
if (exceptionDecl instanceof TypeDeclaration) {
documentedExceptions.add(((TypeDeclaration) exceptionDecl).getType());
}
}
}
final List<Type> thrownExceptions = new ArrayList<Type>();
node.visitChildren(new Visitor() {
@Override
public void visit(Tree.Throw that) {
Expression expression = that.getExpression();
if (expression != null) {
thrownExceptions.add(expression.getTypeModel());
} else {
thrownExceptions.add(unit.getUnit().getExceptionType());
}
}
@Override
public void visit(Tree.Declaration that) {
// the end of searching
}
});
for (Type thrownException : thrownExceptions) {
boolean isDocumented = false;
for (Type documentedException : documentedExceptions) {
if (thrownException.isSubtypeOf(documentedException)) {
isDocumented = true;
break;
}
}
if (!isDocumented) {
richLog.warning(CeylondMessages.msg("warn.missingThrows", thrownException.asString(), getWhere(d), getPosition(getNode(d))));
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Annotation in project ceylon by eclipse.
the class DocVisitor method retrieveDocs.
private boolean retrieveDocs(List<Annotation> annotations, String location) {
boolean rval = false;
for (Annotation ann : annotations) {
if ("doc".equals(ann.getName()) && !ann.getPositionalArguments().isEmpty()) {
String doc = ann.getPositionalArguments().get(0);
if (doc.charAt(0) == '"' && doc.charAt(doc.length() - 1) == '"') {
doc = doc.substring(1, doc.length() - 1);
}
int idx = docs.indexOf(doc);
if (idx < 0) {
idx = docs.size();
docs.add(doc);
}
locs.put(location, idx);
rval = true;
}
}
return rval;
}
Aggregations