AbstractTypeDeclaration.java revision f640162d77a6e37204544eb2ea29dd4ca815ce08
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.logic; 18 19import com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration; 20import com.github.javaparser.symbolsolver.model.declarations.TypeDeclaration; 21import com.github.javaparser.symbolsolver.model.methods.MethodUsage; 22import com.github.javaparser.symbolsolver.model.typesystem.ReferenceType; 23 24import java.util.HashSet; 25import java.util.Set; 26 27/** 28 * Common ancestor for most types. 29 * 30 * @author Federico Tomassetti 31 */ 32public abstract class AbstractTypeDeclaration implements TypeDeclaration { 33 34 @Override 35 public final Set<MethodUsage> getAllMethods() { 36 Set<MethodUsage> methods = new HashSet<>(); 37 38 Set<String> methodsSignatures = new HashSet<>(); 39 40 for (MethodDeclaration methodDeclaration : getDeclaredMethods()) { 41 methods.add(new MethodUsage(methodDeclaration)); 42 methodsSignatures.add(methodDeclaration.getSignature()); 43 } 44 45 for (ReferenceType ancestor : getAllAncestors()) { 46 for (MethodUsage mu : ancestor.getDeclaredMethods()) { 47 String signature = mu.getDeclaration().getSignature(); 48 if (!methodsSignatures.contains(signature)) { 49 methodsSignatures.add(signature); 50 methods.add(mu); 51 } 52 } 53 } 54 55 return methods; 56 } 57 58 @Override 59 public final boolean isFunctionalInterface() { 60 return FunctionalInterfaceLogic.getFunctionalMethod(this).isPresent(); 61 } 62} 63