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

Object only used in String template is marked as unused #39

Open
EotT123 opened this issue Jun 2, 2024 · 7 comments
Open

Object only used in String template is marked as unused #39

EotT123 opened this issue Jun 2, 2024 · 7 comments

Comments

@EotT123
Copy link

EotT123 commented Jun 2, 2024

Objects that are only used in a String Template are marked as unused.

screenshot 47
screenshot 48

Also applies to method parameters:

screenshot 50

@EotT123
Copy link
Author

EotT123 commented Jun 3, 2024

An even worse case:
Using a static method call inside a String template expression, e.g.

String text = "${StringUtils.substring(value, 1)}"

If StringUtils class is not used elsewhere, it is marked as unused. If configured in IntelliJ, it gets removed automatically from the list of imports, resulting in a compilation failure.

@rsmckinney
Copy link
Member

I am not seeing any of this, all of this is implemented.
image
What version of the plugin / IJ / etc. are you using?

@EotT123
Copy link
Author

EotT123 commented Jun 4, 2024

Latest version of everything:

  • Manifold plugin: 2024.1.5
  • IntelliJ IDEA 2024.1.2 (Community Edition)

This also happens for me with the sample project:

screenshot 51

@rsmckinney
Copy link
Member

Looking at your earlier screenshots, it appears string templates aren't really enabled, for instance local var usage s/b highlighted. This is probably the root of the problem. Can you provide your build file[s]? A simple change will probably fix things up for you.

@EotT123
Copy link
Author

EotT123 commented Jun 5, 2024

It is enabled. Using the manifold-strings-test project (I didn't change anything), all tests pass successfully, but the 'never used' warning is still present.

screenshot 48

Edit:
For some reason, it's highlighted now and the warning dissapeared.
screenshot 49

However, it's not fixed everywhere. Method parameters still don't get marked as being used:
screenshot 51

So now I'm not sure anymore what the config should be. When looking at the documentation, I see that only an annotated processor is added:

<annotationProcessorPaths>
  <path>
    <groupId>systems.manifold</groupId>
    <artifactId>manifold-strings</artifactId>
    <version>${manifold.version}</version>
  </path>
</annotationProcessorPaths>

However, I don't see this in the manifold-strings-test project; it is only added as a dependency.
As a test, I've added them both, but it didn't change anything:

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <manifold.version>2024.1.17</manifold.version>
        <maven.compiler.source>22</maven.compiler.source>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <compilerArgs>
                        <arg>-Xplugin:Manifold</arg>
                    </compilerArgs>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>systems.manifold</groupId>
                            <artifactId>manifold-strings</artifactId>
                            <version>${manifold.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>systems.manifold</groupId>
            <artifactId>manifold-strings</artifactId>
            <version>${manifold.version}</version>
        </dependency>
    </dependencies>
</project>

It looks like only the dependency is needed, not the annotationProcessorPath.


edit2: It does work when I add it in the manifold-strings-test project:

screenshot 52

@rsmckinney
Copy link
Member

Yeah, most of the test modules aren't setup for IntelliJ use. Always refer to the setup docs for manifold features. In this case, see the manifold-strings setup docs. Also see the android docs if you're working in that environment.

@superxiao
Copy link

I have the same issue. Intellij thinks a static function that's used in a string template as unused, and removes it when organizing imports. Intellij manifold plugin version 2024.1.6, pom.xml:

  <properties>
    <manifold.version>2024.1.21</manifold.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>systems.manifold</groupId>
      <artifactId>manifold-ext-rt</artifactId>
      <version>${manifold.version}</version>
    </dependency>
    <dependency>
      <groupId>systems.manifold</groupId>
      <artifactId>manifold-rt</artifactId>
      <version>${manifold.version}</version>
    </dependency>
    <dependency>
      <groupId>systems.manifold</groupId>
      <artifactId>manifold-collections</artifactId>
      <version>${manifold.version}</version>
    </dependency>
    <dependency>
      <groupId>systems.manifold</groupId>
      <artifactId>manifold-strings</artifactId>
      <version>${manifold.version}</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.11.0</version>
        <configuration>
          <source>17</source>
          <target>17</target>
          <encoding>UTF-8</encoding>
          <compilerArgs>
            <!-- Configure manifold plugin -->
            <arg>-Xplugin:Manifold</arg>
          </compilerArgs>
          <annotationProcessorPaths>
            <path>
              <groupId>systems.manifold</groupId>
              <artifactId>manifold</artifactId>
              <version>${manifold.version}</version>
            </path>
            <path>
              <groupId>systems.manifold</groupId>
              <artifactId>manifold-ext</artifactId>
              <version>${manifold.version}</version>
            </path>
            <path>
              <groupId>systems.manifold</groupId>
              <artifactId>manifold-strings</artifactId>
              <version>${manifold.version}</version>
            </path>
            <path>
              <groupId>systems.manifold</groupId>
              <artifactId>manifold-exceptions</artifactId>
              <version>${manifold.version}</version>
            </path>
          </annotationProcessorPaths>
        </configuration>
      </plugin>
    </plugins>
  </build>

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

No branches or pull requests

3 participants