Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate MWE (almost entirely) off Guava #287

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion features/org.eclipse.emf.mwe2.launcher-feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ SPDX-License-Identifier: EPL-2.0
<import plugin="org.eclipse.xtext.common.types" version="2.34.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.xtext.xbase" version="2.34.0" match="greaterOrEqual"/>
<import plugin="com.google.inject" version="7.0.0" match="greaterOrEqual"/>
<import plugin="com.google.guava" version="33.2.1" match="greaterOrEqual"/>
<import plugin="org.eclipse.core.runtime"/>
<import plugin="org.eclipse.osgi"/>
<import plugin="org.apache.commons.cli" version="1.8.0" match="compatible"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ SPDX-License-Identifier: EPL-2.0
</url>

<requires>
<import plugin="com.google.guava" version="33.2.1" match="greaterOrEqual"/>
<import plugin="com.google.inject" version="7.0.0" match="greaterOrEqual"/>
</requires>

Expand Down
1 change: 0 additions & 1 deletion maven/org.eclipse.emf.mwe2.parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<maven-deploy-version>2.8.2</maven-deploy-version>
<maven-javadoc-version>3.4.1</maven-javadoc-version>
<commons-cli.version>1.8.0</commons-cli.version>
<guava.version>33.2.1-jre</guava.version>
<google-inject.version>7.0.0</google-inject.version>
<log4j.version>1.2.25</log4j.version>
<commons-logging.version>1.3.3</commons-logging.version>
Expand Down
4 changes: 0 additions & 4 deletions maven/org.eclipse.emf.mwe2.repository/category.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
<feature id="org.eclipse.emf.mwe.sdk" version="0.0.0">
<category name="mwe2lang"/>
</feature>
<bundle id="com.google.guava" version="33.2.1.qualifier"/>
<bundle id="com.google.guava.source" version="33.2.1.qualifier"/>
<bundle id="com.google.guava.failureaccess" version="1.0.2.qualifier"/>
<bundle id="com.google.guava.failureaccess.source" version="1.0.2.qualifier"/>
<bundle id="org.apache.commons.cli" version="1.8.0"/>
<bundle id="org.apache.commons.cli.source" version="1.8.0"/>
<bundle id="org.apache.commons.commons-logging" version="0.0.0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
<unit id="org.junit" version="0.0.0"/>
<unit id="org.apache.commons.cli" version="1.8.0"/>
<unit id="org.apache.commons.commons-logging" version="0.0.0"/>
<unit id="com.google.guava" version="33.2.1.jre"/>
<unit id="com.google.guava.failureaccess" version="1.0.2"/>
<repository location="https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/2024-09"/>
</location>
</locations>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
<unit id="org.junit" version="0.0.0"/>
<unit id="org.apache.commons.cli" version="1.8.0"/>
<unit id="org.apache.commons.commons-logging" version="0.0.0"/>
<unit id="com.google.guava" version="33.2.1.jre"/>
<unit id="com.google.guava.failureaccess" version="1.0.2"/>
<repository location="https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/2024-09"/>
</location>
</locations>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
*******************************************************************************/
package org.eclipse.emf.mwe2.language.ide.contentassist.antlr;

import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import com.google.inject.Singleton;

