Remove outdated methodAliases build parameter

Replace classAliases with classesToPreserve
This commit is contained in:
Alexey Andreev 2018-01-09 23:33:17 +03:00
parent ac236f1ff8
commit 85c686c72a
15 changed files with 86 additions and 273 deletions

1
.gitignore vendored
View File

@ -11,6 +11,7 @@ target
.factorypath .factorypath
.checkstyle .checkstyle
.cache-main .cache-main
.metadata
# IntelliJ IDEA # IntelliJ IDEA
*.iml *.iml

View File

@ -284,16 +284,13 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost {
renderer.render(clsNodes); renderer.render(clsNodes);
renderer.renderStringPool(); renderer.renderStringPool();
renderer.renderStringConstants(); renderer.renderStringConstants();
for (Map.Entry<String, TeaVMEntryPoint> entry : controller.getEntryPoints().entrySet()) { for (Map.Entry<? extends String, ? extends TeaVMEntryPoint> entry
: controller.getEntryPoints().entrySet()) {
sourceWriter.append("var ").append(entry.getKey()).ws().append("=").ws(); sourceWriter.append("var ").append(entry.getKey()).ws().append("=").ws();
MethodReference ref = entry.getValue().getReference(); MethodReference ref = entry.getValue().getReference();
sourceWriter.append(naming.getFullNameFor(ref)); sourceWriter.append(naming.getFullNameFor(ref));
sourceWriter.append(";").newLine(); sourceWriter.append(";").newLine();
} }
for (Map.Entry<String, String> entry : controller.getExportedClasses().entrySet()) {
sourceWriter.append("var ").append(entry.getKey()).ws().append("=").ws()
.appendClass(entry.getValue()).append(";").newLine();
}
for (RendererListener listener : rendererListeners) { for (RendererListener listener : rendererListeners) {
listener.complete(); listener.complete();
} }

View File

@ -22,10 +22,12 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.ServiceLoader; import java.util.ServiceLoader;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.teavm.cache.NoCache; import org.teavm.cache.NoCache;
import org.teavm.common.ServiceRepository; import org.teavm.common.ServiceRepository;
@ -109,8 +111,8 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
private final ClassLoader classLoader; private final ClassLoader classLoader;
private final Map<String, TeaVMEntryPoint> entryPoints = new HashMap<>(); private final Map<String, TeaVMEntryPoint> entryPoints = new HashMap<>();
private final Map<String, TeaVMEntryPoint> readonlyEntryPoints = Collections.unmodifiableMap(entryPoints); private final Map<String, TeaVMEntryPoint> readonlyEntryPoints = Collections.unmodifiableMap(entryPoints);
private final Map<String, String> exportedClasses = new HashMap<>(); private final Set<String> preservedClasses = new HashSet<>();
private final Map<String, String> readonlyExportedClasses = Collections.unmodifiableMap(exportedClasses); private final Set<String> readonlyPreservedClasses = Collections.unmodifiableSet(preservedClasses);
private final Map<Class<?>, Object> services = new HashMap<>(); private final Map<Class<?>, Object> services = new HashMap<>();
private final Properties properties = new Properties(); private final Properties properties = new Properties();
private ProgramCache programCache; private ProgramCache programCache;
@ -288,15 +290,11 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
return entryPoint; return entryPoint;
} }
public void exportType(String name, String className) { public void preserveType(String className) {
if (exportedClasses.containsKey(name)) {
throw new IllegalArgumentException("Class with public name `" + name + "' already defined for class "
+ className);
}
dependencyAnalyzer.defer(() -> { dependencyAnalyzer.defer(() -> {
dependencyAnalyzer.linkClass(className, null).initClass(null); dependencyAnalyzer.linkClass(className, null).initClass(null);
}); });
exportedClasses.put(name, className); preservedClasses.add(className);
} }
/** /**
@ -675,8 +673,8 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
} }
@Override @Override
public Map<String, String> getExportedClasses() { public Set<String> getPreservedClasses() {
return readonlyExportedClasses; return readonlyPreservedClasses;
} }
@Override @Override

View File

@ -38,7 +38,7 @@ import org.teavm.model.MethodReference;
* Let's see how you achieve it:</p> * Let's see how you achieve it:</p>
* *
* <pre>{@code * <pre>{@code
*vm.exportType("JavaHashMap", "java.util.HashMap"); *vm.preserveType("JavaHashMap", "java.util.HashMap");
*vm.entryPoint("initJavaHashMap", new MethodReference("java.util.HashMap", *vm.entryPoint("initJavaHashMap", new MethodReference("java.util.HashMap",
* "<init>", ValueType.VOID)); * "<init>", ValueType.VOID));
*vm.entryPoint("putValueIntoJavaMap", new MethodReference( *vm.entryPoint("putValueIntoJavaMap", new MethodReference(

View File

@ -17,6 +17,7 @@ package org.teavm.vm;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import org.teavm.common.ServiceRepository; import org.teavm.common.ServiceRepository;
import org.teavm.dependency.DependencyInfo; import org.teavm.dependency.DependencyInfo;
import org.teavm.diagnostics.Diagnostics; import org.teavm.diagnostics.Diagnostics;
@ -41,7 +42,7 @@ public interface TeaVMTargetController {
boolean isFriendlyToDebugger(); boolean isFriendlyToDebugger();
Map<String, TeaVMEntryPoint> getEntryPoints(); Map<? extends String, ? extends TeaVMEntryPoint> getEntryPoints();
Map<String, String> getExportedClasses(); Set<? extends String> getPreservedClasses();
} }

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
Copyright 2014 Alexey Andreev. Copyright 2014 Alexey Andreev.
@ -12,10 +13,7 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> --><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.teavm</groupId> <groupId>org.teavm</groupId>

View File

@ -1,37 +0,0 @@
/*
* Copyright 2014 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.tooling;
public class ClassAlias {
private String className;
private String alias;
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
}

View File

@ -1,64 +0,0 @@
/*
* Copyright 2014 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.tooling;
public class MethodAlias {
private String alias;
private String className;
private String methodName;
private String descriptor;
private String[] types;
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
public String getMethodName() {
return methodName;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
public String getDescriptor() {
return descriptor;
}
public void setDescriptor(String descriptor) {
this.descriptor = descriptor;
}
public String[] getTypes() {
return types;
}
public void setTypes(String[] types) {
this.types = types;
}
}

View File

@ -61,7 +61,6 @@ import org.teavm.vm.BuildTarget;
import org.teavm.vm.DirectoryBuildTarget; import org.teavm.vm.DirectoryBuildTarget;
import org.teavm.vm.TeaVM; import org.teavm.vm.TeaVM;
import org.teavm.vm.TeaVMBuilder; import org.teavm.vm.TeaVMBuilder;
import org.teavm.vm.TeaVMEntryPoint;
import org.teavm.vm.TeaVMOptimizationLevel; import org.teavm.vm.TeaVMOptimizationLevel;
import org.teavm.vm.TeaVMProgressListener; import org.teavm.vm.TeaVMProgressListener;
import org.teavm.vm.TeaVMTarget; import org.teavm.vm.TeaVMTarget;
@ -81,8 +80,7 @@ public class TeaVMTool implements BaseTeaVMTool {
private boolean incremental; private boolean incremental;
private File cacheDirectory = new File("./teavm-cache"); private File cacheDirectory = new File("./teavm-cache");
private List<ClassHolderTransformer> transformers = new ArrayList<>(); private List<ClassHolderTransformer> transformers = new ArrayList<>();
private List<ClassAlias> classAliases = new ArrayList<>(); private List<String> classesToPreserve = new ArrayList<>();
private List<MethodAlias> methodAliases = new ArrayList<>();
private TeaVMToolLog log = new EmptyTeaVMToolLog(); private TeaVMToolLog log = new EmptyTeaVMToolLog();
private ClassLoader classLoader = TeaVMTool.class.getClassLoader(); private ClassLoader classLoader = TeaVMTool.class.getClassLoader();
private DiskCachedClassHolderSource cachedClassSource; private DiskCachedClassHolderSource cachedClassSource;
@ -197,12 +195,8 @@ public class TeaVMTool implements BaseTeaVMTool {
return transformers; return transformers;
} }
public List<ClassAlias> getClassAliases() { public List<String> getClassesToPreserve() {
return classAliases; return classesToPreserve;
}
public List<MethodAlias> getMethodAliases() {
return methodAliases;
} }
public TeaVMToolLog getLog() { public TeaVMToolLog getLog() {
@ -392,26 +386,8 @@ public class TeaVMTool implements BaseTeaVMTool {
.withArrayValue(1, "java.lang.String") .withArrayValue(1, "java.lang.String")
.async(); .async();
} }
for (ClassAlias alias : classAliases) { for (String className : classesToPreserve) {
vm.exportType(alias.getAlias(), alias.getClassName()); vm.preserveType(className);
}
for (MethodAlias methodAlias : methodAliases) {
MethodReference ref = new MethodReference(methodAlias.getClassName(), methodAlias.getMethodName(),
MethodDescriptor.parseSignature(methodAlias.getDescriptor()));
TeaVMEntryPoint entryPoint = vm.entryPoint(methodAlias.getAlias(), ref).async();
if (methodAlias.getTypes() != null) {
for (int i = 0; i < methodAlias.getTypes().length; ++i) {
String types = methodAlias.getTypes()[i];
if (types != null) {
for (String type : types.split(" +")) {
type = type.trim();
if (!type.isEmpty()) {
entryPoint.withValue(i, type);
}
}
}
}
}
} }
targetDirectory.mkdirs(); targetDirectory.mkdirs();

View File

@ -144,23 +144,21 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator {
profile.setTransformers(transformers != null ? transformers : new String[0]); profile.setTransformers(transformers != null ? transformers : new String[0]);
monitor.worked(10); monitor.worked(10);
profile.setClassAliases(readClassAliases(execution)); profile.setClassesToPreserve(readClassesToPreserve(execution));
monitor.worked(10); monitor.worked(10);
monitor.done(); monitor.done();
} }
private Map<String, String> readClassAliases(MojoExecution execution) { private Set<? extends String> readClassesToPreserve(MojoExecution execution) {
Map<String, String> aliases = new HashMap<>(); Set<String> classes = new HashSet<>();
Xpp3Dom aliasesElem = execution.getConfiguration().getChild("classAliases"); Xpp3Dom classesElem = execution.getConfiguration().getChild("classesToPreserve");
if (aliasesElem != null) { if (classesElem != null) {
for (Xpp3Dom item : aliasesElem.getChildren()) { for (Xpp3Dom item : classesElem.getChildren()) {
String className = item.getChild("className").getValue(); classes.add(item.getValue());
String alias = item.getChild("alias").getValue();
aliases.put(className, alias);
} }
} }
return aliases; return classes;
} }
private String getProjectBuildDirectory() throws CoreException { private String getProjectBuildDirectory() throws CoreException {

View File

@ -16,6 +16,8 @@
package org.teavm.eclipse; package org.teavm.eclipse;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope; import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -163,7 +165,7 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting
private boolean sourceFilesCopied; private boolean sourceFilesCopied;
private Properties properties = new Properties(); private Properties properties = new Properties();
private String[] transformers = new String[0]; private String[] transformers = new String[0];
private Map<String, String> classAliases = new HashMap<>(); private Set<String> classesToPreserve = new HashSet<>();
private String externalToolId = ""; private String externalToolId = "";
@Override @Override
@ -306,13 +308,14 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting
} }
@Override @Override
public Map<String, String> getClassAliases() { public Set<? extends String> getClassesToPreserve() {
return new HashMap<>(classAliases); return classesToPreserve;
} }
@Override @Override
public void setClassAliases(Map<String, String> classAliases) { public void setClassesToPreserve(Set<? extends String> classesToPreserve) {
this.classAliases = new HashMap<>(classAliases); this.classesToPreserve.clear();
this.classesToPreserve.addAll(classesToPreserve);
} }
@Override @Override
@ -357,11 +360,7 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting
Preferences transformersPrefs = preferences.node(TRANSFORMERS); Preferences transformersPrefs = preferences.node(TRANSFORMERS);
transformersPrefs.sync(); transformersPrefs.sync();
transformers = transformersPrefs.keys(); transformers = transformersPrefs.keys();
Preferences classesPrefs = preferences.node(CLASSES); classesToPreserve.addAll(Arrays.asList(preferences.get(CLASSES, "").split(" ")));
classesPrefs.sync();
for (String key : classesPrefs.keys()) {
classAliases.put(key, classesPrefs.get(key, "_"));
}
externalToolId = preferences.get(EXTERNAL_TOOL_ID, ""); externalToolId = preferences.get(EXTERNAL_TOOL_ID, "");
} }
@ -390,12 +389,7 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting
transformersPrefs.put(transformer, ""); transformersPrefs.put(transformer, "");
} }
transformersPrefs.flush(); transformersPrefs.flush();
Preferences classesPrefs = preferences.node(CLASSES); preferences.put(CLASSES, classesToPreserve.stream().collect(Collectors.joining(" ")));
classesPrefs.clear();
for (String key : classAliases.keySet()) {
classesPrefs.put(key, classAliases.get(key));
}
classesPrefs.flush();
preferences.put(EXTERNAL_TOOL_ID, externalToolId); preferences.put(EXTERNAL_TOOL_ID, externalToolId);
preferences.flush(); preferences.flush();
} }

View File

@ -15,8 +15,8 @@
*/ */
package org.teavm.eclipse; package org.teavm.eclipse;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
public interface TeaVMProfile { public interface TeaVMProfile {
String getName(); String getName();
@ -75,9 +75,9 @@ public interface TeaVMProfile {
void setTransformers(String[] transformers); void setTransformers(String[] transformers);
Map<String, String> getClassAliases(); Set<? extends String> getClassesToPreserve();
void setClassAliases(Map<String, String> classAliases); void setClassesToPreserve(Set<? extends String> classesToPreserve);
String getExternalToolId(); String getExternalToolId();

View File

@ -70,7 +70,6 @@ import org.teavm.model.FieldReference;
import org.teavm.model.MethodReference; import org.teavm.model.MethodReference;
import org.teavm.model.TextLocation; import org.teavm.model.TextLocation;
import org.teavm.model.ValueType; import org.teavm.model.ValueType;
import org.teavm.tooling.ClassAlias;
import org.teavm.tooling.RuntimeCopyOperation; import org.teavm.tooling.RuntimeCopyOperation;
import org.teavm.tooling.TeaVMTool; import org.teavm.tooling.TeaVMTool;
import org.teavm.tooling.TeaVMToolException; import org.teavm.tooling.TeaVMToolException;
@ -163,12 +162,7 @@ public class TeaVMProjectBuilder extends IncrementalProjectBuilder {
for (ClassHolderTransformer transformer : instantiateTransformers(profile, classLoader)) { for (ClassHolderTransformer transformer : instantiateTransformers(profile, classLoader)) {
tool.getTransformers().add(transformer); tool.getTransformers().add(transformer);
} }
for (Map.Entry<String, String> entry : profile.getClassAliases().entrySet()) { tool.getClassesToPreserve().addAll(profile.getClassesToPreserve());
ClassAlias classAlias = new ClassAlias();
classAlias.setClassName(entry.getKey());
classAlias.setAlias(entry.getValue());
tool.getClassAliases().add(classAlias);
}
for (SourceFileProvider provider : sourceProviders) { for (SourceFileProvider provider : sourceProviders) {
tool.addSourceFileProvider(provider); tool.addSourceFileProvider(provider);
} }

View File

@ -15,8 +15,12 @@
*/ */
package org.teavm.eclipse.ui; package org.teavm.eclipse.ui;
import java.util.*; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Properties;
import java.util.Set;
import org.eclipse.core.databinding.observable.list.WritableList; import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
@ -30,14 +34,32 @@ import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.*; import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*; import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.model.WorkbenchContentProvider; import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider; import org.eclipse.ui.model.WorkbenchLabelProvider;
@ -70,10 +92,9 @@ public class TeaVMProfileDialog extends Dialog {
private Button addPropertyButton; private Button addPropertyButton;
private Button deletePropertyButton; private Button deletePropertyButton;
private WritableList propertyList = new WritableList(); private WritableList propertyList = new WritableList();
private TableViewer classAliasesTableViewer; private org.eclipse.swt.widgets.List classAliasesTableViewer;
private Button addClassAliasButton; private Button addClassAliasButton;
private Button removeClassAliasButton; private Button removeClassAliasButton;
private WritableList classAliases = new WritableList();
private org.eclipse.swt.widgets.List transformersList; private org.eclipse.swt.widgets.List transformersList;
private Button addTransformerButton; private Button addTransformerButton;
private Button removeTransformerButton; private Button removeTransformerButton;
@ -290,46 +311,8 @@ public class TeaVMProfileDialog extends Dialog {
private void createClassesGroup(Composite parent) { private void createClassesGroup(Composite parent) {
Group group = createGroup(parent, "Class aliases", 2, true); Group group = createGroup(parent, "Class aliases", 2, true);
classAliasesTableViewer = new TableViewer(group, SWT.BORDER | SWT.V_SCROLL); classAliasesTableViewer = new org.eclipse.swt.widgets.List(group, SWT.BORDER | SWT.SINGLE);
classAliasesTableViewer.getTable().setLinesVisible(true); classAliasesTableViewer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
classAliasesTableViewer.getTable().setHeaderVisible(true);
classAliasesTableViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
classAliasesTableViewer.setContentProvider(new ObservableListContentProvider());
classAliasesTableViewer.setInput(classAliases);
TableViewerColumn classNameColumn = new TableViewerColumn(classAliasesTableViewer, SWT.LEFT);
classNameColumn.getColumn().setWidth(200);
classNameColumn.getColumn().setText("Class");
classNameColumn.setLabelProvider(new ColumnLabelProvider() {
@Override public String getText(Object element) {
ClassAliasRow item = (ClassAliasRow)element;
return item.className;
}
});
TableViewerColumn valueColumn = new TableViewerColumn(classAliasesTableViewer, SWT.LEFT);
valueColumn.getColumn().setWidth(200);
valueColumn.getColumn().setText("Alias");
valueColumn.setLabelProvider(new ColumnLabelProvider() {
@Override public String getText(Object element) {
ClassAliasRow item = (ClassAliasRow)element;
return item.alias;
}
});
valueColumn.setEditingSupport(new EditingSupport(valueColumn.getViewer()) {
private TextCellEditor editor = new TextCellEditor(classAliasesTableViewer.getTable());
@Override protected Object getValue(Object element) {
ClassAliasRow item = (ClassAliasRow)element;
return item.alias;
}
@Override protected void setValue(Object element, Object value) {
ClassAliasRow item = (ClassAliasRow)element;
item.alias = (String)value;
getViewer().update(element, null);
}
@Override protected boolean canEdit(Object element) { return true; }
@Override protected CellEditor getCellEditor(Object element) { return editor; }
});
addClassAliasButton = new Button(group, SWT.PUSH); addClassAliasButton = new Button(group, SWT.PUSH);
addClassAliasButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); addClassAliasButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
@ -346,11 +329,6 @@ public class TeaVMProfileDialog extends Dialog {
}); });
} }
static class ClassAliasRow {
String className;
String alias;
}
private void createTransformersGroup(Composite parent) { private void createTransformersGroup(Composite parent) {
Group group = createGroup(parent, "TeaVM bytecode transformers", 2, true); Group group = createGroup(parent, "TeaVM bytecode transformers", 2, true);
transformersList = new org.eclipse.swt.widgets.List(group, SWT.SINGLE | SWT.BORDER); transformersList = new org.eclipse.swt.widgets.List(group, SWT.SINGLE | SWT.BORDER);
@ -603,31 +581,22 @@ public class TeaVMProfileDialog extends Dialog {
Object[] result = selectionDialog.getResult(); Object[] result = selectionDialog.getResult();
if (result.length > 0) { if (result.length > 0) {
IType type = (IType)result[0]; IType type = (IType)result[0];
for (int i = 0; i < classAliases.size(); ++i) { classAliasesTableViewer.add(type.getFullyQualifiedName());
ClassAliasRow row = (ClassAliasRow)classAliases.get(i);
if (row.className.equals(type.getFullyQualifiedName())) {
return;
}
}
ClassAliasRow row = new ClassAliasRow();
row.alias = "_";
row.className = type.getFullyQualifiedName();
classAliases.add(row);
} }
} }
} }
private void removeClass() { private void removeClass() {
Table table = classAliasesTableViewer.getTable(); if (classAliasesTableViewer.getSelectionCount() != 1) {
if (table.getSelectionCount() != 1) {
return; return;
} }
String className = classAliasesTableViewer.getItem(classAliasesTableViewer.getSelectionIndex());
boolean confirmed = MessageDialog.openConfirm(getShell(), "Removal confirmation", boolean confirmed = MessageDialog.openConfirm(getShell(), "Removal confirmation",
"Are you sure to delete the " + table.getSelection()[0].getText(0) + " class?"); "Are you sure to delete the " + className + " class?");
if (!confirmed) { if (!confirmed) {
return; return;
} }
classAliases.remove(table.getSelectionIndex()); classAliasesTableViewer.remove(classAliasesTableViewer.getSelectionIndex());
} }
@Override @Override
@ -682,11 +651,8 @@ public class TeaVMProfileDialog extends Dialog {
} }
updateCacheFieldsEnabled(); updateCacheFieldsEnabled();
transformersList.setItems(profile.getTransformers()); transformersList.setItems(profile.getTransformers());
for (Map.Entry<String, String> entry : profile.getClassAliases().entrySet()) { for (String className : profile.getClassesToPreserve()) {
ClassAliasRow row = new ClassAliasRow(); classAliasesTableViewer.add(className);
row.className = entry.getKey();
row.alias = entry.getValue();
classAliases.add(row);
} }
for (Control control : tabFolder.getTabList()) { for (Control control : tabFolder.getTabList()) {
if (control instanceof Composite) { if (control instanceof Composite) {
@ -720,12 +686,11 @@ public class TeaVMProfileDialog extends Dialog {
} }
profile.setProperties(properties); profile.setProperties(properties);
profile.setTransformers(transformersList.getItems()); profile.setTransformers(transformersList.getItems());
Map<String, String> classAliasMap = new HashMap<>(); Set<String> classesToPreserve = new HashSet<>();
for (int i = 0; i < classAliases.size(); ++i) { for (int i = 0; i < classAliasesTableViewer.getItemCount(); ++i) {
ClassAliasRow row = (ClassAliasRow)classAliases.get(i); classesToPreserve.add(classAliasesTableViewer.getItem(i));
classAliasMap.put(row.className, row.alias);
} }
profile.setClassAliases(classAliasMap); profile.setClassesToPreserve(classesToPreserve);
return true; return true;
} }
} }

