Skip to content

Commit

Permalink
Adds a @component annotation.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Sep 18, 2024
1 parent f26f63d commit e8dfc59
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
6 changes: 6 additions & 0 deletions structurizr-annotation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@

[![Maven Central](https://img.shields.io/maven-central/v/com.structurizr/structurizr-annotation.svg?label=Maven%20Central)](https://search.maven.org/artifact/com.structurizr/structurizr-annotation)

This library defines some custom annotations that you can add to your code.
These serve to either make it explicit how components should be extracted from your codebase (e.g. `@Component`),
or they help supplement the software architecture model (e.g. `@Property`, `@Tag`).

- This library has no dependencies.
- All annotations have a runtime retention policy, so they will be present in the compiled bytecode.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.structurizr.annotation;

import java.lang.annotation.*;

/**
* A type-level annotation that can be used to indicate the type represents a component.
*/
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Component {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.structurizr.component.matcher;

import com.structurizr.annotation.Component;
import com.structurizr.component.Type;
import org.apache.bcel.classfile.ClassParser;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -54,7 +55,7 @@ void matches_ReturnsTrue_WhenThereIsAMatch() throws Exception {
ClassParser parser = new ClassParser(new File(classes, "com/structurizr/component/matcher/annotationTypeMatcher/CustomerController.class").getAbsolutePath());
Type type = new Type(parser.parse());

assertTrue(new AnnotationTypeMatcher("com.structurizr.component.matcher.annotationTypeMatcher.Controller").matches(type));
assertTrue(new AnnotationTypeMatcher(Component.class.getName()).matches(type));
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.structurizr.component.matcher.annotationTypeMatcher;

@Controller
import com.structurizr.annotation.Component;

@Component
public class CustomerController {
}

0 comments on commit e8dfc59

Please sign in to comment.