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

organize imports seem to ignore and remove static imports without fixing the dependent code #2861

Closed
maxandersen opened this issue Jan 7, 2023 · 4 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#2396
Assignees
Labels

Comments

@maxandersen
Copy link
Contributor

///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 17+
//FILES application.properties=aggregatePom.properties
//DEPS io.quarkus:quarkus-bom:${quarkus.version:2.11.2.Final}@pom
//DEPS io.quarkus:quarkus-picocli
//DEPS io.quarkus:quarkus-qute

import static java.nio.file.Files.*;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List;

import javax.enterprise.context.Dependent;
import javax.inject.Inject;

import org.jboss.logging.Logger;

import io.quarkus.qute.Qute;
import picocli.CommandLine;
import picocli.CommandLine.Option;

@CommandLine.Command(description = "Generate an aggregate POM file for direct sub-folders",
                    version = "aggregatePom 0.1")
public class main implements Runnable {

    @Option(names = { "--groupId" }, description = "The groupId", defaultValue = "org.acme")
    String groupId;

    @Option(names = { "--artifactId" }, description = "The artifactId", defaultValue = "artifactId")
    String artifactId;

    @Option(names = { "--version" }, description = "The version", defaultValue = "999-SNAPSHOT")
    String version;

    @Inject
    Logger log;

    String pomTemplate = """
        <?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 http://maven.apache.org/maven-v4_0_0.xsd">
            <groupId>{GroupId}</groupId>
                <artifactId>{ArtifactId}</artifactId>
                <version>{Version}</version>
                <packaging>pom</packaging>
                <modelVersion>4.0.0</modelVersion>
                <modules>
                {#each Modules}
                        <module>{it}</module>
                {/each}
                </modules>
        </project>
        """;

    @Override
    public void run() {
            try {
                 modules = new ArrayList<>();
    
                list(Path.of(".")).forEach(p -> {
                    if (isDirectory(p) && exists(p.resolve("pom.xml"))) {
                        modules.add(p.getFileName().toString());
                    }
                });
    
                writeString(Path.of("pom.xml"),
                        Qute.fmt(pomTemplate)
                                .data("GroupId", groupId)
                                .data("ArtifactId", artifactId)
                                .data("Version", version)
                                .data("Modules", modules).render(),
                        StandardOpenOption.CREATE,
                        StandardOpenOption.TRUNCATE_EXISTING);
    
            } catch (IOException e) {
                log.fatal(e);
            }
        }
}

try do organize imports and see the static import being removed.

2 issues:

  1. should not remove static imports
  2. if it was to remove static imports; at least fix the existing references to them.
@maxandersen
Copy link
Contributor Author

possibly duplicate of #2294

@fbricon
Copy link
Collaborator

fbricon commented Jan 7, 2023

Does it happen with or without jbang-vscode?

@snjeza
Copy link
Contributor

snjeza commented Jan 11, 2023

This issue can't be reproduced in Eclipse. eclipse-jdtls/eclipse.jdt.ls#2396 fixes it.

possibly duplicate of #2294

The issue described at #2294 can be reproduced in Eclipse and IntelliJ IDEA

@snjeza
Copy link
Contributor

snjeza commented Jan 11, 2023

  1. should not remove static imports

You can add

 "java.sources.organizeImports.staticStarThreshold": 1
  1. if it was to remove static imports; at least fix the existing references to them.
 "java.sources.organizeImports.staticStarThreshold": 99 

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

Successfully merging a pull request may close this issue.

4 participants