use of com.redhat.ceylon.model.typechecker.model.Annotation in project ceylon-compiler by ceylon.
the class AbstractTransformer method getLicenseAuthorsDocAnnotationArguments.
/** Returns a ListBuffer with assignment expressions for the doc, license and by arguments, as well as name,
* to be used in an annotation which requires them (such as Module and Package) */
ListBuffer<JCExpression> getLicenseAuthorsDocAnnotationArguments(String name, java.util.List<Annotation> anns) {
ListBuffer<JCExpression> authors = new ListBuffer<JCTree.JCExpression>();
ListBuffer<JCExpression> res = new ListBuffer<JCExpression>();
res.add(make().Assign(naming.makeUnquotedIdent("name"), make().Literal(name)));
for (Annotation a : anns) {
if (a.getPositionalArguments() != null && !a.getPositionalArguments().isEmpty()) {
if (a.getName().equals("doc")) {
res.add(make().Assign(naming.makeUnquotedIdent("doc"), make().Literal(a.getPositionalArguments().get(0))));
} else if (a.getName().equals("license")) {
res.add(make().Assign(naming.makeUnquotedIdent("license"), make().Literal(a.getPositionalArguments().get(0))));
} else if (a.getName().equals("by")) {
for (String author : a.getPositionalArguments()) {
authors.add(make().Literal(author));
}
}
}
}
if (!authors.isEmpty()) {
res.add(make().Assign(naming.makeUnquotedIdent("by"), make().NewArray(null, null, authors.toList())));
}
return res;
}
use of com.redhat.ceylon.model.typechecker.model.Annotation in project ceylon-compiler by ceylon.
the class Util method getTags.
public static <T extends Referenceable & Annotated> List<String> getTags(T decl) {
List<String> tags = new ArrayList<String>();
Annotation tagged = Util.getAnnotation(decl.getUnit(), decl.getAnnotations(), "tagged");
if (tagged != null) {
tags.addAll(tagged.getPositionalArguments());
}
return tags;
}
use of com.redhat.ceylon.model.typechecker.model.Annotation in project ceylon-compiler by ceylon.
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 com.redhat.ceylon.model.typechecker.model.Annotation in project ceylon-compiler by ceylon.
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 com.redhat.ceylon.model.typechecker.model.Annotation in project ceylon-compiler by ceylon.
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) {
log.warning(CeylondMessages.msg("warn.missingThrows", thrownException.asString(), getWhere(d), getPosition(getNode(d))));
}
}
}
Aggregations