|
| 1 | +/* |
| 2 | + * Copyright 2018 Mr Duy |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.duy.ccppcompiler.compiler.diagnostic; |
| 18 | + |
| 19 | +/** |
| 20 | + * Created by Duy on 28-Apr-18. |
| 21 | + */ |
| 22 | + |
| 23 | +public interface Diagnostic<S> { |
| 24 | + /** |
| 25 | + * Used to signal that no position is available. |
| 26 | + */ |
| 27 | + public final static long NOPOS = -1; |
| 28 | + |
| 29 | + Kind getKind(); |
| 30 | + |
| 31 | + /** |
| 32 | + * Gets the source object associated with this diagnostic. |
| 33 | + * |
| 34 | + * @return the source object associated with this diagnostic. |
| 35 | + * {@code null} if no source object is associated with the |
| 36 | + * diagnostic. |
| 37 | + */ |
| 38 | + S getSource(); |
| 39 | + |
| 40 | + /** |
| 41 | + * Gets a character offset from the beginning of the source object |
| 42 | + * associated with this diagnostic that indicates the location of |
| 43 | + * the problem. In addition, the following must be true: |
| 44 | + * <p> |
| 45 | + * <p>{@code getStartPostion() <= getPosition()} |
| 46 | + * <p>{@code getPosition() <= getEndPosition()} |
| 47 | + * |
| 48 | + * @return character offset from beginning of source; {@link |
| 49 | + * #NOPOS} if {@link #getSource()} would return {@code null} or if |
| 50 | + * no location is suitable |
| 51 | + */ |
| 52 | + long getPosition(); |
| 53 | + |
| 54 | + /** |
| 55 | + * Gets the character offset from the beginning of the file |
| 56 | + * associated with this diagnostic that indicates the start of the |
| 57 | + * problem. |
| 58 | + * |
| 59 | + * @return offset from beginning of file; {@link #NOPOS} if and |
| 60 | + * only if {@link #getPosition()} returns {@link #NOPOS} |
| 61 | + */ |
| 62 | + long getStartPosition(); |
| 63 | + |
| 64 | + /** |
| 65 | + * Gets the character offset from the beginning of the file |
| 66 | + * associated with this diagnostic that indicates the end of the |
| 67 | + * problem. |
| 68 | + * |
| 69 | + * @return offset from beginning of file; {@link #NOPOS} if and |
| 70 | + * only if {@link #getPosition()} returns {@link #NOPOS} |
| 71 | + */ |
| 72 | + long getEndPosition(); |
| 73 | + |
| 74 | + /** |
| 75 | + * Gets the line number of the character offset returned by |
| 76 | + * {@linkplain #getPosition()}. |
| 77 | + * |
| 78 | + * @return a line number or {@link #NOPOS} if and only if {@link |
| 79 | + * #getPosition()} returns {@link #NOPOS} |
| 80 | + */ |
| 81 | + long getLineNumber(); |
| 82 | + |
| 83 | + /** |
| 84 | + * Gets the column number of the character offset returned by |
| 85 | + * {@linkplain #getPosition()}. |
| 86 | + * |
| 87 | + * @return a column number or {@link #NOPOS} if and only if {@link |
| 88 | + * #getPosition()} returns {@link #NOPOS} |
| 89 | + */ |
| 90 | + long getColumnNumber(); |
| 91 | + |
| 92 | + /** |
| 93 | + * Gets a diagnostic code indicating the type of diagnostic. The |
| 94 | + * code is implementation-dependent and might be {@code null}. |
| 95 | + * |
| 96 | + * @return a diagnostic code |
| 97 | + */ |
| 98 | + String getCode(); |
| 99 | + |
| 100 | + public enum Kind { |
| 101 | + /** |
| 102 | + * Problem which prevents the tool's normal completion. |
| 103 | + */ |
| 104 | + ERROR, |
| 105 | + /** |
| 106 | + * Problem which does not usually prevent the tool from |
| 107 | + * completing normally. |
| 108 | + */ |
| 109 | + WARNING, |
| 110 | + /** |
| 111 | + * Informative message from the tool. |
| 112 | + */ |
| 113 | + NOTE, |
| 114 | + /** |
| 115 | + * Diagnostic which does not fit within the other kinds. |
| 116 | + */ |
| 117 | + OTHER, |
| 118 | + } |
| 119 | + |
| 120 | + |
| 121 | +} |
0 commit comments