diff --git a/.idea/libraries/teavm_all.xml b/.idea/libraries/teavm_all.xml
index 1a7362281..55f1409ea 100644
--- a/.idea/libraries/teavm_all.xml
+++ b/.idea/libraries/teavm_all.xml
@@ -4,6 +4,9 @@
-
+
+
+
+
\ No newline at end of file
diff --git a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java
index aa183f62a..1ba36bb43 100644
--- a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java
+++ b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java
@@ -33,6 +33,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.jetbrains.jps.incremental.CompileContext;
import org.jetbrains.jps.incremental.ModuleBuildTarget;
@@ -42,6 +43,7 @@ import org.jetbrains.jps.incremental.messages.ProgressMessage;
import org.jetbrains.jps.model.JpsProject;
import org.jetbrains.jps.model.java.JpsJavaExtensionService;
import org.jetbrains.jps.model.library.JpsLibrary;
+import org.jetbrains.jps.model.library.JpsLibraryRoot;
import org.jetbrains.jps.model.library.JpsOrderRootType;
import org.jetbrains.jps.model.module.JpsDependencyElement;
import org.jetbrains.jps.model.module.JpsLibraryDependency;
@@ -62,19 +64,23 @@ import org.teavm.model.ValueType;
import org.teavm.tooling.EmptyTeaVMToolLog;
import org.teavm.tooling.TeaVMTool;
import org.teavm.tooling.TeaVMToolException;
+import org.teavm.tooling.sources.DirectorySourceFileProvider;
+import org.teavm.tooling.sources.JarSourceFileProvider;
+import org.teavm.tooling.sources.SourceFileProvider;
import org.teavm.vm.TeaVMPhase;
import org.teavm.vm.TeaVMProgressFeedback;
import org.teavm.vm.TeaVMProgressListener;
public class TeaVMBuild {
- private CompileContext context;
- private TeaVMStorageProvider storageProvider = new TeaVMStorageProvider();
- private List classPathEntries = new ArrayList<>();
+ private final CompileContext context;
+ private final TeaVMStorageProvider storageProvider = new TeaVMStorageProvider();
+ private final List classPathEntries = new ArrayList<>();
private List directoryClassPathEntries;
private TeaVMStorage storage;
- private TeaVMBuilderAssistant assistant;
- private Map sourceFileCache = new HashMap<>();
- private Map fileLineCache = new HashMap<>();
+ private final TeaVMBuilderAssistant assistant;
+ private final Map sourceFileCache = new HashMap<>();
+ private final Map fileLineCache = new HashMap<>();
+ private final List sourceFileProviders = new ArrayList<>();
public TeaVMBuild(CompileContext context, TeaVMBuilderAssistant assistant) {
this.context = context;
@@ -102,10 +108,14 @@ public class TeaVMBuild {
tool.setProgressListener(createProgressListener(context));
tool.setLog(new EmptyTeaVMToolLog());
tool.setMainClass(config.getMainClass());
- tool.setSourceMapsFileGenerated(true);
+ tool.setSourceMapsFileGenerated(config.isSourceMapsFileGenerated());
tool.setTargetDirectory(new File(config.getTargetDirectory()));
tool.setClassLoader(buildClassLoader());
- tool.setMinifying(false);
+ tool.setSourceFilesCopied(config.isSourceFilesCopied());
+ tool.setMinifying(config.isMinifying());
+ for (SourceFileProvider fileProvider : sourceFileProviders) {
+ tool.addSourceFileProvider(fileProvider);
+ }
boolean errorOccurred = false;
try {
@@ -366,9 +376,15 @@ public class TeaVMBuild {
if (output != null) {
classPathEntries.add(output.getPath());
}
+
+ sourceFileProviders.addAll(module.getSourceRoots().stream()
+ .map(sourceRoot -> new DirectorySourceFileProvider(sourceRoot.getFile()))
+ .collect(Collectors.toList()));
+
for (JpsDependencyElement dependency : module.getDependenciesList().getDependencies()) {
if (dependency instanceof JpsModuleDependency) {
- buildClassPath(((JpsModuleDependency) dependency).getModule(), visited);
+ JpsModuleDependency moduleDependency = (JpsModuleDependency) dependency;
+ buildClassPath(moduleDependency.getModule(), visited);
} else if (dependency instanceof JpsLibraryDependency) {
JpsLibrary library = ((JpsLibraryDependency) dependency).getLibrary();
if (library == null) {
@@ -376,7 +392,32 @@ public class TeaVMBuild {
}
classPathEntries.addAll(library.getFiles(JpsOrderRootType.COMPILED).stream().map(File::getPath)
.collect(toList()));
+
+ for (JpsLibraryRoot libraryRoot : library.getRoots(JpsOrderRootType.SOURCES)) {
+ File file = getFileFromUrl(libraryRoot.getUrl());
+ if (file != null) {
+ if (file.isDirectory()) {
+ sourceFileProviders.add(new DirectorySourceFileProvider(file));
+ } else {
+ sourceFileProviders.add(new JarSourceFileProvider(file));
+ }
+ }
+ }
}
}
}
+
+ private File getFileFromUrl(String url) {
+ if (url.startsWith("file://")) {
+ return new File(url.substring("file://".length()));
+ } else if (url.startsWith("jar://")) {
+ int index = url.indexOf('!');
+ return new File(url.substring("file://".length(), index));
+ } else if (url.startsWith("jar:file://")) {
+ int index = url.indexOf('!');
+ return new File(url.substring("jar:file://".length(), index));
+ } else {
+ return null;
+ }
+ }
}
diff --git a/tools/idea/src/main/java/org/teavm/idea/TeaVMJPSRemoteService.java b/tools/idea/src/main/java/org/teavm/idea/TeaVMJPSRemoteService.java
index 38e0d72ff..c6cf902ed 100644
--- a/tools/idea/src/main/java/org/teavm/idea/TeaVMJPSRemoteService.java
+++ b/tools/idea/src/main/java/org/teavm/idea/TeaVMJPSRemoteService.java
@@ -22,7 +22,10 @@ import com.intellij.openapi.project.ProjectManager;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
+import com.intellij.psi.PsiParameter;
+import com.intellij.psi.PsiType;
import com.intellij.psi.search.GlobalSearchScope;
+import com.siyeh.ig.fixes.MemberSignature;
import java.rmi.AlreadyBoundException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
@@ -37,7 +40,7 @@ import org.teavm.idea.jps.remote.TeaVMElementLocation;
public class TeaVMJPSRemoteService extends UnicastRemoteObject implements ApplicationComponent, TeaVMBuilderAssistant {
private static final int MIN_PORT = 10000;
private static final int MAX_PORT = 1 << 16;
- private ProjectManager projectManager = ProjectManager.getInstance();
+ private final ProjectManager projectManager = ProjectManager.getInstance();
private int port;
private Registry registry;
@@ -99,10 +102,9 @@ public class TeaVMJPSRemoteService extends UnicastRemoteObject implements Applic
}
for (PsiMethod method : cls.getAllMethods()) {
- if (!method.getName().equals(methodName)) {
+ if (!method.getName().equals(methodName) || !getMethodSignature(method).equals(methodDesc)) {
continue;
}
- // TODO: check method raw signature
resultHolder[0] = getMethodLocation(method);
return;
}
@@ -112,6 +114,18 @@ public class TeaVMJPSRemoteService extends UnicastRemoteObject implements Applic
return resultHolder[0];
}
+ private String getMethodSignature(PsiMethod method) {
+ StringBuilder sb = new StringBuilder("(");
+ for (PsiParameter parameter : method.getParameterList().getParameters()) {
+ sb.append(MemberSignature.createTypeSignature(parameter.getType()));
+ }
+ sb.append(")");
+
+ PsiType returnType = method.getReturnType();
+ sb.append(MemberSignature.createTypeSignature(returnType != null ? returnType : PsiType.VOID));
+ return sb.toString();
+ }
+
private TeaVMElementLocation getMethodLocation(PsiMethod method) {
return new TeaVMElementLocation(method.getTextOffset(), method.getTextOffset() + method.getTextLength(),
-1, -1, method.getContainingFile().getVirtualFile().getPath());