• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
3  * Copyright (C) 2011, 2013-2016 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 
22 package com.github.javaparser.resolution.declarations;
23 
24 /**
25  * A generic declaration.
26  *
27  * @author Federico Tomassetti
28  */
29 public interface ResolvedDeclaration {
30 
31     /**
32      * Anonymous classes do not have a name, for example.
33      */
hasName()34     default boolean hasName() {
35         return true;
36     }
37 
38     /**
39      * Should return the name or throw a RuntimeException if the name is not available.
40      */
getName()41     String getName();
42 
43     /**
44      * Does this declaration represents a class field?
45      */
isField()46     default boolean isField() {
47         return false;
48     }
49 
50     /**
51      * Does this declaration represents a method parameter?
52      */
isParameter()53     default boolean isParameter() {
54         return false;
55     }
56 
57     /**
58      * Does this declaration represents a type?
59      */
isType()60     default boolean isType() {
61         return false;
62     }
63 
64     /**
65      * Does this declaration represents a method?
66      */
isMethod()67     default boolean isMethod() {
68         return false;
69     }
70 
71     /**
72      * Return this as a FieldDeclaration or throw an UnsupportedOperationException
73      */
asField()74     default ResolvedFieldDeclaration asField() {
75         throw new UnsupportedOperationException(String.format("%s is not a FieldDeclaration", this));
76     }
77 
78     /**
79      * Return this as a ParameterDeclaration or throw an UnsupportedOperationException
80      */
asParameter()81     default ResolvedParameterDeclaration asParameter() {
82         throw new UnsupportedOperationException(String.format("%s is not a ParameterDeclaration", this));
83     }
84 
85     /**
86      * Return this as a TypeDeclaration or throw an UnsupportedOperationException
87      */
asType()88     default ResolvedTypeDeclaration asType() {
89         throw new UnsupportedOperationException(String.format("%s is not a TypeDeclaration", this));
90     }
91 
92     /**
93      * Return this as a MethodDeclaration or throw an UnsupportedOperationException
94      */
asMethod()95     default ResolvedMethodDeclaration asMethod() {
96         throw new UnsupportedOperationException(String.format("%s is not a MethodDeclaration", this));
97     }
98 }
99