import java.util.HashMap;
import java.util.Map;
import org.eclipse.emf.mwe2.language.ide.contentassist.antlr.internal.InternalMwe2Parser;
import org.eclipse.emf.mwe2.language.services.Mwe2GrammarAccess;
Expand All @@ -26,16 +27,16 @@ public static final class NameMappings {

@Inject
public NameMappings(Mwe2GrammarAccess grammarAccess) {
ImmutableMap.Builder<AbstractElement, String> builder = ImmutableMap.builder();
Map<AbstractElement, String> builder = new HashMap<>();
init(builder, grammarAccess);
this.mappings = builder.build();
this.mappings = Map.copyOf(builder);
}

public String getRuleName(AbstractElement element) {
return mappings.get(element);
}
private static void init(ImmutableMap.Builder<AbstractElement, String> builder, Mwe2GrammarAccess grammarAccess) {

private static void init(Map<AbstractElement, String> builder, Mwe2GrammarAccess grammarAccess) {
builder.put(grammarAccess.getRootComponentAccess().getAlternatives_1(), "rule__RootComponent__Alternatives_1");
builder.put(grammarAccess.getComponentAccess().getAlternatives_1(), "rule__Component__Alternatives_1");
builder.put(grammarAccess.getValueAccess().getAlternatives(), "rule__Value__Alternatives");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Require-Bundle: org.eclipse.emf.mwe2.language;visibility:=reexport,
org.eclipse.jdt.ui;bundle-version="3.26.0",
org.eclipse.compare,
org.eclipse.xtext.ui.codetemplates.ui,
com.google.guava;bundle-version="[33.2.1,34.0.0)",
org.eclipse.emf.mwe2.runtime,
org.eclipse.emf.mwe2.language.ide
Import-Package: org.apache.log4j;version="1.2.24"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
*******************************************************************************/
package org.eclipse.emf.mwe2.language.ui.internal;

import com.google.common.collect.Maps;
import com.google.inject.Guice;
import com.google.inject.Injector;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import org.eclipse.emf.mwe2.language.Mwe2RuntimeModule;
Expand All @@ -34,7 +34,7 @@ public class LanguageActivator extends AbstractUIPlugin {

private static LanguageActivator INSTANCE;

private Map<String, Injector> injectors = Collections.synchronizedMap(Maps.<String, Injector> newHashMapWithExpectedSize(1));
private Map<String, Injector> injectors = Collections.synchronizedMap(new HashMap<>(1));

@Override
public void start(BundleContext context) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*******************************************************************************/
package org.eclipse.emf.mwe2.language.ui.contentassist;

import java.util.function.Function;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.mwe2.language.mwe2.Assignment;
import org.eclipse.emf.mwe2.language.mwe2.Component;
Expand All @@ -27,7 +29,6 @@
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;

import com.google.common.base.Function;
import com.google.inject.Inject;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@
import org.eclipse.xtext.parser.antlr.IAntlrTokenFileProvider;
import org.eclipse.xtext.parser.antlr.ITokenDefProvider;

import com.google.common.collect.ImmutableMap;

public class TokenDefProvider implements ITokenDefProvider, IAntlrTokenFileProvider {

private ImmutableMap<Integer, String> map;
private Map<Integer, String> map;

@Override
public Map<Integer, String> getTokenDefMap() {
if (map == null) {
AntlrTokenDefProvider provider = new AntlrTokenDefProvider();
provider.setAntlrTokenFileProvider(this);
map = ImmutableMap.copyOf(provider.getTokenDefMap());
map = Map.copyOf(provider.getTokenDefMap());
}
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultAntlrTokenToAttributeIdMapper;
import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration;

import com.google.common.collect.ImmutableSet;

public class TokenToAttributeMapper extends
DefaultAntlrTokenToAttributeIdMapper {

private final Set<String> keywords = ImmutableSet.of(
private final Set<String> keywords = Set.of(
"KEYWORD_TRUE",
"KEYWORD_FALSE",
"KEYWORD_VAR",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.util.Strings;

import com.google.common.collect.ImmutableSet;

public class Mwe2ValueConverters extends DefaultTerminalConverters {

public class FQNConverter extends AbstractNullSafeConverter<String> {
private Set<String> allKeywords = ImmutableSet.copyOf(GrammarUtil.getAllKeywords(getGrammar()));

private Set<String> allKeywords = Set.copyOf(GrammarUtil.getAllKeywords(getGrammar()));

@Override
protected String internalToValue(String string, INode node) {
return string.replaceAll("[\\^\\s]", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*******************************************************************************/
package org.eclipse.emf.mwe2.language.factory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -36,9 +39,6 @@
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.util.PolymorphicDispatcher;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.inject.Inject;

public class Mwe2ExecutionEngine {
Expand All @@ -58,11 +58,11 @@ public class Mwe2ExecutionEngine {
private IQualifiedNameConverter qualifiedNameConverter;

public Object execute(Module m) {
return create(m, Maps.<QualifiedName,Object>newHashMap());
return create(m, new HashMap<>());
}

public Object create(Module m, Map<QualifiedName, Object> params) {
return internalSwitch(m, Maps.newHashMap(params));
return internalSwitch(m, new HashMap<>(params));
}

protected Object internalSwitch(Object o, Map<QualifiedName, Object> variables) {
Expand Down Expand Up @@ -93,10 +93,9 @@ protected Object inCase(DeclaredProperty prop, Map<QualifiedName, Object> variab
}

protected Object inCase(Component comp, Map<QualifiedName, Object> variables) {
List<Assignment> assignments = Lists.newArrayList(comp.getAssignment());
List<Assignment> assignments = new ArrayList<>(comp.getAssignment());
if (comp.getModule() != null) {
Map<QualifiedName, Object> params = comp.isAutoInject() ? Maps
.newHashMap(variables) : Maps.<QualifiedName, Object> newHashMap();
Map<QualifiedName, Object> params = comp.isAutoInject() ? new HashMap<>(variables) : new HashMap<>();
for (Assignment ass : assignments) {
params.put(qualifiedNameConverter.toQualifiedName(((DeclaredProperty)ass.getFeature()).getName()),
internalSwitch(ass.getValue(), variables));
Expand Down Expand Up @@ -127,7 +126,7 @@ protected void internalApplyAssignments(Object object, JvmType type, boolean isA
List<Assignment> assignments, Map<QualifiedName, Object> variables) {
Map<QualifiedName, ISetting> settings = settingProvider.getSettings(object, type);
if (isAutoInject) {
Set<QualifiedName> explicitAssigned = Sets.newHashSet();
Set<QualifiedName> explicitAssigned = new HashSet<>();
for(Assignment assignment: assignments) {
explicitAssigned.add(qualifiedNameConverter.toQualifiedName(assignment.getFeatureName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.mwe2.language.scoping.IInjectableFeatureLookup;
Expand All @@ -21,16 +23,13 @@
import org.eclipse.xtext.common.types.util.JavaReflectAccess;
import org.eclipse.xtext.naming.QualifiedName;

import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.inject.Inject;

public class SettingProviderImpl implements ISettingProvider {

private IInjectableFeatureLookup injectableFeatureLookup;
private JavaReflectAccess reflectAccess;

@Inject
public void setReflectAccess(JavaReflectAccess reflectAccess) {
this.reflectAccess = reflectAccess;
Expand All @@ -44,8 +43,8 @@ public void setInjectableFeatureLookup(
@Override
public Map<QualifiedName,ISetting> getSettings(final Object obj, JvmType type) {
Map<QualifiedName, JvmFeature> features = injectableFeatureLookup.getInjectableFeatures(type);
Iterable<ISetting> settings = Iterables.transform(features.entrySet(), new Function<Map.Entry<QualifiedName, JvmFeature>,ISetting>(){

return features.entrySet().stream().map(new Function<Map.Entry<QualifiedName, JvmFeature>, ISetting>() {
@Override
public ISetting apply(final Map.Entry<QualifiedName, JvmFeature> from) {
if (from.getValue() instanceof JvmOperation) {
Expand All @@ -59,6 +58,7 @@ public void setValue(Object value) {
throw new WrappedException(e);
}
}

@Override
public QualifiedName getName() {
return from.getKey();
Expand All @@ -75,20 +75,16 @@ public void setValue(Object value) {
throw new WrappedException(e);
}
}

@Override
public QualifiedName getName() {
return from.getKey();
}
};
}
throw new IllegalArgumentException(from.getValue().getIdentifier() + " can not be handled.");
}});
return Maps.uniqueIndex(settings, new Function<ISetting, QualifiedName>() {
@Override
public QualifiedName apply(ISetting from) {
return from.getName();
}
});
}).collect(Collectors.toUnmodifiableMap(ISetting::getName, s -> s));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
*******************************************************************************/
package org.eclipse.emf.mwe2.language.resource;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
Expand All @@ -29,10 +33,6 @@
import org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy;
import org.eclipse.xtext.util.IAcceptor;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.ImmutableMap.Builder;

/**
* @author Jan Koehnlein - Initial contribution and API
*/
Expand All @@ -59,40 +59,39 @@ public boolean createEObjectDescriptions(EObject eObject, IAcceptor<IEObjectDesc

protected IEObjectDescription createIEObjectDescription(DeclaredProperty property) {
QualifiedName qualifiedName = getQualifiedNameProvider().getFullyQualifiedName(property);
Builder<String, String> builder = ImmutableMap.builder();
Map<String, String> userData = new HashMap<>();
String nodeModelValue = getValueFromNodeModel(property, Mwe2Package.Literals.REFERRABLE__TYPE);
if (nodeModelValue != null) {
builder.put(DECLARED_PROPERTY__TYPE, nodeModelValue);
userData.put(DECLARED_PROPERTY__TYPE, nodeModelValue);
if ((property).getDefault() == null) {
builder.put(DECLARED_PROPERTY__MANDATORY, MANDATORY_TRUE);
userData.put(DECLARED_PROPERTY__MANDATORY, MANDATORY_TRUE);
}
} else {
Value value = (property).getDefault();
if (value == null) {
builder.put(DECLARED_PROPERTY__TYPE, TYPE__STRING);
builder.put(DECLARED_PROPERTY__MANDATORY, MANDATORY_TRUE);
userData.put(DECLARED_PROPERTY__TYPE, TYPE__STRING);
userData.put(DECLARED_PROPERTY__MANDATORY, MANDATORY_TRUE);
} else if (value instanceof BooleanLiteral) {
builder.put(DECLARED_PROPERTY__TYPE, TYPE__BOOLEAN);
userData.put(DECLARED_PROPERTY__TYPE, TYPE__BOOLEAN);
} else if (value instanceof StringLiteral) {
builder.put(DECLARED_PROPERTY__TYPE, TYPE__STRING);
userData.put(DECLARED_PROPERTY__TYPE, TYPE__STRING);
} else if (value instanceof Component) {
nodeModelValue = getValueFromNodeModel(value, Mwe2Package.Literals.COMPONENT__MODULE);
if (nodeModelValue != null) {
builder.put(DECLARED_PROPERTY__TYPE, nodeModelValue);
userData.put(DECLARED_PROPERTY__TYPE, nodeModelValue);
} else {
nodeModelValue = getValueFromNodeModel(value, Mwe2Package.Literals.REFERRABLE__TYPE);
if (nodeModelValue != null)
builder.put(DECLARED_PROPERTY__TYPE, nodeModelValue);
userData.put(DECLARED_PROPERTY__TYPE, nodeModelValue);
}
} else if (value instanceof Reference) {
nodeModelValue = getValueFromNodeModel(value, Mwe2Package.Literals.ABSTRACT_REFERENCE__REFERABLE);
if (nodeModelValue != null) {
builder.put(DECLARED_PROPERTY__TYPE, nodeModelValue);
userData.put(DECLARED_PROPERTY__TYPE, nodeModelValue);
}
}
}
ImmutableMap<String, String> userData = builder.build();
return EObjectDescription.create(qualifiedName, property, userData);
return EObjectDescription.create(qualifiedName, property, Collections.unmodifiableMap(userData));
}

protected String getValueFromNodeModel(EObject object, EReference feature) {
Expand All @@ -102,7 +101,8 @@ protected String getValueFromNodeModel(EObject object, EReference feature) {
}
if (typeNodes.size() != 1)
throw new IllegalStateException("Unexpected multiple values for feature '" + feature + "' in object '" + object + "'.");
List<ILeafNode> leafNodes = Lists.newArrayList(typeNodes.get(0).getLeafNodes());
List<ILeafNode> leafNodes = new ArrayList<>();
typeNodes.get(0).getLeafNodes().forEach(leafNodes::add);
StringBuilder result = new StringBuilder();
for(ILeafNode leafNode: leafNodes) {
if(!leafNode.isHidden()) {
Expand Down
Loading