mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Start implementing RMI service that reports method locations to JPS builder
This commit is contained in:
parent
da8382271f
commit
93cc51c575
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<TeaVMJpsRemoteConfiguration> {
|
||||
private static final JpsElementChildRole<TeaVMJpsRemoteConfiguration> 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@
|
|||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="IntelliJ IDEA IU-145.844.1" jdkType="IDEA JDK" />
|
||||
<orderEntry type="jdk" jdkName="IntelliJ IDEA" jdkType="IDEA JDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: org.ow2.asm:asm-debug-all:5.0.4" level="project" />
|
||||
<orderEntry type="library" name="teavm-all" level="project" />
|
||||
|
|
|
@ -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<TeaVMJpsConfiguration> {
|
||||
private TeaVMJpsConfiguration state = new TeaVMJpsConfiguration();
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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<TeaVMJpsRemoteConfiguration> {
|
||||
private TeaVMJpsRemoteConfiguration state = new TeaVMJpsRemoteConfiguration();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TeaVMJpsRemoteConfiguration getState() {
|
||||
return state.createCopy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(TeaVMJpsRemoteConfiguration state) {
|
||||
this.state.applyChanges(state);
|
||||
}
|
||||
}
|
|
@ -10,7 +10,7 @@
|
|||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="IntelliJ IDEA IU-145.844.1" jdkType="IDEA JDK" />
|
||||
<orderEntry type="jdk" jdkName="IntelliJ IDEA" jdkType="IDEA JDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="teavm-jps-plugin" />
|
||||
<orderEntry type="library" name="teavm-all" level="project" />
|
||||
|
|
Loading…
Reference in New Issue
Block a user