use of org.eclipse.ceylon.compiler.typechecker.tree.Message in project ceylon by eclipse.
the class PrintVisitor method print.
private void print(Node node) {
print(node.getText());
print(" [" + node.getNodeType() + "]");
if (node.getToken() != null) {
print(" (" + node.getLocation() + ")");
}
if (node instanceof Tree.Term) {
Type type = ((Tree.Term) node).getTypeModel();
if (type != null) {
print(" : " + type.asString() + "");
}
}
if (node instanceof Tree.ComprehensionClause) {
Type type = ((Tree.ComprehensionClause) node).getTypeModel();
if (type != null) {
print(" : " + type.asString() + "");
}
}
if (node instanceof Tree.Type) {
Type type = ((Tree.Type) node).getTypeModel();
if (type != null) {
print(" : " + type.asString() + "");
}
}
if (node instanceof Tree.TypeArguments) {
List<Type> types = ((Tree.TypeArguments) node).getTypeModels();
if (types != null && !types.isEmpty()) {
print(" : <");
int i = 0;
for (Type pt : types) {
if (pt != null) {
print(pt.asString());
}
if (++i != types.size()) {
print(", ");
}
}
print(">");
}
}
if (node instanceof Tree.MemberOrTypeExpression) {
Reference t = ((Tree.MemberOrTypeExpression) node).getTarget();
Declaration d = ((Tree.MemberOrTypeExpression) node).getDeclaration();
if (t != null) {
print(" : " + t.asString() + "");
}
if (d != null) {
print(" : " + d);
}
}
if (node instanceof Tree.Outer) {
Declaration d = ((Tree.Outer) node).getDeclarationModel();
if (d != null) {
print(" : " + d);
}
}
if (node instanceof Tree.SelfExpression) {
Declaration d = ((Tree.SelfExpression) node).getDeclarationModel();
if (d != null) {
print(" : " + d);
}
}
if (node instanceof Tree.Declaration) {
Declaration d = ((Tree.Declaration) node).getDeclarationModel();
if (d != null) {
if (d.isCaptured() || d.isJsCaptured()) {
print("[captured]");
}
print(" : " + d);
Declaration rd = d.getRefinedDeclaration();
if (rd != null && !rd.equals(d)) {
Declaration container = (Declaration) rd.getContainer();
print(" (refines " + container.getName() + "." + rd.getName() + ")");
}
}
}
if (node instanceof Tree.SpecifierStatement) {
Declaration d = ((Tree.SpecifierStatement) node).getDeclaration();
if (d != null) {
print(" : " + d);
}
if (((Tree.SpecifierStatement) node).getRefinement()) {
Declaration rd = d.getRefinedDeclaration();
if (rd != null && !rd.equals(d)) {
Declaration container = (Declaration) rd.getContainer();
print(" (refines " + container.getName() + "." + rd.getName() + ")");
}
}
}
if (node instanceof Tree.SimpleType) {
Declaration d = ((Tree.SimpleType) node).getDeclarationModel();
if (d != null) {
print(" : " + d);
}
}
if (node instanceof Tree.ImportMemberOrType) {
Declaration d = ((Tree.ImportMemberOrType) node).getDeclarationModel();
if (d != null) {
print(" : " + d);
}
}
if (node instanceof Tree.Return) {
Declaration d = ((Tree.Return) node).getDeclaration();
if (d != null) {
print(" : " + d);
}
}
if (node instanceof Tree.PositionalArgument) {
Parameter p = ((Tree.PositionalArgument) node).getParameter();
if (p != null) {
print(" : " + p);
}
}
if (node instanceof Tree.NamedArgument) {
Parameter p = ((Tree.NamedArgument) node).getParameter();
if (p != null) {
print(" : " + p);
}
}
if (node instanceof Tree.SequencedArgument) {
Parameter p = ((Tree.SequencedArgument) node).getParameter();
if (p != null) {
print(" : " + p);
}
}
if (!node.getErrors().isEmpty()) {
String icon = " [!]";
for (Message e : node.getErrors()) {
if (!(e instanceof UsageWarning)) {
icon = " [X]";
}
}
print(icon + node.getErrors());
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Message in project ceylon by eclipse.
the class ErrorCollectingVisitor method printErrors.
public int printErrors(Writer out, DiagnosticListener diagnosticListener, boolean printWarnings, boolean printCount) throws IOException {
int warnings = 0;
int count = 0;
List<PositionedMessage> errors = (!recogErrors.isEmpty()) ? recogErrors : analErrors;
for (PositionedMessage pm : errors) {
Message err = pm.message;
if (err instanceof UsageWarning) {
if (!printWarnings || ((UsageWarning) err).isSuppressed()) {
continue;
}
}
Node node = TreeUtil.getIdentifyingNode(pm.node);
int line = err.getLine();
int position = -1;
if (err instanceof AnalysisMessage) {
if (node != null && node.getToken() != null)
position = node.getToken().getCharPositionInLine();
} else if (err instanceof RecognitionError) {
position = ((RecognitionError) err).getCharacterInLine();
}
String fileName = (node.getUnit() != null) ? node.getUnit().getFullPath() : "unknown";
out.write(OSUtil.color(fileName, OSUtil.Color.blue));
out.write(":");
out.write(String.format("%d", line));
out.write(": ");
if (err instanceof UsageWarning) {
out.write(OSUtil.color("warning", OSUtil.Color.yellow));
warnings++;
} else {
out.write(OSUtil.color("error", OSUtil.Color.red));
count++;
}
out.write(": ");
out.write(err.getMessage());
out.write(System.lineSeparator());
String ln = getErrorSourceLine(pm);
if (ln != null) {
out.write(ln);
out.write(System.lineSeparator());
out.write(getErrorMarkerLine(position));
out.write(System.lineSeparator());
}
if (diagnosticListener != null) {
File file = null;
boolean warning = err instanceof UsageWarning;
if (node.getUnit() != null && node.getUnit().getFullPath() != null)
file = new File(node.getUnit().getFullPath()).getAbsoluteFile();
if (position != -1)
// make it 1-based
position++;
if (warning)
diagnosticListener.warning(file, line, position, err.getMessage());
else
diagnosticListener.error(file, line, position, err.getMessage());
}
}
if (printCount) {
if (count > 0)
out.write(String.format("%d %s%n", count, count == 1 ? "error" : "errors"));
if (warnings > 0)
out.write(String.format("%d %s%n", warnings, warnings == 1 ? "warning" : "warnings"));
}
out.flush();
return count;
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Message in project ceylon by eclipse.
the class DeclarationErrorVisitor method planAccordingToErrors.
/**
* Update the plan according to the errors on the node
*/
private void planAccordingToErrors(Node that) {
List<Message> errors = that.getErrors();
for (Message message : errors) {
if (isError(that, message)) {
TransformationPlan plan;
/*if (message.getCode() == MEMBER_HAS_WRONG_NUMBER_OF_PARAMETERS
&& model.isActual()
&& model.isClassMember()) {
plan = new ThrowerMethod(that, message);
} else if (message.getCode() == TYPE_OF_PARAMETER_IS_DIFFERENT_TO_CORRESPONDING_PARAMETER
&& model.isActual()
&& model.isClassMember()) {
plan = new ThrowerMethod(that, message);
} else if (message.getCode() == COULD_NOT_DETERMINE_PARAMETER_TYPE_SAME_AS_CORRESPONDING_PARAMETER
&& model.isActual()
&& model.isClassMember()) {
plan = new ThrowerMethod(that, message);
} else if ((message.getCode() == REFINED_MEMBER_WRONG_NUM_PL
|| message.getCode() == MISSING_PL_FUNCTION_DECL)
&& model.isActual()
&& model.isClassMember()) {
plan = new ThrowerMethod(that, message);
} else*/
if (message.getCode() == FORMAL_MEMBER_UNIMPLEMENTED_IN_CLASS_HIERARCHY && (model instanceof Class || (model instanceof Value && ((Value) model).getTypeDeclaration().isAnonymous()))) {
plan = new ThrowerMethod(that, message);
} else if ((message.getCode() == PL_AND_CONSTRUCTORS || message.getCode() == NO_CONSTRUCTORS) && (model instanceof Class || (model instanceof Value && ((Value) model).getTypeDeclaration().isAnonymous()))) {
if (message.getCode() == NO_CONSTRUCTORS) {
plan = new PrivateConstructorOnly(that, message);
} else {
plan = new ThrowerCatchallConstructor(that, message);
}
} else if (message.getCode() == FORWARD_DECL_NOT_IN_DECL_SECTION) {
plan = Errors.GENERATE;
} else {
plan = new Drop(that, message);
}
newplan(plan);
}
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Message in project ceylon by eclipse.
the class WarningSuppressionVisitor method visitAny.
public void visitAny(Node that) {
Iterator<Message> errorIter = that.getErrors().iterator();
while (errorIter.hasNext()) {
Message error = errorIter.next();
if (error instanceof UsageWarning) {
UsageWarning warning = (UsageWarning) error;
E warningName = parseName(warning.getWarningName());
if (warningName == null) {
continue;
}
Integer numSuppressed = counts.get(warningName);
if (suppressed.get(warningName) != null) {
warning.setSuppressed(true);
counts.put(warningName, numSuppressed.intValue() + 1);
}
}
}
super.visitAny(that);
}
Aggregations