JavaParser Source Viewer

Home|JavaParser/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java
1/*
2 * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser.
3 * Copyright (C) 2011, 2013-2020 The JavaParser Team.
4 *
5 * This file is part of JavaParser.
6 *
7 * JavaParser can be used either under the terms of
8 * a) the GNU Lesser General Public License as published by
9 *     the Free Software Foundation, either version 3 of the License, or
10 *     (at your option) any later version.
11 * b) the terms of the Apache License
12 *
13 * You should have received a copy of both licenses in LICENCE.LGPL and
14 * LICENCE.APACHE. Please refer to those files for details.
15 *
16 * JavaParser is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 */
21
22package com.github.javaparser.resolution.declarations;
23
24/**
25 * A generic declaration.
26 *
27 * @author Federico Tomassetti
28 */
29public interface ResolvedDeclaration {
30
31    /**
32     * Anonymous classes do not have a name, for example.
33     */
34    default boolean hasName() {
35        return true;
36    }
37
38    /**
39     * Should return the name or return null if the name is not available.
40     */
41    String getName();
42
43    /**
44     * Does this declaration represents a class field?
45     */
46    default boolean isField() {
47        return false;
48    }
49
50    /**
51     * Does this declaration represents a variable?
52     */
53    default boolean isVariable() {
54        return false;
55    }
56
57    default boolean isEnumConstant() {
58        return false;
59    }
60
61    /**
62     * Does this declaration represents a method parameter?
63     */
64    default boolean isParameter() {
65        return false;
66    }
67
68    /**
69     * Does this declaration represents a type?
70     */
71    default boolean isType() {
72        return false;
73    }
74
75    /**
76     * Does this declaration represents a method?
77     */
78    default boolean isMethod() {
79        return false;
80    }
81
82    /**
83     * Return this as a FieldDeclaration or throw an UnsupportedOperationException
84     */
85    default ResolvedFieldDeclaration asField() {
86        throw new UnsupportedOperationException(String.format("%s is not a FieldDeclaration", this));
87    }
88
89    /**
90     * Return this as a ParameterDeclaration or throw an UnsupportedOperationException
91     */
92    default ResolvedParameterDeclaration asParameter() {
93        throw new UnsupportedOperationException(String.format("%s is not a ParameterDeclaration", this));
94    }
95
96    /**
97     * Return this as a TypeDeclaration or throw an UnsupportedOperationException
98     */
99    default ResolvedTypeDeclaration asType() {
100        throw new UnsupportedOperationException(String.format("%s is not a TypeDeclaration", this));
101    }
102
103    /**
104     * Return this as a MethodDeclaration or throw an UnsupportedOperationException
105     */
106    default ResolvedMethodDeclaration asMethod() {
107        throw new UnsupportedOperationException(String.format("%s is not a MethodDeclaration", this));
108    }
109
110    default ResolvedEnumConstantDeclaration asEnumConstant() {
111        throw new UnsupportedOperationException(String.format("%s is not an EnumConstantDeclaration", this));
112    }
113}
114
MembersX
ResolvedDeclaration:getName
ResolvedDeclaration:asField
ResolvedDeclaration:isMethod
ResolvedDeclaration:hasName
ResolvedDeclaration:isEnumConstant
ResolvedDeclaration:isType
ResolvedDeclaration:isParameter
ResolvedDeclaration:isVariable
ResolvedDeclaration:asParameter
ResolvedDeclaration:asEnumConstant
ResolvedDeclaration:asMethod
ResolvedDeclaration:isField
ResolvedDeclaration:asType
Members
X