JavaParser Source Viewer

Home|JavaParser/com/github/javaparser/ast/nodeTypes/NodeWithImplements.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.ast.nodeTypes;
23
24import com.github.javaparser.ast.Node;
25import com.github.javaparser.ast.NodeList;
26import com.github.javaparser.ast.type.ClassOrInterfaceType;
27
28import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType;
29
30/**
31 * A node that implements other types.
32 */
33public interface NodeWithImplements<N extends Node> {
34    NodeList<ClassOrInterfaceTypegetImplementedTypes();
35
36    default ClassOrInterfaceType getImplementedTypes(int i) {
37        return getImplementedTypes().get(i);
38    }
39
40    N setImplementedTypes(NodeList<ClassOrInterfaceTypeimplementsList);
41    
42    void tryAddImportToParentCompilationUnit(Class<?> clazz);
43    
44    @SuppressWarnings("unchecked")
45    default N setImplementedType(int iClassOrInterfaceType implement) {
46        getImplementedTypes().set(iimplement);
47        return (N) this;
48    }
49
50    @SuppressWarnings("unchecked")
51    default N addImplementedType(ClassOrInterfaceType implement) {
52        getImplementedTypes().add(implement);
53        return (N) this;
54    }
55
56    /** @deprecated use addImplementedType instead */
57    default N addImplements(String name) {
58        return addImplementedType(name);
59    }
60
61    /** @deprecated use addImplementedType instead */
62    default N addImplements(Class<?> clazz) {
63        return addImplementedType(clazz);
64    }
65
66    /**
67     * Add an implements to this
68     *
69     * @param name the name of the type to extends from
70     * @return this
71     */
72    @SuppressWarnings("unchecked")
73    default N addImplementedType(String name) {
74        getImplementedTypes().add(parseClassOrInterfaceType(name));
75        return (N) this;
76    }
77
78    /**
79     * Add an implements to this and automatically add the import
80     *
81     * @param clazz the type to implements from
82     * @return this
83     */
84    default N addImplementedType(Class<?> clazz) {
85        tryAddImportToParentCompilationUnit(clazz);
86        return addImplementedType(clazz.getSimpleName());
87    }
88}
89
MembersX
NodeWithImplements:addImplementedType
NodeWithImplements:getImplementedTypes
NodeWithImplements:setImplementedTypes
NodeWithImplements:addImplements
NodeWithImplements:setImplementedType
NodeWithImplements:tryAddImportToParentCompilationUnit
Members
X