Issue18.java revision b54617e765d73b3ce0d187cf12ad8da382bce439
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 17package com.github.javaparser.symbolsolver; 18 19import com.github.javaparser.ParseException; 20import com.github.javaparser.ast.CompilationUnit; 21import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; 22import com.github.javaparser.ast.body.MethodDeclaration; 23import com.github.javaparser.ast.stmt.ExpressionStmt; 24import com.github.javaparser.resolution.types.ResolvedType; 25import com.github.javaparser.symbolsolver.javaparser.Navigator; 26import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; 27import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; 28import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest; 29import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; 30import org.junit.Test; 31 32import static org.junit.Assert.assertEquals; 33 34public class Issue18 extends AbstractResolutionTest { 35 36 @Test 37 public void typeDeclarationSuperClassImplicitlyIncludeObject() { 38 CompilationUnit cu = parseSample("Issue18"); 39 ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "Foo"); 40 MethodDeclaration methodDeclaration = Navigator.demandMethod(clazz, "bar"); 41 ExpressionStmt expr = (ExpressionStmt) methodDeclaration.getBody().get().getStatements().get(1); 42 TypeSolver typeSolver = new ReflectionTypeSolver(); 43 JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver); 44 ResolvedType type = javaParserFacade.getType(expr.getExpression()); 45 assertEquals("java.lang.Object", type.describe()); 46 } 47} 48