class Analyzer::Java::Spring

Defined in:

analyzer/analyzers/java/spring.cr

Constant Summary

ANY_BINDING_RE = Regex.union(SPRING_WEB_BIND_PACKAGE, FEIGN_CLIENT_PACKAGE, "@FeignClient", SPRING_HTTP_EXCHANGE_PACKAGE, "@HttpExchange", "@GetExchange", "@PostExchange", "@PutExchange", "@PatchExchange", "@DeleteExchange", "RouteLocatorBuilder", "PredicateSpec", "org.springframework.cloud.gateway", "org.springframework.web.socket.config.annotation", "WebSocketMessageBrokerConfigurer", "@EnableWebSocketMessageBroker", "org.springframework.messaging.handler.annotation", "@MessageMapping", "@SubscribeMapping", "ResourceHandlerRegistry", "addResourceHandler")

The OR of every marker the annotation branch keys off. A file that misses this cannot set any of the individual flags, so the per-flag scans only run for the handful of files that get past it.

FEIGN_CLIENT_PACKAGE = "org.springframework.cloud.openfeign.FeignClient"
INTERFACE_OR_ABSTRACT_RE = Regex.union("interface", "abstract")

collect_interface_route_index gates.

INTERFACE_ROUTE_MARKER_RE = Regex.union(SPRING_WEB_BIND_PACKAGE, SPRING_HTTP_EXCHANGE_PACKAGE, "@HttpExchange", "@GetExchange", "@PostExchange", "@PutExchange", "@PatchExchange", "@DeleteExchange", "@RequestMapping", "@GetMapping", "@PostMapping")
MESSAGE_MAPPING_BINDING_RE = Regex.union("org.springframework.messaging.handler.annotation", "@MessageMapping", "@SubscribeMapping")
META_ANNOTATION_RE = Regex.union("@interface")
REGEX_ROUTE_CALL = /((?:andRoute|route)\s*\(|\.)\s*(?:RequestPredicates\.)?(GET|POST|DELETE|PUT|PATCH|HEAD|OPTIONS)\s*\(/
REGEX_ROUTER_CODE_BLOCK = /route\(\)?.*?\);/m
RESOURCE_HANDLER_BINDING_RE = Regex.union("ResourceHandlerRegistry", "addResourceHandler")
SPLIT_CONCAT_RULES = Noir::TopLevelSplit::Rules.new(nest: (Noir::TopLevelSplit::Nest::Paren | Noir::TopLevelSplit::Nest::Bracket) | Noir::TopLevelSplit::Nest::Brace, quotes: "\"", escape: Noir::TopLevelSplit::Escape::InQuotes, strip: true, empties: Noir::TopLevelSplit::Empties::DropAll, per_kind: false, clamp: true)

Rules::JAVA minus the single-quote quote style, and dropping EVERY empty part rather than only a trailing one — the old body ended in .map(&.strip).reject(&.empty?), so "a" + + "b" yielded two terms, not three. Both matter to the caller, which concatenates the terms it gets back into a route path. File-local because spring is the only splitter with this combination.

SPRING_HTTP_EXCHANGE_PACKAGE = "org.springframework.web.service.annotation."
SPRING_INDEX_PRESCREEN_RE = Regex.union("setApplicationDestinationPrefixes", SPRING_WEB_BIND_PACKAGE)
SPRING_WEB_BIND_PACKAGE = "org.springframework.web.bind.annotation."
SPRING_WEB_BIND_RE = Regex.union(SPRING_WEB_BIND_PACKAGE)
STOMP_PREFIX_RE = Regex.union("setApplicationDestinationPrefixes")

build_spring_indexes gate: neither index can want a file that mentions neither marker.

WEBSOCKET_BINDING_RE = Regex.union("org.springframework.web.socket.config.annotation", "WebSocketMessageBrokerConfigurer", "@EnableWebSocketMessageBroker")

Every content.includes?(...) below used to be its own Rabin-Karp pass over the whole file. This analyzer asks ~30 such questions per .java file across three walks, and on a monorepo the overwhelming majority of files answer "no" to all of them. One precompiled Regex.union (PCRE2 JIT, via content_matches?) is the same predicate in a single pass — see the note on Analyzer#content_matches?.

Class Method Summary

Instance Method Summary

Instance methods inherited from class Analyzer

analyze analyze, base_path : String base_path, base_paths : Array(String) base_paths, base_relative_path(path : String) : String base_relative_path, callees_needed? : Bool callees_needed?, content_matches?(content : String, markers : Regex) : Bool content_matches?, http_header_name(name : String) : String | Nil http_header_name, line_number_for_index(content : String, char_index : Int32) : Int32 line_number_for_index, logger : NoirLogger logger, parallel_analyze(files : Array(String), &block : String -> Nil) parallel_analyze, read_file_content(path : String) : String read_file_content, result : Array(Endpoint) result, tech : String tech, unique_params(params : Array(Param)) : Array(Param) unique_params, url : String url, web_root_path(path : String, markers : Array(String)) : String web_root_path

Constructor methods inherited from class Analyzer

new(options : Hash(String, YAML::Any)) new

Macros inherited from class Analyzer

analyzer_for(tech) analyzer_for

Instance methods inherited from module FileHelper

all_files : Array(String) all_files, get_files_by_basename(basename : String) : Array(String) get_files_by_basename, get_files_by_extension(extension : String) : Array(String) get_files_by_extension, get_files_by_extensions(extensions : Array(String)) : Array(String) get_files_by_extensions, get_files_by_prefix(prefix : String) : Array(String) get_files_by_prefix, get_files_by_prefix_and_extension(prefix : String, extension : String) : Array(String) get_files_by_prefix_and_extension, get_files_by_relative_path(relative_path : String, root : String = "") : Array(String) get_files_by_relative_path, get_public_dir_files(base_path : String, folder : String) : Array(String) get_public_dir_files, get_public_files(base_path : String, anchors : Array(String) = ["shard.yml", "Gemfile"]) : Array(String) get_public_files, walked_path(expanded : String) : String walked_path

Class Method Detail

def self.tech_name : String #

[View source]

Instance Method Detail

def analyze #

[View source]
def tech : String #

Instance-side view of the same declaration. The per-file rescues live on this base class, which has no way to name the analyzer that is running inside them, so a skipped file could not be attributed to a tech. Deriving it from analyzer_for keeps the name written exactly once.


[View source]