View File

@ -25,8 +25,6 @@ import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.plugins.annotations.ResolutionScope;
import org.teavm.backend.wasm.render.WasmBinaryVersion; import org.teavm.backend.wasm.render.WasmBinaryVersion;
import org.teavm.tooling.ClassAlias;
import org.teavm.tooling.MethodAlias;
import org.teavm.tooling.RuntimeCopyOperation; import org.teavm.tooling.RuntimeCopyOperation;
import org.teavm.tooling.TeaVMTargetType; import org.teavm.tooling.TeaVMTargetType;
import org.teavm.tooling.TeaVMTool; import org.teavm.tooling.TeaVMTool;
@ -52,10 +50,7 @@ public class TeaVMCompileMojo extends AbstractTeaVMMojo {
private String mainClass; private String mainClass;
@Parameter @Parameter
private ClassAlias[] classAliases; private String[] classesToPreserve;
@Parameter
private MethodAlias[] methodAliases;
@Parameter @Parameter
private boolean stopOnErrors = true; private boolean stopOnErrors = true;
@ -94,11 +89,8 @@ public class TeaVMCompileMojo extends AbstractTeaVMMojo {
tool.setTargetFileName(targetFileName); tool.setTargetFileName(targetFileName);
} }
tool.setOptimizationLevel(optimizationLevel); tool.setOptimizationLevel(optimizationLevel);
if (classAliases != null) { if (classesToPreserve != null) {
tool.getClassAliases().addAll(Arrays.asList(classAliases)); tool.getClassesToPreserve().addAll(Arrays.asList(classesToPreserve));
}
if (methodAliases != null) {
tool.getMethodAliases().addAll(Arrays.asList(methodAliases));
} }
tool.setCacheDirectory(cacheDirectory); tool.setCacheDirectory(cacheDirectory);
tool.setTargetType(targetType); tool.setTargetType(targetType);