Skip to content

Commit

Permalink
Switch to Weld's ImmutableList
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting committed Oct 31, 2014
1 parent f478992 commit 580f300
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 68 deletions.
Expand Up @@ -16,7 +16,7 @@
*/
package org.jboss.weld.annotated.enhanced.jlr;

import static org.jboss.weld.util.collections.WeldCollections.immutableList;
import static org.jboss.weld.util.collections.WeldCollections.immutableListView;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -75,7 +75,7 @@ private EnhancedAnnotatedConstructorImpl(AnnotatedConstructor<T> annotatedConstr
EnhancedAnnotatedParameter<?, T> parameter = EnhancedAnnotatedParameterImpl.of(annotatedParameter, this, classTransformer);
parameters.add(parameter);
}
this.parameters = immutableList(parameters);
this.parameters = immutableListView(parameters);
this.signature = new ConstructorSignatureImpl(this);
}

Expand Down
Expand Up @@ -16,13 +16,12 @@
*/
package org.jboss.weld.annotated.enhanced.jlr;

import static org.jboss.weld.util.collections.WeldCollections.immutableList;
import static org.jboss.weld.util.collections.WeldCollections.immutableListView;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -81,7 +80,7 @@ private EnhancedAnnotatedMethodImpl(AnnotatedMethod<X> annotatedMethod, Map<Clas
EnhancedAnnotatedParameter<?, X> parameter = EnhancedAnnotatedParameterImpl.of(annotatedParameter, this, classTransformer);
parameters.add(parameter);
}
this.parameters = immutableList(parameters);
this.parameters = immutableListView(parameters);

