'Is there quick way to find static variables in Java in Netbeans to decrease initial memory?

SITUATION:
Hello; for years in all my projects,
I have been using static variables, to make codes talk with each other.

CONDITION:
I am specifically using Netbeans. But you can share other IDE solutions so people can see.

QUESTION:
Is there any way to find them all?
So, I can turn them into functions, to decrease some initial memory.

Thanks!



Solution 1:[1]

I couldnot find an IDE solution to help coders. So, I came up with my own answer.

  • I recursively find all java files
  • read them as lines
  • selectively log them to a text file

Here is an example:

package com.tugalsan.tryout5;

import com.tugalsan.api.file.server.*;
import com.tugalsan.api.file.txt.server.*;
import java.nio.file.*;
import java.util.stream.*;

public class Run {

    public static void main(String... args) {
        var parentDirectory = Path.of("C:\\me\\codes\\GWT");
        var results = parentDirectory.resolve("results.log");
        TS_FileUtils.deleteFileIfExists(results);
        var append = true;
        var fileNameMatcher = "*.java";
        var sorted = false;
        var recursive = true;
        TS_DirectoryUtils.subFiles(parentDirectory, fileNameMatcher, sorted, recursive).forEach(javaFile -> {
            var lines = TS_FileTXTUtils.toArrayList(javaFile);
            IntStream.range(0, lines.size())
                    .filter(idx -> lines.get(idx).contains("static"))
                    .filter(idx -> !lines.get(idx).contains("import"))
                    .filter(idx -> !lines.get(idx).contains("class"))
                    .filter(idx -> !lines.get(idx).contains("interface"))
                    .filter(idx -> !lines.get(idx).contains("("))
                    .forEach(idx -> {
                        var line = lines.get(idx);
                        var logLine = String.join("", javaFile.toString(), ", ", String.valueOf(idx), ", ", line, "\n");
                        TS_FileTXTUtils.toFile(logLine, results, append);
                    });
        });
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1