• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.ast.CompilationUnit;
20 import com.github.javaparser.ast.expr.FieldAccessExpr;
21 import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration;
22 import com.github.javaparser.resolution.types.ResolvedPrimitiveType;
23 import com.github.javaparser.symbolsolver.javaparser.Navigator;
24 import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade;
25 import com.github.javaparser.symbolsolver.model.resolution.SymbolReference;
26 import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
27 import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest;
28 import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
29 import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver;
30 import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
31 import com.github.javaparser.symbolsolver.utils.LeanParserConfiguration;
32 import org.junit.jupiter.api.Test;
33 
34 import java.io.IOException;
35 import java.nio.file.Path;
36 
37 import static com.github.javaparser.StaticJavaParser.parse;
38 import static org.junit.jupiter.api.Assertions.assertEquals;
39 import static org.junit.jupiter.api.Assertions.assertNotNull;
40 
41 class Issue300Test extends AbstractResolutionTest {
42 
43     @Test
fieldAccessIssue()44     void fieldAccessIssue() throws IOException {
45         Path pathToSourceFile = adaptPath("src/test/resources/issue300/Issue300.java");
46         CompilationUnit cu = parse(pathToSourceFile);
47 
48         final FieldAccessExpr fieldAccess = Navigator.findNodeOfGivenClass(cu, FieldAccessExpr.class);
49         assertNotNull(fieldAccess);
50 
51         TypeSolver typeSolver = new CombinedTypeSolver(
52                 new ReflectionTypeSolver(),
53                 new JavaParserTypeSolver(adaptPath("src/test/resources/issue300"), new LeanParserConfiguration()));
54         final JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
55         final SymbolReference<? extends ResolvedValueDeclaration> ref = javaParserFacade.solve(fieldAccess);
56         assertEquals(ResolvedPrimitiveType.INT, ref.getCorrespondingDeclaration().getType().asPrimitive());
57     }
58 }
59 
60