Skip to content

Commit

Permalink
Use JDK classes instead of Guava to create immutable collections
Browse files Browse the repository at this point in the history
Java itself is powerful enough to express immutability. There is no need
to keep using Guava for this. This change removes all usages of
ImmutableList, ImmutableSet and ImmutableMap and replaces them with
List, Set, Map and the Collections utility class.

Example:
ImmutableList.copyOf(...) -> List.copyOf(...)
ImmutableMap.of(...) -> Map.of(...)
ImmutableSet.of() -> Collections.emptySet()
  • Loading branch information
ptziegler committed Nov 1, 2023
1 parent 224e770 commit 2e1fc17
Show file tree
Hide file tree
Showing 150 changed files with 477 additions and 642 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.wb.core.editor.palette.model.entry;

import com.google.common.collect.ImmutableMap;

import org.eclipse.wb.core.editor.palette.model.CategoryInfo;
import org.eclipse.wb.core.editor.palette.model.EntryInfo;
import org.eclipse.wb.core.editor.palette.model.IPaletteSite;
Expand Down Expand Up @@ -55,6 +53,7 @@

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -450,7 +449,7 @@ public Object getNewObject() {
private Map<String, String> getTypeArguments() throws JavaModelException {
Map<String, TypeParameterDescription> typeParameters = m_creation.getTypeParameters();
if (typeParameters.isEmpty()) {
return ImmutableMap.of();
return Collections.emptyMap();
}
// open dialog
TypeParametersDialog dialog =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.wb.core.eval;

import com.google.common.collect.ImmutableList;

import static org.eclipse.wb.internal.core.utils.ast.AstNodeUtils.getBinding;
import static org.eclipse.wb.internal.core.utils.ast.AstNodeUtils.getConstructor;
import static org.eclipse.wb.internal.core.utils.ast.AstNodeUtils.getCreationBinding;
Expand Down Expand Up @@ -83,6 +81,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
Expand Down Expand Up @@ -638,7 +637,7 @@ private static <T> List<T> getVariableCachedList_notNull(ExecutionFlowDescriptio
String key) {
List<T> result = (List<T>) getVariableCachedValue(flowDescription, variable, key);
if (result == null) {
return ImmutableList.of();
return Collections.emptyList();
} else {
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.wb.internal.core.editor;

import com.google.common.collect.ImmutableList;

import org.eclipse.wb.core.controls.PageBook;
import org.eclipse.wb.core.editor.DesignerEditorListener;
import org.eclipse.wb.core.editor.DesignerState;
Expand Down Expand Up @@ -410,7 +408,7 @@ public void refreshGEF() {
// notify listeners
{
List<DesignerEditorListener> designPageListeners =
ImmutableList.copyOf(m_designerEditor.getDesignPageListeners());
List.copyOf(m_designerEditor.getDesignPageListeners());
for (DesignerEditorListener listener : designPageListeners) {
listener.reparsed();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*******************************************************************************/
package org.eclipse.wb.internal.core.editor.palette;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import org.eclipse.wb.core.controls.palette.ICategory;
Expand Down Expand Up @@ -70,6 +69,7 @@
import org.eclipse.swt.widgets.Shell;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -192,7 +192,7 @@ private void reloadPalette() {
* Adds given {@link Command} to the list and writes commands.
*/
private void commands_addWrite(Command command) {
commands_addWrite(ImmutableList.of(command));
commands_addWrite(List.of(command));
}

/**
Expand Down Expand Up @@ -405,7 +405,7 @@ private void showPalette() {
public List<ICategory> getCategories() {
// check for skipping palette during tests
if (System.getProperty(FLAG_NO_PALETTE) != null) {
return ImmutableList.of();
return Collections.emptyList();
}
// get categories for palette model
final List<CategoryInfo> categoryInfoList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.wb.internal.core.model;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import org.eclipse.wb.core.editor.IDesignPageSite;
Expand Down Expand Up @@ -1002,7 +1001,8 @@ private static List<HierarchyProvider> getHierarchyProviders() {
* Binds any not bound yet components to the given root {@link JavaInfo} or any of its children.
*/
public static void bindBinaryComponents(List<JavaInfo> components) throws Exception {
List<JavaInfo> reverseComponents = ImmutableList.copyOf(components).reverse();
List<JavaInfo> reverseComponents = new ArrayList<>(components);
Collections.reverse(reverseComponents);
// prepare map (object -> JavaInfo)
final Map<Object, JavaInfo> objectToModel;
{
Expand Down Expand Up @@ -2041,7 +2041,7 @@ public static JavaInfo getWrapped(JavaInfo original) throws Exception {
*/
public static void deleteJavaInfo(JavaInfo javaInfo, boolean removeFromParent) throws Exception {
// delete children
List<ObjectInfo> children = ImmutableList.copyOf(javaInfo.getChildren());
List<ObjectInfo> children = List.copyOf(javaInfo.getChildren());
for (ObjectInfo child : children) {
// There are cases when children of some parent are "linked", so one deletes other on delete.
// So, we should check, may be child is already deleted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import org.eclipse.wb.core.eval.AstEvaluationEngine;
import org.eclipse.wb.core.eval.EvaluationContext;
Expand Down Expand Up @@ -461,7 +459,7 @@ class ExcludedPackage {
ExcludedPackage excludedPackage = new ExcludedPackage();
String exceptionMethodsString = entry.getValue();
String[] exceptionMethodsSignatures = StringUtils.split(exceptionMethodsString);
excludedPackage.exceptions = ImmutableSet.copyOf(exceptionMethodsSignatures);
excludedPackage.exceptions = Set.of(exceptionMethodsSignatures);
excludedPackages.put(packageName, excludedPackage);
}
}
Expand Down Expand Up @@ -599,7 +597,7 @@ private Object visitMethod0(Object obj,
m_editorState.getTmp_visitingContext(),
flowDescription,
visitor,
ImmutableList.of(methodDeclaration));
List.of(methodDeclaration));
// during execution we remember "return value", so return it here to binary
return JavaInfoEvaluationHelper.getReturnValue(methodDeclaration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.wb.internal.core.model.description;

import com.google.common.collect.ImmutableMap;

import org.eclipse.wb.internal.core.utils.StringUtilities;
import org.eclipse.wb.internal.core.utils.jdt.core.CodeUtils;
import org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils;
Expand Down Expand Up @@ -217,7 +215,7 @@ public String getTitle() {
public Map<String, TypeParameterDescription> getTypeParameters() {
return m_typeArguments != null
? m_typeArguments
: ImmutableMap.<String, TypeParameterDescription>of();
: Collections.emptyMap();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.wb.internal.core.model.description.helpers;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import org.eclipse.wb.internal.core.model.description.AbstractInvocationDescription;
Expand Down Expand Up @@ -104,6 +103,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

Expand Down Expand Up @@ -278,7 +278,7 @@ private static ComponentDescription getDescription0(AstEditor editor, Class<?> c
}
// OK, get description
ComponentDescriptionKey key = new ComponentDescriptionKey(componentClass);
return getDescription0(editor, key, ImmutableList.<ClassResourceInfo>of());
return getDescription0(editor, key, Collections.emptyList());
}

/**
Expand Down Expand Up @@ -317,7 +317,7 @@ private static ComponentDescription getKeySpecificDescription(AstEditor editor,
}
// OK, get key-specific description
ClassResourceInfo descriptionInfo = new ClassResourceInfo(componentClass, resourceInfo);
return getDescription0(editor, key, ImmutableList.of(descriptionInfo));
return getDescription0(editor, key, List.of(descriptionInfo));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
*******************************************************************************/
package org.eclipse.wb.internal.core.model.description.resource;

import com.google.common.collect.ImmutableList;

import org.eclipse.jdt.core.IJavaProject;

import java.util.Collections;
import java.util.List;

/**
Expand Down Expand Up @@ -42,6 +41,6 @@ private EmptyDescriptionVersionsProvider() {
////////////////////////////////////////////////////////////////////////////
@Override
public List<String> getVersions(Class<?> componentClass) throws Exception {
return ImmutableList.of();
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
*******************************************************************************/
package org.eclipse.wb.internal.core.model.description.resource;

import com.google.common.collect.ImmutableList;

import org.eclipse.wb.internal.core.utils.check.Assert;

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

/**
Expand Down Expand Up @@ -57,7 +56,7 @@ public List<String> getVersions(Class<?> componentClass) throws Exception {
if (validate(componentClass)) {
return m_versions;
}
return ImmutableList.of();
return Collections.emptyList();
}

protected abstract boolean validate(Class<?> componentClass) throws Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.wb.internal.core.model.generation.statement.block;

import com.google.common.collect.ImmutableList;

import org.eclipse.wb.core.model.JavaInfo;
import org.eclipse.wb.core.model.association.Association;
import org.eclipse.wb.internal.core.model.generation.statement.AbstractInsideStatementGenerator;
Expand All @@ -21,6 +19,8 @@
import org.eclipse.jdt.core.dom.Block;
import org.eclipse.jdt.core.dom.Statement;

import java.util.List;

/**
* Implementation of {@link StatementGenerator} that adds {@link Statement}'s in new {@link Block}
* inside of target {@link Block}.
Expand All @@ -47,7 +47,7 @@ private BlockStatementGenerator() {
@Override
public void add(JavaInfo child, StatementTarget target, Association association) throws Exception {
// prepare block
Block block = (Block) child.getEditor().addStatement(ImmutableList.of("{", "}"), target);
Block block = (Block) child.getEditor().addStatement(List.of("{", "}"), target);
// add statements in block
target = new StatementTarget(block, true);
add(child, target, null, association);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.wb.internal.core.model.property.accessor;

import com.google.common.collect.ImmutableList;

import org.eclipse.wb.core.model.JavaInfo;
import org.eclipse.wb.internal.core.model.property.table.PropertyTooltipProvider;
import org.eclipse.wb.internal.core.utils.ast.AstEditor;
Expand All @@ -23,6 +21,7 @@
import org.eclipse.jdt.core.dom.MethodInvocation;

import java.lang.reflect.Method;
import java.util.List;

/**
* The implementation of {@link ExpressionAccessor} for accessing {@link MethodInvocation} of some
Expand Down Expand Up @@ -77,7 +76,7 @@ public void run() throws Exception {
ExecutionUtils.run(javaInfo, new RunnableEx() {
@Override
public void run() throws Exception {
editor.replaceInvocationArguments(invocation, ImmutableList.of(source));
editor.replaceInvocationArguments(invocation, List.of(source));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
*******************************************************************************/
package org.eclipse.wb.internal.core.model.property.editor;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import org.eclipse.wb.core.editor.IDesignPageSite;
import org.eclipse.wb.core.model.JavaInfo;
import org.eclipse.wb.internal.core.DesignerPlugin;
Expand Down Expand Up @@ -45,6 +42,7 @@
import org.apache.commons.lang.StringUtils;

import java.lang.reflect.Constructor;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -197,7 +195,7 @@ private void openClass(Property property) throws Exception {
*/
private void newClass_ANONYMOUS(GenericProperty genericProperty) throws Exception {
JavaInfo javaInfo = genericProperty.getJavaInfo();
String source = TemplateUtils.evaluate(m_source, javaInfo, ImmutableMap.<String, String>of());
String source = TemplateUtils.evaluate(m_source, javaInfo, Collections.emptyMap());
genericProperty.setExpression(source, Property.UNKNOWN_VALUE);
}

Expand All @@ -213,8 +211,8 @@ private void newClass_INNER(GenericProperty genericProperty) throws Exception {
{
newName = editor.getUniqueTypeName(m_baseName);
String newSource =
TemplateUtils.evaluate(m_source, javaInfo, ImmutableMap.of("name", newName));
newLines = ImmutableList.copyOf(StringUtils.split(newSource, "\r\n"));
TemplateUtils.evaluate(m_source, javaInfo, Map.of("name", newName));
newLines = List.of(StringUtils.split(newSource, "\r\n"));
}
// add type
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
package org.eclipse.wb.internal.core.model.property.editor;

import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;

import org.eclipse.wb.core.model.JavaInfo;
import org.eclipse.wb.core.model.ObjectInfo;
Expand Down Expand Up @@ -202,7 +201,7 @@ private void setComponent0(GenericProperty property, JavaInfo component) throws
property.setExpression(TemplateUtils.getExpression(component), component);
return;
}
List<JavaInfo> allComponents = ImmutableList.of(thisComponent, component);
List<JavaInfo> allComponents = List.of(thisComponent, component);
target = JavaInfoUtils.getStatementTarget_whenAllCreated(allComponents);
}
String source =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.wb.internal.core.model.property.editor.complex;

import com.google.common.collect.ImmutableMap;

import org.eclipse.wb.core.editor.IDesignPageSite;
import org.eclipse.wb.core.model.JavaInfo;
import org.eclipse.wb.core.model.association.InvocationChildAssociation;
Expand Down Expand Up @@ -56,6 +54,7 @@

import org.apache.commons.lang.StringUtils;

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

Expand Down Expand Up @@ -276,7 +275,7 @@ public void run() throws Exception {
}
// evaluate new expression
String evaluateSource =
TemplateUtils.evaluate(source, javaInfo, ImmutableMap.<String, String>of());
TemplateUtils.evaluate(source, javaInfo, Collections.emptyMap());
property.setExpression(evaluateSource, Property.UNKNOWN_VALUE);
// create new instance info
{
Expand Down
Loading

0 comments on commit 2e1fc17

Please sign in to comment.