or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

configuration.mdcore-operations.mdfunctional-queries.mdindex.mdlegacy-api.mdscanners.mdserialization.mdutilities.md

core-operations.mddocs/

0

# Core Operations

1

2

Central scanning functionality for indexing classpath metadata and performing reverse queries on the type system. This module provides the main entry points for creating and configuring Reflections instances.

3

4

## Capabilities

5

6

### Reflections Class

7

8

The main entry point class providing both modern functional and legacy query APIs for metadata scanning and querying.

9

10

```java { .api }

11

/**

12

* Main API class for scanning and querying classpath metadata

13

*/

14

class Reflections {

15

/** Create Reflections instance with custom configuration */

16

Reflections(Configuration configuration);

17

18

/** Create Reflections instance from existing metadata store */

19

Reflections(Store store);

20

21

/** Create Reflections instance for package prefix with optional scanners */

22

Reflections(String prefix, Scanner... scanners);

23

24

/** Convenient constructor accepting various parameter types */

25

Reflections(Object... params);

26

27

/** Generic query method using QueryFunction - modern functional API */

28

<T> Set<T> get(QueryFunction<Store, T> query);

29

30

/** Get underlying metadata store */

31

Store getStore();

32

33

/** Get configuration object */

34

Configuration getConfiguration();

35

36

/** Merge another Reflections instance into this one */

37

Reflections merge(Reflections reflections);

38

}

39

```

40

41

### Static Collection Methods

42

43

Static methods for collecting and loading pre-saved metadata from various sources.

44

45

```java { .api }

46

/**

47

* Static methods for collecting saved metadata

48

*/

49

class Reflections {

50

/** Collect saved XML metadata from META-INF/reflections */

51

static Reflections collect();

52

53

/** Collect saved metadata with custom package prefix and filter */

54

static Reflections collect(String packagePrefix, Predicate<String> resourceNameFilter);

55

56

/** Collect saved metadata with custom serializer */

57

static Reflections collect(String packagePrefix, Predicate<String> resourceNameFilter, Serializer serializer);

58

59

/** Collect metadata from input stream using specified serializer */

60

Reflections collect(InputStream inputStream, Serializer serializer);

61

62

/** Collect metadata from file using specified serializer */

63

Reflections collect(File file, Serializer serializer);

64

}

65

```

66

67

### Super Type Expansion

68

69

Methods for expanding super types to achieve transitivity in type hierarchies.

70

71

```java { .api }

72

/**

73

* Super type expansion for transitivity

74

*/

75

class Reflections {

76

/**

77

* Expand super types after scanning for types that were not directly scanned

78

* Provides transitive closure of metadata without scanning large 3rd party URLs

79

*/

80

void expandSuperTypes(Map<String, Set<String>> subTypesStore,

81

Map<String, Set<String>> typesAnnotatedStore);

82

}

83

```

84

85

### Metadata Access Methods

86

87

Methods for accessing specific metadata and usage information.

88

89

```java { .api }

90

/**

91

* Metadata access methods

92

*/

93

class Reflections {

94

/** Get parameter names for method or constructor using MethodParameterNamesScanner */

95

List<String> getMemberParameterNames(Member member);

96

97

/** Get code usage locations for member using MemberUsageScanner */

98

Collection<Member> getMemberUsage(Member member);

99

100

/** Get all keys/values for a specific scanner */

101

Set<String> getAll(Scanner scanner);

102

103

/** @Deprecated Get all scanned type names */

104

@Deprecated Set<String> getAllTypes();

105

}

106

```

107

108

### Serialization Methods

109

110

Methods for saving and loading scanned metadata to and from files.

111

112

```java { .api }

113

/**

114

* Serialization and file operations

115

*/

116

class Reflections {

117

/** Save metadata to file using default XmlSerializer */

118

File save(String filename);

119

120

/** Save metadata to file using specified serializer */

121

File save(String filename, Serializer serializer);

122

}

123

```

124

125

## Usage Examples

126

127

### Basic Setup

128

129

