forked from moditect/deptective
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moditect#7 Find more references (Annotations, Type Parameters) WIP
- Loading branch information
1 parent
e65f5e5
commit 051ac2a
Showing
16 changed files
with
312 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
javac-plugin/src/test/java/org/moditect/deptective/plugintest/deps/DependenciesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.moditect.deptective.plugintest.deps; | ||
|
||
import static com.google.testing.compile.CompilationSubject.assertThat; | ||
|
||
import org.junit.Test; | ||
import org.moditect.deptective.plugintest.PluginTestBase; | ||
import org.moditect.deptective.plugintest.deps.model.Model; | ||
import org.moditect.deptective.plugintest.deps.service.Service; | ||
import org.moditect.deptective.plugintest.deps.ui.InvalidAnnotation; | ||
import org.moditect.deptective.plugintest.deps.ui.InvalidAnnotationParameter; | ||
import org.moditect.deptective.plugintest.deps.ui.InvalidGenericUIView; | ||
import org.moditect.deptective.plugintest.deps.ui.InvalidGenericView; | ||
import org.moditect.deptective.plugintest.deps.ui.InvalidTypeView; | ||
import org.moditect.deptective.plugintest.deps.ui.InvalidView; | ||
|
||
import com.google.testing.compile.Compilation; | ||
import com.google.testing.compile.Compiler; | ||
|
||
public class DependenciesTest extends PluginTestBase { | ||
|
||
protected Compilation compileWithModelAndService(Class<?> testClass) { | ||
Compilation compilation = Compiler.javac().withOptions("-Xplugin:Deptective", getConfigFileOption()) | ||
.compile(forTestClass(Model.class), forTestClass(Service.class), forTestClass(testClass)); | ||
|
||
return compilation; | ||
} | ||
|
||
@Test | ||
public void shouldDetectInvalidRefrencesInMethodParameters() { | ||
Compilation compilation = compileWithModelAndService(InvalidView.class); | ||
assertThat(compilation).failed(); | ||
assertThat(compilation).hadErrorContaining( | ||
"package org.moditect.deptective.plugintest.deps.ui does not read org.moditect.deptective.plugintest.deps.model" | ||
); | ||
} | ||
|
||
@Test | ||
public void shouldDetectInvalidRefrencesInTypeArguments() { | ||
Compilation compilation = compileWithModelAndService(InvalidGenericView.class); | ||
assertThat(compilation).failed(); | ||
assertThat(compilation).hadErrorContaining( | ||
"package org.moditect.deptective.plugintest.deps.ui does not read org.moditect.deptective.plugintest.deps.model" | ||
); | ||
|
||
compilation = compileWithModelAndService(InvalidGenericUIView.class); | ||
assertThat(compilation).failed(); | ||
assertThat(compilation).hadErrorContaining( | ||
"package org.moditect.deptective.plugintest.deps.ui does not read org.moditect.deptective.plugintest.deps.model" | ||
); | ||
|
||
compilation = compileWithModelAndService(InvalidTypeView.class); | ||
assertThat(compilation).failed(); | ||
assertThat(compilation).hadErrorContaining( | ||
"package org.moditect.deptective.plugintest.deps.ui does not read org.moditect.deptective.plugintest.deps.model" | ||
); | ||
} | ||
|
||
|
||
@Test | ||
public void shouldDetectInvalidRefrencesInAnnotations() { | ||
// Compilation compilation = compileWithModelAndService(InvalidAnnotation.class); | ||
// assertThat(compilation).failed(); | ||
// assertThat(compilation).hadErrorContaining( | ||
// "package org.moditect.deptective.plugintest.deps.ui does not read org.moditect.deptective.plugintest.deps.model" | ||
// ); | ||
|
||
Compilation compilation = compileWithModelAndService(InvalidAnnotationParameter.class); | ||
assertThat(compilation).failed(); | ||
assertThat(compilation).hadErrorContaining( | ||
"package org.moditect.deptective.plugintest.deps.ui does not read org.moditect.deptective.plugintest.deps.model" | ||
); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
javac-plugin/src/test/java/org/moditect/deptective/plugintest/deps/model/Model.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.moditect.deptective.plugintest.deps.model; | ||
|
||
public class Model { | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...c-plugin/src/test/java/org/moditect/deptective/plugintest/deps/model/ModelAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.moditect.deptective.plugintest.deps.model; | ||
|
||
import static java.lang.annotation.ElementType.ANNOTATION_TYPE; | ||
import static java.lang.annotation.ElementType.CONSTRUCTOR; | ||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.LOCAL_VARIABLE; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.MODULE; | ||
import static java.lang.annotation.ElementType.PACKAGE; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.ElementType.TYPE_PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE_USE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RUNTIME) | ||
@Target({ TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, ANNOTATION_TYPE, PACKAGE, TYPE_PARAMETER, | ||
TYPE_USE, MODULE }) | ||
public @interface ModelAnnotation { | ||
} |
5 changes: 5 additions & 0 deletions
5
javac-plugin/src/test/java/org/moditect/deptective/plugintest/deps/service/Service.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.moditect.deptective.plugintest.deps.service; | ||
|
||
public class Service { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
javac-plugin/src/test/java/org/moditect/deptective/plugintest/deps/ui/GenericUI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.moditect.deptective.plugintest.deps.ui; | ||
|
||
public class GenericUI<T> { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
javac-plugin/src/test/java/org/moditect/deptective/plugintest/deps/ui/GenericView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.moditect.deptective.plugintest.deps.ui; | ||
|
||
public class GenericView<T> { | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
javac-plugin/src/test/java/org/moditect/deptective/plugintest/deps/ui/InvalidAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.moditect.deptective.plugintest.deps.ui; | ||
|
||
import org.moditect.deptective.plugintest.deps.model.ModelAnnotation; | ||
|
||
@ModelAnnotation | ||
public class InvalidAnnotation { | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
.../src/test/java/org/moditect/deptective/plugintest/deps/ui/InvalidAnnotationParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.moditect.deptective.plugintest.deps.ui; | ||
|
||
@UIAnnotation(uiClass=org.moditect.deptective.plugintest.deps.model.Model.class) | ||
public class InvalidAnnotationParameter { | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...plugin/src/test/java/org/moditect/deptective/plugintest/deps/ui/InvalidGenericUIView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.moditect.deptective.plugintest.deps.ui; | ||
|
||
import org.moditect.deptective.plugintest.deps.model.Model; | ||
|
||
// Access to GenericUI is allowed, | ||
// Access to Mdeol via GenericUI NOT | ||
public class InvalidGenericUIView extends GenericView<GenericUI<Model>>{ | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...c-plugin/src/test/java/org/moditect/deptective/plugintest/deps/ui/InvalidGenericView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.moditect.deptective.plugintest.deps.ui; | ||
|
||
import org.moditect.deptective.plugintest.deps.model.Model; | ||
|
||
public class InvalidGenericView extends GenericView<Model>{ | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
javac-plugin/src/test/java/org/moditect/deptective/plugintest/deps/ui/InvalidModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.moditect.deptective.plugintest.deps.ui; | ||
|
||
|
||
public class InvalidModel extends org.moditect.deptective.plugintest.deps.model.Model{ | ||
|
||
|
||
} |
8 changes: 8 additions & 0 deletions
8
javac-plugin/src/test/java/org/moditect/deptective/plugintest/deps/ui/InvalidTypeView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.moditect.deptective.plugintest.deps.ui; | ||
|
||
import org.moditect.deptective.plugintest.deps.model.Model; | ||
|
||
// Acess to Model forbidden | ||
public class InvalidTypeView<T extends Model> { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
javac-plugin/src/test/java/org/moditect/deptective/plugintest/deps/ui/InvalidView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.moditect.deptective.plugintest.deps.ui; | ||
|
||
import org.moditect.deptective.plugintest.deps.model.Model; | ||
|
||
public class InvalidView { | ||
|
||
public void invalidModelUsage(Model m) { | ||
// | ||
} | ||
|
||
|
||
|
||
} |
24 changes: 24 additions & 0 deletions
24
javac-plugin/src/test/java/org/moditect/deptective/plugintest/deps/ui/UIAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.moditect.deptective.plugintest.deps.ui; | ||
|
||
import static java.lang.annotation.ElementType.ANNOTATION_TYPE; | ||
import static java.lang.annotation.ElementType.CONSTRUCTOR; | ||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.LOCAL_VARIABLE; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.MODULE; | ||
import static java.lang.annotation.ElementType.PACKAGE; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.ElementType.TYPE_PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE_USE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RUNTIME) | ||
@Target({ TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, ANNOTATION_TYPE, PACKAGE, TYPE_PARAMETER, | ||
TYPE_USE, MODULE }) | ||
public @interface UIAnnotation { | ||
Class<?> uiClass() default String.class; | ||
} |
19 changes: 19 additions & 0 deletions
19
javac-plugin/src/test/resources/org/moditect/deptective/plugintest/deps/deptective.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"packages" : [ | ||
{ | ||
"name" : "org.moditect.deptective.plugintest.deps.model" | ||
}, | ||
{ | ||
"name" : "org.moditect.deptective.plugintest.deps.service", | ||
"reads" : [ | ||
"org.moditect.deptective.plugintest.deps.model" | ||
] | ||
}, | ||
{ | ||
"name" : "org.moditect.deptective.plugintest.deps.ui", | ||
"reads" : [ | ||
"org.moditect.deptective.plugintest.deps.service" | ||
] | ||
} | ||
] | ||
} |