use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.CompilationUnit that) {
// unit.setSupportedBackends(that.getUnit().getSupportedBackends());
pkg.removeUnit(unit);
pkg.addUnit(unit);
super.visit(that);
Node firstNonImportNode = null;
int index = -1;
for (Node d : that.getDeclarations()) {
firstNonImportNode = d;
index = d.getToken().getTokenIndex();
break;
}
for (Tree.ModuleDescriptor md : that.getModuleDescriptors()) {
if (index < 0 || md.getToken().getTokenIndex() < index) {
firstNonImportNode = md;
index = md.getToken().getTokenIndex();
}
break;
}
for (Tree.PackageDescriptor pd : that.getPackageDescriptors()) {
if (index < 0 || pd.getToken().getTokenIndex() < index) {
firstNonImportNode = pd;
index = pd.getToken().getTokenIndex();
}
break;
}
if (firstNonImportNode != null) {
for (Tree.Import im : that.getImportList().getImports()) {
if (im.getEndIndex() > firstNonImportNode.getStartIndex()) {
im.addError("import statement must occur before any declaration or descriptor");
}
}
}
boolean first = true;
for (Tree.ModuleDescriptor md : that.getModuleDescriptors()) {
if (!first) {
md.addError("there may be only one module descriptor for a module");
}
first = false;
}
first = true;
for (Tree.PackageDescriptor pd : that.getPackageDescriptors()) {
if (!first) {
pd.addError("there may be only one package descriptor for a module");
}
first = false;
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class ExpressionTransformer method transform.
public JCTree transform(Tree.TypeLiteral expr) {
at(expr);
if (!expr.getWantsDeclaration()) {
if (expr.getDeclaration() instanceof Constructor) {
JCExpression classLiteral = makeTypeLiteralCall(expr.getType().getTypeModel().getQualifyingType(), false, expr.getTypeModel());
TypeDeclaration classModelDeclaration = (TypeDeclaration) typeFact().getLanguageModuleModelDeclaration(expr.getType().getTypeModel().getQualifyingType().getDeclaration().isMember() ? "MemberClass" : "Class");
JCTypeCast typeCast = make().TypeCast(makeJavaType(classModelDeclaration.appliedType(null, List.of(expr.getType().getTypeModel().getQualifyingType(), typeFact().getNothingType()))), classLiteral);
Type callableType = expr.getTypeModel().getFullType();
JCExpression reifiedArgumentsExpr = makeReifiedTypeArgument(typeFact().getCallableTuple(callableType));
return make().Apply(null, naming.makeQualIdent(typeCast, "getConstructor"), List.<JCExpression>of(reifiedArgumentsExpr, make().Literal(expr.getDeclaration().getName())));
} else {
if (coerced) {
Type t = expr.getType().getTypeModel();
if (!typeFact().isJavaObjectArrayType(t) || t.getTypeArgumentList().get(0).isClassOrInterface()) {
return makeSelect(makeJavaType(t, JT_NO_PRIMITIVES | JT_RAW), "class");
}
}
return makeTypeLiteralCall(expr.getType().getTypeModel(), true, expr.getTypeModel());
}
} else if (expr.getDeclaration() instanceof TypeParameter) {
// we must get it from its container
TypeParameter declaration = (TypeParameter) expr.getDeclaration();
Node node = expr;
return makeTypeParameterDeclaration(node, declaration);
} else if (expr.getDeclaration() instanceof Constructor || expr instanceof Tree.NewLiteral) {
Constructor ctor;
if (expr.getDeclaration() instanceof Constructor) {
ctor = (Constructor) expr.getDeclaration();
} else {
ctor = ((Class) expr.getDeclaration()).getDefaultConstructor();
}
JCExpression metamodelCall = makeTypeDeclarationLiteral(ModelUtil.getConstructedClass(ctor));
metamodelCall = make().TypeCast(makeJavaType(typeFact().getClassDeclarationType(), JT_RAW), metamodelCall);
metamodelCall = make().Apply(null, naming.makeQualIdent(metamodelCall, "getConstructorDeclaration"), List.<JCExpression>of(make().Literal(ctor.getName() == null ? "" : ctor.getName())));
if (ModelUtil.isEnumeratedConstructor(ctor)) {
metamodelCall = make().TypeCast(makeJavaType(typeFact().getValueConstructorDeclarationType(), JT_RAW), metamodelCall);
} else /*else if (Decl.isDefaultConstructor(ctor)){
metamodelCall = make().TypeCast(
makeJavaType(typeFact().getDefaultConstructorDeclarationType(), JT_RAW), metamodelCall);
} */
{
metamodelCall = make().TypeCast(makeJavaType(typeFact().getCallableConstructorDeclarationType(), JT_RAW), metamodelCall);
}
return metamodelCall;
} else if (expr.getDeclaration() instanceof ClassOrInterface || expr.getDeclaration() instanceof TypeAlias) {
// use the generated class to get to the declaration literal
JCExpression metamodelCall = makeTypeDeclarationLiteral((TypeDeclaration) expr.getDeclaration());
Type exprType = expr.getTypeModel().resolveAliases();
// now cast if required
if (!exprType.isExactly(((TypeDeclaration) typeFact().getLanguageModuleDeclarationDeclaration("NestableDeclaration")).getType())) {
JCExpression type = makeJavaType(exprType, JT_NO_PRIMITIVES);
return make().TypeCast(type, metamodelCall);
}
return metamodelCall;
} else {
return makeErroneous(expr, "compiler bug: " + expr.getDeclaration() + " is an unsupported declaration type");
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class JavaPositionsRetriever method formatCeylonPosition.
private String formatCeylonPosition(int position) {
String result = ceylonLineMap.getLineNumber(position) + " : " + ceylonLineMap.getColumnNumber(position);
if (ceylonNodesAtPosition != null) {
if (ceylonNodesAtPosition.containsKey(position)) {
List<String> nodeLabels = new LinkedList<String>();
for (Node node : ceylonNodesAtPosition.get(position)) {
nodeLabels.add(node.getNodeType() + " - " + node.getToken().getText());
}
result += "(" + nodeLabels + ")";
}
}
return result;
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class RefinementVisitor method checkParameterTypes.
private void checkParameterTypes(Tree.Declaration that, Tree.ParameterList pl, Reference member, Reference refinedMember, ParameterList params, ParameterList refinedParams, boolean forNative) {
List<Parameter> paramsList = params.getParameters();
List<Parameter> refinedParamsList = refinedParams.getParameters();
if (paramsList.size() != refinedParamsList.size()) {
handleWrongParameterListLength(that, member, refinedMember, forNative, pl);
} else {
for (int i = 0; i < paramsList.size(); i++) {
Parameter rparam = refinedParamsList.get(i);
Parameter param = paramsList.get(i);
Tree.Parameter parameter = pl.getParameters().get(i);
if (forNative && !param.getName().equals(rparam.getName())) {
parameter.addError("parameter does not have the same name as its header: '" + param.getName() + "' is not '" + rparam.getName() + "' for " + message(refinedMember.getDeclaration()));
}
if (rparam.isSequenced() && !param.isSequenced()) {
parameter.addError("parameter must be variadic: parameter '" + rparam.getName() + "' of " + (forNative ? "native header " : "refined member ") + message(refinedMember.getDeclaration()) + " is variadic");
}
if (!rparam.isSequenced() && param.isSequenced()) {
parameter.addError("parameter may not be variadic: parameter '" + rparam.getName() + "' of " + (forNative ? "native header " : "refined member ") + message(refinedMember.getDeclaration()) + " is not variadic");
}
Type refinedParameterType = refinedMember.getTypedParameter(rparam).getFullType();
Type parameterType = member.getTypedParameter(param).getFullType();
Node typeNode = parameter;
if (parameter instanceof Tree.ParameterDeclaration) {
Tree.ParameterDeclaration pd = (Tree.ParameterDeclaration) parameter;
Tree.Type type = pd.getTypedDeclaration().getType();
if (type != null) {
typeNode = type;
}
}
if (parameter != null) {
if (rparam.getModel().isDynamicallyTyped()) {
checkRefiningParameterDynamicallyTyped(member, refinedMember, param, typeNode);
} else if (param.getModel() != null && param.getModel().isDynamicallyTyped()) {
checkRefinedParameterDynamicallyTyped(member, refinedMember, rparam, param, typeNode);
} else if (refinedParameterType == null || parameterType == null) {
handleUnknownParameterType(member, refinedMember, param, typeNode, forNative);
} else {
checkRefiningParameterType(member, refinedMember, refinedParams, rparam, refinedParameterType, param, parameterType, typeNode, forNative);
checkRefiningParameterSmall(typeNode, member.getDeclaration(), param, refinedMember.getDeclaration(), rparam);
}
}
}
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.IfExpression that) {
Node ose = switchStatementOrExpression;
Node oie = ifStatementOrExpression;
switchStatementOrExpression = null;
ifStatementOrExpression = that;
super.visit(that);
List<Type> list = new ArrayList<Type>();
Tree.IfClause ifClause = that.getIfClause();
if (ifClause != null && ifClause.getExpression() != null) {
Type t = ifClause.getExpression().getTypeModel();
if (t != null) {
addToUnion(list, t);
}
} else {
that.addError("missing then expression");
}
Tree.ElseClause elseClause = that.getElseClause();
if (elseClause != null && elseClause.getExpression() != null) {
Type t = elseClause.getExpression().getTypeModel();
if (t != null) {
addToUnion(list, t);
}
} else {
that.addError("missing else expression");
}
that.setTypeModel(union(list, unit));
switchStatementOrExpression = ose;
ifStatementOrExpression = oie;
}
Aggregations