Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Javadoc of class missing #5757

Open
Luro02 opened this issue Apr 10, 2024 · 1 comment
Open

[Bug]: Javadoc of class missing #5757

Luro02 opened this issue Apr 10, 2024 · 1 comment
Labels

Comments

@Luro02
Copy link
Contributor

Luro02 commented Apr 10, 2024

Describe the bug

The javadoc of the class vanishes when it is the first thing in the file. Adding a single space in front of the /** solves the issue.

Source code you are trying to analyze/transform

/**
 * This {@link RunCommand} executes a run on the target.
 * if (a) {
 * print(a);
 * }
 */
public class RunCommand {
    // some comment
}

Source code for your Spoon processing

import spoon.Launcher;
import spoon.reflect.CtModel;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.visitor.filter.TypeFilter;
import spoon.support.compiler.VirtualFile;

public final class Main {
    private static CtModel buildModel() {
        Launcher launcher = new Launcher();

        launcher.addInputResource(new VirtualFile(
            """
                /**
                 * This {@link RunCommand} executes a run on the target.
                 * if (a) {
                 * print(a);
                 * }
                 */
                public class RunCommand {
                    // some comment
                }
                """,
            "RunCommand"
        ));

        return launcher.buildModel();
    }

    public static void main(String[] args) {
        CtModel ctModel = buildModel();

        System.out.println(ctModel.getElements(new TypeFilter<>(CtClass.class)));
    }
}

Actual output

[// some comment
public class RunCommand {}]

Process finished with exit code 0

Expected output

[/**
 * This {@link RunCommand} executes a run on the target.
 * if (a) {
 * print(a);
 * }
 */
// some comment
public class RunCommand {}]

Process finished with exit code 0

Spoon Version

11.0.0

JVM Version

openjdk version "21.0.2" 2024-01-16 LTS OpenJDK Runtime Environment Zulu21.32+17-CA (build 21.0.2+13-LTS) OpenJDK 64-Bit Server VM Zulu21.32+17-CA (build 21.0.2+13-LTS, mixed mode, sharing)

What operating system are you using?

Windows

@Luro02 Luro02 added the bug label Apr 10, 2024
@tenax66
Copy link
Contributor

tenax66 commented May 12, 2024

This seems to be related to the specification of org.eclipse.jdt.internal.compiler.parser.Scanner.

If there is a whitespace at the beginning of the target file, it is consumed before proceeding to Javadoc comment, and Javadoc comment is interpreted as the start of the class definition, so to speak.
However, if there are no spaces at the beginning, Javadoc comment is processed alonely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants