diff --git a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuilder.java b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuilder.java index 47c86abaa..d41da4d05 100644 --- a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuilder.java +++ b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuilder.java @@ -28,8 +28,6 @@ import org.jetbrains.jps.incremental.ProjectBuildException; import org.jetbrains.jps.model.module.JpsModule; public class TeaVMBuilder extends ModuleLevelBuilder { - private TeaVMStorageProvider storageProvider = new TeaVMStorageProvider(); - public TeaVMBuilder() { super(BuilderCategory.CLASS_POST_PROCESSOR); } diff --git a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/model/TeaVMJpsRemoteConfiguration.java b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/model/TeaVMJpsRemoteConfiguration.java new file mode 100644 index 000000000..4a25e06e9 --- /dev/null +++ b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/model/TeaVMJpsRemoteConfiguration.java @@ -0,0 +1,58 @@ +/* + * Copyright 2016 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.idea.jps.model; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.JpsElementChildRole; +import org.jetbrains.jps.model.JpsProject; +import org.jetbrains.jps.model.ex.JpsElementBase; +import org.jetbrains.jps.model.ex.JpsElementChildRoleBase; +import org.jetbrains.jps.model.module.JpsModule; + +public class TeaVMJpsRemoteConfiguration extends JpsElementBase { + private static final JpsElementChildRole ROLE = JpsElementChildRoleBase.create( + "TeaVM remote configuration"); + private int port; + + public static TeaVMJpsRemoteConfiguration get(JpsProject project) { + return project.getContainer().getChild(ROLE); + } + + public void setTo(JpsModule project) { + project.getContainer().setChild(ROLE, this); + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + @NotNull + @Override + public TeaVMJpsRemoteConfiguration createCopy() { + TeaVMJpsRemoteConfiguration copy = new TeaVMJpsRemoteConfiguration(); + copy.port = port; + return copy; + } + + @Override + public void applyChanges(@NotNull TeaVMJpsRemoteConfiguration modified) { + port = modified.port; + } +} diff --git a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/remote/TeaVMBuilderAssistant.java b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/remote/TeaVMBuilderAssistant.java new file mode 100644 index 000000000..fd4ae05d7 --- /dev/null +++ b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/remote/TeaVMBuilderAssistant.java @@ -0,0 +1,24 @@ +/* + * Copyright 2016 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.idea.jps.remote; + +import java.rmi.Remote; +import java.rmi.RemoteException; + +public interface TeaVMBuilderAssistant extends Remote { + TeaVMElementLocation getMethodLocation(String className, String methodName, String methodDesc) + throws RemoteException; +} diff --git a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/remote/TeaVMElementLocation.java b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/remote/TeaVMElementLocation.java new file mode 100644 index 000000000..d4649e77d --- /dev/null +++ b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/remote/TeaVMElementLocation.java @@ -0,0 +1,48 @@ +/* + * Copyright 2016 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.idea.jps.remote; + +import java.io.Serializable; + +public class TeaVMElementLocation implements Serializable { + private int startOffset; + private int endOffset; + private int line; + private int column; + + public TeaVMElementLocation(int startOffset, int endOffset, int line, int column) { + this.startOffset = startOffset; + this.endOffset = endOffset; + this.line = line; + this.column = column; + } + + public int getStartOffset() { + return startOffset; + } + + public int getEndOffset() { + return endOffset; + } + + public int getLine() { + return line; + } + + public int getColumn() { + return column; + } +} diff --git a/tools/idea/jps-plugin/teavm-jps-plugin.iml b/tools/idea/jps-plugin/teavm-jps-plugin.iml index 29b643292..8a7611ab7 100644 --- a/tools/idea/jps-plugin/teavm-jps-plugin.iml +++ b/tools/idea/jps-plugin/teavm-jps-plugin.iml @@ -9,7 +9,7 @@ - + diff --git a/tools/idea/src/main/java/org/teavm/idea/TeaVMConfigurationStorage.java b/tools/idea/src/main/java/org/teavm/idea/TeaVMConfigurationStorage.java index 03481ea7e..773ee37c8 100644 --- a/tools/idea/src/main/java/org/teavm/idea/TeaVMConfigurationStorage.java +++ b/tools/idea/src/main/java/org/teavm/idea/TeaVMConfigurationStorage.java @@ -21,7 +21,7 @@ import com.intellij.openapi.components.Storage; import org.jetbrains.annotations.Nullable; import org.teavm.idea.jps.model.TeaVMJpsConfiguration; -@State(name = "teavm", storages = @Storage(id = "other", file = "$MODULE_FILE$")) +@State(name = "teavm", storages = @Storage(id = "other", file = "$MODULE_FILE$")) public class TeaVMConfigurationStorage implements PersistentStateComponent { private TeaVMJpsConfiguration state = new TeaVMJpsConfiguration(); diff --git a/tools/idea/src/main/java/org/teavm/idea/TeaVMJPSRemoteService.java b/tools/idea/src/main/java/org/teavm/idea/TeaVMJPSRemoteService.java new file mode 100644 index 000000000..2098741c0 --- /dev/null +++ b/tools/idea/src/main/java/org/teavm/idea/TeaVMJPSRemoteService.java @@ -0,0 +1,110 @@ +/* + * Copyright 2016 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.idea; + +import com.intellij.openapi.components.ApplicationComponent; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; +import com.intellij.openapi.project.ProjectManagerAdapter; +import com.intellij.psi.JavaPsiFacade; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiMethod; +import com.intellij.psi.search.GlobalSearchScope; +import java.rmi.AlreadyBoundException; +import java.rmi.NotBoundException; +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.rmi.server.UnicastRemoteObject; +import org.jetbrains.annotations.NotNull; +import org.teavm.idea.jps.model.TeaVMJpsRemoteConfiguration; +import org.teavm.idea.jps.remote.TeaVMBuilderAssistant; +import org.teavm.idea.jps.remote.TeaVMElementLocation; + +public class TeaVMJPSRemoteService implements ApplicationComponent, TeaVMBuilderAssistant { + private ProjectManager projectManager = ProjectManager.getInstance(); + private int port; + private Registry registry; + + @Override + public void initComponent() { + + for (Project project : projectManager.getOpenProjects()) { + configureProject(project); + } + projectManager.addProjectManagerListener(new ProjectManagerAdapter() { + @Override + public void projectOpened(Project project) { + configureProject(project); + } + }); + } + + private void configureProject(Project project) { + try { + registry = LocateRegistry.createRegistry(0); + registry.bind("TeaVM", this); + } catch (RemoteException | AlreadyBoundException e) { + e.printStackTrace(); + } + TeaVMRemoteConfigurationStorage storage = project.getComponent(TeaVMRemoteConfigurationStorage.class); + TeaVMJpsRemoteConfiguration config = storage.getState(); + config.setPort(port); + storage.loadState(config); + } + + @Override + public void disposeComponent() { + try { + registry.unbind("TeaVM"); + UnicastRemoteObject.unexportObject(registry, true); + } catch (RemoteException | NotBoundException e) { + e.printStackTrace(); + } + } + + @NotNull + @Override + public String getComponentName() { + return "TeaVM JPS service"; + } + + @Override + public TeaVMElementLocation getMethodLocation(String className, String methodName, String methodDesc) + throws RemoteException { + for (Project project : projectManager.getOpenProjects()) { + JavaPsiFacade psi = JavaPsiFacade.getInstance(project); + PsiClass cls = psi.findClass(className, GlobalSearchScope.allScope(project)); + if (cls == null) { + continue; + } + + for (PsiMethod method : cls.getAllMethods()) { + if (!method.getName().equals(methodName)) { + continue; + } + // TODO: check method raw signature + return getMethodLocation(method); + } + } + return null; + } + + private TeaVMElementLocation getMethodLocation(PsiMethod method) { + return new TeaVMElementLocation(method.getTextOffset(), method.getTextOffset() + method.getTextLength(), + -1, -1); + } +} diff --git a/tools/idea/src/main/java/org/teavm/idea/TeaVMRemoteConfigurationStorage.java b/tools/idea/src/main/java/org/teavm/idea/TeaVMRemoteConfigurationStorage.java new file mode 100644 index 000000000..de8021013 --- /dev/null +++ b/tools/idea/src/main/java/org/teavm/idea/TeaVMRemoteConfigurationStorage.java @@ -0,0 +1,39 @@ +/* + * Copyright 2016 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.idea; + +import com.intellij.openapi.components.PersistentStateComponent; +import com.intellij.openapi.components.State; +import com.intellij.openapi.components.Storage; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.teavm.idea.jps.model.TeaVMJpsRemoteConfiguration; + +@State(name = "teavm", storages = @Storage(id = "other", file = "$PROJECT_FILE$")) +public class TeaVMRemoteConfigurationStorage implements PersistentStateComponent { + private TeaVMJpsRemoteConfiguration state = new TeaVMJpsRemoteConfiguration(); + + @NotNull + @Override + public TeaVMJpsRemoteConfiguration getState() { + return state.createCopy(); + } + + @Override + public void loadState(TeaVMJpsRemoteConfiguration state) { + this.state.applyChanges(state); + } +} diff --git a/tools/idea/teavm-idea-plugin.iml b/tools/idea/teavm-idea-plugin.iml index 656bd4099..8ec274334 100644 --- a/tools/idea/teavm-idea-plugin.iml +++ b/tools/idea/teavm-idea-plugin.iml @@ -10,7 +10,7 @@ - +