Find Usages in Compiled Dependencies

(Difference between revisions)
Line 1: Line 1:
-
=Find Usages in Compiled Dependencies=
 
To find where a class, interface, method, or field is used in your project, you use the Find Usages command. From NetBeans 8.1 you can also find where they are used in the dependencies of your project. To get the results from your project's dependencies, NetBeans indexes the binary version of these dependencies. Searching for usages in compiled dependencies has certain limitations.
To find where a class, interface, method, or field is used in your project, you use the Find Usages command. From NetBeans 8.1 you can also find where they are used in the dependencies of your project. To get the results from your project's dependencies, NetBeans indexes the binary version of these dependencies. Searching for usages in compiled dependencies has certain limitations.
Line 10: Line 9:
===Missing Annotations with RetentionPolicy.SOURCE===
===Missing Annotations with RetentionPolicy.SOURCE===
 +
Annotations with RetentionPolicy.SOURCE are to be discarded by the compiler.
-
===Missing unused imports===
+
====example from [http://wiki.apidesign.org/wiki/CompileTimeCache API Design]====
 +
<source lang="java">
 +
@Retention(RetentionPolicy.SOURCE)
 +
@Target(ElementType.METHOD)
 +
public @interface Words {
 +
}
 +
</source>
-
===Missing field access on constants.===
+
<source lang="java">
 +
public class WordsFactory {
 +
    @Words
 +
    public static String[] myWords() {
 +
        return new String[] {
 +
            "microprocessor",
 +
            "navigation",
 +
            "optimization",
 +
            "parameter",
 +
            "patrick",
 +
        };
 +
    }
 +
}
 +
</source>
 +
 
 +
The @Words annotation has RetentionPolicy.SOURCE. This means that it shall not propagate to resulting bytecode and will not be found in dependencies.
 +
 
 +
===Unused imports===
 +
Unused imports will be discarded by the compiler.
 +
 
 +
====example====
 +
<source lang="java">
 +
import java.io.File;
 +
public class Foo {
 +
}
 +
</source>
 +
 
 +
===Field access on constants.===
According to JLS the constant is defined as static final primitive type or string which value is constant in compile time. For example: public static final String PROP_ENTRIES = "entries"; In the JDK 9 there should be an unused CONSTANT_Fieldref in constant pool emitted by compiler which will fix the problem.
According to JLS the constant is defined as static final primitive type or string which value is constant in compile time. For example: public static final String PROP_ENTRIES = "entries"; In the JDK 9 there should be an unused CONSTANT_Fieldref in constant pool emitted by compiler which will fix the problem.
-
===Missing references from if (compile time false) blocks.===
+
===References from if (compile time false) blocks.===
 +
 
 +
<source lang="java">
private static final boolean DEBUG = false;
private static final boolean DEBUG = false;
...
...
Line 22: Line 57:
     ....
     ....
}
}
 +
</source>
-
===Missing references on types which are just referred in the method bodies (no method call
+
===LocalVarsTable===
-
or field access is done on them) unless you compile with -g:vars. These references are not present due to missing Local Variable Table.===
+
Missing references on types which are just referred in the method bodies (no method call or field access is done on them) unless you compile with -g:vars. These references are not present due to missing Local Variable Table.

Revision as of 13:20, 30 August 2015

To find where a class, interface, method, or field is used in your project, you use the Find Usages command. From NetBeans 8.1 you can also find where they are used in the dependencies of your project. To get the results from your project's dependencies, NetBeans indexes the binary version of these dependencies. Searching for usages in compiled dependencies has certain limitations.

Contents


Find Usages limitations

Missing type references in the byte code

Missing Annotations with RetentionPolicy.SOURCE

Annotations with RetentionPolicy.SOURCE are to be discarded by the compiler.

example from API Design

@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.METHOD)
public @interface Words {
}
public class WordsFactory {
    @Words
    public static String[] myWords() {
        return new String[] {
            "microprocessor",
            "navigation",
            "optimization",
            "parameter",
            "patrick",
        };
    }
}

The @Words annotation has RetentionPolicy.SOURCE. This means that it shall not propagate to resulting bytecode and will not be found in dependencies.

Unused imports

Unused imports will be discarded by the compiler.

example

import java.io.File;
public class Foo {
}

Field access on constants.

According to JLS the constant is defined as static final primitive type or string which value is constant in compile time. For example: public static final String PROP_ENTRIES = "entries"; In the JDK 9 there should be an unused CONSTANT_Fieldref in constant pool emitted by compiler which will fix the problem.

References from if (compile time false) blocks.

private static final boolean DEBUG = false;
...
if (DEBUG) {
     ....
}

LocalVarsTable

Missing references on types which are just referred in the method bodies (no method call or field access is done on them) unless you compile with -g:vars. These references are not present due to missing Local Variable Table.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo