use of com.redhat.ceylon.model.typechecker.model.Package in project ceylon-compiler by ceylon.
the class ExpressionTransformer method appendDeclarationLiteralForAnnotation.
/**
* Appends into the given builder a String representation of the given
* declaration, suitable for parsing my the DeclarationParser.
*/
private static void appendDeclarationLiteralForAnnotation(Declaration decl, StringBuilder sb) {
Scope container = decl.getContainer();
while (true) {
if (container instanceof Declaration) {
appendDeclarationLiteralForAnnotation((Declaration) container, sb);
sb.append(".");
break;
} else if (container instanceof Package) {
appendDeclarationLiteralForAnnotation((Package) container, sb);
sb.append(":");
break;
}
container = container.getContainer();
}
if (decl instanceof Class) {
sb.append("C").append(decl.getName());
} else if (decl instanceof Interface) {
sb.append("I").append(decl.getName());
} else if (decl instanceof TypeAlias) {
sb.append("A").append(decl.getName());
} else if (decl instanceof Value) {
sb.append("V").append(decl.getName());
} else if (decl instanceof Function) {
sb.append("F").append(decl.getName());
} else if (decl instanceof TypeParameter) {
sb.append("P").append(decl.getName());
} else if (decl instanceof Constructor) {
sb.append("c").append(decl.getName());
} else {
throw BugException.unhandledDeclarationCase(decl);
}
}
use of com.redhat.ceylon.model.typechecker.model.Package in project ceylon-compiler by ceylon.
the class Naming method addNamesForWrapperClass.
private <R> void addNamesForWrapperClass(TypeDeclarationBuilder<R> builder, TypedDeclaration decl, int namingOptions) {
if ((namingOptions & NA_FQ) != 0) {
if ((namingOptions & NA_WRAPPER) == 0 && (namingOptions & NA_WRAPPER_UNQUOTED) == 0) {
throw new BugException("If you pass FQ you must pass WRAPPER or WRAPPER_UNQUOTED too, or there's no class name to qualify!");
}
List<String> outerNames = null;
Scope s = decl.getContainer();
while (s != null) {
if (s instanceof Package) {
final List<String> packageName = ((Package) s).getName();
for (int ii = 0; ii < packageName.size(); ii++) {
if (ii == 0 && packageName.get(ii).isEmpty()) {
continue;
}
builder.select(quoteIfJavaKeyword(packageName.get(ii)));
}
break;
} else if (s instanceof ClassOrInterface) {
if (outerNames == null) {
outerNames = new ArrayList<String>(2);
}
outerNames.add(getQuotedClassName((ClassOrInterface) s, 0));
} else if (s instanceof TypedDeclaration) {
if (outerNames == null) {
outerNames = new ArrayList<String>(2);
}
outerNames.add(quoteIfJavaKeyword(((TypedDeclaration) s).getName()));
}
s = s.getContainer();
}
if (outerNames != null) {
for (int ii = outerNames.size() - 1; ii >= 0; ii--) {
String outerName = outerNames.get(ii);
builder.select(outerName);
}
}
}
if ((namingOptions & NA_WRAPPER) != 0) {
builder.select(getQuotedClassName(decl, namingOptions & (NA_GETTER | NA_SETTER)));
} else if ((namingOptions & NA_WRAPPER_UNQUOTED) != 0) {
builder.select(getRealName(decl, namingOptions & (NA_GETTER | NA_SETTER | NA_WRAPPER_UNQUOTED)));
} else if ((namingOptions & NA_Q_LOCAL_INSTANCE) != 0) {
if (Decl.isBoxedVariable(decl)) {
builder.select(getVariableBoxName(decl));
} else {
builder.select(getAttrClassName(decl, namingOptions & (NA_GETTER | NA_SETTER)));
}
}
if ((namingOptions & NA_WRAPPER_WITH_THIS) != 0) {
builder.select("this");
}
}
use of com.redhat.ceylon.model.typechecker.model.Package in project ceylon-compiler by ceylon.
the class AbstractTransformer method isJavaEnumType.
boolean isJavaEnumType(Type type) {
Module jdkBaseModule = loader().getJDKBaseModule();
Package javaLang = jdkBaseModule.getPackage("java.lang");
TypeDeclaration enumDecl = (TypeDeclaration) javaLang.getDirectMember("Enum", null, false);
if (type.isClass() && type.getDeclaration().isAnonymous()) {
type = type.getExtendedType();
}
return type.isSubtypeOf(enumDecl.appliedType(null, Collections.singletonList(type)));
}
use of com.redhat.ceylon.model.typechecker.model.Package in project ceylon-compiler by ceylon.
the class IndexApiDoc method collectDeclarations.
private List<Declaration> collectDeclarations() {
List<Declaration> declarations = new ArrayList<Declaration>();
for (Package pkg : tool.getPackages(module)) {
if (tool.shouldInclude(pkg)) {
List<Declaration> members = pkg.getMembers();
for (Declaration member : members) {
if (tool.shouldInclude(member)) {
if (member instanceof Value && ((Value) member).getTypeDeclaration().isAnonymous()) {
continue;
}
declarations.add(member);
}
}
}
}
Collections.sort(declarations, ReferenceableComparatorByName.INSTANCE);
return declarations;
}
use of com.redhat.ceylon.model.typechecker.model.Package in project ceylon-compiler by ceylon.
the class LinkRenderer method isLinkable.
private boolean isLinkable(Declaration decl) {
if (decl == null) {
return false;
}
if (decl.isParameter()) {
return true;
}
if (!ceylonDocTool.isIncludeNonShared()) {
if (!decl.isShared()) {
return false;
}
Scope c = decl.getContainer();
while (c != null) {
boolean isShared = true;
if (c instanceof Declaration) {
isShared = ((Declaration) c).isShared();
}
if (c instanceof Package) {
isShared = ((Package) c).isShared();
}
if (!isShared) {
return false;
}
c = c.getContainer();
}
}
return true;
}
Aggregations