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     TypeRef(CXCursor_TypeRef()),
 48     IntegerLiteral(CXCursor_IntegerLiteral()),
 49     FloatingLiteral(CXCursor_FloatingLiteral()),
 50     ImaginaryLiteral(CXCursor_ImaginaryLiteral()),
 51     StringLiteral(CXCursor_StringLiteral()),
 52     CharacterLiteral(CXCursor_CharacterLiteral()),
 53     UnexposedAttr(CXCursor_UnexposedAttr()),
 54     IBActionAttr(CXCursor_IBActionAttr()),
 55     IBOutletAttr(CXCursor_IBOutletAttr()),
 56     IBOutletCollectionAttr(CXCursor_IBOutletCollectionAttr()),
 57     CXXFinalAttr(CXCursor_CXXFinalAttr()),
 58     CXXOverrideAttr(CXCursor_CXXOverrideAttr()),
 59     AnnotateAttr(CXCursor_AnnotateAttr()),
 60     AsmLabelAttr(CXCursor_AsmLabelAttr()),
 61     PackedAttr(CXCursor_PackedAttr()),
 62     PureAttr(CXCursor_PureAttr()),
 63     ConstAttr(CXCursor_ConstAttr()),
 64     NoDuplicateAttr(CXCursor_NoDuplicateAttr()),
 65     CUDAConstantAttr(CXCursor_CUDAConstantAttr()),
 66     CUDADeviceAttr(CXCursor_CUDADeviceAttr()),
 67     CUDAGlobalAttr(CXCursor_CUDAGlobalAttr()),
 68     CUDAHostAttr(CXCursor_CUDAHostAttr()),
 69     CUDASharedAttr(CXCursor_CUDASharedAttr()),
 70     VisibilityAttr(CXCursor_VisibilityAttr()),
 71     DLLExport(CXCursor_DLLExport()),
 72     DLLImport(CXCursor_DLLImport()),
 73     NSReturnsRetained(CXCursor_NSReturnsRetained()),
 74     NSReturnsNotRetained(CXCursor_NSReturnsNotRetained()),
 75     NSReturnsAutoreleased(CXCursor_NSReturnsAutoreleased()),
 76     NSConsumesSelf(CXCursor_NSConsumesSelf()),
 77     NSConsumed(CXCursor_NSConsumed()),
 78     ObjCException(CXCursor_ObjCException()),
 79     ObjCNSObject(CXCursor_ObjCNSObject()),
 80     ObjCIndependentClass(CXCursor_ObjCIndependentClass()),
 81     ObjCPreciseLifetime(CXCursor_ObjCPreciseLifetime()),
 82     ObjCReturnsInnerPointer(CXCursor_ObjCReturnsInnerPointer()),
 83     ObjCRequiresSuper(CXCursor_ObjCRequiresSuper()),
 84     ObjCRootClass(CXCursor_ObjCRootClass()),
 85     ObjCSubclassingRestricted(CXCursor_ObjCSubclassingRestricted()),
 86     ObjCExplicitProtocolImpl(CXCursor_ObjCExplicitProtocolImpl()),
 87     ObjCDesignatedInitializer(CXCursor_ObjCDesignatedInitializer()),
 88     ObjCRuntimeVisible(CXCursor_ObjCRuntimeVisible()),
 89     ObjCBoxable(CXCursor_ObjCBoxable()),
 90     FlagEnum(CXCursor_FlagEnum()),
 91     ConvergentAttr(CXCursor_ConvergentAttr()),
 92     WarnUnusedAttr(CXCursor_WarnUnusedAttr()),
 93     WarnUnusedResultAttr(CXCursor_WarnUnusedResultAttr()),
 94     AlignedAttr(CXCursor_AlignedAttr()),
 95     MacroDefinition(CXCursor_MacroDefinition()),
 96     MacroExpansion(CXCursor_MacroExpansion()),
 97     MacroInstantiation(CXCursor_MacroInstantiation()),
 98     InclusionDirective(CXCursor_InclusionDirective());
 99 
100     private final int value;
101 
102     CursorKind(int value) {
103         this.value = value;
104     }
105 
106     public int value() {
107         return value;
108     }
109 
110     private final static Map<Integer, CursorKind> lookup;
111 
112     static {
113         lookup = new HashMap<>();
114         for (CursorKind e: CursorKind.values()) {
115             lookup.put(e.value(), e);
116         }
117     }
118 
119     public final static CursorKind valueOf(int value) {
120         CursorKind x = lookup.get(value);
121         if (null == x) {
122             throw new NoSuchElementException("Invalid Cursor kind value: " + value);
123         }
124         return x;
125     }
126 }