|
45 | 45 | import com.puppycrawl.tools.checkstyle.LocalizedMessage.Utf8Control; |
46 | 46 | import com.puppycrawl.tools.checkstyle.api.AuditListener; |
47 | 47 | import com.puppycrawl.tools.checkstyle.api.Configuration; |
| 48 | +import com.puppycrawl.tools.checkstyle.api.DetailAST; |
48 | 49 | import com.puppycrawl.tools.checkstyle.bdd.InlineConfigParser; |
49 | 50 | import com.puppycrawl.tools.checkstyle.bdd.TestInputConfiguration; |
50 | 51 | import com.puppycrawl.tools.checkstyle.bdd.TestInputViolation; |
51 | 52 | import com.puppycrawl.tools.checkstyle.internal.utils.BriefUtLogger; |
52 | 53 | import com.puppycrawl.tools.checkstyle.internal.utils.TestUtil; |
53 | 54 | import com.puppycrawl.tools.checkstyle.utils.CommonUtil; |
54 | 55 | import com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtil; |
| 56 | +import com.puppycrawl.tools.checkstyle.xpath.RootNode; |
55 | 57 |
|
56 | 58 | public abstract class AbstractModuleTestSupport extends AbstractPathTestSupport { |
57 | 59 |
|
@@ -180,6 +182,19 @@ protected final String getNonCompilablePath(String filename) throws IOException |
180 | 182 | + filename).getCanonicalPath(); |
181 | 183 | } |
182 | 184 |
|
| 185 | + /** |
| 186 | + * Creates a RootNode for non-compilable test files. |
| 187 | + * |
| 188 | + * @param fileName name of the test file |
| 189 | + * @return RootNode for the parsed AST |
| 190 | + * @throws Exception if file parsing fails |
| 191 | + */ |
| 192 | + protected RootNode getRootNodeForNonCompilable(String fileName) throws Exception { |
| 193 | + final File file = new File(getNonCompilablePath(fileName)); |
| 194 | + final DetailAST rootAst = JavaParser.parseFile(file, JavaParser.Options.WITHOUT_COMMENTS); |
| 195 | + return new RootNode(rootAst); |
| 196 | + } |
| 197 | + |
183 | 198 | /** |
184 | 199 | * Returns URI-representation of the path for the given file name. |
185 | 200 | * The path is formed base on the root location. |
|
0 commit comments