File indexing completed on 2024-04-28 04:35:54

0001 /*
0002  * This file is part of KDevelop
0003  * Copyright (C) 2012-2015 Miquel Sabaté Solà <mikisabate@gmail.com>
0004  *
0005  * This program is free software: you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation, either version 3 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017  */
0018 
0019 #ifndef RUBY_CLASS_TYPE_H
0020 #define RUBY_CLASS_TYPE_H
0021 
0022 #include <duchain/duchainexport.h>
0023 #include <language/duchain/types/structuretype.h>
0024 
0025 namespace ruby {
0026 
0027 struct KDEVRUBYDUCHAIN_EXPORT ClassTypeData : public KDevelop::StructureTypeData
0028 {
0029     ClassTypeData() : KDevelop::StructureTypeData(), contentType()
0030     {
0031     }
0032 
0033     /// Copy constructor. @param rhs data to copy.
0034     explicit ClassTypeData(const ClassTypeData &rhs)
0035         : KDevelop::StructureTypeData(rhs)
0036         , contentType(rhs.contentType)
0037     {
0038     }
0039 
0040     /// The type of the content.
0041     KDevelop::IndexedType contentType;
0042 };
0043 
0044 /**
0045  * @class ClassType
0046  *
0047  * This is the type to be used when declaring classes in this plugin. It's
0048  * similar to the Python's VariableLengthContainer in that in Ruby, every class
0049  * can potentially become a container. The contained type can be accessed
0050  * through the methods addContentType(newType) and contentType().
0051  */
0052 struct KDEVRUBYDUCHAIN_EXPORT ClassType : public KDevelop::StructureType
0053 {
0054     using BaseType = KDevelop::StructureType;
0055     using Data = ClassTypeData;
0056     using Ptr = KDevelop::TypePtr<ClassType>;
0057 
0058     /// The different constructors.
0059     ClassType();
0060     explicit ClassType(const ClassType &rhs);
0061     explicit ClassType(ClassTypeData &data);
0062 
0063     /// Add the given type @p typeToAdd to the contents.
0064     void addContentType(AbstractType::Ptr typeToAdd);
0065 
0066     /// @returns the content type.
0067     const KDevelop::IndexedType & contentType() const;
0068 
0069     /// Get if this class is useful.
0070     bool isUseful() const;
0071 
0072     /// Create a clone of this type.
0073     AbstractType * clone() const override;
0074 
0075     /// The hash-value for this type.
0076     uint hash() const override;
0077 
0078     /// @returns this type as a string.
0079     QString toString() const override;
0080 
0081     /// @returns true if @p rhs is the same as this type
0082     bool equals(const AbstractType *rhs) const override;
0083 
0084     /// @returns the container's type as a string.
0085     QString containerToString() const;
0086 
0087     enum { Identity = 41 /** The id of this Type. */ };
0088 
0089 protected:
0090     TYPE_DECLARE_DATA(ClassType);
0091 };
0092 
0093 }
0094 
0095 #endif // CLASSTYPE_H