Migration Deep Dive für 14 · Annotations und Reflection öffnen →
⌂ ÜbersichtAlle Vergleiche
Modul 14 · 100 % Codeabdeckung

Annotations und Reflection

Vollständiger Legacy-Modern-Vergleich aller Java-Klassen, Tests, Maven-POMs und relevanten Ressourcen dieses Moduls. Jede Datei ist genau einmal einer fachlich passenden Vergleichsgruppe zugeordnet.

4Legacy-Dateien
5Modern-Dateien
77 → 105Codezeilen
10/10vollständig erfasst

Fachliche Einordnung

Legacy

Namenskonvention und Reflection

Methoden werden über Namen oder implizite Konventionen erkannt.

Modern

Eigene @Command-Annotation

Eine Runtime-Annotation markiert die erlaubten Methoden explizit.

Vergleichsfokus: Alle Dateien werden nach technischer Rolle und fachlicher Verantwortung gruppiert.
Wichtige Abgrenzung: One-to-many-Änderungen werden als Gruppe dargestellt; eine künstliche 1:1-Zuordnung wird vermieden.

Vollständige Abdeckungsmatrix

Die Ähnlichkeit ist eine technische Orientierung auf normalisiertem Quelltext. Sie ersetzt keine fachliche Bewertung.

VergleichsgruppeLegacy-DateienModern-DateienLegacy-ZeilenModern-ZeilenÄhnlichkeit
Build-Konfiguration113434100%
Registry, Annotation und Test23325841%
Kommandos11111380%

Gemeinsame Modulstruktur

Das Pair-POM bindet die Legacy- und Modern-Submodule zusammen und gehört deshalb ebenfalls zur vollständigen Codeabdeckung.

Gemeinsam · 19 Zeilenpom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>at.aydin.academy</groupId>
        <artifactId>java-modernization-deep-dive</artifactId>
        <version>1.0.0</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>
    <artifactId>14annotationsreflection-pair</artifactId>
    <packaging>pom</packaging>
    <name>Annotations und Reflection: Legacy und Modern</name>
    <modules>
        <module>legacy</module>
        <module>modern</module>
    </modules>
</project>

Alle semantischen Codevergleiche

01Build-KonfigurationDirektvergleich · Legacy 34 / Modern 34 Zeilen · Ähnlichkeit 100%

Reflection-/Testkonfiguration wird verglichen.

Legacy-DateienModern-DateienEinordnung
pom.xmlpom.xmlDirektvergleich
Semantische Ähnlichkeit: 100%

Legacy

Legacy · 34 Zeilenlegacy/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
        <project xmlns="http://maven.apache.org/POM/4.0.0"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
            <modelVersion>4.0.0</modelVersion>
            <parent>
                <groupId>at.aydin.academy</groupId>
                <artifactId>14annotationsreflection-pair</artifactId>
                <version>1.0.0</version>
                <relativePath>../pom.xml</relativePath>
            </parent>
            <artifactId>annotations-reflection-legacy</artifactId>
            <packaging>jar</packaging>
            <name>Annotations Reflection Legacy</name>

            <dependencies>

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <scope>test</scope>
</dependency>

            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                    </plugin>

                </plugins>
            </build>
        </project>

Modern

Modern · 34 Zeilenmodern/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
        <project xmlns="http://maven.apache.org/POM/4.0.0"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
            <modelVersion>4.0.0</modelVersion>
            <parent>
                <groupId>at.aydin.academy</groupId>
                <artifactId>14annotationsreflection-pair</artifactId>
                <version>1.0.0</version>
                <relativePath>../pom.xml</relativePath>
            </parent>
            <artifactId>annotations-reflection-modern</artifactId>
            <packaging>jar</packaging>
            <name>Annotations Reflection Modern</name>

            <dependencies>

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <scope>test</scope>
</dependency>

            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                    </plugin>

                </plugins>
            </build>
        </project>
02Registry, Annotation und TestDirektvergleich · Legacy 32 / Modern 58 Zeilen · Ähnlichkeit 41%

Namenskonvention wird durch explizite Annotation und geprüfte Registry ersetzt.

Legacy-DateienModern-DateienEinordnung
LegacyCommandRegistry.java
LegacyCommandRegistryTest.java
Command.java
CommandRegistry.java
CommandRegistryTest.java
Direktvergleich
Semantische Ähnlichkeit: 41%

Legacy

package at.aydin.lab.annotations.legacy;

import java.lang.reflect.*;

// Design Pattern: Registry
// Zweck: Historische Registrierung über String-Konventionen und Reflection.
public final class LegacyCommandRegistry {
    private final Object target;
    public LegacyCommandRegistry(Object target) {
        this.target = target;
    }

    public String execute(String command, String argument) {
        try {
            Method m = target.getClass().getMethod("command_" + command, String.class);
            return (String) m.invoke(target, argument);
        } catch (ReflectiveOperationException ex) {
            throw new IllegalArgumentException("Unbekanntes Kommando: " + command, ex);
        }
    }
}
package at.aydin.lab.annotations.legacy;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

class LegacyCommandRegistryTest {
    @Test
    void invokesByNamingConvention() {
        assertEquals("Hallo Test", new LegacyCommandRegistry(new LegacyCommands()).execute("hello", "Test"));
    }
}

Modern

package at.aydin.lab.annotations.modern;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

// Design Pattern: Command + Metadata Registry
// Zweck: Annotationen machen Namen explizit und entkoppeln sie von Methodenkonventionen.
public final class CommandRegistry {
    private record Handler(Object target, Method method) {}

    private final Map<String, Handler> handlers = new HashMap<>();

    public CommandRegistry(Object... targets) {
        for (Object target : targets) {
            for (Method method : target.getClass().getDeclaredMethods()) {
                Command command = method.getAnnotation(Command.class);
                if (command != null) {
                    handlers.put(command.value(), new Handler(target, method));
                }
            }
        }
    }

    public String execute(String command, String argument) {
        Handler handler = Optional.ofNullable(handlers.get(command))
                .orElseThrow(() -> new IllegalArgumentException(
                        "Unbekanntes Kommando: " + command));
        try {
            return (String) handler.method().invoke(handler.target(), argument);
        } catch (ReflectiveOperationException exception) {
            throw new IllegalStateException(exception);
        }
    }
}
package at.aydin.lab.annotations.modern;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

class CommandRegistryTest {
    @Test
    void usesExplicitAnnotation() {
        assertEquals("Hallo Test", new CommandRegistry(new ModernCommands()).execute("hello", "Test"));
    }
}
03KommandosDirektvergleich · Legacy 11 / Modern 13 Zeilen · Ähnlichkeit 80%

Aufrufbare Methoden werden direkt verglichen.

Legacy-DateienModern-DateienEinordnung
LegacyCommands.javaModernCommands.javaDirektvergleich
Semantische Ähnlichkeit: 80%

Legacy

Modern

⌂ Cockpit