1 package com.github.javaparser.symbolsolver;
2 
3 import com.github.javaparser.JavaParser;
4 import com.github.javaparser.ast.CompilationUnit;
5 import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
6 import com.github.javaparser.ast.body.FieldDeclaration;
7 import com.github.javaparser.ast.body.MethodDeclaration;
8 import com.github.javaparser.resolution.types.ResolvedType;
9 import com.github.javaparser.symbolsolver.javaparser.Navigator;
10 import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade;
11 import com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodContext;
12 import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
13 import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest;
14 import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
15 import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver;
16 import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
17 import org.junit.Assert;
18 import org.junit.Before;
19 import org.junit.Test;
20 
21 import java.io.File;
22 import java.io.FileNotFoundException;
23 import java.util.List;
24 
25 import static org.junit.Assert.assertEquals;
26 
27 public class Issue347 extends AbstractResolutionTest{
28 
29     private TypeSolver typeSolver;
30     private JavaParserFacade javaParserFacade;
31 
32     @Before
setup()33     public void setup() {
34         typeSolver = new ReflectionTypeSolver();
35         javaParserFacade = JavaParserFacade.get(typeSolver);
36     }
37 
38     @Test
resolvingReferenceToEnumDeclarationInSameFile()39     public void resolvingReferenceToEnumDeclarationInSameFile() {
40         String code = "package foo.bar;\nenum Foo {\n" +
41                 "    FOO_A, FOO_B\n" +
42                 "}\n" +
43                 "\n" +
44                 "class UsingFoo {\n" +
45                 "    Foo myFooField;\n" +
46                 "}";
47         CompilationUnit cu = JavaParser.parse(code);
48         FieldDeclaration fieldDeclaration = Navigator.findNodeOfGivenClass(cu, FieldDeclaration.class);
49         ResolvedType fieldType = javaParserFacade.getType(fieldDeclaration);
50         assertEquals(true, fieldType.isReferenceType());
51         assertEquals(true, fieldType.asReferenceType().getTypeDeclaration().isEnum());
52         assertEquals("foo.bar.Foo", fieldType.asReferenceType().getQualifiedName());
53     }
54 }
55 
56