-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support method and constructor parameter annotations #701
This will extend the domain model of ArchUnit by providing * `List<Parameter> JavaCodeUnit.getParameters()` * `List<List<JavaAnnotation<Parameter>> JavaCodeUnit.getParameterAnnotations()` where `Parameter` also offers `getParameterType()`, `getRawParameterType()` and `getAnnotations()`. Furthermore parameter annotations are now part of `JavaClass.directDependencies{From/To}Self`. On the contrary to the Java Reflection API the `JavaCodeUnit.getParameters()` will exactly mirror the (possibly generic) signature and not the raw types. This means that for generic signatures synthetic raw type parameter types (like `name` and `ordinal` for an enum constructor) will not be visible in the `List<Parameter>`. I think for ArchUnit this makes sense, as there is limited interest in synthetic parts of the code and users are only interested in the parameters that have really been introduced by source code. Unfortunately there are many cases where the bytecode does not contain the signature attribute (whenever the signature is non-generic, i.e. does not contain any parameterized types, type variables, etc.). In these cases the parameters will still mirror the raw types (including possible synthetic parameters), because there is no other source of information where the parameters could be derived from. It is also not i.g. possible to derive which parameters are synthetic and which are not, so ArchUnit does not attempt this at all at the moment. Resolves: #404 Resolves: #373 Resolves: #113
- Loading branch information
Showing
34 changed files
with
1,309 additions
and
220 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
...e-plain/src/main/java/com/tngtech/archunit/example/layers/controller/OtherController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.tngtech.archunit.example.layers.controller; | ||
|
||
import com.tngtech.archunit.example.layers.controller.marshaller.StringUnmarshaller; | ||
|
||
@SuppressWarnings("unused") | ||
public class OtherController { | ||
void receive(@UnmarshalTransport(StringUnmarshaller.class) Object param) { | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...lain/src/main/java/com/tngtech/archunit/example/layers/controller/UnmarshalTransport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.tngtech.archunit.example.layers.controller; | ||
|
||
import java.lang.annotation.Retention; | ||
|
||
import com.tngtech.archunit.example.layers.controller.marshaller.Unmarshaller; | ||
|
||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
@Retention(RUNTIME) | ||
public @interface UnmarshalTransport { | ||
Class<? extends Unmarshaller<?>>[] value(); | ||
} |
8 changes: 8 additions & 0 deletions
8
...main/java/com/tngtech/archunit/example/layers/controller/marshaller/ByteUnmarshaller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.tngtech.archunit.example.layers.controller.marshaller; | ||
|
||
public class ByteUnmarshaller implements Unmarshaller<Byte> { | ||
@Override | ||
public <T> T unmarschal(Byte from) { | ||
return null; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...in/java/com/tngtech/archunit/example/layers/controller/marshaller/StringUnmarshaller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.tngtech.archunit.example.layers.controller.marshaller; | ||
|
||
public class StringUnmarshaller implements Unmarshaller<String> { | ||
@Override | ||
public <T> T unmarschal(String from) { | ||
return null; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...src/main/java/com/tngtech/archunit/example/layers/controller/marshaller/Unmarshaller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.tngtech.archunit.example.layers.controller.marshaller; | ||
|
||
public interface Unmarshaller<F> { | ||
@SuppressWarnings("unused") | ||
<T> T unmarschal(F from); | ||
} |
11 changes: 11 additions & 0 deletions
11
...ain/java/com/tngtech/archunit/example/layers/service/OtherServiceViolatingLayerRules.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.tngtech.archunit.example.layers.service; | ||
|
||
import com.tngtech.archunit.example.layers.controller.UnmarshalTransport; | ||
import com.tngtech.archunit.example.layers.controller.marshaller.ByteUnmarshaller; | ||
import com.tngtech.archunit.example.layers.controller.marshaller.StringUnmarshaller; | ||
|
||
public class OtherServiceViolatingLayerRules { | ||
@SuppressWarnings("unused") | ||
public void dependentOnParameterAnnotation(@UnmarshalTransport({StringUnmarshaller.class, ByteUnmarshaller.class}) Object param) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.