Skip to content

Expose line number of the definition of a JavaMember #75

@rweisleder

Description

@rweisleder

For a custom ArchCondition that checks the definition of a JavaClass/JavaMethod/JavaField it would be useful to append the declaration line to the error message as clickable link.

Example:

all(javaMethods).should(haveNameStartingWithLowerCase()).check(javaClasses);

private ArchCondition<JavaMethod> haveNameStartingWithLowerCase() {
    return new ArchCondition<JavaMethod>("have name starting with lower case") {
        @Override
        public void check(JavaMethod item, ConditionEvents events) {
            boolean satisfied = Character.isLowerCase(item.getName().charAt(0));
            String message = item.getFullName() + " " + Formatters.formatLocation(item.getOwner(), item.getDeclarationLineNumber());
            events.add(new SimpleConditionEvent(item, satisfied, message));
        }
    };
}

would print

java.lang.AssertionError: Architecture Violation [Priority: MEDIUM] - Rule 'methods should have name starting with lower case' was violated (1 times):
demo.GreetEndpoint.Greet(java.lang.String) (GreetEndpoint.java:23)

Relates to #38

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions