use of com.redhat.ceylon.model.typechecker.model.ClassOrInterface in project ceylon-compiler by ceylon.
the class CeylonDoc method getIcons.
protected final List<String> getIcons(Object obj) {
List<String> icons = new ArrayList<String>();
if (obj instanceof Declaration) {
Declaration decl = (Declaration) obj;
Annotation deprecated = Util.findAnnotation(decl, "deprecated");
if (deprecated != null) {
icons.add("icon-decoration-deprecated");
}
if (decl instanceof ClassOrInterface || decl instanceof Constructor) {
if (decl instanceof Interface) {
icons.add("icon-interface");
if (Util.isEnumerated((ClassOrInterface) decl)) {
icons.add("icon-decoration-enumerated");
}
}
if (decl instanceof Class) {
Class klass = (Class) decl;
if (klass.isAnonymous()) {
icons.add("icon-object");
} else {
icons.add("icon-class");
}
if (klass.isAbstract()) {
icons.add("icon-decoration-abstract");
}
if (klass.isFinal() && !klass.isAnonymous() && !klass.isAnnotation()) {
icons.add("icon-decoration-final");
}
if (Util.isEnumerated(klass)) {
icons.add("icon-decoration-enumerated");
}
}
if (decl instanceof Constructor) {
icons.add("icon-class");
}
if (!decl.isShared()) {
icons.add("icon-decoration-local");
}
}
if (decl instanceof TypedDeclaration) {
if (decl.isShared()) {
icons.add("icon-shared-member");
} else {
icons.add("icon-local-member");
}
if (decl.isFormal()) {
icons.add("icon-decoration-formal");
}
if (decl.isActual()) {
Declaration refinedDeclaration = decl.getRefinedDeclaration();
if (refinedDeclaration != null) {
if (refinedDeclaration.isFormal()) {
icons.add("icon-decoration-impl");
}
if (refinedDeclaration.isDefault()) {
icons.add("icon-decoration-over");
}
}
}
if (((TypedDeclaration) decl).isVariable()) {
icons.add("icon-decoration-variable");
}
}
if (decl instanceof TypeAlias || decl instanceof NothingType) {
icons.add("icon-type-alias");
}
if (decl.isAnnotation()) {
icons.add("icon-decoration-annotation");
}
}
if (obj instanceof Package) {
Package pkg = (Package) obj;
icons.add("icon-package");
if (!pkg.isShared()) {
icons.add("icon-decoration-local");
}
}
if (obj instanceof ModuleImport) {
ModuleImport moduleImport = (ModuleImport) obj;
icons.add("icon-module");
if (moduleImport.isExport()) {
icons.add("icon-module-exported-decoration");
}
if (moduleImport.isOptional()) {
icons.add("icon-module-optional-decoration");
}
}
if (obj instanceof Module) {
icons.add("icon-module");
}
return icons;
}
use of com.redhat.ceylon.model.typechecker.model.ClassOrInterface in project ceylon-compiler by ceylon.
the class LinkRenderer method getExternalUrl.
private String getExternalUrl(Object to) {
String url = null;
if (to instanceof Module) {
url = getExternalModuleUrl((Module) to);
if (url != null) {
url += "index.html";
}
} else if (to instanceof Package) {
Package pkg = (Package) to;
url = getExternalModuleUrl(pkg.getModule());
if (url != null) {
url += buildPackageUrlPath(pkg);
url += "index.html";
}
} else if (to instanceof ClassOrInterface) {
ClassOrInterface klass = (ClassOrInterface) to;
Package pkg = getPackage(klass);
url = getExternalModuleUrl(pkg.getModule());
if (url != null) {
url += buildPackageUrlPath(pkg);
url += ceylonDocTool.getFileName(klass);
}
}
return url;
}
use of com.redhat.ceylon.model.typechecker.model.ClassOrInterface in project ceylon-compiler by ceylon.
the class AbstractTransformer method canOptimiseReifiedTypeTest.
/**
* Determine whether we can use a plain {@code instanceof} instead of
* a full {@code Util.isReified()} for a {@code is} test
*/
private boolean canOptimiseReifiedTypeTest(Type type) {
if (isJavaArray(type)) {
if (isJavaObjectArray(type)) {
MultidimensionalArray multiArray = getMultiDimensionalArrayInfo(type);
// we can test, even if not fully reified in Java
return multiArray.type.getDeclaration() instanceof ClassOrInterface;
} else {
// primitive array we can test
return true;
}
}
// we can optimise it if we've got a ClassOrInterface with only Anything type parameters
if (type.getDeclaration() instanceof ClassOrInterface == false)
return false;
for (Entry<TypeParameter, Type> entry : type.getTypeArguments().entrySet()) {
TypeParameter tp = entry.getKey();
if (!type.isCovariant(tp)) {
return false;
}
java.util.List<Type> bounds = tp.getSatisfiedTypes();
Type ta = entry.getValue();
if ((bounds == null || bounds.isEmpty()) && !isAnything(ta)) {
return false;
}
for (Type bound : bounds) {
if (!ta.isSupertypeOf(bound)) {
return false;
}
}
}
// they're all Anything (or supertypes of their upper bound) we can optimise, unless we have a container with type arguments
Type qualifyingType = type.getQualifyingType();
if (qualifyingType == null && // ignore qualifying types of static java declarations
(Decl.isCeylon(type.getDeclaration()) || !type.getDeclaration().isStaticallyImportable())) {
Declaration declaration = type.getDeclaration();
do {
// it may be contained in a function or value, and we want its type
Declaration enclosingDeclaration = getDeclarationContainer(declaration);
if (enclosingDeclaration instanceof TypedDeclaration) {
// must be in scope
if (enclosingDeclaration instanceof Generic && !((Generic) enclosingDeclaration).getTypeParameters().isEmpty())
return false;
// look up the containers
declaration = enclosingDeclaration;
} else if (enclosingDeclaration instanceof TypeDeclaration) {
// we can't optimise if that container has type arguments as they are not provided
if (enclosingDeclaration instanceof Generic && !((Generic) enclosingDeclaration).getTypeParameters().isEmpty())
return false;
// look up the containers
declaration = enclosingDeclaration;
} else {
// that's fucked up
break;
}
// go up every containing typed declaration
} while (declaration != null);
// we can optimise!
return true;
} else if (qualifyingType != null) {
// we can only optimise if the qualifying type can also be optimised
return canOptimiseReifiedTypeTest(qualifyingType);
} else {
// we can optimise!
return true;
}
}
use of com.redhat.ceylon.model.typechecker.model.ClassOrInterface in project ceylon-compiler by ceylon.
the class AbstractTransformer method getSimpleNumParametersOfCallable.
private int getSimpleNumParametersOfCallable(Type args) {
// can be a defaulted tuple of Empty|Tuple
if (args.isUnion()) {
java.util.List<Type> caseTypes = args.getCaseTypes();
if (caseTypes == null || caseTypes.size() != 2)
return -1;
Type caseA = caseTypes.get(0);
TypeDeclaration caseADecl = caseA.getDeclaration();
Type caseB = caseTypes.get(1);
TypeDeclaration caseBDecl = caseB.getDeclaration();
if (caseADecl instanceof ClassOrInterface == false || caseBDecl instanceof ClassOrInterface == false)
return -1;
if (caseADecl.getQualifiedNameString().equals("ceylon.language::Empty") && caseBDecl.getQualifiedNameString().equals("ceylon.language::Tuple"))
return getSimpleNumParametersOfCallable(caseB);
if (caseBDecl.getQualifiedNameString().equals("ceylon.language::Empty") && caseADecl.getQualifiedNameString().equals("ceylon.language::Tuple"))
return getSimpleNumParametersOfCallable(caseA);
return -1;
}
// can be Tuple, Empty, Sequence or Sequential
if (!args.isClassOrInterface())
return -1;
TypeDeclaration declaration = args.getDeclaration();
String name = declaration.getQualifiedNameString();
if (name.equals("ceylon.language::Tuple")) {
Type rest = args.getTypeArgumentList().get(2);
int ret = getSimpleNumParametersOfCallable(rest);
if (ret == -1)
return -1;
return ret + 1;
}
if (name.equals("ceylon.language::Empty")) {
return 0;
}
if (name.equals("ceylon.language::Sequential") || name.equals("ceylon.language::Sequence")) {
return 1;
}
return -1;
}
use of com.redhat.ceylon.model.typechecker.model.ClassOrInterface in project ceylon-compiler by ceylon.
the class InterfaceVisitor method visit.
@Override
public void visit(Tree.ClassOrInterface that) {
ClassOrInterface model = that.getDeclarationModel();
// and they are useless at runtime
if (!model.isAlias()) {
// we never need to collect other local declaration names since only interfaces compete in the $impl name range
if (model instanceof Interface)
collect(that, (Interface) model);
Set<String> old = localCompanionClasses;
localCompanionClasses = new HashSet<String>();
super.visit(that);
localCompanionClasses = old;
}
if (model instanceof Interface) {
((Interface) model).setCompanionClassNeeded(isInterfaceWithCode(model));
}
}
Aggregations