use of abs.frontend.ast.TypeParameterDecl in project abstools by abstools.
the class TypingTest method functionTypeArgs5.
@Test
public void functionTypeArgs5() {
Model m = assertParseOkStdLib("def B nth<B>(List<B> list, Int n) = nth(tail(list), n-1) ; ");
ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
TypeParameterDecl typeParameter = d.getTypeParameter(0);
TypeParameter type = (TypeParameter) ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType();
assertEquals(typeParameter.getName(), type.getDecl().getName());
}
use of abs.frontend.ast.TypeParameterDecl in project abstools by abstools.
the class PureExpressionBuilder method importType.
void importType(Decl decl) {
importModules.add(decl.getModuleDecl().getName());
if (decl instanceof TypeSynDecl) {
decl = resolveTypeSynonym((TypeSynDecl) decl);
importModules.add(decl.getModuleDecl().getName());
}
// import type parameters
if (decl instanceof ParametricDataTypeDecl) {
for (TypeParameterDecl t : ((ParametricDataTypeDecl) decl).getTypeParameters()) {
Decl type = getDecl(model, Decl.class, namePred(t.getName()));
if (type == null) {
// most likely a generic type
continue;
}
importType(type);
}
}
}
use of abs.frontend.ast.TypeParameterDecl in project abstools by abstools.
the class TypingTest method functionTypeArgs3.
@Test
public void functionTypeArgs3() {
Model m = assertParseOkStdLib(" def A f<A>(Maybe<A> o) = case o { Just(a) => a; } ;");
ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
TypeParameterDecl typeParameter = d.getTypeParameter(0);
TypeParameter type = (TypeParameter) ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType();
TypeParameterDecl decl = type.getDecl();
assertEquals(typeParameter, decl);
}
use of abs.frontend.ast.TypeParameterDecl in project abstools by abstools.
the class JavaGeneratorHelper method generateTypeParameters.
public static void generateTypeParameters(PrintStream stream, Decl dtd, boolean plusExtends) {
List<TypeParameterDecl> typeParams = null;
if (dtd instanceof HasTypeParameters) {
typeParams = ((HasTypeParameters) dtd).getTypeParameters();
} else
return;
if (typeParams.getNumChild() > 0) {
stream.print("<");
boolean isFirst = true;
for (TypeParameterDecl d : typeParams) {
if (isFirst)
isFirst = false;
else
stream.print(",");
stream.print(d.getName());
if (plusExtends)
stream.print(" extends " + ABSValue.class.getName());
}
stream.print(">");
}
}
Aggregations