use of org.eclipse.ceylon.model.typechecker.model.Unit in project ceylon by eclipse.
the class CeylonDocTool method getSrcUrl.
/**
* Gets a URL for the source file containing the given thing
* @param from Where the link is relative to
* @param modPkgOrDecl e.g. Module, Package or Declaration
* @return A (relative) URL, or null if no source file exists (e.g. for a
* package or a module without a descriptor)
* @throws IOException
*/
protected String getSrcUrl(Object from, Object modPkgOrDecl) throws IOException {
URI fromUrl = getAbsoluteObjectUrl(from);
Module module = getModule(from);
String filename;
File folder;
if (modPkgOrDecl instanceof Element) {
Unit unit = ((Element) modPkgOrDecl).getUnit();
filename = unit.getFilename();
folder = getFolder(unit.getPackage());
} else if (modPkgOrDecl instanceof Package) {
filename = "package.ceylon";
folder = getFolder((Package) modPkgOrDecl);
} else if (modPkgOrDecl instanceof Module) {
Module moduleDecl = (Module) modPkgOrDecl;
folder = getApiOutputFolder(moduleDecl);
filename = Constants.MODULE_DESCRIPTOR;
} else {
throw new RuntimeException(CeylondMessages.msg("error.unexpected", modPkgOrDecl));
}
File srcFile = new File(folder, filename + ".html").getCanonicalFile();
String result;
if (srcFile.exists()) {
URI url = srcFile.toURI();
result = relativize(module, fromUrl, url).toString();
} else {
result = null;
}
return result;
}
use of org.eclipse.ceylon.model.typechecker.model.Unit in project ceylon by eclipse.
the class ClassOrPackageDoc method isConstantValue.
private boolean isConstantValue(Declaration d) {
if (Decl.isValue(d)) {
Value value = (Value) d;
if (value.isShared() && !value.isVariable() && !value.isDynamicallyTyped()) {
Unit unit = value.getUnit();
Type type = value.getType();
if (type.isSequential()) {
type = unit.getSequentialElementType(type);
}
if (type.isString() || type.isInteger() || type.isFloat() || type.isCharacter()) {
return true;
}
}
}
return false;
}
use of org.eclipse.ceylon.model.typechecker.model.Unit in project ceylon by eclipse.
the class LinkRenderer method decorateWithLinkDropdownMenu.
private String decorateWithLinkDropdownMenu(String link, Type producedType) {
if (!printLinkDropdownMenu || !printAbbreviated || !canLinkToCeylonLanguageModule()) {
return link;
}
List<Type> producedTypes = new ArrayList<Type>();
decompose(producedType, producedTypes);
boolean containsOptional = false;
boolean containsSequential = false;
boolean containsSequence = false;
boolean containsIterable = false;
boolean containsEntry = false;
boolean containsCallable = false;
boolean containsTuple = false;
for (Type pt : producedTypes) {
if (abbreviateOptional(pt)) {
containsOptional = true;
} else if (abbreviateSequential(pt) && !link.contains("'Go to ceylon.language::Sequential'")) {
containsSequential = true;
} else if (abbreviateSequence(pt) && !link.contains("'Go to ceylon.language::Sequence'")) {
containsSequence = true;
} else if (abbreviateIterable(pt) && !link.contains("'Go to ceylon.language::Iterable'")) {
containsIterable = true;
} else if (abbreviateEntry(pt) && !link.contains("'Go to ceylon.language::Entry'")) {
containsEntry = true;
} else if (abbreviateCallable(pt) && !link.contains("'Go to ceylon.language::Callable'")) {
containsCallable = true;
} else if (abbreviateTuple(pt) && !link.contains("'Go to ceylon.language::Tuple'")) {
containsTuple = true;
}
}
Unit unit = producedType.getDeclaration().getUnit();
if (containsOptional || containsSequential || containsSequence || containsIterable || containsEntry || containsCallable || containsTuple) {
StringBuilder sb = new StringBuilder();
sb.append("<span class='link-dropdown'>");
sb.append(link.replaceAll("class='link'", "class='link type-identifier'"));
sb.append("<span class='dropdown'>");
sb.append("<a class='dropdown-toggle' data-toggle='dropdown' href='#'><b title='Show more links' class='caret'></b></a>");
sb.append("<ul class='dropdown-menu'>");
if (containsOptional) {
sb.append(getLinkMenuItem(unit.getNullDeclaration(), "abbreviations X? means Null|X"));
}
if (containsSequential) {
sb.append(getLinkMenuItem(unit.getSequentialDeclaration(), "abbreviation X[] or [X*] means Sequential<X>"));
}
if (containsSequence) {
sb.append(getLinkMenuItem(unit.getSequenceDeclaration(), "abbreviation [X+] means Sequence<X>"));
}
if (containsIterable) {
sb.append(getLinkMenuItem(unit.getIterableDeclaration(), "abbreviation {X+} or {X*} means Iterable<X,Nothing> or Iterable<X,Null>"));
}
if (containsEntry) {
sb.append(getLinkMenuItem(unit.getEntryDeclaration(), "abbreviation X->Y means Entry<X,Y>"));
}
if (containsCallable) {
sb.append(getLinkMenuItem(unit.getCallableDeclaration(), "abbreviation X(Y,Z) means Callable<X,[Y,Z]>"));
}
if (containsTuple) {
sb.append(getLinkMenuItem(unit.getTupleDeclaration(), "abbreviation [X,Y] means Tuple<X|Y,X,Tuple<Y,Y,[]>>"));
}
// dropdown-menu
sb.append("</ul>");
// dropdown
sb.append("</span>");
// link-dropdown
sb.append("</span>");
return sb.toString();
}
return link;
}
use of org.eclipse.ceylon.model.typechecker.model.Unit in project ceylon by eclipse.
the class TypePrinter method abbreviateIterable.
public static boolean abbreviateIterable(Type pt) {
if (pt.isIterable()) {
Unit unit = pt.getDeclaration().getUnit();
Type et = unit.getIteratedType(pt);
List<Type> typeArgs = pt.getTypeArgumentList();
if (et != null && typeArgs.size() == 2) {
Type at = typeArgs.get(1);
if (at != null) {
return at.isNothing() || at.isNull();
}
}
// && et.isPrimitiveAbbreviatedType();
}
return false;
}
use of org.eclipse.ceylon.model.typechecker.model.Unit in project ceylon by eclipse.
the class TypePrinter method getTupleElementTypeNames.
private String getTupleElementTypeNames(Type args, Unit unit) {
if (args != null) {
Unit u = args.getDeclaration().getUnit();
boolean defaulted = false;
if (args.isUnion()) {
List<Type> cts = args.getCaseTypes();
if (cts.size() == 2) {
Type lc = cts.get(0);
if (lc.isEmpty()) {
args = cts.get(1);
defaulted = true;
}
Type rc = cts.get(1);
if (rc.isEmpty()) {
args = cts.get(0);
defaulted = true;
}
}
}
if (args.isClassOrInterface()) {
if (args.isTuple()) {
List<Type> tal = args.getTypeArgumentList();
if (tal.size() >= 3) {
Type first = tal.get(1);
Type rest = tal.get(2);
if (first != null && rest != null) {
String argtype = print(first, unit);
if (rest.isEmpty()) {
return defaulted ? argtype + "=" : argtype;
}
String argtypes = getTupleElementTypeNames(rest, unit);
if (argtypes != null) {
return defaulted ? argtype + "=, " + argtypes : argtype + ", " + argtypes;
}
}
}
} else if (args.isEmpty()) {
return defaulted ? "=" : "";
} else if (!defaulted && args.isSequential()) {
Type elementType = u.getIteratedType(args);
if (elementType != null) {
String elemtype = print(elementType, unit);
if (isPrimitiveAbbreviatedType(elementType)) {
return elemtype + "*";
} else {
return lt() + elemtype + gt() + "*";
}
}
} else if (!defaulted && args.isSequence()) {
Type elementType = u.getIteratedType(args);
if (elementType != null) {
String elemtype = print(elementType, unit);
if (isPrimitiveAbbreviatedType(elementType)) {
return elemtype + "+";
} else {
return lt() + elemtype + gt() + "+";
}
}
}
}
}
return null;
}
Aggregations