org.eclipse.sisu.wire.ElementAnalyzer Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2010-present Sonatype, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Stuart McCulloch (Sonatype, Inc.) - initial API and implementation
*******************************************************************************/
package org.eclipse.sisu.wire;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.sisu.Parameters;
import org.eclipse.sisu.inject.BeanLocator;
import org.eclipse.sisu.inject.DefaultBeanLocator;
import org.eclipse.sisu.inject.Guice4;
import org.eclipse.sisu.inject.Logs;
import org.eclipse.sisu.inject.MutableBeanLocator;
import org.eclipse.sisu.inject.RankingFunction;
import org.eclipse.sisu.inject.TypeArguments;
import org.eclipse.sisu.wire.WireModule.Strategy;
import com.google.inject.Binder;
import com.google.inject.Binding;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.PrivateBinder;
import com.google.inject.TypeLiteral;
import com.google.inject.spi.DefaultElementVisitor;
import com.google.inject.spi.Element;
import com.google.inject.spi.ElementVisitor;
import com.google.inject.spi.Elements;
import com.google.inject.spi.InjectionRequest;
import com.google.inject.spi.PrivateElements;
import com.google.inject.spi.ProviderLookup;
import com.google.inject.spi.RequireExplicitBindingsOption;
import com.google.inject.spi.StaticInjectionRequest;
/**
* {@link ElementVisitor} that analyzes {@link Binding}s for unresolved injection dependencies.
*/
final class ElementAnalyzer
extends DefaultElementVisitor
{
// ----------------------------------------------------------------------
// Static initialization
// ----------------------------------------------------------------------
static
{
final Map, Key> aliases = new HashMap, Key>();
try
{
addLegacyKeyAlias( aliases, BeanLocator.class );
addLegacyKeyAlias( aliases, MutableBeanLocator.class );
addLegacyKeyAlias( aliases, RankingFunction.class );
}
catch ( final Exception e ) // NOPMD
{
// legacy wrappers are not available
}
catch ( final LinkageError e ) // NOPMD
{
// legacy wrappers are not available
}
LEGACY_KEY_ALIASES = aliases.isEmpty() ? null : aliases;
}
// ----------------------------------------------------------------------
// Constants
// ----------------------------------------------------------------------
private static final Map, Key> LEGACY_KEY_ALIASES;
private static final List JIT_BINDINGS = Elements.getElements( new Module()
{
public void configure( final Binder binder )
{
binder.bind( BeanLocator.class ).to( MutableBeanLocator.class );
binder.bind( MutableBeanLocator.class ).to( DefaultBeanLocator.class );
binder.bind( TypeConverterCache.class );
}
} );
// ----------------------------------------------------------------------
// Implementation fields
// ----------------------------------------------------------------------
private final Set> localKeys = new HashSet>();
private final DependencyAnalyzer analyzer = new DependencyAnalyzer();
private final List privateAnalyzers = new ArrayList();
private final List