1 /*
2  * Copyright 2016 Federico Tomassetti
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.github.javaparser.symbolsolver;
18 
19 import com.github.javaparser.utils.CodeGenerationUtils;
20 
21 import java.nio.file.Files;
22 import java.nio.file.Path;
23 import java.nio.file.Paths;
24 
25 public abstract class AbstractSymbolResolutionTest {
26 
adaptPath(Path path)27     protected static Path adaptPath(Path path) {
28         if (Files.exists(path)) {
29             return path.toAbsolutePath();
30         }
31         Path underSymbolSolver = CodeGenerationUtils.mavenModuleRoot(AbstractSymbolResolutionTest.class).resolve("javaparser-symbol-solver-testing").resolve(path);
32         if (Files.exists(underSymbolSolver)) {
33             return underSymbolSolver;
34         } else {
35             throw new IllegalArgumentException("I cannot adapt the path " + path);
36         }
37     }
38 
adaptPath(String path)39     protected static Path adaptPath(String path) {
40         return adaptPath(Paths.get(path));
41     }
42 
isJavaVersion9OrAbove()43     protected boolean isJavaVersion9OrAbove() {
44         String jdkVersion = System.getProperty("java.version");
45         return Integer.parseInt(jdkVersion.substring(0, jdkVersion.indexOf('.'))) >= 9;
46     }
47 }
48