1 /*
  2  *  Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
  3  *  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  *  This code is free software; you can redistribute it and/or modify it
  6  *  under the terms of the GNU General Public License version 2 only, as
  7  *  published by the Free Software Foundation.  Oracle designates this
  8  *  particular file as subject to the "Classpath" exception as provided
  9  *  by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  *  This code is distributed in the hope that it will be useful, but WITHOUT
 12  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  *  version 2 for more details (a copy is included in the LICENSE file that
 15  *  accompanied this code).
 16  *
 17  *  You should have received a copy of the GNU General Public License version
 18  *  2 along with this work; if not, write to the Free Software Foundation,
 19  *  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  *   Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  *  or visit www.oracle.com if you need additional information or have any
 23  *  questions.
 24  *
 25  */
 26 package jdk.internal.clang;
 27 
 28 import java.util.HashMap;
 29 import java.util.Map;
 30 import java.util.NoSuchElementException;
 31 import static jdk.internal.clang.libclang.Index_h.*;
 32 
 33 public enum CursorKind {
 34 
 35     UnexposedDecl(CXCursor_UnexposedDecl()),
 36     StructDecl(CXCursor_StructDecl()),
 37     UnionDecl(CXCursor_UnionDecl()),
 38     ClassDecl(CXCursor_ClassDecl()),
 39     EnumDecl(CXCursor_EnumDecl()),
 40     FieldDecl(CXCursor_FieldDecl()),
 41     EnumConstantDecl(CXCursor_EnumConstantDecl()),
 42     FunctionDecl(CXCursor_FunctionDecl()),
 43     VarDecl(CXCursor_VarDecl()),
 44     ParmDecl(CXCursor_ParmDecl()),
 45     TypedefDecl(CXCursor_TypedefDecl()),
 46     Namespace(CXCursor_Namespace()),
 47     IntegerLiteral(CXCursor_IntegerLiteral()),
 48     FloatingLiteral(CXCursor_FloatingLiteral()),
 49     ImaginaryLiteral(CXCursor_ImaginaryLiteral()),
 50     StringLiteral(CXCursor_StringLiteral()),
 51     CharacterLiteral(CXCursor_CharacterLiteral()),
 52     UnexposedAttr(CXCursor_UnexposedAttr()),
 53     IBActionAttr(CXCursor_IBActionAttr()),
 54     IBOutletAttr(CXCursor_IBOutletAttr()),
 55     IBOutletCollectionAttr(CXCursor_IBOutletCollectionAttr()),
 56     CXXFinalAttr(CXCursor_CXXFinalAttr()),
 57     CXXOverrideAttr(CXCursor_CXXOverrideAttr()),
 58     AnnotateAttr(CXCursor_AnnotateAttr()),
 59     AsmLabelAttr(CXCursor_AsmLabelAttr()),
 60     PackedAttr(CXCursor_PackedAttr()),
 61     PureAttr(CXCursor_PureAttr()),
 62     ConstAttr(CXCursor_ConstAttr()),
 63     NoDuplicateAttr(CXCursor_NoDuplicateAttr()),
 64     CUDAConstantAttr(CXCursor_CUDAConstantAttr()),
 65     CUDADeviceAttr(CXCursor_CUDADeviceAttr()),
 66     CUDAGlobalAttr(CXCursor_CUDAGlobalAttr()),
 67     CUDAHostAttr(CXCursor_CUDAHostAttr()),
 68     CUDASharedAttr(CXCursor_CUDASharedAttr()),
 69     VisibilityAttr(CXCursor_VisibilityAttr()),
 70     DLLExport(CXCursor_DLLExport()),
 71     DLLImport(CXCursor_DLLImport()),
 72     NSReturnsRetained(CXCursor_NSReturnsRetained()),
 73     NSReturnsNotRetained(CXCursor_NSReturnsNotRetained()),
 74     NSReturnsAutoreleased(CXCursor_NSReturnsAutoreleased()),
 75     NSConsumesSelf(CXCursor_NSConsumesSelf()),
 76     NSConsumed(CXCursor_NSConsumed()),
 77     ObjCException(CXCursor_ObjCException()),
 78     ObjCNSObject(CXCursor_ObjCNSObject()),
 79     ObjCIndependentClass(CXCursor_ObjCIndependentClass()),
 80     ObjCPreciseLifetime(CXCursor_ObjCPreciseLifetime()),
 81     ObjCReturnsInnerPointer(CXCursor_ObjCReturnsInnerPointer()),
 82     ObjCRequiresSuper(CXCursor_ObjCRequiresSuper()),
 83     ObjCRootClass(CXCursor_ObjCRootClass()),
 84     ObjCSubclassingRestricted(CXCursor_ObjCSubclassingRestricted()),
 85     ObjCExplicitProtocolImpl(CXCursor_ObjCExplicitProtocolImpl()),
 86     ObjCDesignatedInitializer(CXCursor_ObjCDesignatedInitializer()),
 87     ObjCRuntimeVisible(CXCursor_ObjCRuntimeVisible()),
 88     ObjCBoxable(CXCursor_ObjCBoxable()),
 89     FlagEnum(CXCursor_FlagEnum()),
 90     ConvergentAttr(CXCursor_ConvergentAttr()),
 91     WarnUnusedAttr(CXCursor_WarnUnusedAttr()),
 92     WarnUnusedResultAttr(CXCursor_WarnUnusedResultAttr()),
 93     AlignedAttr(CXCursor_AlignedAttr()),
 94     MacroDefinition(CXCursor_MacroDefinition()),
 95     MacroExpansion(CXCursor_MacroExpansion()),
 96     MacroInstantiation(CXCursor_MacroInstantiation()),
 97     InclusionDirective(CXCursor_InclusionDirective());
 98 
 99     private final int value;
100 
101     CursorKind(int value) {
102         this.value = value;
103     }
104 
105     public int value() {
106         return value;
107     }
108 
109     private final static Map<Integer, CursorKind> lookup;
110 
111     static {
112         lookup = new HashMap<>();
113         for (CursorKind e: CursorKind.values()) {
114             lookup.put(e.value(), e);
115         }
116     }
117 
118     public final static CursorKind valueOf(int value) {
119         CursorKind x = lookup.get(value);
120         if (null == x) {
121             throw new NoSuchElementException("Invalid Cursor kind value: " + value);
122         }
123         return x;
124     }
125 }