String propertyName = Reflections.getPropertyName(getDelegate());
if (propertyName == null) {
Expand All @@ -99,7 +98,7 @@ public Method getDelegate() {
}

public List<EnhancedAnnotatedParameter<?, X>> getEnhancedParameters() {
return Collections.unmodifiableList(parameters);
return parameters;
}

public Class<?>[] getParameterTypesAsArray() {
Expand Down Expand Up @@ -135,7 +134,7 @@ public MethodSignature getSignature() {
}

public List<AnnotatedParameter<X>> getParameters() {
return Collections.unmodifiableList(Reflections.<List<AnnotatedParameter<X>>>cast(parameters));
return Reflections.<List<AnnotatedParameter<X>>>cast(parameters);
}

public boolean isGeneric() {
Expand Down
Expand Up @@ -21,10 +21,9 @@
import org.jboss.weld.logging.BeanLogger;
import org.jboss.weld.resources.ReflectionCache;
import org.jboss.weld.resources.SharedObjectCache;
import org.jboss.weld.util.collections.ImmutableList;
import org.jboss.weld.util.reflection.Formats;

import com.google.common.collect.ImmutableList;

import edu.umd.cs.findbugs.annotations.SuppressWarnings;

@SuppressWarnings(value = { "SE_BAD_FIELD", "SE_NO_SUITABLE_CONSTRUCTOR", "SE_NO_SERIALVERSIONID" }, justification = "False positive from FindBugs - serialization is handled by SerializationProxy.")
Expand Down
@@ -1,7 +1,5 @@
package org.jboss.weld.annotated.slim.unbacked;

import static org.jboss.weld.util.collections.WeldCollections.immutableList;

import java.io.ObjectInputStream;
import java.io.ObjectStreamException;
import java.io.Serializable;
Expand All @@ -19,6 +17,7 @@
import org.jboss.weld.logging.BeanLogger;
import org.jboss.weld.resources.SharedObjectCache;
import org.jboss.weld.util.AnnotatedTypes;
import org.jboss.weld.util.collections.ImmutableList;
import org.jboss.weld.util.reflection.Formats;

import edu.umd.cs.findbugs.annotations.SuppressWarnings;
Expand All @@ -43,7 +42,7 @@ public UnbackedAnnotatedConstructor(Type baseType, Set<Type> typeClosure, Set<An
parameters.add(new UnbackedAnnotatedParameter<X>(originalParameter.getBaseType(), originalParameter.getTypeClosure(), cache.getSharedSet(originalParameter.getAnnotations()),
originalParameter.getPosition(), this));
}
this.parameters = immutableList(parameters);
this.parameters = ImmutableList.copyOf(parameters);
}

public Constructor<X> getJavaMember() {
Expand Down
@@ -1,6 +1,5 @@
package org.jboss.weld.annotated.slim.unbacked;

import static org.jboss.weld.util.collections.WeldCollections.immutableList;
import static org.jboss.weld.util.reflection.Reflections.cast;

import java.io.ObjectInputStream;
Expand All @@ -20,6 +19,7 @@
import org.jboss.weld.logging.BeanLogger;
import org.jboss.weld.resources.SharedObjectCache;
import org.jboss.weld.util.AnnotatedTypes;
import org.jboss.weld.util.collections.ImmutableList;
import org.jboss.weld.util.reflection.Formats;

import edu.umd.cs.findbugs.annotations.SuppressWarnings;
Expand All @@ -45,7 +45,7 @@ public UnbackedAnnotatedMethod(Type baseType, Set<Type> typeClosure, Set<Annotat
parameters.add(new UnbackedAnnotatedParameter<X>(originalParameter.getBaseType(), originalParameter.getTypeClosure(), cache.getSharedSet(originalParameter.getAnnotations()),
originalParameter.getPosition(), this));
}
this.parameters = immutableList(parameters);
this.parameters = ImmutableList.copyOf(parameters);
}

public Method getJavaMember() {
Expand Down
Expand Up @@ -40,12 +40,12 @@
import org.jboss.weld.resources.spi.ResourceLoader;
import org.jboss.weld.resources.spi.ResourceLoadingException;
import org.jboss.weld.util.Preconditions;
import org.jboss.weld.util.collections.ImmutableList;
import org.jboss.weld.util.collections.ImmutableSet;
import org.jboss.weld.util.collections.ListView;
import org.jboss.weld.util.collections.ViewProvider;

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

/**
Expand Down
Expand Up @@ -20,7 +20,6 @@
import static org.jboss.weld.util.Observers.validateObserverMethod;

import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;

import javax.enterprise.inject.spi.AnnotatedMethod;
Expand All @@ -31,6 +30,7 @@
import org.jboss.weld.experimental.ExperimentalProcessObserverMethod;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.Preconditions;
import org.jboss.weld.util.collections.WeldCollections;

/**
* Implementation of the event used to notify observers for each observer
Expand Down Expand Up @@ -75,7 +75,7 @@ public ExperimentalObserverMethod<T> getObserverMethod() {
}

public List<Throwable> getDefinitionErrors() {
return Collections.unmodifiableList(getErrors());
return WeldCollections.immutableListView(getErrors());
}

@Override
Expand Down
Expand Up @@ -32,6 +32,7 @@
import org.jboss.weld.construction.api.AroundConstructCallback;
import org.jboss.weld.context.api.ContextualInstance;
import org.jboss.weld.injection.spi.ResourceReference;
import org.jboss.weld.util.collections.WeldCollections;
import org.jboss.weld.util.reflection.Reflections;

import edu.umd.cs.findbugs.annotations.SuppressWarnings;
Expand Down Expand Up @@ -150,7 +151,7 @@ public CreationalContextImpl<?> getParentCreationalContext() {
* Returns an unmodifiable list of dependent instances.
*/
public List<ContextualInstance<?>> getDependentInstances() {
return Collections.unmodifiableList(dependentInstances);
return WeldCollections.immutableListView(dependentInstances);
}

// Serialization
Expand Down
Expand Up @@ -16,9 +16,6 @@
*/
package org.jboss.weld.injection;

import static org.jboss.weld.util.collections.WeldCollections.immutableGuavaList;
import static org.jboss.weld.util.collections.WeldCollections.immutableList;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -46,6 +43,7 @@
import org.jboss.weld.logging.UtilLogger;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.Beans;
import org.jboss.weld.util.collections.ImmutableList;
import org.jboss.weld.util.collections.ImmutableSet;

/**
Expand Down Expand Up @@ -210,7 +208,7 @@ public <T, X> MethodInjectionPoint<T, X> createMethodInjectionPoint(EnhancedAnno
injectableFieldsList.add(0, fields.build());
}
}
return immutableGuavaList(injectableFieldsList);
return ImmutableList.copyOf(injectableFieldsList);
}

private void addFieldInjectionPoint(EnhancedAnnotatedField<?, ?> annotatedField,
Expand Down Expand Up @@ -248,7 +246,7 @@ public <X> List<ParameterInjectionPoint<?, X>> getParameterInjectionPoints(Enhan
parameters.add(createParameterInjectionPoint(parameter, bean, declaringComponentClass, manager));
}
}
return immutableList(parameters);
return ImmutableList.copyOf(parameters);
}

private boolean isSpecialParameter(EnhancedAnnotatedParameter<?, ?> parameter) {
Expand Down
Expand Up @@ -19,7 +19,6 @@
import java.lang.reflect.Method;
import java.security.AccessController;
import java.util.List;
import java.util.stream.Collectors;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
Expand All @@ -30,8 +29,7 @@
import org.jboss.weld.logging.BeanLogger;
import org.jboss.weld.security.GetAccessibleCopyOfMember;
import org.jboss.weld.util.BeanMethods;

import com.google.common.collect.ImmutableList;
import org.jboss.weld.util.collections.ImmutableList;

/**
* If the component is not intercepted this implementation takes care of invoking its lifecycle callback methods. If the
Expand All @@ -56,8 +54,7 @@ public DefaultLifecycleCallbackInvoker(EnhancedAnnotatedType<T> type) {
}

private List<Method> initMethodList(List<? extends AnnotatedMethod<?>> methods) {
return ImmutableList.copyOf(methods.stream()
.map((method) -> AccessController.doPrivileged(new GetAccessibleCopyOfMember<Method>(method.getJavaMember()))).collect(Collectors.toList()));
return methods.stream().map((method) -> AccessController.doPrivileged(new GetAccessibleCopyOfMember<Method>(method.getJavaMember()))).collect(ImmutableList.collector());
}

@Override
Expand Down
Expand Up @@ -16,8 +16,6 @@
*/
package org.jboss.weld.injection.producer;

import static org.jboss.weld.util.collections.WeldCollections.immutableGuavaList;

import java.util.List;
import java.util.Set;

Expand All @@ -32,6 +30,7 @@
import org.jboss.weld.injection.ResourceInjectionFactory;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.Beans;
import org.jboss.weld.util.collections.ImmutableList;

/**
* {@link Injector} that adds support for resource field and setter injection.
Expand All @@ -56,7 +55,7 @@ public static <T> ResourceInjector<T> of(EnhancedAnnotatedType<T> type, Bean<T>

protected ResourceInjector(EnhancedAnnotatedType<T> type, Bean<T> bean, BeanManagerImpl beanManager) {
super(type, bean, beanManager);
this.resourceInjectionsHierarchy = immutableGuavaList(ResourceInjectionFactory.instance().getResourceInjections(bean, type,
this.resourceInjectionsHierarchy = ImmutableList.copyOf(ResourceInjectionFactory.instance().getResourceInjections(bean, type,
beanManager));
}

Expand Down
Expand Up @@ -25,8 +25,7 @@
import org.jboss.weld.interceptor.proxy.InterceptorInvocation;
import org.jboss.weld.interceptor.proxy.InterceptorMethodInvocation;
import org.jboss.weld.interceptor.spi.model.InterceptionType;

import com.google.common.collect.ImmutableList;
import org.jboss.weld.util.collections.ImmutableList;

/**
* @author Marius Bogoevici
Expand Down
Expand Up @@ -607,19 +607,19 @@ public Map<EjbDescriptor<?>, SessionBean<?>> getEnterpriseBeans() {
* @return The list of known beans
*/
public List<Bean<?>> getBeans() {
return Collections.unmodifiableList(enabledBeans);
return WeldCollections.immutableListView(enabledBeans);
}

List<Bean<?>> getSharedBeans() {
return Collections.unmodifiableList(sharedBeans);
return WeldCollections.immutableListView(sharedBeans);
}

public List<Decorator<?>> getDecorators() {
return Collections.unmodifiableList(decorators);
return WeldCollections.immutableListView(decorators);
}

public List<Interceptor<?>> getInterceptors() {
return Collections.unmodifiableList(interceptors);
return WeldCollections.immutableListView(interceptors);
}

public Iterable<Bean<?>> getAccessibleBeans() {
Expand Down
Expand Up @@ -26,6 +26,7 @@

import org.jboss.weld.util.cache.ComputingCache;
import org.jboss.weld.util.cache.ComputingCacheBuilder;
import org.jboss.weld.util.collections.ImmutableList;
import org.jboss.weld.util.collections.WeldCollections;

/**
Expand Down Expand Up @@ -131,7 +132,7 @@ protected Iterable<? extends T> getAllBeans() {

protected C makeResultImmutable(C result) {
if (result instanceof List<?>) {
return cast(WeldCollections.immutableList((List<?>) result));
return cast(ImmutableList.copyOf(((List<?>) result)));
}
if (result instanceof Set<?>) {
return cast(WeldCollections.immutableSetView((Set<?>) result));
Expand Down
8 changes: 3 additions & 5 deletions impl/src/main/java/org/jboss/weld/util/BeanMethods.java
Expand Up @@ -48,10 +48,8 @@
import org.jboss.weld.logging.UtilLogger;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.security.SetAccessibleAction;
import org.jboss.weld.util.collections.ImmutableList;
import org.jboss.weld.util.collections.ImmutableSet;
import org.jboss.weld.util.collections.WeldCollections;

import com.google.common.collect.ImmutableList;

public class BeanMethods {

Expand Down Expand Up @@ -171,7 +169,7 @@ public void levelFinish() {
@Override
public List<AnnotatedMethod<? super T>> create() {
Collections.reverse(result);
return WeldCollections.immutableList(result);
return ImmutableList.copyOf(result);
}

/**
Expand Down Expand Up @@ -243,7 +241,7 @@ public void levelFinish() {
@Override
public List<Set<MethodInjectionPoint<?, ?>>> create() {
Collections.reverse(result); // because we want methods that are lower in the hierarchy to be called first
return WeldCollections.immutableGuavaList(result);
return ImmutableList.copyOf(result);
}
}

Expand Down
2 changes: 0 additions & 2 deletions impl/src/main/java/org/jboss/weld/util/collections/Sets.java
Expand Up @@ -24,8 +24,6 @@
import java.util.Iterator;
import java.util.Set;

import com.google.common.collect.ImmutableList;

/**
* Static utility methods for {@link Set}.
*
Expand Down

0 comments on commit 580f300

Please sign in to comment.