use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class LinkRenderer method processAnnotationParam.
private String processAnnotationParam(String text) {
if (text.equals("module")) {
Module mod = getCurrentModule();
if (mod != null) {
return processModule(mod);
}
}
if (text.startsWith("module ")) {
String modName = text.substring(7);
for (Module m : ceylonDocTool.getTypeChecker().getContext().getModules().getListOfModules()) {
if (m.getNameAsString().equals(modName)) {
return processModule(m);
}
}
}
if (text.equals("package")) {
Package pkg = getCurrentPackage();
if (pkg != null) {
return processPackage(pkg);
}
}
if (text.startsWith("package ")) {
String pkgName = text.substring(8);
for (Module m : ceylonDocTool.getTypeChecker().getContext().getModules().getListOfModules()) {
if (pkgName.startsWith(m.getNameAsString() + ".")) {
Package pkg = m.getPackage(pkgName);
if (pkg != null) {
return processPackage(pkg);
}
}
}
}
if (text.equals("interface")) {
Interface interf = getCurrentInterface();
if (interf != null) {
return processProducedType(interf.getType());
}
}
if (text.equals("class")) {
Class clazz = getCurrentClass();
if (clazz != null) {
return processProducedType(clazz.getType());
}
}
String declName;
Scope currentScope;
int pkgSeparatorIndex = text.indexOf("::");
if (pkgSeparatorIndex == -1) {
declName = text;
currentScope = resolveScope(scope);
} else {
String pkgName = text.substring(0, pkgSeparatorIndex);
declName = text.substring(pkgSeparatorIndex + 2, text.length());
currentScope = ceylonDocTool.getCurrentModule().getPackage(pkgName);
}
String[] declNames = declName.split("\\.");
Declaration currentDecl = null;
boolean isNested = false;
for (String currentDeclName : declNames) {
currentDecl = resolveDeclaration(currentScope, currentDeclName, isNested);
if (currentDecl != null) {
if (isValueWithTypeObject(currentDecl)) {
TypeDeclaration objectType = ((Value) currentDecl).getTypeDeclaration();
currentScope = objectType;
currentDecl = objectType;
} else {
currentScope = resolveScope(currentDecl);
}
isNested = true;
} else {
break;
}
}
// we can't link to parameters yet, unless they're toplevel
if (currentDecl != null && !isParameter(currentDecl)) {
if (currentDecl instanceof TypeDeclaration) {
return processProducedType(((TypeDeclaration) currentDecl).getType());
} else {
return processTypedDeclaration((TypedDeclaration) currentDecl);
}
} else {
return getUnresolvableLink(text);
}
}
use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class Util method getSuperInterfaces.
public static List<TypeDeclaration> getSuperInterfaces(TypeDeclaration decl) {
Set<TypeDeclaration> superInterfaces = new HashSet<TypeDeclaration>();
for (Type satisfiedType : decl.getSatisfiedTypes()) {
superInterfaces.add(satisfiedType.getDeclaration());
superInterfaces.addAll(getSuperInterfaces(satisfiedType.getDeclaration()));
}
List<TypeDeclaration> list = new ArrayList<TypeDeclaration>();
list.addAll(superInterfaces);
removeDuplicates(list);
return list;
}
use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class AbstractTransformer method collectRefinedMembers.
private void collectRefinedMembers(Type currentType, String name, java.util.List<Type> signature, boolean ellipsis, java.util.Set<TypeDeclaration> visited, Set<TypedDeclaration> ret, boolean ignoreFirst) {
TypeDeclaration decl = currentType.getDeclaration();
if (visited.contains(decl)) {
return;
} else {
visited.add(decl);
Type et = currentType.getExtendedType();
if (et != null) {
collectRefinedMembers(et, name, signature, ellipsis, visited, ret, false);
}
for (Type st : currentType.getSatisfiedTypes()) {
collectRefinedMembers(st, name, signature, ellipsis, visited, ret, false);
}
// we're collecting refined members, not the refining one
if (!ignoreFirst) {
TypedDeclaration found = (TypedDeclaration) decl.getDirectMember(name, signature, ellipsis);
if (found instanceof Function) {
// do not trust getDirectMember because if you ask it for [Integer,String] and it has [Integer,E] it does not
// know that E=String and will not make it match, and will just return any member when there is overloading,
// including one with signature [String] when you asked for [Integer,String]
java.util.List<Type> typedSignature = getTypedSignature(currentType, found);
if (typedSignature != null && hasMatchingSignature(signature, typedSignature))
ret.add(found);
}
}
}
}
use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class AbstractTransformer method hasDependentCovariantTypeParameters.
boolean hasDependentCovariantTypeParameters(Type type) {
if (type.isUnion()) {
for (Type m : type.getCaseTypes()) if (hasDependentCovariantTypeParameters(m))
return true;
return false;
}
if (type.isIntersection()) {
for (Type m : type.getSatisfiedTypes()) if (hasDependentCovariantTypeParameters(m))
return true;
return false;
}
// check its type arguments
// special case for Callable which has only a single type param in Java
boolean isCallable = isCeylonCallable(type);
// check if any type parameter is dependent on and covariant
TypeDeclaration declaration = type.getDeclaration();
java.util.List<TypeParameter> typeParams = declaration.getTypeParameters();
Map<TypeParameter, Type> typeArguments = type.getTypeArguments();
for (TypeParameter typeParam : typeParams) {
Type typeArg = typeArguments.get(typeParam);
if (type.isCovariant(typeParam) && hasDependentTypeParameters(typeParams, typeParam)) {
// see if the type argument in question contains type parameters and is erased to Object
if (containsTypeParameter(typeArg) && willEraseToObject(typeArg))
return true;
}
// now check if we the type argument has the same problem
if (hasDependentCovariantTypeParameters(typeArg))
return true;
// stop after the first type arg for Callable
if (isCallable)
break;
}
return false;
}
use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration 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)));
}
Aggregations