use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.TypeLiteral that) {
if (that instanceof Tree.InterfaceLiteral || that instanceof Tree.ClassLiteral || that instanceof Tree.NewLiteral || that instanceof Tree.AliasLiteral || that instanceof Tree.TypeParameterLiteral) {
declarationLiteral = true;
} else {
modelLiteral = true;
}
try {
super.visit(that);
} finally {
declarationLiteral = false;
modelLiteral = false;
}
Type t;
TypeDeclaration d;
Tree.StaticType type = that.getType();
Node errorNode;
if (type != null) {
t = type.getTypeModel();
d = t.getDeclaration();
errorNode = type;
} else {
errorNode = that;
ClassOrInterface classOrInterface = getContainingClassOrInterface(that.getScope());
if (that instanceof Tree.ClassLiteral || that instanceof Tree.InterfaceLiteral) {
d = classOrInterface;
if (d == null) {
errorNode.addError("no containing type");
// EARLY EXIT!!
return;
} else {
t = classOrInterface.getType();
}
} else {
errorNode.addError("missing type reference");
// EARLY EXIT!!
return;
}
}
if (t != null) {
that.setDeclaration(d);
that.setWantsDeclaration(true);
if (that instanceof Tree.ClassLiteral) {
if (!(d instanceof Class)) {
if (d != null) {
errorNode.addError("referenced declaration is not a class" + getDeclarationReferenceSuggestion(d));
}
that.setTypeModel(unit.getClassDeclarationType());
} else {
that.setTypeModel(unit.getClassDeclarationType((Class) d));
}
} else if (that instanceof Tree.NewLiteral) {
if (d instanceof Class) {
Class c = (Class) d;
Constructor defaultConstructor = c.getDefaultConstructor();
if (defaultConstructor != null) {
d = defaultConstructor;
}
}
if (d instanceof Constructor) {
Constructor c = (Constructor) d;
if (c.getParameterList() == null) {
that.setTypeModel(unit.getValueConstructorDeclarationType());
} else {
that.setTypeModel(unit.getCallableConstructorDeclarationType());
}
} else if (d != null) {
errorNode.addError("referenced declaration is not a constructor" + getDeclarationReferenceSuggestion(d));
}
} else if (that instanceof Tree.InterfaceLiteral) {
if (!(d instanceof Interface)) {
if (d != null) {
errorNode.addError("referenced declaration is not an interface" + getDeclarationReferenceSuggestion(d));
}
}
that.setTypeModel(unit.getInterfaceDeclarationType());
} else if (that instanceof Tree.AliasLiteral) {
if (!(d instanceof TypeAlias)) {
errorNode.addError("referenced declaration is not a type alias" + getDeclarationReferenceSuggestion(d));
}
that.setTypeModel(unit.getAliasDeclarationType());
} else if (that instanceof Tree.TypeParameterLiteral) {
if (!(d instanceof TypeParameter)) {
errorNode.addError("referenced declaration is not a type parameter" + getDeclarationReferenceSuggestion(d));
}
that.setTypeModel(unit.getTypeParameterDeclarationType());
} else if (d != null) {
that.setWantsDeclaration(false);
t = t.resolveAliases();
if (t == null || t.isUnknown()) {
return;
}
// checkNonlocalType(that.getType(), t.getDeclaration());
if (d instanceof Constructor) {
if (((Constructor) d).isAbstraction()) {
errorNode.addError("constructor is overloaded");
} else {
that.setTypeModel(unit.getConstructorMetatype(t));
}
} else if (d instanceof Class) {
// checkNonlocal(that, t.getDeclaration());
that.setTypeModel(unit.getClassMetatype(t));
} else if (d instanceof Interface) {
that.setTypeModel(unit.getInterfaceMetatype(t));
} else {
that.setTypeModel(unit.getTypeMetaType(t));
}
}
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class ClassOrPackageDoc method writeConstantValue.
private void writeConstantValue(Value v) throws IOException {
Node node = tool.getNode(v);
PhasedUnit pu = tool.getUnit(v);
if (pu == null || !(node instanceof Tree.AttributeDeclaration)) {
return;
}
Tree.AttributeDeclaration attribute = (Tree.AttributeDeclaration) node;
Tree.SpecifierOrInitializerExpression specifierExpression = attribute.getSpecifierOrInitializerExpression();
if (specifierExpression == null) {
return;
}
String value = getSourceCode(pu, specifierExpression);
int newLineIndex = value.indexOf("\n");
String valueFirstLine = newLineIndex != -1 ? value.substring(0, newLineIndex) : value;
around("span class='specifier'", valueFirstLine);
if (newLineIndex != -1) {
around("a class='specifier-ellipsis' href='#' title='Click for expand the rest of value.'", "...");
open("div class='specifier-rest'");
write(value.substring(newLineIndex + 1));
close("div");
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class CeylonDocTool method warningMissingThrows.
protected void warningMissingThrows(Declaration d) {
if (ignoreMissingThrows) {
return;
}
final Scope scope = d.getScope();
final PhasedUnit unit = getUnit(d);
final Node node = getNode(d);
if (scope == null || unit == null || unit.getUnit() == null || node == null || !(d instanceof FunctionOrValue)) {
return;
}
List<Type> documentedExceptions = new ArrayList<Type>();
for (Annotation annotation : d.getAnnotations()) {
if (annotation.getName().equals("throws")) {
String exceptionName = annotation.getPositionalArguments().get(0);
Declaration exceptionDecl = scope.getMemberOrParameter(unit.getUnit(), exceptionName, null, false);
if (exceptionDecl instanceof TypeDeclaration) {
documentedExceptions.add(((TypeDeclaration) exceptionDecl).getType());
}
}
}
final List<Type> thrownExceptions = new ArrayList<Type>();
node.visitChildren(new Visitor() {
@Override
public void visit(Tree.Throw that) {
Expression expression = that.getExpression();
if (expression != null) {
thrownExceptions.add(expression.getTypeModel());
} else {
thrownExceptions.add(unit.getUnit().getExceptionType());
}
}
@Override
public void visit(Tree.Declaration that) {
// the end of searching
}
});
for (Type thrownException : thrownExceptions) {
boolean isDocumented = false;
for (Type documentedException : documentedExceptions) {
if (thrownException.isSubtypeOf(documentedException)) {
isDocumented = true;
break;
}
}
if (!isDocumented) {
richLog.warning(CeylondMessages.msg("warn.missingThrows", thrownException.asString(), getWhere(d), getPosition(getNode(d))));
}
}
}
Aggregations