45 * @return 0 - break, 1 - continue, 2 - recurse 46 */ 47 VisitResult visit(Cursor current, Cursor parent, Object data); 48 } 49 50 private static int visit(Visitor v, ByteBuffer c, ByteBuffer p, Object data) { 51 return v.visit(new Cursor(c), new Cursor(p), data).ordinal(); 52 } 53 54 Cursor(ByteBuffer buf) { 55 super(buf); 56 } 57 58 public native boolean isDeclaration(); 59 public native boolean isPreprocessing(); 60 public native boolean isInvalid(); 61 public native boolean isDefinition(); 62 public native boolean isAnonymousStruct(); 63 public native boolean isMacroFunctionLike(); 64 65 public boolean isAnonymousEnum() { 66 // libclang::clang_Cursor_isAnonymous only applies to struct, not enum 67 return (type().kind() == TypeKind.Enum && spelling().isEmpty()); 68 } 69 70 public boolean isAnonymous() { 71 return isAnonymousStruct() || isAnonymousEnum(); 72 } 73 74 public native String spelling(); 75 public native String USR(); 76 77 public native int kind1(); 78 79 public native int visitChildren(Visitor visitor, Object data); 80 81 public native boolean equalCursor(Cursor other); 82 83 public native Type type(); 84 public native Type getEnumDeclIntegerType(); 85 86 public native Cursor getDefinition(); 87 88 public native SourceLocation getSourceLocation(); 89 public native SourceRange getExtent(); 90 91 public native int numberOfArgs(); 92 public native Cursor getArgument(int idx); 93 94 // C long long, 64-bit 95 public native long getEnumConstantValue(); 96 // C unsigned long long, 64-bit 97 public native long getEnumConstantUnsignedValue(); 98 99 public native boolean isBitField(); 100 public native int getBitFieldWidth(); 101 102 native long getTranslationUnit0(); 103 public final TranslationUnit getTranslationUnit() { 104 return new TranslationUnit(getTranslationUnit0()); 105 } 106 107 public native String getMangling(); 108 109 public CursorKind kind() { 110 int v = kind1(); 111 // FIXME: assert(v == getData().getInt(0)); 112 return CursorKind.valueOf(v); 113 } 114 115 public boolean equals(Cursor other) { 116 return getData().equals(other.getData()); 117 } 118 119 public Stream<Cursor> children() { 120 ArrayList<Cursor> ar = new ArrayList<>(); 121 visitChildren((c, p, d) -> { 122 @SuppressWarnings("unchecked") 123 List<Cursor> a = (List<Cursor>) d; 124 a.add(c); 125 return VisitResult.Continue; 126 }, ar); 127 return ar.stream(); 128 } 129 130 public Stream<Cursor> stream() { 131 return children().flatMap(c -> Stream.concat(Stream.of(c), c.children())); 132 } 133 } | 45 * @return 0 - break, 1 - continue, 2 - recurse 46 */ 47 VisitResult visit(Cursor current, Cursor parent, Object data); 48 } 49 50 private static int visit(Visitor v, ByteBuffer c, ByteBuffer p, Object data) { 51 return v.visit(new Cursor(c), new Cursor(p), data).ordinal(); 52 } 53 54 Cursor(ByteBuffer buf) { 55 super(buf); 56 } 57 58 public native boolean isDeclaration(); 59 public native boolean isPreprocessing(); 60 public native boolean isInvalid(); 61 public native boolean isDefinition(); 62 public native boolean isAnonymousStruct(); 63 public native boolean isMacroFunctionLike(); 64 65 public native String spelling(); 66 public native String USR(); 67 68 public native int kind1(); 69 70 public native int visitChildren(Visitor visitor, Object data); 71 72 public native Type type(); 73 public native Type getEnumDeclIntegerType(); 74 75 public native Cursor getDefinition(); 76 77 public native SourceLocation getSourceLocation(); 78 public native SourceRange getExtent(); 79 80 public native int numberOfArgs(); 81 public native Cursor getArgument(int idx); 82 83 // C long long, 64-bit 84 public native long getEnumConstantValue(); 85 // C unsigned long long, 64-bit 86 public native long getEnumConstantUnsignedValue(); 87 88 public native boolean isBitField(); 89 public native int getBitFieldWidth(); 90 91 native long getTranslationUnit0(); 92 public final TranslationUnit getTranslationUnit() { 93 return new TranslationUnit(getTranslationUnit0()); 94 } 95 96 public native String getMangling(); 97 98 public CursorKind kind() { 99 int v = kind1(); 100 // FIXME: assert(v == getData().getInt(0)); 101 return CursorKind.valueOf(v); 102 } 103 104 public Stream<Cursor> children() { 105 ArrayList<Cursor> ar = new ArrayList<>(); 106 visitChildren((c, p, d) -> { 107 @SuppressWarnings("unchecked") 108 List<Cursor> a = (List<Cursor>) d; 109 a.add(c); 110 return VisitResult.Continue; 111 }, ar); 112 return ar.stream(); 113 } 114 115 public Stream<Cursor> allChildren() { 116 return children().flatMap(c -> Stream.concat(Stream.of(c), c.children())); 117 } 118 119 public native boolean equalCursor(Cursor other); 120 121 @Override 122 public boolean equals(Object other) { 123 if (this == other) { 124 return true; 125 } 126 if (!(other instanceof Cursor)) { 127 return false; 128 } 129 return equalCursor((Cursor)other); 130 } 131 132 @Override 133 public int hashCode() { 134 return spelling().hashCode(); 135 } 136 } |