Using annotations from reexported libraries
This commit is contained in:
+16
-22
@@ -27,17 +27,13 @@ import org.jetbrains.jps.incremental.CompileContext;
|
||||
import org.jetbrains.jps.incremental.ModuleBuildTarget;
|
||||
import org.jetbrains.jps.incremental.messages.BuildMessage;
|
||||
import org.jetbrains.jps.incremental.messages.CompilerMessage;
|
||||
import org.jetbrains.jps.model.java.JpsAnnotationRootType;
|
||||
import org.jetbrains.jps.model.java.JpsJavaClasspathKind;
|
||||
import org.jetbrains.jps.model.java.JpsJavaDependenciesEnumerator;
|
||||
import org.jetbrains.jps.model.java.JpsJavaExtensionService;
|
||||
import org.jetbrains.jps.model.JpsDummyElement;
|
||||
import org.jetbrains.jps.model.java.*;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.library.JpsLibraryRoot;
|
||||
import org.jetbrains.jps.model.library.sdk.JpsSdk;
|
||||
import org.jetbrains.jps.model.module.JpsDependencyElement;
|
||||
import org.jetbrains.jps.model.module.JpsLibraryDependency;
|
||||
import org.jetbrains.jps.model.module.JpsModule;
|
||||
import org.jetbrains.jps.model.module.JpsSdkDependency;
|
||||
import org.jetbrains.jps.util.JpsPathUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -92,11 +88,8 @@ public class KotlinBuilderModuleScriptGenerator {
|
||||
|
||||
@NotNull
|
||||
private static Collection<File> findClassPathRoots(@NotNull ModuleBuildTarget target) {
|
||||
JpsModule module = target.getModule();
|
||||
JpsJavaDependenciesEnumerator dependencies = JpsJavaExtensionService.dependencies(module).recursively().exportedOnly()
|
||||
.includedIn(JpsJavaClasspathKind.compile(target.isTests()));
|
||||
|
||||
return dependencies.classes().getRoots();
|
||||
return getAllDependencies(target).classes().getRoots();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -114,20 +107,15 @@ public class KotlinBuilderModuleScriptGenerator {
|
||||
|
||||
@NotNull
|
||||
private static List<File> findAnnotationRoots(@NotNull ModuleBuildTarget target) {
|
||||
JpsModule module = target.getModule();
|
||||
List<JpsDependencyElement> dependencies = module.getDependenciesList().getDependencies();
|
||||
|
||||
List<File> annotationRootFiles = ContainerUtil.newArrayList();
|
||||
for (JpsDependencyElement dependencyElement : dependencies) {
|
||||
JpsLibrary library = getLibrary(dependencyElement);
|
||||
if (library == null) continue;
|
||||
|
||||
List<JpsLibraryRoot> annotationRoots = library.getRoots(JpsAnnotationRootType.INSTANCE);
|
||||
for (JpsLibraryRoot root : annotationRoots) {
|
||||
File file = new File(JpsPathUtil.urlToPath(root.getUrl()));
|
||||
JpsSdk<JpsDummyElement> sdk = target.getModule().getSdk(JpsJavaSdkType.INSTANCE);
|
||||
if (sdk != null) {
|
||||
annotationRootFiles.addAll(sdk.getParent().getFiles(JpsAnnotationRootType.INSTANCE));
|
||||
}
|
||||
|
||||
annotationRootFiles.add(file);
|
||||
}
|
||||
for (JpsLibrary library : getAllDependencies(target).getLibraries()) {
|
||||
annotationRootFiles.addAll(library.getFiles(JpsAnnotationRootType.INSTANCE));
|
||||
}
|
||||
|
||||
// JDK is stored locally on user's machine, so its configuration, including external annotation paths
|
||||
@@ -143,6 +131,12 @@ public class KotlinBuilderModuleScriptGenerator {
|
||||
return annotationRootFiles;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JpsJavaDependenciesEnumerator getAllDependencies(@NotNull ModuleBuildTarget target) {
|
||||
return JpsJavaExtensionService.dependencies(target.getModule()).recursively().exportedOnly()
|
||||
.includedIn(JpsJavaClasspathKind.compile(target.isTests()));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JpsLibrary getLibrary(@NotNull JpsDependencyElement dependencyElement) {
|
||||
if (dependencyElement instanceof JpsSdkDependency) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="module3" />
|
||||
</component>
|
||||
|
||||
@@ -13,4 +13,19 @@
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA_JDK" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
<component name="libraryTable">
|
||||
<library name="lib">
|
||||
<ANNOTATIONS>
|
||||
<root url="file://$PROJECT_DIR$/module2/lib" />
|
||||
</ANNOTATIONS>
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/module2/lib" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="file://$PROJECT_DIR$/module2/lib" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
package j;
|
||||
|
||||
import java.lang.String;
|
||||
|
||||
public class J {
|
||||
public String foo() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<root>
|
||||
<item name='j.J java.lang.String foo()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
</root>
|
||||
@@ -5,9 +5,10 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinRuntime" level="project" exported="" />
|
||||
<orderEntry type="library" exported="" name="KotlinRuntime" level="project" />
|
||||
<orderEntry type="library" exported="" name="lib" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="module2" exported="" />
|
||||
</component>
|
||||
|
||||
@@ -2,4 +2,7 @@ fun f() {
|
||||
JSecond()
|
||||
K2()
|
||||
println("Hi")
|
||||
}
|
||||
takeNN(j.J().foo())
|
||||
}
|
||||
|
||||
fun takeNN(a: Any) {}
|
||||
@@ -3,4 +3,5 @@ fun main() {
|
||||
JSecond()
|
||||
K2()
|
||||
println("Hi")
|
||||
takeNN(j.J().foo())
|
||||
}
|
||||
Reference in New Issue
Block a user