```java

130

import org.reflections.Reflections;

131

import org.reflections.util.ConfigurationBuilder;

132

133

// Simple package scanning with defaults

134

Reflections reflections = new Reflections("com.mycompany");

135

136

// Custom configuration

137

Reflections reflections = new Reflections(new ConfigurationBuilder()

138

.forPackages("com.mycompany.api", "com.mycompany.core")

139

.addScanners(Scanners.SubTypes, Scanners.TypesAnnotated)

140

.filterInputsBy(new FilterBuilder().includePackage("com.mycompany")));

141

```

142

143

### Modern Functional Query API

144

145

```java

146

import static org.reflections.scanners.Scanners.*;

147

148

// Query subtypes using functional API

149

Set<Class<?>> subtypes = reflections.get(SubTypes.of(MyInterface.class).asClass());

150

151

// Query annotated methods with filtering

152

Set<Method> publicMethods = reflections.get(

153

MethodsAnnotated.with(MyAnnotation.class)

154

.as(Method.class)

155

.filter(method -> Modifier.isPublic(method.getModifiers())));

156

157

// Query resources with pattern matching

158

Set<String> configFiles = reflections.get(Resources.with(".*\\.xml"));

159

```

160

161

### Collection and Merging

162

163

```java

164

// Collect pre-saved metadata

165

Reflections collected = Reflections.collect();

166

167

// Merge multiple Reflections instances

168

Reflections combined = new Reflections("com.mycompany.core")

169

.merge(new Reflections("com.mycompany.api"))

170

.merge(collected);

171

172

// Access underlying store and configuration

173

Store store = reflections.getStore();

174

Configuration config = reflections.getConfiguration();

175

```

176

177

### Store Management

178

179

```java

180

// Create from existing store

181

Store existingStore = new Store();

182

Reflections fromStore = new Reflections(existingStore);

183

184

// Get raw store data

185

Map<String, Map<String, Set<String>>> storeData = reflections.getStore();

186

187

// Expand super types for transitivity

188

reflections.expandSuperTypes(

189

store.get("SubTypes"),

190

store.get("TypesAnnotated"));

191

```

192

193

### Member Information Access

194

195

```java

196

// Get parameter names for methods/constructors (requires MethodParameterNamesScanner)

197

Method method = MyClass.class.getMethod("myMethod", String.class, int.class);

198

List<String> paramNames = reflections.getMemberParameterNames(method);

199

200

// Get code usage locations for members (requires MemberUsageScanner)

201

Field field = MyClass.class.getField("myField");

202

Collection<Member> usages = reflections.getMemberUsage(field);

203

204

// Get all scanned data for a specific scanner

205

Set<String> allSubTypes = reflections.getAll(Scanners.SubTypes);

206

```

207

208

### Saving and Loading Metadata

209

210

```java

211

// Save to XML file (default serializer)

212

File xmlFile = reflections.save("/path/to/reflections-metadata.xml");

213

214

// Save using specific serializer

215

File jsonFile = reflections.save("/path/to/metadata.json", new JsonSerializer());

216

217

// Save to Java source code

218

File javaFile = reflections.save("/path/to/ReflectionsMetadata.java", new JavaCodeSerializer());

219

```

220

221

## Types

222

223

```java { .api }

224

/**

225

* Multimap storage for scanned metadata

226

*/

227

class Store extends HashMap<String, Map<String, Set<String>>> {

228

/** Default constructor */

229

Store();

230

231

/** Constructor with initial store data */

232

Store(Map<String, Map<String, Set<String>>> storeMap);

233

}

234

235

/**

236

* Configuration contract for Reflections instances

237

*/

238

interface Configuration {

239

/** Scanner instances used for indexing metadata */

240

Set<Scanner> getScanners();

241

242

/** URLs to be scanned */

243

Set<URL> getUrls();

244

245

/** Filter used to filter types to be scanned */

246

Predicate<String> getInputsFilter();

247

248

/** Whether to scan URLs in parallel */

249

boolean isParallel();

250

251

/** Optional class loaders for resolving types */

252

ClassLoader[] getClassLoaders();

253

254

/** Whether to expand super types after scanning */

255

boolean shouldExpandSuperTypes();

256

}

257

258

/**

259

* Runtime exception for Reflections operations

260

*/

261

class ReflectionsException extends RuntimeException {

262

ReflectionsException(String message);

263

ReflectionsException(String message, Throwable cause);

264

ReflectionsException(Throwable cause);

265

}

266

```