blob: cb89d0b4a8c56f5af0869693731f95006d23a0b4 [file] [log] [blame]
// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.errors;
import com.android.tools.r8.Diagnostic;
import com.android.tools.r8.origin.Origin;
import com.android.tools.r8.position.Position;
import com.android.tools.r8.utils.StringDiagnostic;
/**
* Exception to signal an compilation error.
*
* <p>This is always an expected error and considered a user input issue. A user-understandable
* message must be provided.
*/
public class CompilationError extends RuntimeException {
private final Origin origin;
private final Position position;
public CompilationError(String message) {
this(message, Origin.unknown());
}
public CompilationError(String message, Throwable cause) {
this(message, cause, Origin.unknown());
}
public CompilationError(String message, Origin origin) {
this(message, null, origin);
}
public CompilationError(String message, Origin origin, Position position) {
this(message, null, origin, position);
}
public CompilationError(String message, Throwable cause, Origin origin) {
this(message, cause, origin, Position.UNKNOWN);
}
public CompilationError(String message, Throwable cause, Origin origin, Position position) {
super(message, cause);
this.origin = origin;
this.position = position;
}
public Origin getOrigin() {
return origin;
}
public Position getPosition() {
return position;
}
public Diagnostic toStringDiagnostic() {
return new StringDiagnostic(getMessage(), origin, position);
}
}