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