How kusumotolab/lgmatcher works
Project type and purpose
• This is a Java library (LGMatcher) that provides a line-based matching algorithm built on top of GumTree’s AST diff engine.
• Its purpose is to expose a Matcher API (LGMatcher.create(...)) that takes source/destination code content, their parsed ASTs, and initial mappings, then produces line-level diffs and match information.
File structure
• Top-level:
• build.gradle, settings.gradle, Gradle wrapper → standard Java/Gradle build
• src/main/java/com/github/kusumotolab/lgmatcher → core library code
• example/LGMatcherSample → sample application demonstrating usage
• Core packages:
• FilePosConverter.java → converts GumTree node positions into file offsets
• LGMatcher.java → factory for the Matcher instance
• LineMatcher.java → orchestrates the matching pipeline
• MayersDiff.java (in line subpackage) → implements the Myers diff algorithm on line sequences
• entity subpackage → data classes: LineDiff, LineMatch, MatchInformation, Range
• No UI or network components; this is a “library + example app” structure.
Key README insights
• The only external runtime dependency is GumTree (for AST parsing/diffing).
• Usage is via a single static factory method.
1. Example App (LGMatcherSample)
2. LGMatcher Library
3. GumTree Engine (external dependency)
4. Output Entities (LineDiff, LineMatch, MatchInformation)
• Example App → calls → LGMatcher.create(srcContent, dstContent, srcTree, dstTree, mappings)
• LGMatcher Library → invokes → GumTree Engine (for AST parsing & initial mappings)
• LGMatcher Library internal pipeline:
‑ FilePosConverter
‑ LineMatcher
‑ MayersDiff
• LineMatcher → produces → Entities
• Entities → returned → Example App
c. Architectural patterns / principles:
• Layered pipeline: input conversion → matching algorithm → entity construction
• Separation of concerns: conversion, matching logic, data representation
• Dependency inversion: core algorithm depends on abstract mappings from GumTree
d. Key technologies:
• Java 8+
• Gradle build system
• GumTree (AST diff)