Skip to content

Commit a443c8d

Browse files
doc
1 parent e635614 commit a443c8d

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ The best analysis is performed using [external annotations](http://help.eclipse.
77

88
[This repository/project](https://github.com/sylvainlaurent/eclipse-external-annotations) contains a (non-exhaustive but growing) number of external annotations for usual classes (e.g. Map, List, some guava classes...).
99

10-
To automatically associate an "annotation path" with the "Maven Dependencies" and "JRE" libraries in eclipse build path, install eclipse-external-annotations-m2e-plugin from [this p2 repository](http://sylvainlaurent.github.io/eclipse-external-annotations/p2/).
11-
Then add a maven property `m2e.jdt.annotationpath` in your pom, as demonstrated in [with-external-annotations/pom.xml](with-external-annotations/pom.xml).
12-
And finally perform a full `Maven/Update project...` in eclipse.
10+
## Inside eclipse IDE
11+
To automatically associate an "annotation path" with the "Maven Dependencies" and "JRE" libraries in eclipse build path:
12+
- install eclipse-external-annotations-m2e-plugin from [this p2 repository](http://sylvainlaurent.github.io/eclipse-external-annotations/p2/).
13+
- add a maven property `m2e.jdt.annotationpath` in your pom, as demonstrated in [with-external-annotations/pom.xml](with-external-annotations/pom.xml).
14+
- perform a full `Maven/Update project...` in eclipse.
15+
1316
Tip: place the property in a `m2e` profile activated only inside eclipse, not in the command-line (see below for command-line usage).
14-
Using a source project for external annotations in the same eclipse workspace allows to quickly add missing annotations directly from eclipse (by pressing Cmd-1 or Ctr-1 on the type of a method signature).
17+
Using a source project for external annotations in the same eclipse workspace allows to quickly [add missing annotations directly from eclipse](http://help.eclipse.org/neon/topic/org.eclipse.jdt.doc.user/tasks/task-using_external_null_annotations.htm?cp=1_3_9_2_2#create).
1518

1619
```xml
1720
<profile>
@@ -28,6 +31,7 @@ Using a source project for external annotations in the same eclipse workspace al
2831
</profile>
2932
```
3033

34+
## When running maven from the command-line
3135
To perform null-analysis during a maven build, the jdt compiler must be used in place of the default javac, as demonstrated in the `not-m2e` maven profile of [with-external-annotations/pom.xml](with-external-annotations/pom.xml).
3236

3337
```xml
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package packageNonNull;
2+
3+
import org.eclipse.jdt.annotation.NonNullByDefault;
4+
5+
/**
6+
* since the whole package is annotated with {@link NonNullByDefault},
7+
* nullability constraints also apply to this class.
8+
*/
9+
public class ClassInAnnotatedPackage {
10+
11+
public void demo() {
12+
// should report error
13+
echo(null);
14+
}
15+
16+
public String echo(final String str) {
17+
// should warn about useless check / dead code
18+
if (str == null) {
19+
return null;
20+
}
21+
return "hello " + str;
22+
}
23+
}

no-external-annotations/src/main/java/packageNonNull/Main.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
<configuration>
9696
<compilerId>jdt</compilerId>
9797
<compilerArgs>
98-
<!-- <arg>-properties ${project.basedir}/.settings/org.eclipse.jdt.core.prefs</arg> -->
9998
<arg>-properties</arg>
10099
<arg>${project.basedir}/.settings/org.eclipse.jdt.core.prefs</arg>
101100
<arg>-annotationpath</arg>

0 commit comments

Comments
 (0)