|
| 1 | +/* |
| 2 | + * Copyright 2024 Web3 Labs Ltd. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 5 | + * the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 10 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 11 | + * specific language governing permissions and limitations under the License. |
| 12 | + */ |
1 | 13 | package org.web3j.codegen;
|
2 | 14 |
|
3 |
| -import javax.tools.*; |
4 | 15 | import java.io.IOException;
|
5 | 16 | import java.util.Collections;
|
| 17 | +import javax.tools.*; |
6 | 18 |
|
7 | 19 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
8 | 20 |
|
9 | 21 | public class GeneraterTestUtils {
|
10 | 22 |
|
11 |
| - public static void verifyGeneratedCode(String sourceFile) throws IOException { |
12 |
| - JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
13 |
| - DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); |
| 23 | + public static void verifyGeneratedCode(String sourceFile) throws IOException { |
| 24 | + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
| 25 | + DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); |
14 | 26 |
|
15 |
| - try (StandardJavaFileManager fileManager = |
16 |
| - compiler.getStandardFileManager(diagnostics, null, null)) { |
17 |
| - Iterable<? extends JavaFileObject> compilationUnits = |
18 |
| - fileManager.getJavaFileObjectsFromStrings( |
19 |
| - Collections.singletonList(sourceFile)); |
20 |
| - JavaCompiler.CompilationTask task = |
21 |
| - compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits); |
22 |
| - assertTrue(task.call(), "Generated contract contains compile time error"); |
23 |
| - } |
24 |
| - } |
| 27 | + try (StandardJavaFileManager fileManager = |
| 28 | + compiler.getStandardFileManager(diagnostics, null, null)) { |
| 29 | + Iterable<? extends JavaFileObject> compilationUnits = |
| 30 | + fileManager.getJavaFileObjectsFromStrings( |
| 31 | + Collections.singletonList(sourceFile)); |
| 32 | + JavaCompiler.CompilationTask task = |
| 33 | + compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits); |
| 34 | + assertTrue(task.call(), "Generated contract contains compile time error"); |
| 35 | + } |
| 36 | + } |
25 | 37 | }
|
0 commit comments